public static void RegisterI18NEntity(this I18NComponent self, Entity entity) { if (!self.I18NEntity.ContainsKey(entity.Id)) { self.I18NEntity.Add(entity.Id, entity); } }
/// <summary> /// 切换语言,外部接口 /// </summary> /// <param name="langType"></param> public static void SwitchLanguage(this I18NComponent self, int langType) { //修改当前语言 PlayerPrefs.SetInt(CacheKeys.CurLangType, langType); self.curLangType = langType; var res = I18NConfigCategory.Instance.GetAll(); self.i18nTextKeyDic.Clear(); foreach (var item in res) { switch (self.curLangType) { case I18NComponent.LangType.Chinese: self.i18nTextKeyDic.Add(item.Value.Key, item.Value.Chinese); break; case I18NComponent.LangType.English: self.i18nTextKeyDic.Add(item.Value.Key, item.Value.English); break; default: self.i18nTextKeyDic.Add(item.Value.Key, item.Value.Chinese); break; } } var values = self.I18NEntity.Values; foreach (var entity in values) { UIEventSystem.Instance.OnLanguageChange(entity); } I18NBridge.Instance.OnLanguageChange(); }
public static string I18NGetText(this I18NComponent self, string key) { if (!self.i18nTextKeyDic.TryGetValue(key, out var value)) { return(key); } return(value); }
/// <summary> /// 取不到返回key /// </summary> /// <param name="self"></param> /// <param name="key"></param> /// <returns></returns> public static bool I18NTryGetText(this I18NComponent self, string key, out string result) { if (!self.i18nTextKeyDic.TryGetValue(key, out result)) { result = key; return(false); } return(true); }
/// <summary> /// 根据key取多语言取不到返回key /// </summary> /// <param name="self"></param> /// <param name="key"></param> /// <param name="paras"></param> /// <returns></returns> public static string I18NGetParamText(this I18NComponent self, string key, params object[] paras) { if (!self.i18nTextKeyDic.TryGetValue(key, out var value)) { return(key); } if (paras != null) { return(string.Format(value, paras)); } else { return(value); } }
public static void RemoveI18NEntity(this I18NComponent self, Entity entity) { self.I18NEntity.Remove(entity.Id); }