diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2022-10-31 14:30:18 +0100 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2022-10-31 14:30:18 +0100 |
commit | 0e9878b12a1e91d0f9ce2c1b56d1d469dd1758f6 (patch) | |
tree | 3bf7b195c822674a2ecce665495457fa842a7f49 /core/string | |
parent | c866f349ce5f7f75aa4c9a5d7562571c22aa7c76 (diff) | |
parent | ec3c4fcba9e93514aadee82621c322acb7c21a5c (diff) |
Merge pull request #67931 from bruvzg/locale_no_def
Do not auto add default script and country codes to the locale.
Diffstat (limited to 'core/string')
-rw-r--r-- | core/string/translation.cpp | 40 | ||||
-rw-r--r-- | core/string/translation.h | 1 |
2 files changed, 24 insertions, 17 deletions
diff --git a/core/string/translation.cpp b/core/string/translation.cpp index 1f5c84c321..2bed3543dc 100644 --- a/core/string/translation.cpp +++ b/core/string/translation.cpp @@ -293,6 +293,10 @@ void TranslationServer::init_locale_info() { } String TranslationServer::standardize_locale(const String &p_locale) const { + return _standardize_locale(p_locale, false); +} + +String TranslationServer::_standardize_locale(const String &p_locale, bool p_add_defaults) const { // Replaces '-' with '_' for macOS style locales. String univ_locale = p_locale.replace("-", "_"); @@ -354,24 +358,26 @@ String TranslationServer::standardize_locale(const String &p_locale) const { } // Add script code base on language and country codes for some ambiguous cases. - if (script_name.is_empty()) { - for (int i = 0; i < locale_script_info.size(); i++) { - const LocaleScriptInfo &info = locale_script_info[i]; - if (info.name == lang_name) { - if (country_name.is_empty() || info.supported_countries.has(country_name)) { - script_name = info.script; - break; + if (p_add_defaults) { + if (script_name.is_empty()) { + for (int i = 0; i < locale_script_info.size(); i++) { + const LocaleScriptInfo &info = locale_script_info[i]; + if (info.name == lang_name) { + if (country_name.is_empty() || info.supported_countries.has(country_name)) { + script_name = info.script; + break; + } } } } - } - if (!script_name.is_empty() && country_name.is_empty()) { - // Add conntry code based on script for some ambiguous cases. - for (int i = 0; i < locale_script_info.size(); i++) { - const LocaleScriptInfo &info = locale_script_info[i]; - if (info.name == lang_name && info.script == script_name) { - country_name = info.default_country; - break; + if (!script_name.is_empty() && country_name.is_empty()) { + // Add conntry code based on script for some ambiguous cases. + for (int i = 0; i < locale_script_info.size(); i++) { + const LocaleScriptInfo &info = locale_script_info[i]; + if (info.name == lang_name && info.script == script_name) { + country_name = info.default_country; + break; + } } } } @@ -391,8 +397,8 @@ String TranslationServer::standardize_locale(const String &p_locale) const { } int TranslationServer::compare_locales(const String &p_locale_a, const String &p_locale_b) const { - String locale_a = standardize_locale(p_locale_a); - String locale_b = standardize_locale(p_locale_b); + String locale_a = _standardize_locale(p_locale_a, true); + String locale_b = _standardize_locale(p_locale_b, true); if (locale_a == locale_b) { // Exact match. diff --git a/core/string/translation.h b/core/string/translation.h index 3f97a8d4fc..9a369b0b05 100644 --- a/core/string/translation.h +++ b/core/string/translation.h @@ -102,6 +102,7 @@ class TranslationServer : public Object { static TranslationServer *singleton; bool _load_translations(const String &p_from); + String _standardize_locale(const String &p_locale, bool p_add_defaults) const; StringName _get_message_from_translations(const StringName &p_message, const StringName &p_context, const String &p_locale, bool plural, const String &p_message_plural = "", int p_n = 0) const; |