From 5afbbc71a43ff0ca373d1bfb583b1f55900f95c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pa=CC=84vels=20Nadtoc=CC=8Cajevs?= <7645683+bruvzg@users.noreply.github.com> Date: Tue, 30 Sep 2025 11:34:07 +0300 Subject: [PATCH] Automatically include text server data if project includes translations requiring it. --- doc/classes/TextServer.xml | 7 ++ doc/classes/TextServerExtension.xml | 7 ++ editor/export/editor_export_platform.cpp | 75 ++++++++++++--------- modules/text_server_adv/text_server_adv.cpp | 10 +++ modules/text_server_adv/text_server_adv.h | 1 + modules/text_server_fb/text_server_fb.cpp | 4 ++ modules/text_server_fb/text_server_fb.h | 1 + servers/text/text_server.cpp | 1 + servers/text/text_server.h | 1 + servers/text/text_server_extension.cpp | 7 ++ servers/text/text_server_extension.h | 2 + 11 files changed, 85 insertions(+), 31 deletions(-) diff --git a/doc/classes/TextServer.xml b/doc/classes/TextServer.xml index 4192cfd4283..a6ff9cb8321 100644 --- a/doc/classes/TextServer.xml +++ b/doc/classes/TextServer.xml @@ -1160,6 +1160,13 @@ Returns [code]true[/code] if locale is right-to-left. + + + + + Returns [code]true[/code] if the locale requires text server support data for line/word breaking. + + diff --git a/doc/classes/TextServerExtension.xml b/doc/classes/TextServerExtension.xml index fe329ff6735..65dbb212e88 100644 --- a/doc/classes/TextServerExtension.xml +++ b/doc/classes/TextServerExtension.xml @@ -1137,6 +1137,13 @@ Returns [code]true[/code] if locale is right-to-left. + + + + + Returns [code]true[/code] if the locale requires text server support data for line/word breaking. + + diff --git a/editor/export/editor_export_platform.cpp b/editor/export/editor_export_platform.cpp index 84c2e1ac9f7..ee4eb922ddf 100644 --- a/editor/export/editor_export_platform.cpp +++ b/editor/export/editor_export_platform.cpp @@ -1004,45 +1004,58 @@ Dictionary EditorExportPlatform::get_internal_export_files(const Refhas_feature(TextServer::FEATURE_USE_SUPPORT_DATA) && (bool)get_project_setting(p_preset, "internationalization/locale/include_text_server_data")) { - String ts_name = TS->get_support_data_filename(); - String ts_target = "res://" + ts_name; - if (!ts_name.is_empty()) { - bool export_ok = false; - if (FileAccess::exists(ts_target)) { // Include user supplied data file. - const PackedByteArray &ts_data = FileAccess::get_file_as_bytes(ts_target); - if (!ts_data.is_empty()) { - add_message(EXPORT_MESSAGE_INFO, TTR("Export"), TTR("Using user provided text server data, text display in the exported project might be broken if export template was built with different ICU version!")); - files[ts_target] = ts_data; - export_ok = true; + if (TS->has_feature(TextServer::FEATURE_USE_SUPPORT_DATA)) { + bool include_data = (bool)get_project_setting(p_preset, "internationalization/locale/include_text_server_data"); + if (!include_data) { + Vector translations = get_project_setting(p_preset, "internationalization/locale/translations"); + translations.push_back(get_project_setting(p_preset, "internationalization/locale/fallback")); + for (const String &t : translations) { + if (TS->is_locale_using_support_data(t)) { + include_data = true; + break; } - } else { - String current_version = GODOT_VERSION_FULL_CONFIG; - String template_path = EditorPaths::get_singleton()->get_export_templates_dir().path_join(current_version); - if (p_debug && p_preset->has("custom_template/debug") && p_preset->get("custom_template/debug") != "") { - template_path = p_preset->get("custom_template/debug").operator String().get_base_dir(); - } else if (!p_debug && p_preset->has("custom_template/release") && p_preset->get("custom_template/release") != "") { - template_path = p_preset->get("custom_template/release").operator String().get_base_dir(); - } - String data_file_name = template_path.path_join(ts_name); - if (FileAccess::exists(data_file_name)) { - const PackedByteArray &ts_data = FileAccess::get_file_as_bytes(data_file_name); + } + } + if (include_data) { + String ts_name = TS->get_support_data_filename(); + String ts_target = "res://" + ts_name; + if (!ts_name.is_empty()) { + bool export_ok = false; + if (FileAccess::exists(ts_target)) { // Include user supplied data file. + const PackedByteArray &ts_data = FileAccess::get_file_as_bytes(ts_target); if (!ts_data.is_empty()) { - print_line("Using text server data from export templates."); + add_message(EXPORT_MESSAGE_INFO, TTR("Export"), TTR("Using user provided text server data, text display in the exported project might be broken if export template was built with different ICU version!")); files[ts_target] = ts_data; export_ok = true; } } else { - const PackedByteArray &ts_data = TS->get_support_data(); - if (!ts_data.is_empty()) { - add_message(EXPORT_MESSAGE_INFO, TTR("Export"), TTR("Using editor embedded text server data, text display in the exported project might be broken if export template was built with different ICU version!")); - files[ts_target] = ts_data; - export_ok = true; + String current_version = GODOT_VERSION_FULL_CONFIG; + String template_path = EditorPaths::get_singleton()->get_export_templates_dir().path_join(current_version); + if (p_debug && p_preset->has("custom_template/debug") && p_preset->get("custom_template/debug") != "") { + template_path = p_preset->get("custom_template/debug").operator String().get_base_dir(); + } else if (!p_debug && p_preset->has("custom_template/release") && p_preset->get("custom_template/release") != "") { + template_path = p_preset->get("custom_template/release").operator String().get_base_dir(); + } + String data_file_name = template_path.path_join(ts_name); + if (FileAccess::exists(data_file_name)) { + const PackedByteArray &ts_data = FileAccess::get_file_as_bytes(data_file_name); + if (!ts_data.is_empty()) { + print_line("Using text server data from export templates."); + files[ts_target] = ts_data; + export_ok = true; + } + } else { + const PackedByteArray &ts_data = TS->get_support_data(); + if (!ts_data.is_empty()) { + add_message(EXPORT_MESSAGE_INFO, TTR("Export"), TTR("Using editor embedded text server data, text display in the exported project might be broken if export template was built with different ICU version!")); + files[ts_target] = ts_data; + export_ok = true; + } } } - } - if (!export_ok) { - add_message(EXPORT_MESSAGE_WARNING, TTR("Export"), TTR("Missing text server data, text display in the exported project might be broken!")); + if (!export_ok) { + add_message(EXPORT_MESSAGE_WARNING, TTR("Export"), TTR("Missing text server data, text display in the exported project might be broken!")); + } } } } diff --git a/modules/text_server_adv/text_server_adv.cpp b/modules/text_server_adv/text_server_adv.cpp index 55303452dea..6437067c75b 100644 --- a/modules/text_server_adv/text_server_adv.cpp +++ b/modules/text_server_adv/text_server_adv.cpp @@ -522,6 +522,15 @@ PackedByteArray TextServerAdvanced::_get_support_data() const { #endif } +bool TextServerAdvanced::_is_locale_using_support_data(const String &p_locale) const { + String l = p_locale.get_slicec('_', 0); + if ((l == "my") || (l == "zh") || (l == "ja") || (l == "ko") || (l == "km") || (l == "lo") || (l == "th")) { + return true; + } else { + return false; + } +} + bool TextServerAdvanced::_is_locale_right_to_left(const String &p_locale) const { String l = p_locale.get_slicec('_', 0); if ((l == "ar") || (l == "dv") || (l == "he") || (l == "fa") || (l == "ff") || (l == "ku") || (l == "ur")) { @@ -5727,6 +5736,7 @@ RID TextServerAdvanced::_find_sys_font_for_text(const RID &p_fdef, const String String locale = (p_language.is_empty()) ? TranslationServer::get_singleton()->get_tool_locale() : p_language; PackedStringArray fallback_font_name = OS::get_singleton()->get_system_font_path_for_text(font_name, p_text, locale, p_script_code, font_weight, font_stretch, font_style & TextServer::FONT_ITALIC); + print_line("sysf x ", p_text, " --> ", fallback_font_name); #ifdef GDEXTENSION for (int fb = 0; fb < fallback_font_name.size(); fb++) { const String &E = fallback_font_name[fb]; diff --git a/modules/text_server_adv/text_server_adv.h b/modules/text_server_adv/text_server_adv.h index 448a365fdfd..6eb3e105b83 100644 --- a/modules/text_server_adv/text_server_adv.h +++ b/modules/text_server_adv/text_server_adv.h @@ -833,6 +833,7 @@ public: MODBIND0RC(String, get_support_data_info); MODBIND1RC(bool, save_support_data, const String &); MODBIND0RC(PackedByteArray, get_support_data); + MODBIND1RC(bool, is_locale_using_support_data, const String &); MODBIND1RC(bool, is_locale_right_to_left, const String &); diff --git a/modules/text_server_fb/text_server_fb.cpp b/modules/text_server_fb/text_server_fb.cpp index 7edd1ed8487..91ddf4ab8ca 100644 --- a/modules/text_server_fb/text_server_fb.cpp +++ b/modules/text_server_fb/text_server_fb.cpp @@ -183,6 +183,10 @@ PackedByteArray TextServerFallback::_get_support_data() const { return PackedByteArray(); // No extra data used. } +bool TextServerFallback::_is_locale_using_support_data(const String &p_locale) const { + return false; // No data support. +} + bool TextServerFallback::_is_locale_right_to_left(const String &p_locale) const { return false; // No RTL support. } diff --git a/modules/text_server_fb/text_server_fb.h b/modules/text_server_fb/text_server_fb.h index 7cc02985330..d714062ed9f 100644 --- a/modules/text_server_fb/text_server_fb.h +++ b/modules/text_server_fb/text_server_fb.h @@ -616,6 +616,7 @@ public: MODBIND0RC(String, get_support_data_info); MODBIND1RC(bool, save_support_data, const String &); MODBIND0RC(PackedByteArray, get_support_data); + MODBIND1RC(bool, is_locale_using_support_data, const String &); MODBIND1RC(bool, is_locale_right_to_left, const String &); diff --git a/servers/text/text_server.cpp b/servers/text/text_server.cpp index 3f1927411a9..b3548a72e80 100644 --- a/servers/text/text_server.cpp +++ b/servers/text/text_server.cpp @@ -205,6 +205,7 @@ void TextServer::_bind_methods() { ClassDB::bind_method(D_METHOD("get_support_data_info"), &TextServer::get_support_data_info); ClassDB::bind_method(D_METHOD("save_support_data", "filename"), &TextServer::save_support_data); ClassDB::bind_method(D_METHOD("get_support_data"), &TextServer::get_support_data); + ClassDB::bind_method(D_METHOD("is_locale_using_support_data", "locale"), &TextServer::is_locale_using_support_data); ClassDB::bind_method(D_METHOD("is_locale_right_to_left", "locale"), &TextServer::is_locale_right_to_left); diff --git a/servers/text/text_server.h b/servers/text/text_server.h index 3b08c305b45..fc3a2b75bb8 100644 --- a/servers/text/text_server.h +++ b/servers/text/text_server.h @@ -261,6 +261,7 @@ public: virtual String get_support_data_info() const = 0; virtual bool save_support_data(const String &p_filename) const = 0; virtual PackedByteArray get_support_data() const = 0; + virtual bool is_locale_using_support_data(const String &p_locale) const { return false; } virtual bool is_locale_right_to_left(const String &p_locale) const = 0; diff --git a/servers/text/text_server_extension.cpp b/servers/text/text_server_extension.cpp index 9882800f9a2..47e4ea4798f 100644 --- a/servers/text/text_server_extension.cpp +++ b/servers/text/text_server_extension.cpp @@ -43,6 +43,7 @@ void TextServerExtension::_bind_methods() { GDVIRTUAL_BIND(_get_support_data_info); GDVIRTUAL_BIND(_save_support_data, "filename"); GDVIRTUAL_BIND(_get_support_data); + GDVIRTUAL_BIND(_is_locale_using_support_data, "locale"); GDVIRTUAL_BIND(_is_locale_right_to_left, "locale"); @@ -448,6 +449,12 @@ PackedByteArray TextServerExtension::get_support_data() const { return ret; } +bool TextServerExtension::is_locale_using_support_data(const String &p_locale) const { + bool ret = false; + GDVIRTUAL_CALL(_is_locale_using_support_data, p_locale, ret); + return ret; +} + bool TextServerExtension::is_locale_right_to_left(const String &p_locale) const { bool ret = false; GDVIRTUAL_CALL(_is_locale_right_to_left, p_locale, ret); diff --git a/servers/text/text_server_extension.h b/servers/text/text_server_extension.h index b764addcf83..b5b16e97a85 100644 --- a/servers/text/text_server_extension.h +++ b/servers/text/text_server_extension.h @@ -67,6 +67,8 @@ public: GDVIRTUAL0RC(String, _get_support_data_info); GDVIRTUAL1RC(bool, _save_support_data, const String &); GDVIRTUAL0RC(PackedByteArray, _get_support_data); + virtual bool is_locale_using_support_data(const String &p_locale) const override; + GDVIRTUAL1RC(bool, _is_locale_using_support_data, const String &); virtual bool is_locale_right_to_left(const String &p_locale) const override; GDVIRTUAL1RC(bool, _is_locale_right_to_left, const String &);