2025-01-26 09:15:28 +00:00
|
|
|
using Godot;
|
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using Godot.Collections;
|
|
|
|
|
|
|
|
namespace Rokojori
|
|
|
|
{
|
|
|
|
[Tool]
|
2025-02-12 16:48:15 +00:00
|
|
|
[GlobalClass,Icon("res://addons/rokojori_action_library/Icons/LocalizedString.svg")]
|
2025-01-26 09:15:28 +00:00
|
|
|
public partial class LocaleText:LocalizedString
|
|
|
|
{
|
|
|
|
[Export(PropertyHint.MultilineText)]
|
|
|
|
public string en;
|
|
|
|
|
|
|
|
[ExportGroup("Translations")]
|
|
|
|
[Export]
|
2025-02-12 16:48:15 +00:00
|
|
|
public LocaleTextEntry[] entries = new LocaleTextEntry[ 0 ];
|
2025-01-26 09:15:28 +00:00
|
|
|
|
|
|
|
[ExportGroup("Context")]
|
|
|
|
[Export(PropertyHint.MultilineText)]
|
|
|
|
public string context;
|
|
|
|
|
2025-02-12 16:48:15 +00:00
|
|
|
public static LocaleText Create( string en )
|
|
|
|
{
|
|
|
|
var lt = new LocaleText();
|
|
|
|
lt.en = en;
|
|
|
|
|
|
|
|
return lt;
|
|
|
|
}
|
2025-01-26 09:15:28 +00:00
|
|
|
|
|
|
|
public override string GetLocalizedString( LocaleCode localeCode )
|
|
|
|
{
|
2025-02-12 16:48:15 +00:00
|
|
|
if ( localeCode == LocaleCode.en || entries == null )
|
2025-01-26 09:15:28 +00:00
|
|
|
{
|
|
|
|
return en;
|
|
|
|
}
|
|
|
|
|
2025-02-12 16:48:15 +00:00
|
|
|
|
2025-01-26 09:15:28 +00:00
|
|
|
var entry = Arrays.Find( entries, e => e.code == localeCode );
|
|
|
|
|
|
|
|
if ( entry != null )
|
|
|
|
{
|
|
|
|
return entry.content;
|
|
|
|
}
|
|
|
|
|
|
|
|
return en;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|