1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-11 13:10:58 +00:00

Cleanup editor translation related methods

- Unify logic for loading editor/property/doc/extractable translations.
- Replace legacy `TranslationServer` methods with translation domains for internal translations.
- Only pre-create editor/property/doc translation domains in editor builds.
- Prevent adding `null` translation.
- Fixes potential loading of duplicated editor translations.
- Add internal `has_translation_for_locale()` instead of calling `get_loaded_translations().has()`.
This commit is contained in:
Haoyu Qiu
2025-06-26 15:16:30 +08:00
parent 8b4b93a82e
commit 3f03260a21
12 changed files with 77 additions and 163 deletions

View File

@@ -470,8 +470,7 @@ void TranslationServer::setup() {
String TranslationServer::get_tool_locale() {
#ifdef TOOLS_ENABLED
if (Engine::get_singleton()->is_editor_hint() || Engine::get_singleton()->is_project_manager_hint()) {
const PackedStringArray &locales = editor_domain->get_loaded_locales();
if (locales.has(locale)) {
if (editor_domain->has_translation_for_locale(locale)) {
return locale;
}
return "en";
@@ -488,26 +487,6 @@ String TranslationServer::get_tool_locale() {
}
}
StringName TranslationServer::tool_translate(const StringName &p_message, const StringName &p_context) const {
return editor_domain->translate(p_message, p_context);
}
StringName TranslationServer::tool_translate_plural(const StringName &p_message, const StringName &p_message_plural, int p_n, const StringName &p_context) const {
return editor_domain->translate_plural(p_message, p_message_plural, p_n, p_context);
}
StringName TranslationServer::property_translate(const StringName &p_message, const StringName &p_context) const {
return property_domain->translate(p_message, p_context);
}
StringName TranslationServer::doc_translate(const StringName &p_message, const StringName &p_context) const {
return doc_domain->translate(p_message, p_context);
}
StringName TranslationServer::doc_translate_plural(const StringName &p_message, const StringName &p_message_plural, int p_n, const StringName &p_context) const {
return doc_domain->translate_plural(p_message, p_message_plural, p_n, p_context);
}
bool TranslationServer::is_pseudolocalization_enabled() const {
return main_domain->is_pseudolocalization_enabled();
}
@@ -623,9 +602,14 @@ void TranslationServer::load_translations() {
TranslationServer::TranslationServer() {
singleton = this;
main_domain.instantiate();
#ifdef TOOLS_ENABLED
editor_domain = get_or_add_domain("godot.editor");
property_domain = get_or_add_domain("godot.properties");
doc_domain = get_or_add_domain("godot.documentation");
#endif // TOOLS_ENABLED
init_locale_info();
}