From e1d01aad7cf77523aedfb442ffade1847b6266ae Mon Sep 17 00:00:00 2001 From: Andrew James Date: Thu, 30 Dec 2021 14:12:17 +1100 Subject: [PATCH] Replace en_US code with en when searching for user preferred languages (#3859) --- Source/options.cpp | 7 ++++++- Source/utils/language.cpp | 5 +++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Source/options.cpp b/Source/options.cpp index 489a88aaf..4add9541f 100644 --- a/Source/options.cpp +++ b/Source/options.cpp @@ -1030,7 +1030,12 @@ void OptionEntryLanguageCode::LoadFromIni(string_view category) locales.emplace_back(std::locale("").name().substr(0, 5)); #endif - // Insert non-regional locale codes after the last regional variation so we fallback to neutral translations if no regional translation exists that meets user preferences. + // So that the correct language is shown in the settings menu for users with US english set as a preferred language + // we need to replace the "en_US" locale code with the neutral string "en" as expected by the available options + std::replace(locales.begin(), locales.end(), std::string { "en_US" }, std::string { "en" }); + + // Insert non-regional locale codes after the last regional variation so we fallback to neutral translations if no + // regional translation exists that meets user preferences. for (auto localeIter = locales.rbegin(); localeIter != locales.rend(); localeIter++) { auto regionSeparator = localeIter->find('_'); if (regionSeparator != std::string::npos) { diff --git a/Source/utils/language.cpp b/Source/utils/language.cpp index 2893a9ac3..888384fcc 100644 --- a/Source/utils/language.cpp +++ b/Source/utils/language.cpp @@ -270,8 +270,9 @@ const std::string &LanguageTranslate(const char *key) bool HasTranslation(const std::string &locale) { - if (locale == "en" || locale == "en_US") { - // the base translation is en_US. No translation file will be present for these codes but we want the check to succeed to prevent further searches. + if (locale == "en") { + // the base translation is en (really en_US). No translation file will be present for this code but we want + // the check to succeed to prevent further searches. return true; }