diff options
author | Bernhard Liebl <Bernhard.Liebl@gmx.org> | 2018-01-06 13:17:12 +0100 |
---|---|---|
committer | Bernhard Liebl <Bernhard.Liebl@gmx.org> | 2018-01-06 13:18:28 +0100 |
commit | 7ef4caa6910335c100333f0cb33ceafac2ef1e26 (patch) | |
tree | c09429c3dca33300e221552a34dafb65eab8a919 | |
parent | fab0d53f7ef94e0eaf8ad4f1dbe1f8746b0cfdd4 (diff) |
Load needed translation on demand
-rw-r--r-- | editor/editor_settings.cpp | 56 | ||||
-rw-r--r-- | editor/editor_settings.h | 1 |
2 files changed, 29 insertions, 28 deletions
diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp index be03e24eee..241ccec6e1 100644 --- a/editor/editor_settings.cpp +++ b/editor/editor_settings.cpp @@ -248,8 +248,11 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) { String best; - for (int i = 0; i < translations.size(); i++) { - String locale = translations[i]->get_locale(); + EditorTranslationList *etl = _editor_translations; + + while (etl->data) { + + const String &locale = etl->lang; lang_hint += ","; lang_hint += locale; @@ -260,6 +263,8 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) { if (best == String() && host_lang.begins_with(locale)) { best = locale; } + + etl++; } if (best == String()) { @@ -874,11 +879,29 @@ void EditorSettings::setup_language() { if (lang == "en") return; //none to do - for (int i = 0; i < translations.size(); i++) { - if (translations[i]->get_locale() == lang) { - TranslationServer::get_singleton()->set_tool_translation(translations[i]); - break; + EditorTranslationList *etl = _editor_translations; + + while (etl->data) { + + if (etl->lang == lang) { + + Vector<uint8_t> data; + data.resize(etl->uncomp_size); + Compression::decompress(data.ptrw(), etl->uncomp_size, etl->data, etl->comp_size, Compression::MODE_DEFLATE); + + FileAccessMemory *fa = memnew(FileAccessMemory); + fa->open_custom(data.ptr(), data.size()); + + Ref<Translation> tr = TranslationLoaderPO::load_translation(fa, NULL, "translation_" + String(etl->lang)); + + if (tr.is_valid()) { + tr->set_locale(etl->lang); + TranslationServer::get_singleton()->set_tool_translation(tr); + break; + } } + + etl++; } } @@ -1443,27 +1466,6 @@ EditorSettings::EditorSettings() { optimize_save = true; save_changed_setting = true; - EditorTranslationList *etl = _editor_translations; - - while (etl->data) { - - Vector<uint8_t> data; - data.resize(etl->uncomp_size); - Compression::decompress(data.ptrw(), etl->uncomp_size, etl->data, etl->comp_size, Compression::MODE_DEFLATE); - - FileAccessMemory *fa = memnew(FileAccessMemory); - fa->open_custom(data.ptr(), data.size()); - - Ref<Translation> tr = TranslationLoaderPO::load_translation(fa, NULL, "translation_" + String(etl->lang)); - - if (tr.is_valid()) { - tr->set_locale(etl->lang); - translations.push_back(tr); - } - - etl++; - } - _load_defaults(); } diff --git a/editor/editor_settings.h b/editor/editor_settings.h index 0a20212ccd..63c32b3a64 100644 --- a/editor/editor_settings.h +++ b/editor/editor_settings.h @@ -95,7 +95,6 @@ private: int last_order; Ref<Resource> clipboard; - Vector<Ref<Translation> > translations; Map<String, Ref<ShortCut> > shortcuts; String resource_path; |