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.
This commit is contained in:
Haoyu Qiu 2022-12-27 10:58:01 +08:00 committed by Rémi Verschelde
parent bdad9770d6
commit 5d7e003b29
No known key found for this signature in database
GPG key ID: C3336907360768E1
10 changed files with 82 additions and 11 deletions

View file

@ -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;
}

View file

@ -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();

View file

@ -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",

View file

@ -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")

View file

@ -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);

View file

@ -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",

View file

@ -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();
};

View file

@ -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);

View file

@ -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++;
}
}

View file

@ -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