/// <summary> /// 获取已加载的全部语言的翻译内容 /// </summary> /// <param name="isUseAlias">是否获取别名索引中的翻译内容(这里请先设置false)</param> /// <returns></returns> public List <LanguageShowData> GetLanguageShowDatas(bool isUseAlias) { List <LanguageShowData> languageShowDataList = new List <LanguageShowData>(); foreach (var item in _managerLanguageListIndex) { if (!isUseAlias) { if (item.Value.IndexType == "AliasName") { continue; } } var TranslateList = GetTranslateList(item.Key); var CultureCodeCountry = new CultureCodeCountry(item.Key, item.Value.SingleLanguage.Culture); bool IsDefault; if (item.Value.SingleLanguage.CultureName == DefaultLanguage) { IsDefault = true; } else { IsDefault = false; } LanguageShowData languageShowData = new LanguageShowData(TranslateList, CultureCodeCountry, IsDefault); languageShowDataList.Add(languageShowData); } return(languageShowDataList); }
/// <summary> /// 添加一门语言 /// </summary> /// <param name="singleLanguage"></param> /// <returns></returns> public bool AddSingleLanguage(SingleLanguage singleLanguage) { var result = false; if (_managerLanguageCountryList.ContainsKey(singleLanguage.CultureName)) { return(false); } _managerLanguageList.Add(singleLanguage); var TempindexList = singleLanguage.GetAllIndexName(); for (int i = 0; i < TempindexList.Count; i++) { // 加载语言索引 // 异常处理,当索引字典中已经包含对应字段时 if (_managerLanguageListIndex.ContainsKey(TempindexList[i].Index)) { ////当该索引对象的类型为CultureName(标准索引),则替换之前的字典值 //if (TempindexList[i].IndexType == "CultureName") //{ // _managerLanguageListIndex[TempindexList[i].Index] = TempindexList[i]; //} ////该索引为别名索引,则直接跳过,不予加载入字典表 //else if (TempindexList[i].IndexType == "AliasName") //{ //} ////默认处理 //else //{ // continue; //} return(false); } else { //将索引加入字典表 _managerLanguageListIndex[TempindexList[i].Index] = TempindexList[i]; } // 加载语言国别 if (_managerLanguageCountryList.ContainsKey(TempindexList[i].Index)) { continue; } else { string index = TempindexList[i].Index; string country = TempindexList[i].SingleLanguage.Culture; string cultureCode = TempindexList[i].SingleLanguage.CultureName; CultureCodeCountry cultureCodeCountry = new CultureCodeCountry(cultureCode, country); _managerLanguageCountryList.Add(index, cultureCodeCountry); } } return(true); }
/// <summary> /// 通过语言索引类初始化字典 /// </summary> private void InitManagerLanguageListIndex() { _managerLanguageListIndex = new Dictionary <string, LannguageIndex>(); _managerLanguageCountryList = new Dictionary <string, CultureCodeCountry>(); foreach (var item in _managerLanguageList) { //获取每种语言对应的全部索引 var TempindexList = item.GetAllIndexName(); for (int i = 0; i < TempindexList.Count; i++) { // 加载语言索引 // 异常处理,当索引字典中已经包含对应字段时 if (_managerLanguageListIndex.ContainsKey(TempindexList[i].Index)) { ////当该索引对象的类型为CultureName(标准索引),则替换之前的字典值 //if (TempindexList[i].IndexType == "CultureName") //{ // _managerLanguageListIndex[TempindexList[i].Index] = TempindexList[i]; //} ////该索引为别名索引,则直接跳过,不予加载入字典表 //else if (TempindexList[i].IndexType == "AliasName") //{ //} ////默认处理 //else //{ // continue; //} throw new Exception("语言名和别名中有重复项。"); } else { //将索引加入字典表 _managerLanguageListIndex[TempindexList[i].Index] = TempindexList[i]; } // 加载语言国别 if (_managerLanguageCountryList.ContainsKey(TempindexList[i].Index)) { continue; } else { string index = TempindexList[i].Index; string country = TempindexList[i].SingleLanguage.Culture; string cultureCode = TempindexList[i].SingleLanguage.CultureName; CultureCodeCountry cultureCodeCountry = new CultureCodeCountry(cultureCode, country); _managerLanguageCountryList.Add(index, cultureCodeCountry); } } } }
/// <summary> /// 获取语言在cultureCode中,msgid在Msgid中的翻译结果(获取自定义翻译结果) /// </summary> /// <param name="cultureCode">需要加载的语言标识</param> /// <param name="Msgid">语言的msgid</param> /// <param name="isUseAlias">是否使用别名索引,目前请设置false</param> /// <returns></returns> public List <LanguageShowData> GetLanguageShowDataParts(List <string> cultureCode, List <string> Msgid, bool isUseAlias) { List <LanguageShowData> languageShowDatasList = null; if (cultureCode.Count < 1 || Msgid.Count < 1) { } else { languageShowDatasList = new List <LanguageShowData>(); foreach (var item in _managerLanguageListIndex) { if (!isUseAlias) { if (item.Value.IndexType == "AliasName") { continue; } } if (null == cultureCode.Find(x => x == item.Value.Index)) { continue; } var TranslateList = GetTranslateList(item.Key); var CultureCodeCountry = new CultureCodeCountry(item.Key, item.Value.SingleLanguage.Culture); bool IsDefault; if (item.Value.SingleLanguage.CultureName == DefaultLanguage) { IsDefault = true; } else { IsDefault = false; } LanguageShowData languageShowData = new LanguageShowData(TranslateList, CultureCodeCountry, IsDefault); for (int j = 0; j < languageShowData.TranslateList.Count; j++) { if (null == Msgid.Find(x => x == languageShowData.TranslateList[j].Source)) { languageShowData.TranslateList.Remove(languageShowData.TranslateList[j]); j--; } else { continue; } } languageShowDatasList.Add(languageShowData); } } return(languageShowDatasList); }