1
0

language.py 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. # -*- coding: UTF-8 -*-
  2. # The contents of this file are subject to the BitTorrent Open Source License
  3. # Version 1.1 (the License). You may not copy or use this file, in either
  4. # source code or executable form, except in compliance with the License. You
  5. # may obtain a copy of the License at http://www.bittorrent.com/license/.
  6. #
  7. # Software distributed under the License is distributed on an AS IS basis,
  8. # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  9. # for the specific language governing rights and limitations under the
  10. # License.
  11. # http://people.w3.org/rishida/names/languages.html
  12. import gettext
  13. class LanguageDict(dict):
  14. def __getitem__(self, key):
  15. for k in gettext._expand_lang(key):
  16. if self.has_key(k):
  17. return dict.__getitem__(self, key)
  18. raise KeyError(key)
  19. language_names = LanguageDict()
  20. language_names.update( {
  21. 'af' :u'Afrikaans' , 'bg' :u'Български' ,
  22. 'da' :u'Dansk' , 'ca' :u'Català' ,
  23. 'cs' :u'Čeština' , 'de' :u'Deutsch' ,
  24. 'en' :u'English' , 'es' :u'Español' ,
  25. 'es_MX':u'Español de Mexico ' , 'fr' :u'Français' ,
  26. 'el' :u'Ελληνικά' , 'he' :u'עברית' ,
  27. 'hu' :u'Magyar' , 'it' :u'Italiano' ,
  28. 'is' :u'Íslenska' , 'ja' :u'日本語' ,
  29. 'ko' :u'한국어' ,'nl' :u'Nederlands' ,
  30. 'nb_NO':u'Norsk bokmål' , 'pl' :u'Polski' ,
  31. 'pt' :u'Português' , 'pt_BR':u'Português do Brasil' ,
  32. 'ro' :u'Română' , 'ru' :u'Русский' ,
  33. 'sk' :u'Slovenský' , 'sl' :u'Slovensko' ,
  34. 'sv' :u'Svenska' , 'tr' :u'Türkçe' ,
  35. 'vi' :u'Tiê?ng Viê?t' ,
  36. 'zh_CN':u'简体中文' , # Simplified
  37. 'zh_TW':u'繁體中文' , # Traditional
  38. } )
  39. unfinished_language_names = {
  40. 'ar' :u'العربية' , 'bs' :u'Bosanski' ,
  41. 'eo' :u'Esperanto' , 'eu' :u'Euskara' ,
  42. 'et' :u'Eesti' , 'fi' :u'Suomi' ,
  43. 'fa' :u'فارسی' , 'ga' :u'Gaeilge' ,
  44. 'gl' :u'Galego' , 'hr' :u'Hrvatski' ,
  45. 'hy' :u'Հայերեն' , 'in' :u'Bahasa indonesia' ,
  46. 'ka' :u'ქართული ენა', 'lt' :u'Lietuvių' ,
  47. 'ms' :u'Bahasa melayu' , 'ml' :u'Malayalam' ,
  48. 'sq' :u'Shqipe' , 'th' :u'ภาษาไทย' ,
  49. 'tlh' :u'tlhIngan-Hol' , 'uk' :u'Українська' ,
  50. 'hi' :u'हिंदी' , 'cy' :u'Cymraeg' ,
  51. 'nn_NO':u'Norsk Nynorsk' , 'te' :u' తెలుగు' ,
  52. }
  53. #language_names.update(unfinished_language_names)
  54. class LanguageCodeList(list):
  55. def index(self, value):
  56. for v in gettext._expand_lang(value):
  57. try:
  58. i = list.index(self, v)
  59. return i
  60. except ValueError:
  61. pass
  62. raise ValueError('%v not in list'%value)
  63. languages = LanguageCodeList()
  64. languages.extend(language_names.keys())
  65. languages.sort()
  66. # windows codepage to locale mapping
  67. locale_sucks = {
  68. 0x0436: "af", # Afrikaans
  69. 0x3801: "ar_AE", # Arabic - United Arab Emirates
  70. 0x3C01: "ar_BH", # Arabic - Bahrain
  71. 0x1401: "ar_DZ", # Arabic - Algeria
  72. 0x0C01: "ar_EG", # Arabic - Egypt
  73. 0x0801: "ar_IQ", # Arabic - Iraq
  74. 0x2C01: "ar_JO", # Arabic - Jordan
  75. 0x3401: "ar_KW", # Arabic - Kuwait
  76. 0x3001: "ar_LB", # Arabic - Lebanon
  77. 0x1001: "ar_LY", # Arabic - Libya
  78. 0x1801: "ar_MA", # Arabic - Morocco
  79. 0x2001: "ar_OM", # Arabic - Oman
  80. 0x4001: "ar_QA", # Arabic - Qatar
  81. 0x0401: "ar_SA", # Arabic - Saudi Arabia
  82. 0x2801: "ar_SY", # Arabic - Syria
  83. 0x1C01: "ar_TN", # Arabic - Tunisia
  84. 0x2401: "ar_YE", # Arabic - Yemen
  85. 0x082C: "az_AZ", # Azeri - Cyrillic
  86. 0x0423: "be", # Belarusian
  87. 0x0402: "bg", # Bulgarian
  88. 0x0403: "ca", # Catalan
  89. 0x0405: "cs", # Czech
  90. 0x0406: "da", # Danish
  91. 0x0007: "de", # German
  92. 0x0C07: "de_AT", # German - Austria
  93. 0x0807: "de_CH", # German - Switzerland
  94. 0x0407: "de_DE", # German - Germany
  95. 0x1407: "de_LI", # German - Liechtenstein
  96. 0x1007: "de_LU", # German - Luxembourg
  97. 0x0408: "el", # Greek
  98. 0x0C09: "en_AU", # English - Australia
  99. 0x2809: "en_BZ", # English - Belize
  100. 0x1009: "en_CA", # English - Canada
  101. 0x2409: "en_CB", # English - Carribbean
  102. 0x0809: "en_GB", # English - United Kingdom
  103. 0x1809: "en_IE", # English - Ireland
  104. 0x2009: "en_JM", # English - Jamaica
  105. 0x1409: "en_NZ", # English - New Zealand
  106. 0x3409: "en_PH", # English - Phillippines
  107. 0x2C09: "en_TT", # English - Trinidad
  108. 0x0409: "en_US", # English - United States
  109. 0x1C09: "en_ZA", # English - South Africa
  110. 0x000A: "es", # Spanish (added)
  111. 0x2C0A: "es_AR", # Spanish - Argentina
  112. 0x400A: "es_BO", # Spanish - Bolivia
  113. 0x340A: "es_CL", # Spanish - Chile
  114. 0x240A: "es_CO", # Spanish - Colombia
  115. 0x140A: "es_CR", # Spanish - Costa Rica
  116. 0x1C0A: "es_DO", # Spanish - Dominican Republic
  117. 0x300A: "es_EC", # Spanish - Ecuador
  118. 0x040a: "es_ES", # Spanish - Spain
  119. 0x100A: "es_GT", # Spanish - Guatemala
  120. 0x480A: "es_HN", # Spanish - Honduras
  121. 0x080A: "es_MX", # Spanish - Mexico
  122. 0x4C0A: "es_NI", # Spanish - Nicaragua
  123. 0x180A: "es_PA", # Spanish - Panama
  124. 0x280A: "es_PE", # Spanish - Peru
  125. 0x500A: "es_PR", # Spanish - Puerto Rico
  126. 0x3C0A: "es_PY", # Spanish - Paraguay
  127. 0x440A: "es_SV", # Spanish - El Salvador
  128. 0x380A: "es_UY", # Spanish - Uruguay
  129. 0x200A: "es_VE", # Spanish - Venezuela
  130. 0x0425: "et", # Estonian
  131. 0x0009: "en", # English (added)
  132. 0x042D: "eu", # Basque
  133. 0x0429: "fa", # Farsi
  134. 0x040B: "fi", # Finnish
  135. 0x0438: "fo", # Faroese
  136. 0x000C: "fr", # French (added)
  137. 0x080C: "fr_BE", # French - Belgium
  138. 0x0C0C: "fr_CA", # French - Canada
  139. 0x100C: "fr_CH", # French - Switzerland
  140. 0x040C: "fr_FR", # French - France
  141. 0x140C: "fr_LU", # French - Luxembourg
  142. 0x043C: "gd", # Gaelic - Scotland
  143. 0x083C: "gd_IE", # Gaelic - Ireland
  144. 0x040D: "he", # Hebrew
  145. 0x0439: "hi", # Hindi
  146. 0x041A: "hr", # Croatian
  147. 0x040E: "hu", # Hungarian
  148. 0x042B: "hy", # Armenian
  149. 0x0421: "id", # Indonesian
  150. 0x040F: "is", # Icelandic
  151. 0x0010: "it", # Italian (added)
  152. 0x0810: "it_CH", # Italian - Switzerland
  153. 0x0410: "it_IT", # Italian - Italy
  154. 0x0411: "ja", # Japanese
  155. 0x0412: "ko", # Korean
  156. 0x0427: "lt", # Lithuanian
  157. 0x0426: "lv", # Latvian
  158. 0x042F: "mk", # FYRO Macedonian
  159. 0x044E: "mr", # Marathi
  160. 0x083E: "ms_BN", # Malay - Brunei
  161. 0x043E: "ms_MY", # Malay - Malaysia
  162. 0x043A: "mt", # Maltese
  163. 0x0013: "nl", # Dutch (added)
  164. 0x0813: "nl_BE", # Dutch - Belgium
  165. 0x0413: "nl_NL", # Dutch - The Netherlands
  166. 0x0814: "no_NO", # Norwegian - Nynorsk
  167. 0x0414: "nb_NO", # Norwegian - Bokmal (?)
  168. 0x0415: "pl", # Polish
  169. 0x0016: "pt", # Portuguese (added)
  170. 0x0416: "pt_BR", # Portuguese - Brazil
  171. 0x0816: "pt_PT", # Portuguese - Portugal
  172. 0x0417: "rm", # Raeto-Romance
  173. 0x0418: "ro", # Romanian - Romania
  174. 0x0818: "ro_MO", # Romanian - Moldova
  175. 0x0419: "ru", # Russian
  176. 0x0819: "ru_MO", # Russian - Moldova
  177. 0x044F: "sa", # Sanskrit
  178. 0x042E: "sb", # Sorbian
  179. 0x041B: "sk", # Slovak
  180. 0x0424: "sl", # Slovenian
  181. 0x041C: "sq", # Albanian
  182. 0x081A: "sr_SP", # Serbian - Latin
  183. 0x001D: "sv", # Swedish (added)
  184. 0x081D: "sv_FI", # Swedish - Finland
  185. 0x041D: "sv_SE", # Swedish - Sweden
  186. 0x0441: "sw", # Swahili
  187. 0x0430: "sx", # Sutu
  188. 0x0449: "ta", # Tamil
  189. 0x041E: "th", # Thai
  190. 0x0432: "tn", # Setsuana
  191. 0x041F: "tr", # Turkish
  192. 0x0431: "ts", # Tsonga
  193. 0X0444: "tt", # Tatar
  194. 0x0422: "uk", # Ukrainian
  195. 0x0420: "ur", # Urdu
  196. 0x0443: "uz_UZ", # Uzbek - Latin
  197. 0x042A: "vi", # Vietnamese
  198. 0x0434: "xh", # Xhosa
  199. 0x043D: "yi", # Yiddish
  200. 0x0804: "zh_CN", # Chinese - China
  201. 0x0C04: "zh_HK", # Chinese - Hong Kong S.A.R.
  202. 0x1404: "zh_MO", # Chinese - Macau S.A.R
  203. 0x1004: "zh_SG", # Chinese - Singapore
  204. 0x0404: "zh_TW", # Chinese - Taiwan
  205. 0x0435: "zu", # Zulu
  206. }
  207. if __name__ == '__main__':
  208. from BTL.obsoletepythonsupport import set
  209. internal = set([x.lower() for x in languages])
  210. windows = set(locale_sucks.values())
  211. if not windows.issuperset(internal):
  212. diff = list(internal.difference(windows))
  213. diff.sort()
  214. print diff