Merge pull request #98109 from jitspoe/3.x.fix_localization_default_codes

[3.x] Do not auto add default script and country codes to the locale.
This commit is contained in:
lawnjelly 2024-10-13 18:08:45 +01:00 committed by GitHub
commit 54b7231415
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 24 additions and 17 deletions

View file

@ -261,6 +261,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("-", "_");
@ -322,6 +326,7 @@ String TranslationServer::standardize_locale(const String &p_locale) const {
}
// Add script code base on language and country codes for some ambiguous cases.
if (p_add_defaults) {
if (script.empty()) {
for (int i = 0; i < locale_script_info.size(); i++) {
const LocaleScriptInfo &info = locale_script_info[i];
@ -343,6 +348,7 @@ String TranslationServer::standardize_locale(const String &p_locale) const {
}
}
}
}
// Combine results.
String locale = lang;
@ -359,8 +365,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.

View file

@ -122,6 +122,7 @@ public:
int compare_locales(const String &p_locale_a, const String &p_locale_b) const;
String standardize_locale(const String &p_locale) const;
String _standardize_locale(const String &p_locale, bool p_add_defaults) const;
Vector<String> get_all_languages() const;
String get_language_name(const String &p_language) const;