translation.cpp 29 KB

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