Пример #1
0
 // 根据语言索引返回主语言
 public Lang GetLangByLangIndex(int index)
 {
     if (AllLangList.Any(x => x.Value.LangIndex == index))
     {
         return(AllLangList.FirstOrDefault(x => x.Value.LangIndex == index).Value);
     }
     return(AllLangList[0]);
 }
Пример #2
0
 /// <summary>
 /// 根据语言名返回索引
 /// </summary>
 /// <param name="LangName"></param>
 /// <returns></returns>
 public Lang GetLangByLangName(string LangName)
 {
     if (AllLangList.Any(x => x.Value.LangName == LangName))
     {
         return(AllLangList.FirstOrDefault(x => x.Value.LangName == LangName).Value);
     }
     else
     {
         return(AllLangList[0]);
     }
 }
Пример #3
0
        /// <summary>
        /// 初始化所有语言
        /// </summary>
        private void InitialAllLang()
        {
            int orderIndex = 0;

            AllLangList.Clear();


            // zh-CN
            CultureInfo ci = new CultureInfo("zh-CN");

            AllLangList.Add(orderIndex, new Lang()
            {
                Culture = ci, LangIndex = orderIndex, LangOrder = orderIndex, LangName = GetString("LangName", ci)
            });                                                                                                                                             // index 0


            // ug-CN
            ++orderIndex;
            ci = new CultureInfo("ug-CN");
            AllLangList.Add(orderIndex, new Lang()
            {
                Culture = ci, LangIndex = orderIndex, LangOrder = orderIndex, LangName = GetString("LangName", ci)
            });                                                                                                                                             // index 1


            //en-US
            ++orderIndex;
            ci = new CultureInfo("en-US");
            AllLangList.Add(orderIndex, new Lang()
            {
                Culture = ci, LangIndex = orderIndex, LangOrder = orderIndex, LangName = GetString("LangName", ci)
            });                                                                                                                                             // index 2


            //fr-FR
            ++orderIndex;
            ci = new CultureInfo("fr-FR");
            AllLangList.Add(orderIndex, new Lang()
            {
                Culture = ci, LangIndex = orderIndex, LangOrder = orderIndex, LangName = GetString("LangName", ci)
            });                                                                                                                                             // index 3

            //ja-JP
            ++orderIndex;
            ci = new CultureInfo("ja-JP");
            AllLangList.Add(orderIndex, new Lang()
            {
                Culture = ci, LangIndex = orderIndex, LangOrder = orderIndex, LangName = GetString("LangName", ci)
            });                                                                                                                                             // index 4

            //ko-KR
            ++orderIndex;
            ci = new CultureInfo("ko-KR");
            AllLangList.Add(orderIndex, new Lang()
            {
                Culture = ci, LangIndex = orderIndex, LangOrder = orderIndex, LangName = GetString("LangName", ci)
            });                                                                                                                                             // index 5

            //th-TH
            ++orderIndex;
            ci = new CultureInfo("th-TH");
            AllLangList.Add(orderIndex, new Lang()
            {
                Culture = ci, LangIndex = orderIndex, LangOrder = orderIndex, LangName = GetString("LangName", ci)
            });                                                                                                                                             // index 6

            //pt-PT
            ++orderIndex;
            ci = new CultureInfo("pt-PT");
            AllLangList.Add(orderIndex, new Lang()
            {
                Culture = ci, LangIndex = orderIndex, LangOrder = orderIndex, LangName = GetString("LangName", ci)
            });                                                                                                                                             // index 7

            //es-ES
            ++orderIndex;
            ci = new CultureInfo("es-ES");
            AllLangList.Add(orderIndex, new Lang()
            {
                Culture = ci, LangIndex = orderIndex, LangOrder = orderIndex, LangName = GetString("LangName", ci)
            });                                                                                                                                             // index 8

            //he-IL
            ++orderIndex;
            ci = new CultureInfo("he-IL");
            AllLangList.Add(orderIndex, new Lang()
            {
                Culture = ci, LangIndex = orderIndex, LangOrder = orderIndex, LangName = GetString("LangName", ci)
            });                                                                                                                                             // index 9

            //tr-TR
            ++orderIndex;
            ci = new CultureInfo("tr-TR");
            AllLangList.Add(orderIndex, new Lang()
            {
                Culture = ci, LangIndex = orderIndex, LangOrder = orderIndex, LangName = GetString("LangName", ci)
            });                                                                                                                                             // index 10


            //de-DE
            ++orderIndex;
            ci = new CultureInfo("de-DE");
            AllLangList.Add(orderIndex, new Lang()
            {
                Culture = ci, LangIndex = orderIndex, LangOrder = orderIndex, LangName = GetString("LangName", ci)
            });                                                                                                                                             // index 11

            //ru-RU
            ++orderIndex;
            ci = new CultureInfo("ru-RU");
            AllLangList.Add(orderIndex, new Lang()
            {
                Culture = ci, LangIndex = orderIndex, LangOrder = orderIndex, LangName = GetString("LangName", ci)
            });                                                                                                                                             // index 12

            //it-IT
            ++orderIndex;
            ci = new CultureInfo("it-IT");
            AllLangList.Add(orderIndex, new Lang()
            {
                Culture = ci, LangIndex = orderIndex, LangOrder = orderIndex, LangName = GetString("LangName", ci)
            });                                                                                                                                             // index 13

            //hi-IN
            ++orderIndex;
            ci = new CultureInfo("hi-IN");
            AllLangList.Add(orderIndex, new Lang()
            {
                Culture = ci, LangIndex = orderIndex, LangOrder = orderIndex, LangName = GetString("LangName", ci)
            });                                                                                                                                             // index 14

            //ar-SA
            ++orderIndex;
            ci = new CultureInfo("ar-SA");
            AllLangList.Add(orderIndex, new Lang()
            {
                Culture = ci, LangIndex = orderIndex, LangOrder = orderIndex, LangName = GetString("LangName", ci)
            });                                                                                                                                             // index 15

            //ur-PK
            ++orderIndex;
            ci = new CultureInfo("ur-PK");
            AllLangList.Add(orderIndex, new Lang()
            {
                Culture = ci, LangIndex = orderIndex, LangOrder = orderIndex, LangName = GetString("LangName", ci)
            });                                                                                                                                             // index 16

            //uz-Latn
            ++orderIndex;
            ci = new CultureInfo("uz-Latn");
            AllLangList.Add(orderIndex, new Lang()
            {
                Culture = ci, LangIndex = orderIndex, LangOrder = orderIndex, LangName = GetString("LangName", ci)
            });                                                                                                                                             // index 17
        }
