Пример #1
0
        /// <summary>
        /// 获取当前全部语言
        /// </summary>
        /// <returns></returns>
        public static LanguageDic AllLang()
        {
            string basePath = AppDomain.CurrentDomain.BaseDirectory;

            string base_path = $"{basePath}..\\..\\..\\i18n\\";

            if (CurrLangDic == null)
            {
                CurrLangDic = new LanguageDic();
                var files = System.IO.Directory.GetFiles(base_path);
                if (files.HasItem())
                {
                    foreach (var item in files)
                    {
                        var lang_kv_json = item.GetTextFile();
                        if (lang_kv_json.NotNullEmpty())
                        {
                            LanguageKV curr_kv = lang_kv_json.ToObj <LanguageKV>();
                            var        key     = item.RightSinceStr("\\", ".");
                            CurrLangDic.Add(key, curr_kv);
                        }
                    }
                }
            }
            return(CurrLangDic);
        }
Пример #2
0
        /// <summary>
        /// 获取当前语言,全部语言来自外部
        /// </summary>
        /// <param name="allLang"></param>
        /// <param name="defLangKV"></param>
        /// <returns></returns>
        private static LanguageKV GetCurrLang(LanguageDic allLang, LanguageKV defLangKV = null)
        {
            var all_lang = allLang;

            if (!all_lang.ContainsKey(all_lang.DefLang) && defLangKV.NotNull())
            {
                all_lang.Add(all_lang.DefLang, defLangKV);
            }
            if (all_lang.ContainsKey(all_lang.CurrLang))
            {
                return(all_lang[all_lang.CurrLang]);
            }
            else
            {
                return(all_lang[all_lang.DefLang]);
            }
        }