summaryrefslogtreecommitdiffstats
path: root/core/string/translation.cpp
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2023-03-06 10:57:56 +0100
committerRémi Verschelde <rverschelde@gmail.com>2023-03-06 10:57:56 +0100
commit0b98b470ccdb2cd87b6ae3fe14b0f58920eaa6ea (patch)
treecf5c5351b8f961de1d9641b32de5ada80283d087 /core/string/translation.cpp
parent45738d078ad17565f2285ddeba6e6fd3662ed6af (diff)
parent82d7923c653b6328ba279bd4183b63b69e21edfc (diff)
downloadredot-engine-0b98b470ccdb2cd87b6ae3fe14b0f58920eaa6ea.tar.gz
Merge pull request #73716 from bruvzg/improve_locale_selection
Improve layout direction/locale automatic selection.
Diffstat (limited to 'core/string/translation.cpp')
-rw-r--r--core/string/translation.cpp20
1 files changed, 19 insertions, 1 deletions
diff --git a/core/string/translation.cpp b/core/string/translation.cpp
index b9d5d3b538..160bad14ab 100644
--- a/core/string/translation.cpp
+++ b/core/string/translation.cpp
@@ -712,7 +712,25 @@ String TranslationServer::get_tool_locale() {
#else
{
#endif
- return get_locale();
+ // Look for best matching loaded translation.
+ String best_locale = "en";
+ int best_score = 0;
+
+ for (const Ref<Translation> &E : translations) {
+ const Ref<Translation> &t = E;
+ ERR_FAIL_COND_V(t.is_null(), best_locale);
+ String l = t->get_locale();
+
+ int score = compare_locales(locale, l);
+ if (score > 0 && score >= best_score) {
+ best_locale = l;
+ best_score = score;
+ if (score == 10) {
+ break; // Exact match, skip the rest.
+ }
+ }
+ }
+ return best_locale;
}
}