diff options
author | Haoyu Qiu <timothyqiu32@gmail.com> | 2022-12-27 10:58:01 +0800 |
---|---|---|
committer | RĂ©mi Verschelde <rverschelde@gmail.com> | 2023-02-07 14:20:40 +0100 |
commit | 5d7e003b29cf9b57168e459469e13468a49c3da6 (patch) | |
tree | 2303ec8b584f3949acc4acf1396ef47b6a2d86ca | |
parent | bdad9770d64914da3b77bee49916419b5df87d1c (diff) |
Prepare for moving editor and classref translations to godot-editor-l10n repo
- Separate editor interface and property translations.
- Add property translation in TranslationServer.
- The split and merge of the POT/PO/Makefiles and extract scripts is done
directly in godot-editor-l10n, the files will be removed in the next commit.
- Remove the hardcoded "to_include" lists from the SCsub, we'll only commit the
files which are ready to inclue.
-rw-r--r-- | core/string/translation.cpp | 14 | ||||
-rw-r--r-- | core/string/translation.h | 3 | ||||
-rw-r--r-- | editor/SCsub | 17 | ||||
-rw-r--r-- | editor/editor_builders.py | 4 | ||||
-rw-r--r-- | editor/editor_inspector.cpp | 4 | ||||
-rw-r--r-- | editor/editor_property_name_processor.cpp | 19 | ||||
-rw-r--r-- | editor/editor_property_name_processor.h | 3 | ||||
-rw-r--r-- | editor/editor_settings.cpp | 1 | ||||
-rw-r--r-- | editor/editor_translation.cpp | 27 | ||||
-rw-r--r-- | editor/editor_translation.h | 1 |
10 files changed, 82 insertions, 11 deletions
diff --git a/core/string/translation.cpp b/core/string/translation.cpp index 60dca8ebc6..b9d5d3b538 100644 --- a/core/string/translation.cpp +++ b/core/string/translation.cpp @@ -768,6 +768,20 @@ StringName TranslationServer::doc_translate_plural(const StringName &p_message, return p_message_plural; } +void TranslationServer::set_property_translation(const Ref<Translation> &p_translation) { + property_translation = p_translation; +} + +StringName TranslationServer::property_translate(const StringName &p_message) const { + if (property_translation.is_valid()) { + StringName r = property_translation->get_message(p_message); + if (r) { + return r; + } + } + return p_message; +} + bool TranslationServer::is_pseudolocalization_enabled() const { return pseudolocalization_enabled; } diff --git a/core/string/translation.h b/core/string/translation.h index 8646635eb8..01d239f81c 100644 --- a/core/string/translation.h +++ b/core/string/translation.h @@ -78,6 +78,7 @@ class TranslationServer : public Object { HashSet<Ref<Translation>> translations; Ref<Translation> tool_translation; Ref<Translation> doc_translation; + Ref<Translation> property_translation; bool enabled = true; @@ -174,6 +175,8 @@ public: void set_doc_translation(const Ref<Translation> &p_translation); StringName doc_translate(const StringName &p_message, const StringName &p_context = "") const; StringName doc_translate_plural(const StringName &p_message, const StringName &p_message_plural, int p_n, const StringName &p_context = "") const; + void set_property_translation(const Ref<Translation> &p_translation); + StringName property_translate(const StringName &p_message) const; void setup(); diff --git a/editor/SCsub b/editor/SCsub index 32ad88add5..dddec55ed6 100644 --- a/editor/SCsub +++ b/editor/SCsub @@ -75,10 +75,7 @@ if env.editor_build: # Generated with `make include-list` for each resource. # Editor translations - to_include = ( - "ar,bg,ca,cs,de,el,eo,es_AR,es,fi,fr,gl,he,hu,id,it,ja,ko,lv,ms,nb,nl,pl,pt_BR,pt,ro,ru,sk,sv,th,tr,uk,vi,zh_CN,zh_TW" - ).split(",") - tlist = [env.Dir("#editor/translations").abspath + "/" + f + ".po" for f in to_include] + tlist = glob.glob(env.Dir("#editor/translations/editor").abspath + "/*.po") env.Depends("#editor/editor_translations.gen.h", tlist) env.CommandNoCache( "#editor/editor_translations.gen.h", @@ -86,9 +83,17 @@ if env.editor_build: env.Run(editor_builders.make_editor_translations_header, "Generating editor translations header."), ) + # Property translations + tlist = glob.glob(env.Dir("#editor/translations/properties").abspath + "/*.po") + env.Depends("#editor/property_translations.gen.h", tlist) + env.CommandNoCache( + "#editor/property_translations.gen.h", + tlist, + env.Run(editor_builders.make_property_translations_header, "Generating property translations header."), + ) + # Documentation translations - to_include = "de,es,fr,ja,zh_CN".split(",") - tlist = [env.Dir("#doc/translations").abspath + "/" + f + ".po" for f in to_include] + tlist = glob.glob(env.Dir("#doc/translations").abspath + "/*.po") env.Depends("#editor/doc_translations.gen.h", tlist) env.CommandNoCache( "#editor/doc_translations.gen.h", diff --git a/editor/editor_builders.py b/editor/editor_builders.py index 696e3b64ec..2a4f79548f 100644 --- a/editor/editor_builders.py +++ b/editor/editor_builders.py @@ -161,6 +161,10 @@ def make_editor_translations_header(target, source, env): make_translations_header(target, source, env, "editor") +def make_property_translations_header(target, source, env): + make_translations_header(target, source, env, "property") + + def make_doc_translations_header(target, source, env): make_translations_header(target, source, env, "doc") diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp index 42d8f48ea0..275e47e370 100644 --- a/editor/editor_inspector.cpp +++ b/editor/editor_inspector.cpp @@ -2974,11 +2974,11 @@ void EditorInspector::update_tree() { // Only process group label if this is not the group or subgroup. if ((i == 0 && component == group) || (i == 1 && component == subgroup)) { if (section_name_style == EditorPropertyNameProcessor::STYLE_LOCALIZED) { - label = TTRGET(component); + label = EditorPropertyNameProcessor::get_singleton()->translate_group_name(component); tooltip = component; } else { label = component; - tooltip = TTRGET(component); + tooltip = EditorPropertyNameProcessor::get_singleton()->translate_group_name(component); } } else { label = EditorPropertyNameProcessor::get_singleton()->process_name(component, section_name_style); diff --git a/editor/editor_property_name_processor.cpp b/editor/editor_property_name_processor.cpp index 5380fddde2..a183e62618 100644 --- a/editor/editor_property_name_processor.cpp +++ b/editor/editor_property_name_processor.cpp @@ -30,6 +30,7 @@ #include "editor_property_name_processor.h" +#include "core/string/translation.h" #include "editor_settings.h" EditorPropertyNameProcessor *EditorPropertyNameProcessor::singleton = nullptr; @@ -92,18 +93,30 @@ String EditorPropertyNameProcessor::process_name(const String &p_name, Style p_s } break; case STYLE_LOCALIZED: { - return TTRGET(_capitalize_name(p_name)); + const String capitalized = _capitalize_name(p_name); + if (TranslationServer::get_singleton()) { + return TranslationServer::get_singleton()->property_translate(capitalized); + } + return capitalized; } break; } ERR_FAIL_V_MSG(p_name, "Unexpected property name style."); } +String EditorPropertyNameProcessor::translate_group_name(const String &p_name) const { + if (TranslationServer::get_singleton()) { + return TranslationServer::get_singleton()->property_translate(p_name); + } + return p_name; +} + EditorPropertyNameProcessor::EditorPropertyNameProcessor() { ERR_FAIL_COND(singleton != nullptr); singleton = this; - // The following initialization is parsed in `editor/translations/extract.py` with a regex. + // The following initialization is parsed by the l10n extraction script with a regex. // The map name and value definition format should be kept synced with the regex. + // https://github.com/godotengine/godot-editor-l10n/blob/main/scripts/common.py capitalize_string_remaps["2d"] = "2D"; capitalize_string_remaps["3d"] = "3D"; capitalize_string_remaps["aa"] = "AA"; @@ -263,7 +276,7 @@ EditorPropertyNameProcessor::EditorPropertyNameProcessor() { capitalize_string_remaps["yz"] = "YZ"; // Articles, conjunctions, prepositions. - // The following initialization is parsed in `editor/translations/extract.py` with a regex. + // The following initialization is parsed in `editor/translations/scripts/common.py` with a regex. // The word definition format should be kept synced with the regex. stop_words = LocalVector<String>({ "a", diff --git a/editor/editor_property_name_processor.h b/editor/editor_property_name_processor.h index f32cb9f43a..8e3cecb45b 100644 --- a/editor/editor_property_name_processor.h +++ b/editor/editor_property_name_processor.h @@ -64,6 +64,9 @@ public: // Turns property path segment into the given style. String process_name(const String &p_name, Style p_style) const; + // Translate plain text group names. + String translate_group_name(const String &p_name) const; + EditorPropertyNameProcessor(); ~EditorPropertyNameProcessor(); }; diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp index 1c988840ac..8eb2551843 100644 --- a/editor/editor_settings.cpp +++ b/editor/editor_settings.cpp @@ -922,6 +922,7 @@ void EditorSettings::setup_language() { } // Load editor translation for configured/detected locale. load_editor_translations(lang); + load_property_translations(lang); // Load class reference translation. load_doc_translations(lang); diff --git a/editor/editor_translation.cpp b/editor/editor_translation.cpp index 426daad823..54a9d2f068 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/property_translations.gen.h" Vector<String> get_editor_locales() { Vector<String> locales; @@ -101,3 +102,29 @@ void load_doc_translations(const String &p_locale) { dtl++; } } + +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++; + } +} diff --git a/editor/editor_translation.h b/editor/editor_translation.h index 3717d0cbf5..bd6db32536 100644 --- a/editor/editor_translation.h +++ b/editor/editor_translation.h @@ -37,5 +37,6 @@ Vector<String> get_editor_locales(); void load_editor_translations(const String &p_locale); void load_doc_translations(const String &p_locale); +void load_property_translations(const String &p_locale); #endif // EDITOR_TRANSLATION_H |