using Godot; using Models; namespace Core; /// /// i18n 服务抽象 /// 设计说明: /// 1) Model 只持有 LocalizedText(Key/Fallback),具体翻译交给服务层。 /// 2) 便于后续替换为自定义多语言系统或 Mod 词库。 /// 注意事项: /// - TranslationServer 的翻译表应通过 Godot Editor 管理。 /// 未来扩展: /// - 可加入“参数化翻译”和“运行时语言切换事件”。 /// public interface ILocalizationService { /// /// 翻译本地化文本对象 /// /// 文本对象 /// 翻译后的字符串 string Translate(LocalizedText text); /// /// 翻译键值 /// /// 键值 /// 默认值 /// 翻译后的字符串 string Translate(string key, string fallback = null); } /// /// Godot 本地化服务实现 /// public sealed class GodotLocalizationService : ILocalizationService { /// /// 翻译本地化文本对象 /// /// 文本对象 /// 翻译后的字符串 public string Translate(LocalizedText text) { if (text == null) return string.Empty; return Translate(text.Key, text.Fallback); } /// /// 翻译键值 /// /// 键值 /// 默认值 /// 翻译后的字符串 public string Translate(string key, string fallback = null) { if (string.IsNullOrWhiteSpace(key)) return fallback ?? string.Empty; var translated = TranslationServer.Translate(key); if (translated == key && !string.IsNullOrWhiteSpace(fallback)) return fallback; return translated; } }