translation.cpp 28 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151
  1. /*************************************************************************/
  2. /* translation.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #include "translation.h"
  30. #include "globals.h"
  31. #include "io/resource_loader.h"
  32. #include "os/os.h"
  33. static const char* locale_list[]={
  34. "aa", // Afar
  35. "aa_DJ", // Afar (Djibouti)
  36. "aa_ER", // Afar (Eritrea)
  37. "aa_ET", // Afar (Ethiopia)
  38. "af", // Afrikaans
  39. "af_ZA", // Afrikaans (South Africa)
  40. "agr_PE", // Aguaruna (Peru)
  41. "ak_GH", // Akan (Ghana)
  42. "am_ET", // Amharic (Ethiopia)
  43. "an_ES", // Aragonese (Spain)
  44. "anp_IN", // Angika (India)
  45. "ar", // Arabic
  46. "ar_AE", // Arabic (United Arab Emirates)
  47. "ar_BH", // Arabic (Bahrain)
  48. "ar_DZ", // Arabic (Algeria)
  49. "ar_EG", // Arabic (Egypt)
  50. "ar_IN", // Arabic (India)
  51. "ar_IQ", // Arabic (Iraq)
  52. "ar_JO", // Arabic (Jordan)
  53. "ar_KW", // Arabic (Kuwait)
  54. "ar_LB", // Arabic (Lebanon)
  55. "ar_LY", // Arabic (Libya)
  56. "ar_MA", // Arabic (Morocco)
  57. "ar_OM", // Arabic (Oman)
  58. "ar_QA", // Arabic (Qatar)
  59. "ar_SA", // Arabic (Saudi Arabia)
  60. "ar_SD", // Arabic (Sudan)
  61. "ar_SS", // Arabic (South Soudan)
  62. "ar_SY", // Arabic (Syria)
  63. "ar_TN", // Arabic (Tunisia)
  64. "ar_YE", // Arabic (Yemen)
  65. "as_IN", // Assamese (India)
  66. "ast_ES", // Asturian (Spain)
  67. "ayc_PE", // Southern Aymara (Peru)
  68. "ay_PE", // Aymara (Peru)
  69. "az_AZ", // Azerbaijani (Azerbaijan)
  70. "be", // Belarusian
  71. "be_BY", // Belarusian (Belarus)
  72. "bem_ZM", // Bemba (Zambia)
  73. "ber_DZ", // Berber languages (Algeria)
  74. "ber_MA", // Berber languages (Morocco)
  75. "bg", // Bulgarian
  76. "bg_BG", // Bulgarian (Bulgaria)
  77. "bhb_IN", // Bhili (India)
  78. "bho_IN", // Bhojpuri (India)
  79. "bi_TV", // Bislama (Tuvalu)
  80. "bn", // Bengali
  81. "bn_BD", // Bengali (Bangladesh)
  82. "bn_IN", // Bengali (India)
  83. "bo", // Tibetan
  84. "bo_CN", // Tibetan (China)
  85. "bo_IN", // Tibetan (India)
  86. "br_FR", // Breton (France)
  87. "brx_IN", // Bodo (India)
  88. "bs_BA", // Bosnian (Bosnia and Herzegovina)
  89. "byn_ER", // Bilin (Eritrea)
  90. "ca", // Catalan
  91. "ca_AD", // Catalan (Andorra)
  92. "ca_ES", // Catalan (Spain)
  93. "ca_FR", // Catalan (France)
  94. "ca_IT", // Catalan (Italy)
  95. "ce_RU", // Chechen (Russia)
  96. "chr_US", // Cherokee (United States)
  97. "cmn_TW", // Mandarin Chinese (Taiwan)
  98. "crh_UA", // Crimean Tatar (Ukraine)
  99. "csb_PL", // Kashubian (Poland)
  100. "cs", // Czech
  101. "cs_CZ", // Czech (Czech Republic)
  102. "cv_RU", // Chuvash (Russia)
  103. "cy_GB", // Welsh (United Kingdom)
  104. "da", // Danish
  105. "da_DK", // Danish (Denmark)
  106. "de", // German
  107. "de_AT", // German (Austria)
  108. "de_BE", // German (Belgium)
  109. "de_CH", // German (Switzerland)
  110. "de_DE", // German (Germany)
  111. "de_IT", // German (Italy)
  112. "de_LU", // German (Luxembourg)
  113. "doi_IN", // Dogri (India)
  114. "dv_MV", // Dhivehi (Maldives)
  115. "dz_BT", // Dzongkha (Bhutan)
  116. "el", // Greek
  117. "el_CY", // Greek (Cyprus)
  118. "el_GR", // Greek (Greece)
  119. "en", // English
  120. "en_AG", // English (Antigua and Barbuda)
  121. "en_AU", // English (Australia)
  122. "en_BW", // English (Botswana)
  123. "en_CA", // English (Canada)
  124. "en_DK", // English (Denmark)
  125. "en_GB", // English (United Kingdom)
  126. "en_HK", // English (Hong Kong)
  127. "en_IE", // English (Ireland)
  128. "en_IL", // English (Israel)
  129. "en_IN", // English (India)
  130. "en_NG", // English (Nigeria)
  131. "en_NZ", // English (New Zealand)
  132. "en_PH", // English (Philippines)
  133. "en_SG", // English (Singapore)
  134. "en_US", // English (United States)
  135. "en_ZA", // English (South Africa)
  136. "en_ZM", // English (Zambia)
  137. "en_ZW", // English (Zimbabwe)
  138. "eo", // Esperanto
  139. "es", // Spanish
  140. "es_AR", // Spanish (Argentina)
  141. "es_BO", // Spanish (Bolivia)
  142. "es_CL", // Spanish (Chile)
  143. "es_CO", // Spanish (Colombia)
  144. "es_CR", // Spanish (Costa Rica)
  145. "es_CU", // Spanish (Cuba)
  146. "es_DO", // Spanish (Dominican Republic)
  147. "es_EC", // Spanish (Ecuador)
  148. "es_ES", // Spanish (Spain)
  149. "es_GT", // Spanish (Guatemala)
  150. "es_HN", // Spanish (Honduras)
  151. "es_MX", // Spanish (Mexico)
  152. "es_NI", // Spanish (Nicaragua)
  153. "es_PA", // Spanish (Panama)
  154. "es_PE", // Spanish (Peru)
  155. "es_PR", // Spanish (Puerto Rico)
  156. "es_PY", // Spanish (Paraguay)
  157. "es_SV", // Spanish (El Salvador)
  158. "es_US", // Spanish (United States)
  159. "es_UY", // Spanish (Uruguay)
  160. "es_VE", // Spanish (Venezuela)
  161. "et", // Estonian
  162. "et_EE", // Estonian (Estonia)
  163. "eu", // Basque
  164. "eu_ES", // Basque (Spain)
  165. "fa", // Persian
  166. "fa_IR", // Persian (Iran)
  167. "ff_SN", // Fulah (Senegal)
  168. "fi", // Finnish
  169. "fi_FI", // Finnish (Finland)
  170. "fil_PH", // Filipino (Philippines)
  171. "fo_FO", // Faroese (Faroe Islands)
  172. "fr", // French
  173. "fr_BE", // French (Belgium)
  174. "fr_CA", // French (Canada)
  175. "fr_CH", // French (Switzerland)
  176. "fr_FR", // French (France)
  177. "fr_LU", // French (Luxembourg)
  178. "fur_IT", // Friulian (Italy)
  179. "fy_DE", // Western Frisian (Germany)
  180. "fy_NL", // Western Frisian (Netherlands)
  181. "ga", // Irish
  182. "ga_IE", // Irish (Ireland)
  183. "gd_GB", // Scottish Gaelic (United Kingdom)
  184. "gez_ER", // Geez (Eritrea)
  185. "gez_ET", // Geez (Ethiopia)
  186. "gl_ES", // Galician (Spain)
  187. "gu_IN", // Gujarati (India)
  188. "gv_GB", // Manx (United Kingdom)
  189. "hak_TW", // Hakka Chinese (Taiwan)
  190. "ha_NG", // Hausa (Nigeria)
  191. "he", // Hebrew
  192. "he_IL", // Hebrew (Israel)
  193. "hi", // Hindi
  194. "hi_IN", // Hindi (India)
  195. "hne_IN", // Chhattisgarhi (India)
  196. "hr", // Croatian
  197. "hr_HR", // Croatian (Croatia)
  198. "hsb_DE", // Upper Sorbian (Germany)
  199. "ht_HT", // Haitian (Haiti)
  200. "hu", // Hungarian
  201. "hu_HU", // Hungarian (Hungary)
  202. "hus_MX", // Huastec (Mexico)
  203. "hy_AM", // Armenian (Armenia)
  204. "ia_FR", // Interlingua (France)
  205. "id", // Indonesian
  206. "id_ID", // Indonesian (Indonesia)
  207. "ig_NG", // Igbo (Nigeria)
  208. "ik_CA", // Inupiaq (Canada)
  209. "is", // Icelandic
  210. "is_IS", // Icelandic (Iceland)
  211. "it", // Italian
  212. "it_CH", // Italian (Switzerland)
  213. "it_IT", // Italian (Italy)
  214. "iu_CA", // Inuktitut (Canada)
  215. "ja", // Japanese
  216. "ja_JP", // Japanese (Japan)
  217. "kab_DZ", // Kabyle (Algeria)
  218. "ka_GE", // Georgian (Georgia)
  219. "kk_KZ", // Kazakh (Kazakhstan)
  220. "kl_GL", // Kalaallisut (Greenland)
  221. "km_KH", // Central Khmer (Cambodia)
  222. "kn_IN", // Kannada (India)
  223. "kok_IN", // Konkani (India)
  224. "ko", // Korean
  225. "ko_KR", // Korean (South Korea)
  226. "ks_IN", // Kashmiri (India)
  227. "ku", // Kurdish
  228. "ku_TR", // Kurdish (Turkey)
  229. "kw_GB", // Cornish (United Kingdom)
  230. "ky_KG", // Kirghiz (Kyrgyzstan)
  231. "lb_LU", // Luxembourgish (Luxembourg)
  232. "lg_UG", // Ganda (Uganda)
  233. "li_BE", // Limburgan (Belgium)
  234. "li_NL", // Limburgan (Netherlands)
  235. "lij_IT", // Ligurian (Italy)
  236. "ln_CD", // Lingala (Congo)
  237. "lo_LA", // Lao (Laos)
  238. "lt", // Lithuanian
  239. "lt_LT", // Lithuanian (Lithuania)
  240. "lv", // Latvian
  241. "lv_LV", // Latvian (Latvia)
  242. "lzh_TW", // Literary Chinese (Taiwan)
  243. "mag_IN", // Magahi (India)
  244. "mai_IN", // Maithili (India)
  245. "mg_MG", // Malagasy (Madagascar)
  246. "mh_MH", // Marshallese (Marshall Islands)
  247. "mhr_RU", // Eastern Mari (Russia)
  248. "mi_NZ", // Maori (New Zealand)
  249. "miq_NI", // Mískito (Nicaragua)
  250. "mk", // Macedonian
  251. "mk_MK", // Macedonian (Macedonia)
  252. "ml_IN", // Malayalam (India)
  253. "mni_IN", // Manipuri (India)
  254. "mn_MN", // Mongolian (Mongolia)
  255. "mr_IN", // Marathi (India)
  256. "ms", // Malay
  257. "ms_MY", // Malay (Malaysia)
  258. "mt", // Maltese
  259. "mt_MT", // Maltese (Malta)
  260. "my_MM", // Burmese (Myanmar)
  261. "myv_RU", // Erzya (Russia)
  262. "nah_MX", // Nahuatl languages (Mexico)
  263. "nan_TW", // Min Nan Chinese (Taiwan)
  264. "nb", // Norwegian Bokmål
  265. "nb_NO", // Norwegian Bokmål (Norway)
  266. "nds_DE", // Low German (Germany)
  267. "nds_NL", // Low German (Netherlands)
  268. "ne_NP", // Nepali (Nepal)
  269. "nhn_MX", // Central Nahuatl (Mexico)
  270. "niu_NU", // Niuean (Niue)
  271. "niu_NZ", // Niuean (New Zealand)
  272. "nl", // Dutch
  273. "nl_AW", // Dutch (Aruba)
  274. "nl_BE", // Dutch (Belgium)
  275. "nl_NL", // Dutch (Netherlands)
  276. "nn", // Norwegian Nynorsk
  277. "nn_NO", // Norwegian Nynorsk (Norway)
  278. "nr_ZA", // South Ndebele (South Africa)
  279. "nso_ZA", // Pedi (South Africa)
  280. "oc_FR", // Occitan (France)
  281. "om", // Oromo
  282. "om_ET", // Oromo (Ethiopia)
  283. "om_KE", // Oromo (Kenya)
  284. "or_IN", // Oriya (India)
  285. "os_RU", // Ossetian (Russia)
  286. "pa_IN", // Panjabi (India)
  287. "pap", // Papiamento
  288. "pap_AN", // Papiamento (Netherlands Antilles)
  289. "pap_AW", // Papiamento (Aruba)
  290. "pap_CW", // Papiamento (Curaçao)
  291. "pa_PK", // Panjabi (Pakistan)
  292. "pl", // Polish
  293. "pl_PL", // Polish (Poland)
  294. "ps_AF", // Pushto (Afghanistan)
  295. "pt", // Portuguese
  296. "pt_BR", // Portuguese (Brazil)
  297. "pt_PT", // Portuguese (Portugal)
  298. "quy_PE", // Ayacucho Quechua (Peru)
  299. "quz_PE", // Cusco Quechua (Peru)
  300. "raj_IN", // Rajasthani (India)
  301. "ro", // Romanian
  302. "ro_RO", // Romanian (Romania)
  303. "ru", // Russian
  304. "ru_RU", // Russian (Russia)
  305. "ru_UA", // Russian (Ukraine)
  306. "rw_RW", // Kinyarwanda (Rwanda)
  307. "sa_IN", // Sanskrit (India)
  308. "sat_IN", // Santali (India)
  309. "sc_IT", // Sardinian (Italy)
  310. "sd_IN", // Sindhi (India)
  311. "se_NO", // Northern Sami (Norway)
  312. "sgs_LT", // Samogitian (Lithuania)
  313. "shs_CA", // Shuswap (Canada)
  314. "sid_ET", // Sidamo (Ethiopia)
  315. "si_LK", // Sinhala (Sri Lanka)
  316. "sk", // Slovak
  317. "sk_SK", // Slovak (Slovakia)
  318. "sl", // Slovenian
  319. "sl_SI", // Slovenian (Slovenia)
  320. "so", // Somali
  321. "so_DJ", // Somali (Djibouti)
  322. "so_ET", // Somali (Ethiopia)
  323. "so_KE", // Somali (Kenya)
  324. "so_SO", // Somali (Somalia)
  325. "son_ML", // Songhai languages (Mali)
  326. "sq", // Albanian
  327. "sq_AL", // Albanian (Albania)
  328. "sq_KV", // Albanian (Kosovo)
  329. "sq_MK", // Albanian (Macedonia)
  330. "sr", // Serbian
  331. "sr_ME", // Serbian (Montenegro)
  332. "sr_RS", // Serbian (Serbia)
  333. "ss_ZA", // Swati (South Africa)
  334. "st_ZA", // Southern Sotho (South Africa)
  335. "sv", // Swedish
  336. "sv_FI", // Swedish (Finland)
  337. "sv_SE", // Swedish (Sweden)
  338. "sw_KE", // Swahili (Kenya)
  339. "sw_TZ", // Swahili (Tanzania)
  340. "szl_PL", // Silesian (Poland)
  341. "ta", // Tamil
  342. "ta_IN", // Tamil (India)
  343. "ta_LK", // Tamil (Sri Lanka)
  344. "tcy_IN", // Tulu (India)
  345. "te_IN", // Telugu (India)
  346. "tg_TJ", // Tajik (Tajikistan)
  347. "the_NP", // Chitwania Tharu (Nepal)
  348. "th", // Thai
  349. "th_TH", // Thai (Thailand)
  350. "ti", // Tigrinya
  351. "ti_ER", // Tigrinya (Eritrea)
  352. "ti_ET", // Tigrinya (Ethiopia)
  353. "tig_ER", // Tigre (Eritrea)
  354. "tk_TM", // Turkmen (Turkmenistan)
  355. "tl_PH", // Tagalog (Philippines)
  356. "tn_ZA", // Tswana (South Africa)
  357. "tr", // Turkish
  358. "tr_CY", // Turkish (Cyprus)
  359. "tr_TR", // Turkish (Turkey)
  360. "ts_ZA", // Tsonga (South Africa)
  361. "tt_RU", // Tatar (Russia)
  362. "ug_CN", // Uighur (China)
  363. "uk", // Ukrainian
  364. "uk_UA", // Ukrainian (Ukraine)
  365. "unm_US", // Unami (United States)
  366. "ur", // Urdu
  367. "ur_IN", // Urdu (India)
  368. "ur_PK", // Urdu (Pakistan)
  369. "uz", // Uzbek
  370. "uz_UZ", // Uzbek (Uzbekistan)
  371. "ve_ZA", // Venda (South Africa)
  372. "vi", // Vietnamese
  373. "vi_VN", // Vietnamese (Vietnam)
  374. "wa_BE", // Walloon (Belgium)
  375. "wae_CH", // Walser (Switzerland)
  376. "wal_ET", // Wolaytta (Ethiopia)
  377. "wo_SN", // Wolof (Senegal)
  378. "xh_ZA", // Xhosa (South Africa)
  379. "yi_US", // Yiddish (United States)
  380. "yo_NG", // Yoruba (Nigeria)
  381. "yue_HK", // Yue Chinese (Hong Kong)
  382. "zh", // Chinese
  383. "zh_CN", // Chinese (China)
  384. "zh_HK", // Chinese (Hong Kong)
  385. "zh_SG", // Chinese (Singapore)
  386. "zh_TW", // Chinese (Taiwan)
  387. "zu_ZA", // Zulu (South Africa)
  388. 0
  389. };
  390. static const char* locale_names[]={
  391. "Afar",
  392. "Afar (Djibouti)",
  393. "Afar (Eritrea)",
  394. "Afar (Ethiopia)",
  395. "Afrikaans",
  396. "Afrikaans (South Africa)",
  397. "Aguaruna (Peru)",
  398. "Akan (Ghana)",
  399. "Amharic (Ethiopia)",
  400. "Aragonese (Spain)",
  401. "Angika (India)",
  402. "Arabic",
  403. "Arabic (United Arab Emirates)",
  404. "Arabic (Bahrain)",
  405. "Arabic (Algeria)",
  406. "Arabic (Egypt)",
  407. "Arabic (India)",
  408. "Arabic (Iraq)",
  409. "Arabic (Jordan)",
  410. "Arabic (Kuwait)",
  411. "Arabic (Lebanon)",
  412. "Arabic (Libya)",
  413. "Arabic (Morocco)",
  414. "Arabic (Oman)",
  415. "Arabic (Qatar)",
  416. "Arabic (Saudi Arabia)",
  417. "Arabic (Sudan)",
  418. "Arabic (South Soudan)",
  419. "Arabic (Syria)",
  420. "Arabic (Tunisia)",
  421. "Arabic (Yemen)",
  422. "Assamese (India)",
  423. "Asturian (Spain)",
  424. "Southern Aymara (Peru)",
  425. "Aymara (Peru)",
  426. "Azerbaijani (Azerbaijan)",
  427. "Belarusian",
  428. "Belarusian (Belarus)",
  429. "Bemba (Zambia)",
  430. "Berber languages (Algeria)",
  431. "Berber languages (Morocco)",
  432. "Bulgarian",
  433. "Bulgarian (Bulgaria)",
  434. "Bhili (India)",
  435. "Bhojpuri (India)",
  436. "Bislama (Tuvalu)",
  437. "Bengali",
  438. "Bengali (Bangladesh)",
  439. "Bengali (India)",
  440. "Tibetan",
  441. "Tibetan (China)",
  442. "Tibetan (India)",
  443. "Breton (France)",
  444. "Bodo (India)",
  445. "Bosnian (Bosnia and Herzegovina)",
  446. "Bilin (Eritrea)",
  447. "Catalan",
  448. "Catalan (Andorra)",
  449. "Catalan (Spain)",
  450. "Catalan (France)",
  451. "Catalan (Italy)",
  452. "Chechen (Russia)",
  453. "Cherokee (United States)",
  454. "Mandarin Chinese (Taiwan)",
  455. "Crimean Tatar (Ukraine)",
  456. "Kashubian (Poland)",
  457. "Czech",
  458. "Czech (Czech Republic)",
  459. "Chuvash (Russia)",
  460. "Welsh (United Kingdom)",
  461. "Danish",
  462. "Danish (Denmark)",
  463. "German",
  464. "German (Austria)",
  465. "German (Belgium)",
  466. "German (Switzerland)",
  467. "German (Germany)",
  468. "German (Italy)",
  469. "German (Luxembourg)",
  470. "Dogri (India)",
  471. "Dhivehi (Maldives)",
  472. "Dzongkha (Bhutan)",
  473. "Greek",
  474. "Greek (Cyprus)",
  475. "Greek (Greece)",
  476. "English",
  477. "English (Antigua and Barbuda)",
  478. "English (Australia)",
  479. "English (Botswana)",
  480. "English (Canada)",
  481. "English (Denmark)",
  482. "English (United Kingdom)",
  483. "English (Hong Kong)",
  484. "English (Ireland)",
  485. "English (Israel)",
  486. "English (India)",
  487. "English (Nigeria)",
  488. "English (New Zealand)",
  489. "English (Philippines)",
  490. "English (Singapore)",
  491. "English (United States)",
  492. "English (South Africa)",
  493. "English (Zambia)",
  494. "English (Zimbabwe)",
  495. "Esperanto",
  496. "Spanish",
  497. "Spanish (Argentina)",
  498. "Spanish (Bolivia)",
  499. "Spanish (Chile)",
  500. "Spanish (Colombia)",
  501. "Spanish (Costa Rica)",
  502. "Spanish (Cuba)",
  503. "Spanish (Dominican Republic)",
  504. "Spanish (Ecuador)",
  505. "Spanish (Spain)",
  506. "Spanish (Guatemala)",
  507. "Spanish (Honduras)",
  508. "Spanish (Mexico)",
  509. "Spanish (Nicaragua)",
  510. "Spanish (Panama)",
  511. "Spanish (Peru)",
  512. "Spanish (Puerto Rico)",
  513. "Spanish (Paraguay)",
  514. "Spanish (El Salvador)",
  515. "Spanish (United States)",
  516. "Spanish (Uruguay)",
  517. "Spanish (Venezuela)",
  518. "Estonian",
  519. "Estonian (Estonia)",
  520. "Basque",
  521. "Basque (Spain)",
  522. "Persian",
  523. "Persian (Iran)",
  524. "Fulah (Senegal)",
  525. "Finnish",
  526. "Finnish (Finland)",
  527. "Filipino (Philippines)",
  528. "Faroese (Faroe Islands)",
  529. "French",
  530. "French (Belgium)",
  531. "French (Canada)",
  532. "French (Switzerland)",
  533. "French (France)",
  534. "French (Luxembourg)",
  535. "Friulian (Italy)",
  536. "Western Frisian (Germany)",
  537. "Western Frisian (Netherlands)",
  538. "Irish",
  539. "Irish (Ireland)",
  540. "Scottish Gaelic (United Kingdom)",
  541. "Geez (Eritrea)",
  542. "Geez (Ethiopia)",
  543. "Galician (Spain)",
  544. "Gujarati (India)",
  545. "Manx (United Kingdom)",
  546. "Hakka Chinese (Taiwan)",
  547. "Hausa (Nigeria)",
  548. "Hebrew",
  549. "Hebrew (Israel)",
  550. "Hindi",
  551. "Hindi (India)",
  552. "Chhattisgarhi (India)",
  553. "Croatian",
  554. "Croatian (Croatia)",
  555. "Upper Sorbian (Germany)",
  556. "Haitian (Haiti)",
  557. "Hungarian",
  558. "Hungarian (Hungary)",
  559. "Huastec (Mexico)",
  560. "Armenian (Armenia)",
  561. "Interlingua (France)",
  562. "Indonesian",
  563. "Indonesian (Indonesia)",
  564. "Igbo (Nigeria)",
  565. "Inupiaq (Canada)",
  566. "Icelandic",
  567. "Icelandic (Iceland)",
  568. "Italian",
  569. "Italian (Switzerland)",
  570. "Italian (Italy)",
  571. "Inuktitut (Canada)",
  572. "Japanese",
  573. "Japanese (Japan)",
  574. "Kabyle (Algeria)",
  575. "Georgian (Georgia)",
  576. "Kazakh (Kazakhstan)",
  577. "Kalaallisut (Greenland)",
  578. "Central Khmer (Cambodia)",
  579. "Kannada (India)",
  580. "Konkani (India)",
  581. "Korean",
  582. "Korean (South Korea)",
  583. "Kashmiri (India)",
  584. "Kurdish",
  585. "Kurdish (Turkey)",
  586. "Cornish (United Kingdom)",
  587. "Kirghiz (Kyrgyzstan)",
  588. "Luxembourgish (Luxembourg)",
  589. "Ganda (Uganda)",
  590. "Limburgan (Belgium)",
  591. "Limburgan (Netherlands)",
  592. "Ligurian (Italy)",
  593. "Lingala (Congo)",
  594. "Lao (Laos)",
  595. "Lithuanian",
  596. "Lithuanian (Lithuania)",
  597. "Latvian",
  598. "Latvian (Latvia)",
  599. "Literary Chinese (Taiwan)",
  600. "Magahi (India)",
  601. "Maithili (India)",
  602. "Malagasy (Madagascar)",
  603. "Marshallese (Marshall Islands)",
  604. "Eastern Mari (Russia)",
  605. "Maori (New Zealand)",
  606. "Mískito (Nicaragua)",
  607. "Macedonian",
  608. "Macedonian (Macedonia)",
  609. "Malayalam (India)",
  610. "Manipuri (India)",
  611. "Mongolian (Mongolia)",
  612. "Marathi (India)",
  613. "Malay",
  614. "Malay (Malaysia)",
  615. "Maltese",
  616. "Maltese (Malta)",
  617. "Burmese (Myanmar)",
  618. "Erzya (Russia)",
  619. "Nahuatl languages (Mexico)",
  620. "Min Nan Chinese (Taiwan)",
  621. "Norwegian Bokmål",
  622. "Norwegian Bokmål (Norway)",
  623. "Low German (Germany)",
  624. "Low German (Netherlands)",
  625. "Nepali (Nepal)",
  626. "Central Nahuatl (Mexico)",
  627. "Niuean (Niue)",
  628. "Niuean (New Zealand)",
  629. "Dutch",
  630. "Dutch (Aruba)",
  631. "Dutch (Belgium)",
  632. "Dutch (Netherlands)",
  633. "Norwegian Nynorsk",
  634. "Norwegian Nynorsk (Norway)",
  635. "South Ndebele (South Africa)",
  636. "Pedi (South Africa)",
  637. "Occitan (France)",
  638. "Oromo",
  639. "Oromo (Ethiopia)",
  640. "Oromo (Kenya)",
  641. "Oriya (India)",
  642. "Ossetian (Russia)",
  643. "Panjabi (India)",
  644. "Papiamento",
  645. "Papiamento (Netherlands Antilles)",
  646. "Papiamento (Aruba)",
  647. "Papiamento (Curaçao)",
  648. "Panjabi (Pakistan)",
  649. "Polish",
  650. "Polish (Poland)",
  651. "Pushto (Afghanistan)",
  652. "Portuguese",
  653. "Portuguese (Brazil)",
  654. "Portuguese (Portugal)",
  655. "Ayacucho Quechua (Peru)",
  656. "Cusco Quechua (Peru)",
  657. "Rajasthani (India)",
  658. "Romanian",
  659. "Romanian (Romania)",
  660. "Russian",
  661. "Russian (Russia)",
  662. "Russian (Ukraine)",
  663. "Kinyarwanda (Rwanda)",
  664. "Sanskrit (India)",
  665. "Santali (India)",
  666. "Sardinian (Italy)",
  667. "Sindhi (India)",
  668. "Northern Sami (Norway)",
  669. "Samogitian (Lithuania)",
  670. "Shuswap (Canada)",
  671. "Sidamo (Ethiopia)",
  672. "Sinhala (Sri Lanka)",
  673. "Slovak",
  674. "Slovak (Slovakia)",
  675. "Slovenian",
  676. "Slovenian (Slovenia)",
  677. "Somali",
  678. "Somali (Djibouti)",
  679. "Somali (Ethiopia)",
  680. "Somali (Kenya)",
  681. "Somali (Somalia)",
  682. "Songhai languages (Mali)",
  683. "Albanian",
  684. "Albanian (Albania)",
  685. "Albanian (Kosovo)",
  686. "Albanian (Macedonia)",
  687. "Serbian",
  688. "Serbian (Montenegro)",
  689. "Serbian (Serbia)",
  690. "Swati (South Africa)",
  691. "Southern Sotho (South Africa)",
  692. "Swedish",
  693. "Swedish (Finland)",
  694. "Swedish (Sweden)",
  695. "Swahili (Kenya)",
  696. "Swahili (Tanzania)",
  697. "Silesian (Poland)",
  698. "Tamil",
  699. "Tamil (India)",
  700. "Tamil (Sri Lanka)",
  701. "Tulu (India)",
  702. "Telugu (India)",
  703. "Tajik (Tajikistan)",
  704. "Chitwania Tharu (Nepal)",
  705. "Thai",
  706. "Thai (Thailand)",
  707. "Tigrinya",
  708. "Tigrinya (Eritrea)",
  709. "Tigrinya (Ethiopia)",
  710. "Tigre (Eritrea)",
  711. "Turkmen (Turkmenistan)",
  712. "Tagalog (Philippines)",
  713. "Tswana (South Africa)",
  714. "Turkish",
  715. "Turkish (Cyprus)",
  716. "Turkish (Turkey)",
  717. "Tsonga (South Africa)",
  718. "Tatar (Russia)",
  719. "Uighur (China)",
  720. "Ukrainian",
  721. "Ukrainian (Ukraine)",
  722. "Unami (United States)",
  723. "Urdu",
  724. "Urdu (India)",
  725. "Urdu (Pakistan)",
  726. "Uzbek",
  727. "Uzbek (Uzbekistan)",
  728. "Venda (South Africa)",
  729. "Vietnamese",
  730. "Vietnamese (Vietnam)",
  731. "Walloon (Belgium)",
  732. "Walser (Switzerland)",
  733. "Wolaytta (Ethiopia)",
  734. "Wolof (Senegal)",
  735. "Xhosa (South Africa)",
  736. "Yiddish (United States)",
  737. "Yoruba (Nigeria)",
  738. "Yue Chinese (Hong Kong)",
  739. "Chinese",
  740. "Chinese (China)",
  741. "Chinese (Hong Kong)",
  742. "Chinese (Singapore)",
  743. "Chinese (Taiwan)",
  744. "Zulu (South Africa)",
  745. 0
  746. };
  747. Vector<String> TranslationServer::get_all_locales() {
  748. Vector<String> locales;
  749. const char **ptr=locale_list;
  750. while (*ptr) {
  751. locales.push_back(*ptr);
  752. ptr++;
  753. }
  754. return locales;
  755. }
  756. Vector<String> TranslationServer::get_all_locale_names(){
  757. Vector<String> locales;
  758. const char **ptr=locale_names;
  759. while (*ptr) {
  760. locales.push_back(*ptr);
  761. ptr++;
  762. }
  763. return locales;
  764. }
  765. static String get_trimmed_locale(const String& p_locale) {
  766. return p_locale.substr(0,2);
  767. }
  768. static bool is_valid_locale(const String& p_locale) {
  769. const char **ptr=locale_list;
  770. while (*ptr) {
  771. if (p_locale==*ptr)
  772. return true;
  773. ptr++;
  774. }
  775. return false;
  776. }
  777. DVector<String> Translation::_get_messages() const {
  778. DVector<String> msgs;
  779. msgs.resize(translation_map.size()*2);
  780. int idx=0;
  781. for (const Map<StringName, StringName>::Element *E=translation_map.front();E;E=E->next()) {
  782. msgs.set(idx+0,E->key());
  783. msgs.set(idx+1,E->get());
  784. idx+=2;
  785. }
  786. return msgs;
  787. }
  788. DVector<String> Translation::_get_message_list() const {
  789. DVector<String> msgs;
  790. msgs.resize(translation_map.size());
  791. int idx=0;
  792. for (const Map<StringName, StringName>::Element *E=translation_map.front();E;E=E->next()) {
  793. msgs.set(idx,E->key());
  794. idx+=1;
  795. }
  796. return msgs;
  797. }
  798. void Translation::_set_messages(const DVector<String>& p_messages){
  799. int msg_count=p_messages.size();
  800. ERR_FAIL_COND(msg_count%2);
  801. DVector<String>::Read r = p_messages.read();
  802. for(int i=0;i<msg_count;i+=2) {
  803. add_message( r[i+0], r[i+1] );
  804. }
  805. }
  806. void Translation::set_locale(const String& p_locale) {
  807. // replaces '-' with '_' for macOS Sierra-style locales
  808. String univ_locale = p_locale.replace("-", "_");
  809. if(!is_valid_locale(univ_locale)) {
  810. String trimmed_locale = get_trimmed_locale(univ_locale);
  811. ERR_EXPLAIN("Invalid Locale: "+trimmed_locale);
  812. ERR_FAIL_COND(!is_valid_locale(trimmed_locale));
  813. locale=trimmed_locale;
  814. }
  815. else {
  816. locale=univ_locale;
  817. }
  818. }
  819. void Translation::add_message( const StringName& p_src_text, const StringName& p_xlated_text ) {
  820. translation_map[p_src_text]=p_xlated_text;
  821. }
  822. StringName Translation::get_message(const StringName& p_src_text) const {
  823. const Map<StringName, StringName>::Element *E=translation_map.find(p_src_text);
  824. if (!E)
  825. return StringName();
  826. return E->get();
  827. }
  828. void Translation::erase_message(const StringName& p_src_text) {
  829. translation_map.erase(p_src_text);
  830. }
  831. void Translation::get_message_list(List<StringName> *r_messages) const {
  832. for (const Map<StringName, StringName>::Element *E=translation_map.front();E;E=E->next()) {
  833. r_messages->push_back(E->key());
  834. }
  835. }
  836. int Translation::get_message_count() const {
  837. return translation_map.size();
  838. };
  839. void Translation::_bind_methods() {
  840. ObjectTypeDB::bind_method(_MD("set_locale","locale"),&Translation::set_locale);
  841. ObjectTypeDB::bind_method(_MD("get_locale"),&Translation::get_locale);
  842. ObjectTypeDB::bind_method(_MD("add_message","src_message","xlated_message"),&Translation::add_message);
  843. ObjectTypeDB::bind_method(_MD("get_message","src_message"),&Translation::get_message);
  844. ObjectTypeDB::bind_method(_MD("erase_message","src_message"),&Translation::erase_message);
  845. ObjectTypeDB::bind_method(_MD("get_message_list"),&Translation::_get_message_list);
  846. ObjectTypeDB::bind_method(_MD("get_message_count"),&Translation::get_message_count);
  847. ObjectTypeDB::bind_method(_MD("_set_messages"),&Translation::_set_messages);
  848. ObjectTypeDB::bind_method(_MD("_get_messages"),&Translation::_get_messages);
  849. ADD_PROPERTY( PropertyInfo(Variant::STRING_ARRAY,"messages",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR), _SCS("_set_messages"), _SCS("_get_messages") );
  850. ADD_PROPERTY( PropertyInfo(Variant::STRING,"locale"), _SCS("set_locale"), _SCS("get_locale") );
  851. }
  852. Translation::Translation() {
  853. locale="en";
  854. }
  855. ///////////////////////////////////////////////
  856. void TranslationServer::set_locale(const String& p_locale) {
  857. // replaces '-' with '_' for macOS Sierra-style locales
  858. String univ_locale = p_locale.replace("-", "_");
  859. if(!is_valid_locale(univ_locale)) {
  860. String trimmed_locale = get_trimmed_locale(univ_locale);
  861. ERR_EXPLAIN("Invalid Locale: "+trimmed_locale);
  862. ERR_FAIL_COND(!is_valid_locale(trimmed_locale));
  863. locale=trimmed_locale;
  864. }
  865. else {
  866. locale=univ_locale;
  867. }
  868. }
  869. String TranslationServer::get_locale() const {
  870. return locale;
  871. }
  872. void TranslationServer::add_translation(const Ref<Translation> &p_translation) {
  873. translations.insert(p_translation);
  874. }
  875. void TranslationServer::remove_translation(const Ref<Translation> &p_translation) {
  876. translations.erase(p_translation);
  877. }
  878. void TranslationServer::clear() {
  879. translations.clear();
  880. };
  881. StringName TranslationServer::translate(const StringName& p_message) const {
  882. //translate using locale
  883. if (!enabled)
  884. return p_message;
  885. StringName res;
  886. bool near_match=false;
  887. const CharType *lptr=&locale[0];
  888. for (const Set< Ref<Translation> >::Element *E=translations.front();E;E=E->next()) {
  889. const Ref<Translation>& t = E->get();
  890. String l = t->get_locale();
  891. if (lptr[0]!=l[0] || lptr[1]!=l[1])
  892. continue; // locale not match
  893. //near match
  894. bool match = (l!=locale);
  895. if (near_match && !match)
  896. continue; //only near-match once
  897. StringName r=t->get_message(p_message);
  898. if (!r)
  899. continue;
  900. res=r;
  901. if (match)
  902. break;
  903. else
  904. near_match=true;
  905. }
  906. if (!res) {
  907. //try again with fallback
  908. if (fallback.length()>=2) {
  909. const CharType *fptr=&fallback[0];
  910. bool near_match=false;
  911. for (const Set< Ref<Translation> >::Element *E=translations.front();E;E=E->next()) {
  912. const Ref<Translation>& t = E->get();
  913. String l = t->get_locale();
  914. if (fptr[0]!=l[0] || fptr[1]!=l[1])
  915. continue; // locale not match
  916. //near match
  917. bool match = (l!=fallback);
  918. if (near_match && !match)
  919. continue; //only near-match once
  920. StringName r=t->get_message(p_message);
  921. if (!r)
  922. continue;
  923. res=r;
  924. if (match)
  925. break;
  926. else
  927. near_match=true;
  928. }
  929. }
  930. }
  931. if (!res)
  932. return p_message;
  933. return res;
  934. }
  935. TranslationServer *TranslationServer::singleton=NULL;
  936. bool TranslationServer::_load_translations(const String& p_from) {
  937. if (Globals::get_singleton()->has(p_from)) {
  938. DVector<String> translations=Globals::get_singleton()->get(p_from);
  939. int tcount=translations.size();
  940. if (tcount) {
  941. DVector<String>::Read r = translations.read();
  942. for(int i=0;i<tcount;i++) {
  943. //print_line( "Loading translation from " + r[i] );
  944. Ref<Translation> tr = ResourceLoader::load(r[i]);
  945. if (tr.is_valid())
  946. add_translation(tr);
  947. }
  948. }
  949. return true;
  950. }
  951. return false;
  952. }
  953. void TranslationServer::setup() {
  954. String test = GLOBAL_DEF("locale/test","");
  955. test=test.strip_edges();
  956. if (test!="")
  957. set_locale( test );
  958. else
  959. set_locale( OS::get_singleton()->get_locale() );
  960. fallback = GLOBAL_DEF("locale/fallback","en");
  961. #ifdef TOOLS_ENABLED
  962. {
  963. String options="";
  964. int idx=0;
  965. while(locale_list[idx]) {
  966. if (idx>0)
  967. options+=", ";
  968. options+=locale_list[idx];
  969. idx++;
  970. }
  971. Globals::get_singleton()->set_custom_property_info("locale/fallback",PropertyInfo(Variant::STRING,"locale/fallback",PROPERTY_HINT_ENUM,options));
  972. }
  973. #endif
  974. //load translations
  975. }
  976. void TranslationServer::set_tool_translation(const Ref<Translation>& p_translation) {
  977. tool_translation=p_translation;
  978. }
  979. StringName TranslationServer::tool_translate(const StringName& p_message) const {
  980. if (tool_translation.is_valid()) {
  981. StringName r = tool_translation->get_message(p_message);
  982. if (r) {
  983. return r;
  984. }
  985. }
  986. return p_message;
  987. }
  988. void TranslationServer::_bind_methods() {
  989. ObjectTypeDB::bind_method(_MD("set_locale","locale"),&TranslationServer::set_locale);
  990. ObjectTypeDB::bind_method(_MD("get_locale"),&TranslationServer::get_locale);
  991. ObjectTypeDB::bind_method(_MD("translate","message"),&TranslationServer::translate);
  992. ObjectTypeDB::bind_method(_MD("add_translation","translation:Translation"),&TranslationServer::add_translation);
  993. ObjectTypeDB::bind_method(_MD("remove_translation","translation:Translation"),&TranslationServer::remove_translation);
  994. ObjectTypeDB::bind_method(_MD("clear"),&TranslationServer::clear);
  995. }
  996. void TranslationServer::load_translations() {
  997. String locale = get_locale();
  998. bool found = _load_translations("locale/translations"); //all
  999. if (_load_translations("locale/translations_"+locale.substr(0,2)))
  1000. found=true;
  1001. if ( locale.substr(0,2) != locale ) {
  1002. if (_load_translations("locale/translations_"+locale))
  1003. found=true;
  1004. }
  1005. }
  1006. TranslationServer::TranslationServer() {
  1007. singleton=this;
  1008. locale="en";
  1009. enabled=true;
  1010. }