You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-04 12:00:25 +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:
@@ -5944,7 +5944,7 @@ Vector<uint8_t> String::to_multibyte_char_buffer(const String &p_encoding) const
|
||||
*/
|
||||
String TTR(const String &p_text, const String &p_context) {
|
||||
if (TranslationServer::get_singleton()) {
|
||||
return TranslationServer::get_singleton()->tool_translate(p_text, p_context);
|
||||
return TranslationServer::get_singleton()->get_editor_domain()->translate(p_text, p_context);
|
||||
}
|
||||
|
||||
return p_text;
|
||||
@@ -5964,7 +5964,7 @@ String TTR(const String &p_text, const String &p_context) {
|
||||
*/
|
||||
String TTRN(const String &p_text, const String &p_text_plural, int p_n, const String &p_context) {
|
||||
if (TranslationServer::get_singleton()) {
|
||||
return TranslationServer::get_singleton()->tool_translate_plural(p_text, p_text_plural, p_n, p_context);
|
||||
return TranslationServer::get_singleton()->get_editor_domain()->translate_plural(p_text, p_text_plural, p_n, p_context);
|
||||
}
|
||||
|
||||
// Return message based on English plural rule if translation is not possible.
|
||||
@@ -5985,7 +5985,7 @@ String DTR(const String &p_text, const String &p_context) {
|
||||
const String text = p_text.dedent().strip_edges();
|
||||
|
||||
if (TranslationServer::get_singleton()) {
|
||||
return String(TranslationServer::get_singleton()->doc_translate(text, p_context)).replace("$DOCS_URL", GODOT_VERSION_DOCS_URL);
|
||||
return String(TranslationServer::get_singleton()->get_doc_domain()->translate(text, p_context)).replace("$DOCS_URL", GODOT_VERSION_DOCS_URL);
|
||||
}
|
||||
|
||||
return text.replace("$DOCS_URL", GODOT_VERSION_DOCS_URL);
|
||||
@@ -6002,7 +6002,7 @@ String DTRN(const String &p_text, const String &p_text_plural, int p_n, const St
|
||||
const String text_plural = p_text_plural.dedent().strip_edges();
|
||||
|
||||
if (TranslationServer::get_singleton()) {
|
||||
return String(TranslationServer::get_singleton()->doc_translate_plural(text, text_plural, p_n, p_context)).replace("$DOCS_URL", GODOT_VERSION_DOCS_URL);
|
||||
return String(TranslationServer::get_singleton()->get_doc_domain()->translate_plural(text, text_plural, p_n, p_context)).replace("$DOCS_URL", GODOT_VERSION_DOCS_URL);
|
||||
}
|
||||
|
||||
// Return message based on English plural rule if translation is not possible.
|
||||
@@ -6026,11 +6026,13 @@ String DTRN(const String &p_text, const String &p_text_plural, int p_n, const St
|
||||
*/
|
||||
String RTR(const String &p_text, const String &p_context) {
|
||||
if (TranslationServer::get_singleton()) {
|
||||
String rtr = TranslationServer::get_singleton()->tool_translate(p_text, p_context);
|
||||
if (rtr.is_empty() || rtr == p_text) {
|
||||
return TranslationServer::get_singleton()->translate(p_text, p_context);
|
||||
#ifdef TOOLS_ENABLED
|
||||
String rtr = TranslationServer::get_singleton()->get_editor_domain()->translate(p_text, p_context);
|
||||
if (!rtr.is_empty() && rtr != p_text) {
|
||||
return rtr;
|
||||
}
|
||||
return rtr;
|
||||
#endif // TOOLS_ENABLED
|
||||
return TranslationServer::get_singleton()->translate(p_text, p_context);
|
||||
}
|
||||
|
||||
return p_text;
|
||||
@@ -6049,11 +6051,13 @@ String RTR(const String &p_text, const String &p_context) {
|
||||
*/
|
||||
String RTRN(const String &p_text, const String &p_text_plural, int p_n, const String &p_context) {
|
||||
if (TranslationServer::get_singleton()) {
|
||||
String rtr = TranslationServer::get_singleton()->tool_translate_plural(p_text, p_text_plural, p_n, p_context);
|
||||
if (rtr.is_empty() || rtr == p_text || rtr == p_text_plural) {
|
||||
return TranslationServer::get_singleton()->translate_plural(p_text, p_text_plural, p_n, p_context);
|
||||
#ifdef TOOLS_ENABLED
|
||||
String rtr = TranslationServer::get_singleton()->get_editor_domain()->translate_plural(p_text, p_text_plural, p_n, p_context);
|
||||
if (!rtr.is_empty() && rtr != p_text && rtr != p_text_plural) {
|
||||
return rtr;
|
||||
}
|
||||
return rtr;
|
||||
#endif // TOOLS_ENABLED
|
||||
return TranslationServer::get_singleton()->translate_plural(p_text, p_text_plural, p_n, p_context);
|
||||
}
|
||||
|
||||
// Return message based on English plural rule if translation is not possible.
|
||||
|
||||
Reference in New Issue
Block a user