using System.Collections.Generic; namespace XGame.Framework.i18n { public static class LanguageUtils { private static Dictionary _langFlagNameMap = new Dictionary() { {"ar",LanguageType.AR }, {"en",LanguageType.EN }, {"zh-cn",LanguageType.ZH_CN }, {"zh-hk",LanguageType.ZH_HK }, {"zh-sg",LanguageType.ZH_SG }, }; public static string ToName(this LanguageType flag) { switch(flag) { case LanguageType.ZH_CN: return "zh-cn"; case LanguageType.ZH_HK: return "zh-hk"; case LanguageType.ZH_SG: return "zh-sg"; default: return flag.ToString().ToLower(); } } public static LanguageType ToLanguageType(string languageName) { if (_langFlagNameMap.TryGetValue(languageName, out var langFlag)) { return langFlag; } Log.Error($"多语言类型转换错误. Name:{languageName}"); return LanguageType.NONE; } public static bool IsLanguage(string languageName) { return _langFlagNameMap.ContainsKey(languageName); } } }