rj-action-library/Runtime/Localization/LocaleText.cs

51 lines
1.0 KiB
C#
Raw Normal View History

2025-01-26 09:15:28 +00:00
using Godot;
using System.Collections;
using System.Collections.Generic;
using Godot.Collections;
namespace Rokojori
{
[Tool]
[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]
public LocaleTextEntry[] entries = new LocaleTextEntry[ 0 ];
2025-01-26 09:15:28 +00:00
[ExportGroup("Context")]
[Export(PropertyHint.MultilineText)]
public string context;
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 )
{
if ( localeCode == LocaleCode.en || entries == null )
2025-01-26 09:15:28 +00:00
{
return en;
}
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;
}
}
}