translation.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  1. /*************************************************************************/
  2. /* translation.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2015 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. "ar", // Arabic
  35. "ar_AE", // Arabic (United Arab Emirates)
  36. "ar_BH", // Arabic (Bahrain)
  37. "ar_DZ", // Arabic (Algeria)
  38. "ar_EG", // Arabic (Egypt)
  39. "ar_IQ", // Arabic (Iraq)
  40. "ar_JO", // Arabic (Jordan)
  41. "ar_KW", // Arabic (Kuwait)
  42. "ar_LB", // Arabic (Lebanon)
  43. "ar_LY", // Arabic (Libya)
  44. "ar_MA", // Arabic (Morocco)
  45. "ar_OM", // Arabic (Oman)
  46. "ar_QA", // Arabic (Qatar)
  47. "ar_SA", // Arabic (Saudi Arabia)
  48. "ar_SD", // Arabic (Sudan)
  49. "ar_SY", // Arabic (Syria)
  50. "ar_TN", // Arabic (Tunisia)
  51. "ar_YE", // Arabic (Yemen)
  52. "be", // Belarusian
  53. "be_BY", // Belarusian (Belarus)
  54. "bg", // Bulgarian
  55. "bg_BG", // Bulgarian (Bulgaria)
  56. "ca", // Catalan
  57. "ca_ES", // Catalan (Spain)
  58. "cs", // Czech
  59. "cs_CZ", // Czech (Czech Republic)
  60. "da", // Danish
  61. "da_DK", // Danish (Denmark)
  62. "de", // German
  63. "de_AT", // German (Austria)
  64. "de_CH", // German (Switzerland)
  65. "de_DE", // German (Germany)
  66. "de_LU", // German (Luxembourg)
  67. "el", // Greek
  68. "el_CY", // Greek (Cyprus)
  69. "el_GR", // Greek (Greece)
  70. "en", // English
  71. "en_AU", // English (Australia)
  72. "en_CA", // English (Canada)
  73. "en_GB", // English (United Kingdom)
  74. "en_IE", // English (Ireland)
  75. "en_IN", // English (India)
  76. "en_MT", // English (Malta)
  77. "en_NZ", // English (New Zealand)
  78. "en_PH", // English (Philippines)
  79. "en_SG", // English (Singapore)
  80. "en_US", // English (United States)
  81. "en_ZA", // English (South Africa)
  82. "es", // Spanish
  83. "es_AR", // Spanish (Argentina)
  84. "es_BO", // Spanish (Bolivia)
  85. "es_CL", // Spanish (Chile)
  86. "es_CO", // Spanish (Colombia)
  87. "es_CR", // Spanish (Costa Rica)
  88. "es_DO", // Spanish (Dominican Republic)
  89. "es_EC", // Spanish (Ecuador)
  90. "es_ES", // Spanish (Spain)
  91. "es_GT", // Spanish (Guatemala)
  92. "es_HN", // Spanish (Honduras)
  93. "es_MX", // Spanish (Mexico)
  94. "es_NI", // Spanish (Nicaragua)
  95. "es_PA", // Spanish (Panama)
  96. "es_PE", // Spanish (Peru)
  97. "es_PR", // Spanish (Puerto Rico)
  98. "es_PY", // Spanish (Paraguay)
  99. "es_SV", // Spanish (El Salvador)
  100. "es_US", // Spanish (United States)
  101. "es_UY", // Spanish (Uruguay)
  102. "es_VE", // Spanish (Venezuela)
  103. "et", // Estonian
  104. "et_EE", // Estonian (Estonia)
  105. "fi", // Finnish
  106. "fi_FI", // Finnish (Finland)
  107. "fr", // French
  108. "fr_BE", // French (Belgium)
  109. "fr_CA", // French (Canada)
  110. "fr_CH", // French (Switzerland)
  111. "fr_FR", // French (France)
  112. "fr_LU", // French (Luxembourg)
  113. "ga", // Irish
  114. "ga_IE", // Irish (Ireland)
  115. "hi", // Hindi (India)
  116. "hi_IN", // Hindi (India)
  117. "hr", // Croatian
  118. "hr_HR", // Croatian (Croatia)
  119. "hu", // Hungarian
  120. "hu_HU", // Hungarian (Hungary)
  121. "in", // Indonesian
  122. "in_ID", // Indonesian (Indonesia)
  123. "is", // Icelandic
  124. "is_IS", // Icelandic (Iceland)
  125. "it", // Italian
  126. "it_CH", // Italian (Switzerland)
  127. "it_IT", // Italian (Italy)
  128. "iw", // Hebrew
  129. "iw_IL", // Hebrew (Israel)
  130. "ja", // Japanese
  131. "ja_JP", // Japanese (Japan)
  132. "ja_JP_JP", // Japanese (Japan,JP)
  133. "ko", // Korean
  134. "ko_KR", // Korean (South Korea)
  135. "lt", // Lithuanian
  136. "lt_LT", // Lithuanian (Lithuania)
  137. "lv", // Latvian
  138. "lv_LV", // Latvian (Latvia)
  139. "mk", // Macedonian
  140. "mk_MK", // Macedonian (Macedonia)
  141. "ms", // Malay
  142. "ms_MY", // Malay (Malaysia)
  143. "mt", // Maltese
  144. "mt_MT", // Maltese (Malta)
  145. "nl", // Dutch
  146. "nl_BE", // Dutch (Belgium)
  147. "nl_NL", // Dutch (Netherlands)
  148. "no", // Norwegian
  149. "no_NO", // Norwegian (Norway)
  150. "no_NO_NY", // Norwegian (Norway,Nynorsk)
  151. "pl", // Polish
  152. "pl_PL", // Polish (Poland)
  153. "pt", // Portuguese
  154. "pt_BR", // Portuguese (Brazil)
  155. "pt_PT", // Portuguese (Portugal)
  156. "ro", // Romanian
  157. "ro_RO", // Romanian (Romania)
  158. "ru", // Russian
  159. "ru_RU", // Russian (Russia)
  160. "sk", // Slovak
  161. "sk_SK", // Slovak (Slovakia)
  162. "sl", // Slovenian
  163. "sl_SI", // Slovenian (Slovenia)
  164. "sq", // Albanian
  165. "sq_AL", // Albanian (Albania)
  166. "sr", // Serbian
  167. "sr_BA", // Serbian (Bosnia and Herzegovina)
  168. "sr_CS", // Serbian (Serbia and Montenegro)
  169. "sr_ME", // Serbian (Montenegro)
  170. "sr_RS", // Serbian (Serbia)
  171. "sv", // Swedish
  172. "sv_SE", // Swedish (Sweden)
  173. "th", // Thai
  174. "th_TH", // Thai (Thailand)
  175. "th_TH_TH", // Thai (Thailand,TH)
  176. "tr", // Turkish
  177. "tr_TR", // Turkish (Turkey)
  178. "uk", // Ukrainian
  179. "uk_UA", // Ukrainian (Ukraine)
  180. "vi", // Vietnamese
  181. "vi_VN", // Vietnamese (Vietnam)
  182. "zh", // Chinese
  183. "zh_CN", // Chinese (China)
  184. "zh_HK", // Chinese (Hong Kong)
  185. "zh_SG", // Chinese (Singapore)
  186. "zh_TW", // Chinese (Taiwan)
  187. 0
  188. };
  189. static const char* locale_names[]={
  190. "Arabic",
  191. "Arabic (United Arab Emirates)",
  192. "Arabic (Bahrain)",
  193. "Arabic (Algeria)",
  194. "Arabic (Egypt)",
  195. "Arabic (Iraq)",
  196. "Arabic (Jordan)",
  197. "Arabic (Kuwait)",
  198. "Arabic (Lebanon)",
  199. "Arabic (Libya)",
  200. "Arabic (Morocco)",
  201. "Arabic (Oman)",
  202. "Arabic (Qatar)",
  203. "Arabic (Saudi Arabia)",
  204. "Arabic (Sudan)",
  205. "Arabic (Syria)",
  206. "Arabic (Tunisia)",
  207. "Arabic (Yemen)",
  208. "Belarusian",
  209. "Belarusian (Belarus)",
  210. "Bulgarian",
  211. "Bulgarian (Bulgaria)",
  212. "Catalan",
  213. "Catalan (Spain)",
  214. "Czech",
  215. "Czech (Czech Republic)",
  216. "Danish",
  217. "Danish (Denmark)",
  218. "German",
  219. "German (Austria)",
  220. "German (Switzerland)",
  221. "German (Germany)",
  222. "German (Luxembourg)",
  223. "Greek",
  224. "Greek (Cyprus)",
  225. "Greek (Greece)",
  226. "English",
  227. "English (Australia)",
  228. "English (Canada)",
  229. "English (United Kingdom)",
  230. "English (Ireland)",
  231. "English (India)",
  232. "English (Malta)",
  233. "English (New Zealand)",
  234. "English (Philippines)",
  235. "English (Singapore)",
  236. "English (United States)",
  237. "English (South Africa)",
  238. "Spanish",
  239. "Spanish (Argentina)",
  240. "Spanish (Bolivia)",
  241. "Spanish (Chile)",
  242. "Spanish (Colombia)",
  243. "Spanish (Costa Rica)",
  244. "Spanish (Dominican Republic)",
  245. "Spanish (Ecuador)",
  246. "Spanish (Spain)",
  247. "Spanish (Guatemala)",
  248. "Spanish (Honduras)",
  249. "Spanish (Mexico)",
  250. "Spanish (Nicaragua)",
  251. "Spanish (Panama)",
  252. "Spanish (Peru)",
  253. "Spanish (Puerto Rico)",
  254. "Spanish (Paraguay)",
  255. "Spanish (El Salvador)",
  256. "Spanish (United States)",
  257. "Spanish (Uruguay)",
  258. "Spanish (Venezuela)",
  259. "Estonian",
  260. "Estonian (Estonia)",
  261. "Finnish",
  262. "Finnish (Finland)",
  263. "French",
  264. "French (Belgium)",
  265. "French (Canada)",
  266. "French (Switzerland)",
  267. "French (France)",
  268. "French (Luxembourg)",
  269. "Irish",
  270. "Irish (Ireland)",
  271. "Hindi (India)",
  272. "Hindi (India)",
  273. "Croatian",
  274. "Croatian (Croatia)",
  275. "Hungarian",
  276. "Hungarian (Hungary)",
  277. "Indonesian",
  278. "Indonesian (Indonesia)",
  279. "Icelandic",
  280. "Icelandic (Iceland)",
  281. "Italian",
  282. "Italian (Switzerland)",
  283. "Italian (Italy)",
  284. "Hebrew",
  285. "Hebrew (Israel)",
  286. "Japanese",
  287. "Japanese (Japan)",
  288. "Japanese (Japan JP)",
  289. "Korean",
  290. "Korean (South Korea)",
  291. "Lithuanian",
  292. "Lithuanian (Lithuania)",
  293. "Latvian",
  294. "Latvian (Latvia)",
  295. "Macedonian",
  296. "Macedonian (Macedonia)",
  297. "Malay",
  298. "Malay (Malaysia)",
  299. "Maltese",
  300. "Maltese (Malta)",
  301. "Dutch",
  302. "Dutch (Belgium)",
  303. "Dutch (Netherlands)",
  304. "Norwegian",
  305. "Norwegian (Norway)",
  306. "Norwegian (Norway Nynorsk)",
  307. "Polish",
  308. "Polish (Poland)",
  309. "Portuguese",
  310. "Portuguese (Brazil)",
  311. "Portuguese (Portugal)",
  312. "Romanian",
  313. "Romanian (Romania)",
  314. "Russian",
  315. "Russian (Russia)",
  316. "Slovak",
  317. "Slovak (Slovakia)",
  318. "Slovenian",
  319. "Slovenian (Slovenia)",
  320. "Albanian",
  321. "Albanian (Albania)",
  322. "Serbian",
  323. "Serbian (Bosnia and Herzegovina)",
  324. "Serbian (Serbia and Montenegro)",
  325. "Serbian (Montenegro)",
  326. "Serbian (Serbia)",
  327. "Swedish",
  328. "Swedish (Sweden)",
  329. "Thai",
  330. "Thai (Thailand)",
  331. "Thai (Thailand TH)",
  332. "Turkish",
  333. "Turkish (Turkey)",
  334. "Ukrainian",
  335. "Ukrainian (Ukraine)",
  336. "Vietnamese",
  337. "Vietnamese (Vietnam)",
  338. "Chinese",
  339. "Chinese (China)",
  340. "Chinese (Hong Kong)",
  341. "Chinese (Singapore)",
  342. "Chinese (Taiwan)",
  343. 0
  344. };
  345. Vector<String> TranslationServer::get_all_locales() {
  346. Vector<String> locales;
  347. const char **ptr=locale_list;
  348. while (*ptr) {
  349. locales.push_back(*ptr);
  350. ptr++;
  351. }
  352. return locales;
  353. }
  354. Vector<String> TranslationServer::get_all_locale_names(){
  355. Vector<String> locales;
  356. const char **ptr=locale_names;
  357. while (*ptr) {
  358. locales.push_back(*ptr);
  359. ptr++;
  360. }
  361. return locales;
  362. }
  363. static bool is_valid_locale(const String& p_locale) {
  364. const char **ptr=locale_list;
  365. while (*ptr) {
  366. if (p_locale==*ptr)
  367. return true;
  368. ptr++;
  369. }
  370. return false;
  371. }
  372. DVector<String> Translation::_get_messages() const {
  373. DVector<String> msgs;
  374. msgs.resize(translation_map.size()*2);
  375. int idx=0;
  376. for (const Map<StringName, StringName>::Element *E=translation_map.front();E;E=E->next()) {
  377. msgs.set(idx+0,E->key());
  378. msgs.set(idx+1,E->get());
  379. idx+=2;
  380. }
  381. return msgs;
  382. }
  383. DVector<String> Translation::_get_message_list() const {
  384. DVector<String> msgs;
  385. msgs.resize(translation_map.size());
  386. int idx=0;
  387. for (const Map<StringName, StringName>::Element *E=translation_map.front();E;E=E->next()) {
  388. msgs.set(idx,E->key());
  389. idx+=1;
  390. }
  391. return msgs;
  392. }
  393. void Translation::_set_messages(const DVector<String>& p_messages){
  394. int msg_count=p_messages.size();
  395. ERR_FAIL_COND(msg_count%2);
  396. DVector<String>::Read r = p_messages.read();
  397. for(int i=0;i<msg_count;i+=2) {
  398. add_message( r[i+0], r[i+1] );
  399. }
  400. }
  401. void Translation::set_locale(const String& p_locale) {
  402. ERR_EXPLAIN("Invalid Locale: "+p_locale);
  403. ERR_FAIL_COND(!is_valid_locale(p_locale));
  404. locale=p_locale;
  405. }
  406. void Translation::add_message( const StringName& p_src_text, const StringName& p_xlated_text ) {
  407. translation_map[p_src_text]=p_xlated_text;
  408. }
  409. StringName Translation::get_message(const StringName& p_src_text) const {
  410. const Map<StringName, StringName>::Element *E=translation_map.find(p_src_text);
  411. if (!E)
  412. return StringName();
  413. return E->get();
  414. }
  415. void Translation::erase_message(const StringName& p_src_text) {
  416. translation_map.erase(p_src_text);
  417. }
  418. void Translation::get_message_list(List<StringName> *r_messages) const {
  419. for (const Map<StringName, StringName>::Element *E=translation_map.front();E;E=E->next()) {
  420. r_messages->push_back(E->key());
  421. }
  422. }
  423. int Translation::get_message_count() const {
  424. return translation_map.size();
  425. };
  426. void Translation::_bind_methods() {
  427. ObjectTypeDB::bind_method(_MD("set_locale","locale"),&Translation::set_locale);
  428. ObjectTypeDB::bind_method(_MD("get_locale"),&Translation::get_locale);
  429. ObjectTypeDB::bind_method(_MD("add_message","src_message","xlated_message"),&Translation::add_message);
  430. ObjectTypeDB::bind_method(_MD("get_message","src_message"),&Translation::get_message);
  431. ObjectTypeDB::bind_method(_MD("erase_message","src_message"),&Translation::erase_message);
  432. ObjectTypeDB::bind_method(_MD("get_message_list"),&Translation::_get_message_list);
  433. ObjectTypeDB::bind_method(_MD("get_message_count"),&Translation::get_message_count);
  434. ObjectTypeDB::bind_method(_MD("_set_messages"),&Translation::_set_messages);
  435. ObjectTypeDB::bind_method(_MD("_get_messages"),&Translation::_get_messages);
  436. ADD_PROPERTY( PropertyInfo(Variant::STRING_ARRAY,"messages",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR), _SCS("_set_messages"), _SCS("_get_messages") );
  437. ADD_PROPERTY( PropertyInfo(Variant::STRING,"locale"), _SCS("set_locale"), _SCS("get_locale") );
  438. }
  439. Translation::Translation() {
  440. locale="en";
  441. }
  442. ///////////////////////////////////////////////
  443. void TranslationServer::set_locale(const String& p_locale) {
  444. ERR_EXPLAIN("Invalid Locale: "+p_locale);
  445. ERR_FAIL_COND(!is_valid_locale(p_locale));
  446. locale=p_locale;
  447. }
  448. String TranslationServer::get_locale() const {
  449. return locale;
  450. }
  451. void TranslationServer::add_translation(const Ref<Translation> &p_translation) {
  452. translations.insert(p_translation);
  453. }
  454. void TranslationServer::remove_translation(const Ref<Translation> &p_translation) {
  455. translations.erase(p_translation);
  456. }
  457. void TranslationServer::clear() {
  458. translations.clear();
  459. };
  460. StringName TranslationServer::translate(const StringName& p_message) const {
  461. //translate using locale
  462. if (!enabled)
  463. return p_message;
  464. StringName res;
  465. bool near_match=false;
  466. const CharType *lptr=&locale[0];
  467. for (const Set< Ref<Translation> >::Element *E=translations.front();E;E=E->next()) {
  468. const Ref<Translation>& t = E->get();
  469. String l = t->get_locale();
  470. if (lptr[0]!=l[0] || lptr[1]!=l[1])
  471. continue; // locale not match
  472. //near match
  473. bool match = (l!=locale);
  474. if (near_match && !match)
  475. continue; //only near-match once
  476. StringName r=t->get_message(p_message);
  477. if (!r)
  478. continue;
  479. res=r;
  480. if (match)
  481. break;
  482. else
  483. near_match=true;
  484. }
  485. if (!res) {
  486. //try again with fallback
  487. if (fallback.length()>=2) {
  488. const CharType *fptr=&fallback[0];
  489. bool near_match=false;
  490. for (const Set< Ref<Translation> >::Element *E=translations.front();E;E=E->next()) {
  491. const Ref<Translation>& t = E->get();
  492. String l = t->get_locale();
  493. if (fptr[0]!=l[0] || fptr[1]!=l[1])
  494. continue; // locale not match
  495. //near match
  496. bool match = (l!=fallback);
  497. if (near_match && !match)
  498. continue; //only near-match once
  499. StringName r=t->get_message(p_message);
  500. if (!r)
  501. continue;
  502. res=r;
  503. if (match)
  504. break;
  505. else
  506. near_match=true;
  507. }
  508. }
  509. }
  510. if (!res)
  511. return p_message;
  512. return res;
  513. }
  514. TranslationServer *TranslationServer::singleton=NULL;
  515. bool TranslationServer::_load_translations(const String& p_from) {
  516. if (Globals::get_singleton()->has(p_from)) {
  517. DVector<String> translations=Globals::get_singleton()->get(p_from);
  518. int tcount=translations.size();
  519. if (tcount) {
  520. DVector<String>::Read r = translations.read();
  521. for(int i=0;i<tcount;i++) {
  522. print_line( "Loading translation from " + r[i] );
  523. Ref<Translation> tr = ResourceLoader::load(r[i]);
  524. if (tr.is_valid())
  525. add_translation(tr);
  526. }
  527. }
  528. return true;
  529. }
  530. return false;
  531. }
  532. void TranslationServer::setup() {
  533. String test = GLOBAL_DEF("locale/test","");
  534. test=test.strip_edges();
  535. if (test!="")
  536. set_locale( test );
  537. else
  538. set_locale( OS::get_singleton()->get_locale() );
  539. fallback = GLOBAL_DEF("locale/fallback","en");
  540. #ifdef TOOLS_ENABLED
  541. {
  542. String options="";
  543. int idx=0;
  544. while(locale_list[idx]) {
  545. if (idx>0)
  546. options+=", ";
  547. options+=locale_list[idx];
  548. idx++;
  549. }
  550. Globals::get_singleton()->set_custom_property_info("locale/fallback",PropertyInfo(Variant::STRING,"locale/fallback",PROPERTY_HINT_ENUM,options));
  551. }
  552. #endif
  553. //load translations
  554. }
  555. void TranslationServer::_bind_methods() {
  556. ObjectTypeDB::bind_method(_MD("set_locale","locale"),&TranslationServer::set_locale);
  557. ObjectTypeDB::bind_method(_MD("get_locale"),&TranslationServer::get_locale);
  558. ObjectTypeDB::bind_method(_MD("translate"),&TranslationServer::translate);
  559. ObjectTypeDB::bind_method(_MD("add_translation"),&TranslationServer::add_translation);
  560. ObjectTypeDB::bind_method(_MD("remove_translation"),&TranslationServer::remove_translation);
  561. ObjectTypeDB::bind_method(_MD("clear"),&TranslationServer::clear);
  562. }
  563. void TranslationServer::load_translations() {
  564. String locale = get_locale();
  565. bool found = _load_translations("locale/translations"); //all
  566. if (_load_translations("locale/translations_"+locale.substr(0,2)))
  567. found=true;
  568. if ( locale.substr(0,2) != locale ) {
  569. if (_load_translations("locale/translations_"+locale))
  570. found=true;
  571. }
  572. }
  573. TranslationServer::TranslationServer() {
  574. singleton=this;
  575. locale="en";
  576. enabled=true;
  577. }