Esempio n. 1
0
        /// <summary>
        /// 获取某一语言下的全部翻译
        /// </summary>
        /// <param name="cultureCode">语言code,如zh-CN</param>
        /// <returns></returns>
        public List <TranslateResult> GetTranslateList(string cultureCode)
        {
            List <TranslateResult> resultList;

            if (_managerLanguageListIndex.ContainsKey(cultureCode))
            {
                LannguageIndex lannguageIndex = _managerLanguageListIndex[cultureCode];
                SingleLanguage singleLanguage = lannguageIndex.SingleLanguage;

                var TranslatesList = singleLanguage.GetTranslatesList();

                if (TranslatesList.Count > 0)
                {
                    resultList = TranslatesList;
                }
                else
                {
                    resultList = null;
                }
            }
            else
            {
                resultList = null;
            }


            return(resultList);
        }
Esempio n. 2
0
        /// <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);
        }
Esempio n. 3
0
        /// <summary>
        ///  更新多语言
        /// </summary>
        /// <param name="singleLanguages"></param>
        /// <param name="IsRenew"></param>
        /// <returns></returns>
        public void UpdateSingleLanguage(List <SingleLanguage> singleLanguages, bool IsRenew)
        {
            lock (_updateLock)
            {
                List <SingleLanguage> singleLanguageList = new List <SingleLanguage>();

                if (IsRenew)
                {
                    //以singleLanguages为基础重新构造
                    for (int i = 0; i < singleLanguages.Count; i++)
                    {
                        singleLanguageList.Add(singleLanguages[i]);
                    }
                }
                else
                {
                    //在原有数据基础上,进行singleLanguages改造



                    // 进行深拷贝
                    for (int i = 0; i < _managerLanguageList.Count; i++)
                    {
                        var newLanguage = singleLanguages.Find(x => x.CultureName == _managerLanguageList[i].CultureName);
                        if (newLanguage != null)
                        {
                            // 新的类型里包含了之前的旧数据
                            singleLanguageList.Add(newLanguage);
                        }
                        else
                        {
                            var moUrl       = _managerLanguageList[i].MoFilePosition;
                            var cultureName = _managerLanguageList[i].CultureName;
                            var aliasName   = _managerLanguageList[i].AliasName;
                            var flagUrl     = _managerLanguageList[i].FlagUrl;
                            var culture     = _managerLanguageList[i].Culture;

                            var language = new SingleLanguage(cultureName, moUrl, aliasName, culture, flagUrl);
                            singleLanguageList.Add(language);
                        }
                    }
                }


                // 生成好新的singleLanguageList,进行赋值
                _managerLanguageList = singleLanguageList;
            }
        }
 /// <summary>
 /// 向已经初始化完成的manager中添加一门新的语言
 /// </summary>
 /// <param name="singleLanguage"></param>
 /// <returns></returns>
 public bool AddSingleLanguage(SingleLanguage singleLanguage)
 {
     return(false);
 }