Пример #4
0
        /// <summary>
        /// 初始化所有语言
        /// </summary>
        private void InitialAllLang()
        {
            int orderIndex = 0;

            AllLangList.Clear();

            // Maybe we need to change the language order in the future

            // zh-CN
            CultureInfo ci = new CultureInfo("zh-CN");

            AllLangList.Add(orderIndex, new Lang()
            {
                Culture = ci, LangIndex = orderIndex, LangOrder = orderIndex, LangName = GetString("LangName", ci)
            });                                                                                                                                             // index 0


            // ug-CN
            ++orderIndex;
            ci = new CultureInfo("ug-CN");
            AllLangList.Add(orderIndex, new Lang()
            {
                Culture = ci, LangIndex = orderIndex, LangOrder = orderIndex, LangName = GetString("LangName", ci)
            });                                                                                                                                             // index 1


            //en-US
            ++orderIndex;
            ci = new CultureInfo("en-US");
            AllLangList.Add(orderIndex, new Lang()
            {
                Culture = ci, LangIndex = orderIndex, LangOrder = orderIndex, LangName = GetString("LangName", ci)
            });                                                                                                                                             // index 2

            //fr-FR
            ++orderIndex;
            ci = new CultureInfo("fr-FR");
            AllLangList.Add(orderIndex, new Lang()
            {
                Culture = ci, LangIndex = orderIndex, LangOrder = orderIndex, LangName = GetString("LangName", ci)
            });                                                                                                                                             // index 3

            //ja-JP
            ++orderIndex;
            ci = new CultureInfo("ja-JP");
            AllLangList.Add(orderIndex, new Lang()
            {
                Culture = ci, LangIndex = orderIndex, LangOrder = orderIndex, LangName = GetString("LangName", ci)
            });                                                                                                                                             // index 4

            //ko-KR
            ++orderIndex;
            ci = new CultureInfo("ko-KR");
            AllLangList.Add(orderIndex, new Lang()
            {
                Culture = ci, LangIndex = orderIndex, LangOrder = orderIndex, LangName = GetString("LangName", ci)
            });                                                                                                                                             // index 5

            //th-TH
            ++orderIndex;
            ci = new CultureInfo("th-TH");
            AllLangList.Add(orderIndex, new Lang()
            {
                Culture = ci, LangIndex = orderIndex, LangOrder = orderIndex, LangName = GetString("LangName", ci)
            });                                                                                                                                             // index 6

            //pt-PT
            ++orderIndex;
            ci = new CultureInfo("pt-PT");
            AllLangList.Add(orderIndex, new Lang()
            {
                Culture = ci, LangIndex = orderIndex, LangOrder = orderIndex, LangName = GetString("LangName", ci)
            });                                                                                                                                             // index 7

            //es-ES
            ++orderIndex;
            ci = new CultureInfo("es-ES");
            AllLangList.Add(orderIndex, new Lang()
            {
                Culture = ci, LangIndex = orderIndex, LangOrder = orderIndex, LangName = GetString("LangName", ci)
            });                                                                                                                                             // index 8

            //he-IL
            ++orderIndex;
            ci = new CultureInfo("he-IL");
            AllLangList.Add(orderIndex, new Lang()
            {
                Culture = ci, LangIndex = orderIndex, LangOrder = orderIndex, LangName = GetString("LangName", ci)
            });                                                                                                                                             // index 9

            //tr-TR
            ++orderIndex;
            ci = new CultureInfo("tr-TR");
            AllLangList.Add(orderIndex, new Lang()
            {
                Culture = ci, LangIndex = orderIndex, LangOrder = orderIndex, LangName = GetString("LangName", ci)
            });                                                                                                                                             // index 10

            //de-DE
            ++orderIndex;
            ci = new CultureInfo("de-DE");
            AllLangList.Add(orderIndex, new Lang()
            {
                Culture = ci, LangIndex = orderIndex, LangOrder = orderIndex, LangName = GetString("LangName", ci)
            });                                                                                                                                             // index 11

            //ru-RU
            ++orderIndex;
            ci = new CultureInfo("ru-RU");
            AllLangList.Add(orderIndex, new Lang()
            {
                Culture = ci, LangIndex = orderIndex, LangOrder = orderIndex, LangName = GetString("LangName", ci)
            });                                                                                                                                             // index 12

            //it-IT
            ++orderIndex;
            ci = new CultureInfo("it-IT");
            AllLangList.Add(orderIndex, new Lang()
            {
                Culture = ci, LangIndex = orderIndex, LangOrder = orderIndex, LangName = GetString("LangName", ci)
            });                                                                                                                                             // index 13

            //hi-IN
            ++orderIndex;
            ci = new CultureInfo("hi-IN");
            AllLangList.Add(orderIndex, new Lang()
            {
                Culture = ci, LangIndex = orderIndex, LangOrder = orderIndex, LangName = GetString("LangName", ci)
            });                                                                                                                                             // index 14

            //ar-SA
            ++orderIndex;
            ci = new CultureInfo("ar-SA");
            AllLangList.Add(orderIndex, new Lang()
            {
                Culture = ci, LangIndex = orderIndex, LangOrder = orderIndex, LangName = GetString("LangName", ci)
            });                                                                                                                                             // index 15

            //ur-PK
            ++orderIndex;
            ci = new CultureInfo("ur-PK");
            AllLangList.Add(orderIndex, new Lang()
            {
                Culture = ci, LangIndex = orderIndex, LangOrder = orderIndex, LangName = GetString("LangName", ci)
            });                                                                                                                                             // index 16

            //uz-Latn
            ++orderIndex;
            ci = new CultureInfo("uz-Latn");
            AllLangList.Add(orderIndex, new Lang()
            {
                Culture = ci, LangIndex = orderIndex, LangOrder = orderIndex, LangName = GetString("LangName", ci)
            });                                                                                                                                             // index 17



            var currentLang = AllLangList.Where(x => x.Value.Culture.Name == System.Globalization.CultureInfo.CurrentCulture.Name).Select(x => x.Value).FirstOrDefault();

            if (null != currentLang)
            {
                CurrentLangIndex = currentLang.LangIndex;
            }
            else
            {
                CurrentLangIndex = 1; // english for default
            }
        }