diff options
author | Michael Alexsander <michaelalexsander@protonmail.com> | 2023-12-15 20:56:06 -0300 |
---|---|---|
committer | Michael Alexsander <michaelalexsander@protonmail.com> | 2024-02-28 11:34:26 -0300 |
commit | d70c45b5c85022fb02224235ff6df24ebf83dcf1 (patch) | |
tree | dc37699af2d104e811a67d220fa270abcd206b10 /editor/editor_translation.cpp | |
parent | df78c0636d79c9545a283e0e2a926d623998cc27 (diff) | |
download | redot-engine-d70c45b5c85022fb02224235ff6df24ebf83dcf1.tar.gz |
Add option to add built-in strings in the POT generation
Diffstat (limited to 'editor/editor_translation.cpp')
-rw-r--r-- | editor/editor_translation.cpp | 59 |
1 files changed, 56 insertions, 3 deletions
diff --git a/editor/editor_translation.cpp b/editor/editor_translation.cpp index 54a9d2f068..302a81669d 100644 --- a/editor/editor_translation.cpp +++ b/editor/editor_translation.cpp @@ -35,6 +35,7 @@ #include "core/io/translation_loader_po.h" #include "editor/doc_translations.gen.h" #include "editor/editor_translations.gen.h" +#include "editor/extractable_translations.gen.h" #include "editor/property_translations.gen.h" Vector<String> get_editor_locales() { @@ -77,6 +78,32 @@ void load_editor_translations(const String &p_locale) { } } +void load_property_translations(const String &p_locale) { + PropertyTranslationList *etl = _property_translations; + while (etl->data) { + if (etl->lang == p_locale) { + Vector<uint8_t> data; + data.resize(etl->uncomp_size); + int ret = Compression::decompress(data.ptrw(), etl->uncomp_size, etl->data, etl->comp_size, Compression::MODE_DEFLATE); + ERR_FAIL_COND_MSG(ret == -1, "Compressed file is corrupt."); + + Ref<FileAccessMemory> fa; + fa.instantiate(); + fa->open_custom(data.ptr(), data.size()); + + Ref<Translation> tr = TranslationLoaderPO::load_translation(fa); + + if (tr.is_valid()) { + tr->set_locale(etl->lang); + TranslationServer::get_singleton()->set_property_translation(tr); + break; + } + } + + etl++; + } +} + void load_doc_translations(const String &p_locale) { DocTranslationList *dtl = _doc_translations; while (dtl->data) { @@ -103,8 +130,8 @@ void load_doc_translations(const String &p_locale) { } } -void load_property_translations(const String &p_locale) { - PropertyTranslationList *etl = _property_translations; +void load_extractable_translations(const String &p_locale) { + ExtractableTranslationList *etl = _extractable_translations; while (etl->data) { if (etl->lang == p_locale) { Vector<uint8_t> data; @@ -120,7 +147,7 @@ void load_property_translations(const String &p_locale) { if (tr.is_valid()) { tr->set_locale(etl->lang); - TranslationServer::get_singleton()->set_property_translation(tr); + TranslationServer::get_singleton()->set_extractable_translation(tr); break; } } @@ -128,3 +155,29 @@ void load_property_translations(const String &p_locale) { etl++; } } + +List<StringName> get_extractable_message_list() { + ExtractableTranslationList *etl = _extractable_translations; + List<StringName> msgids; + while (etl->data) { + Vector<uint8_t> data; + data.resize(etl->uncomp_size); + int ret = Compression::decompress(data.ptrw(), etl->uncomp_size, etl->data, etl->comp_size, Compression::MODE_DEFLATE); + ERR_FAIL_COND_V_MSG(ret == -1, msgids, "Compressed file is corrupt."); + + Ref<FileAccessMemory> fa; + fa.instantiate(); + fa->open_custom(data.ptr(), data.size()); + + Ref<Translation> tr = TranslationLoaderPO::load_translation(fa); + + if (tr.is_valid()) { + tr->get_message_list(&msgids); + break; + } + + etl++; + } + + return msgids; +} |