Fix translation with multiple sources for the same language.

Remove unnecessary locale length checks.
Add "C" -> "en" locale remap.
This commit is contained in:
bruvzg 2022-01-24 18:58:16 +02:00
parent fc09d783f4
commit 9456454109
No known key found for this signature in database
GPG Key ID: 7960FCF39844EC38
4 changed files with 11 additions and 10 deletions

View File

@ -820,7 +820,7 @@ String ResourceLoader::_path_remap(const String &p_path, bool *r_translation_rem
} }
String l = res_remaps[i].substr(split + 1).strip_edges(); String l = res_remaps[i].substr(split + 1).strip_edges();
int score = TranslationServer::get_singleton()->compare_locales(locale, l); int score = TranslationServer::get_singleton()->compare_locales(locale, l);
if (score > best_score) { if (score > 0 && score >= best_score) {
new_path = res_remaps[i].left(split); new_path = res_remaps[i].left(split);
best_score = score; best_score = score;
if (score == 10) { if (score == 10) {

View File

@ -42,6 +42,7 @@ static const char *locale_renames[][2] = {
{ "in", "id" }, // Indonesian { "in", "id" }, // Indonesian
{ "iw", "he" }, // Hebrew { "iw", "he" }, // Hebrew
{ "no", "nb" }, // Norwegian Bokmål { "no", "nb" }, // Norwegian Bokmål
{ "C", "en" }, // Locale is not set, fallback to English.
{ nullptr, nullptr } { nullptr, nullptr }
}; };

View File

@ -544,7 +544,7 @@ Ref<Translation> TranslationServer::get_translation_object(const String &p_local
String l = t->get_locale(); String l = t->get_locale();
int score = compare_locales(p_locale, l); int score = compare_locales(p_locale, l);
if (score > best_score) { if (score > 0 && score >= best_score) {
res = t; res = t;
best_score = score; best_score = score;
if (score == 10) { if (score == 10) {
@ -566,8 +566,6 @@ StringName TranslationServer::translate(const StringName &p_message, const Strin
return p_message; return p_message;
} }
ERR_FAIL_COND_V_MSG(locale.length() < 2, p_message, "Could not translate message as configured locale '" + locale + "' is invalid.");
StringName res = _get_message_from_translations(p_message, p_context, locale, false); StringName res = _get_message_from_translations(p_message, p_context, locale, false);
if (!res && fallback.length() >= 2) { if (!res && fallback.length() >= 2) {
@ -589,8 +587,6 @@ StringName TranslationServer::translate_plural(const StringName &p_message, cons
return p_message_plural; return p_message_plural;
} }
ERR_FAIL_COND_V_MSG(locale.length() < 2, p_message, "Could not translate message as configured locale '" + locale + "' is invalid.");
StringName res = _get_message_from_translations(p_message, p_context, locale, true, p_message_plural, p_n); StringName res = _get_message_from_translations(p_message, p_context, locale, true, p_message_plural, p_n);
if (!res && fallback.length() >= 2) { if (!res && fallback.length() >= 2) {
@ -617,13 +613,17 @@ StringName TranslationServer::_get_message_from_translations(const StringName &p
String l = t->get_locale(); String l = t->get_locale();
int score = compare_locales(p_locale, l); int score = compare_locales(p_locale, l);
if (score > best_score) { if (score > 0 && score >= best_score) {
StringName r; StringName r;
if (!plural) { if (!plural) {
res = t->get_message(p_message, p_context); r = t->get_message(p_message, p_context);
} else { } else {
res = t->get_plural_message(p_message, p_message_plural, p_n, p_context); r = t->get_plural_message(p_message, p_message_plural, p_n, p_context);
} }
if (!r) {
continue;
}
res = r;
best_score = score; best_score = score;
if (score == 10) { if (score == 10) {
break; // Exact match, skip the rest. break; // Exact match, skip the rest.

View File

@ -377,7 +377,7 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) {
lang_hint += locale; lang_hint += locale;
int score = TranslationServer::get_singleton()->compare_locales(host_lang, locale); int score = TranslationServer::get_singleton()->compare_locales(host_lang, locale);
if (score > best_score) { if (score > 0 && score >= best_score) {
best = locale; best = locale;
best_score = score; best_score = score;
if (score == 10) { if (score == 10) {