mirror of
https://github.com/godotengine/godot.git
synced 2026-01-01 05:49:28 +03:00
Automatically include text server data if project includes translations requiring it.
This commit is contained in:
@@ -1160,6 +1160,13 @@
|
||||
Returns [code]true[/code] if locale is right-to-left.
|
||||
</description>
|
||||
</method>
|
||||
<method name="is_locale_using_support_data" qualifiers="const">
|
||||
<return type="bool" />
|
||||
<param index="0" name="locale" type="String" />
|
||||
<description>
|
||||
Returns [code]true[/code] if the locale requires text server support data for line/word breaking.
|
||||
</description>
|
||||
</method>
|
||||
<method name="is_valid_identifier" qualifiers="const">
|
||||
<return type="bool" />
|
||||
<param index="0" name="string" type="String" />
|
||||
|
||||
@@ -1137,6 +1137,13 @@
|
||||
Returns [code]true[/code] if locale is right-to-left.
|
||||
</description>
|
||||
</method>
|
||||
<method name="_is_locale_using_support_data" qualifiers="virtual const">
|
||||
<return type="bool" />
|
||||
<param index="0" name="locale" type="String" />
|
||||
<description>
|
||||
Returns [code]true[/code] if the locale requires text server support data for line/word breaking.
|
||||
</description>
|
||||
</method>
|
||||
<method name="_is_valid_identifier" qualifiers="virtual const">
|
||||
<return type="bool" />
|
||||
<param index="0" name="string" type="String" />
|
||||
|
||||
@@ -1004,45 +1004,58 @@ Dictionary EditorExportPlatform::get_internal_export_files(const Ref<EditorExpor
|
||||
Dictionary files;
|
||||
|
||||
// Text server support data.
|
||||
if (TS->has_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<String> 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!"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -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 &);
|
||||
|
||||
|
||||
@@ -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.
|
||||
}
|
||||
|
||||
@@ -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 &);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 &);
|
||||
|
||||
Reference in New Issue
Block a user