mirror of
https://github.com/godotengine/godot.git
synced 2026-01-03 18:11:19 +03:00
Fix translation with multiple sources for the same language.
Remove unnecessary locale length checks. Add "C" -> "en" locale remap.
This commit is contained in:
@@ -544,7 +544,7 @@ Ref<Translation> TranslationServer::get_translation_object(const String &p_local
|
||||
String l = t->get_locale();
|
||||
|
||||
int score = compare_locales(p_locale, l);
|
||||
if (score > best_score) {
|
||||
if (score > 0 && score >= best_score) {
|
||||
res = t;
|
||||
best_score = score;
|
||||
if (score == 10) {
|
||||
@@ -566,8 +566,6 @@ StringName TranslationServer::translate(const StringName &p_message, const Strin
|
||||
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);
|
||||
|
||||
if (!res && fallback.length() >= 2) {
|
||||
@@ -589,8 +587,6 @@ StringName TranslationServer::translate_plural(const StringName &p_message, cons
|
||||
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);
|
||||
|
||||
if (!res && fallback.length() >= 2) {
|
||||
@@ -617,13 +613,17 @@ StringName TranslationServer::_get_message_from_translations(const StringName &p
|
||||
String l = t->get_locale();
|
||||
|
||||
int score = compare_locales(p_locale, l);
|
||||
if (score > best_score) {
|
||||
if (score > 0 && score >= best_score) {
|
||||
StringName r;
|
||||
if (!plural) {
|
||||
res = t->get_message(p_message, p_context);
|
||||
r = t->get_message(p_message, p_context);
|
||||
} 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;
|
||||
if (score == 10) {
|
||||
break; // Exact match, skip the rest.
|
||||
|
||||
Reference in New Issue
Block a user