UILanguage.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. using System;
  2. using System.Collections.Generic;
  3. using I2.Loc;
  4. public static class UILanguage
  5. {
  6. public static List<string> Languages
  7. {
  8. get
  9. {
  10. List<string> result;
  11. if ((result = UILanguage._languages) == null)
  12. {
  13. result = (UILanguage._languages = LocalizationManager.GetAllLanguages(true));
  14. }
  15. return result;
  16. }
  17. }
  18. public static UILanguage.LanguageInfo CurrentLanguage
  19. {
  20. get
  21. {
  22. return UILanguage.LanguageInfoDic[R.Settings.Language];
  23. }
  24. }
  25. public static bool IsChinese
  26. {
  27. get
  28. {
  29. return UILanguage.Is(new string[]
  30. {
  31. "Chinese (Simplified)",
  32. "Chinese (Traditional)"
  33. });
  34. }
  35. }
  36. public static bool IsTraditionalChinese
  37. {
  38. get
  39. {
  40. return UILanguage.Is(new string[]
  41. {
  42. "Chinese (Traditional)"
  43. });
  44. }
  45. }
  46. public static bool IsSimplifiedChinese
  47. {
  48. get
  49. {
  50. return UILanguage.Is(new string[]
  51. {
  52. "Chinese (Simplified)"
  53. });
  54. }
  55. }
  56. public static bool IsEnglish
  57. {
  58. get
  59. {
  60. return UILanguage.Is(new string[]
  61. {
  62. "English (United States)"
  63. });
  64. }
  65. }
  66. public static bool IsJapanese
  67. {
  68. get
  69. {
  70. return UILanguage.Is(new string[]
  71. {
  72. "Japanese"
  73. });
  74. }
  75. }
  76. private static bool Is(params string[] languages)
  77. {
  78. string currentLanguage = LocalizationManager.CurrentLanguage;
  79. for (int i = 0; i < languages.Length; i++)
  80. {
  81. if (currentLanguage == languages[i])
  82. {
  83. return true;
  84. }
  85. }
  86. return false;
  87. }
  88. public const string Default = "English (United States)";
  89. public const string English = "English (United States)";
  90. public const string SimplifiedChinese = "Chinese (Simplified)";
  91. public const string TraditionalChinese = "Chinese (Traditional)";
  92. public const string Japanese = "Japanese";
  93. public const string French = "French";
  94. public const string Spanish = "Spanish";
  95. private static readonly Dictionary<string, UILanguage.LanguageInfo> LanguageInfoDic = new Dictionary<string, UILanguage.LanguageInfo>
  96. {
  97. {
  98. "English (United States)",
  99. new UILanguage.LanguageInfo("English", 2f, "English")
  100. },
  101. {
  102. "Chinese (Simplified)",
  103. new UILanguage.LanguageInfo("中文(简体)", 1f, "Chinese (Mandarin)")
  104. },
  105. {
  106. "Chinese (Traditional)",
  107. new UILanguage.LanguageInfo("中文(繁體)", 1f, "Chinese (Mandarin)")
  108. },
  109. {
  110. "Japanese",
  111. new UILanguage.LanguageInfo("日本語", 2f, "Japanese")
  112. },
  113. {
  114. "French",
  115. new UILanguage.LanguageInfo("français", 2f, "English")
  116. },
  117. {
  118. "Spanish",
  119. new UILanguage.LanguageInfo("Español", 2f, "English")
  120. }
  121. };
  122. private static List<string> _languages;
  123. public class LanguageInfo
  124. {
  125. public LanguageInfo(string localizedName, float typeSpeed, string defaultAudioLanguage)
  126. {
  127. this.LocalizedName = localizedName;
  128. this.TypeSpeed = typeSpeed;
  129. this.DefaultAudioLanguage = defaultAudioLanguage;
  130. }
  131. public readonly string DefaultAudioLanguage;
  132. public readonly string LocalizedName;
  133. public readonly float TypeSpeed;
  134. }
  135. }