diff --git a/Source/options.cpp b/Source/options.cpp index e4cffee48..50f89c16d 100644 --- a/Source/options.cpp +++ b/Source/options.cpp @@ -986,6 +986,17 @@ 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. + for (auto localeIter = locales.rbegin(); localeIter != locales.rend(); localeIter++) { + auto regionSeparator = localeIter->find('_'); + if (regionSeparator != std::string::npos) { + std::string neutralLocale = localeIter->substr(0, regionSeparator); + if (std::find(locales.rbegin(), localeIter, neutralLocale) == localeIter) { + localeIter = std::make_reverse_iterator(locales.insert(localeIter.base(), neutralLocale)); + } + } + } + LogVerbose("Found {} user preferred locales", locales); for (const auto &locale : locales) { @@ -997,25 +1008,6 @@ void OptionEntryLanguageCode::LoadFromIni(string_view category) } } - std::vector fallbackLocales; - fallbackLocales.reserve(locales.size()); - - for (const auto &locale : locales) { - std::string neutralLocale = locale.substr(0, locale.find('_')); - if (std::find(fallbackLocales.cbegin(), fallbackLocales.cend(), neutralLocale) == fallbackLocales.cend()) { - fallbackLocales.push_back(neutralLocale); - } - } - - for (const auto &fallbackLocale : fallbackLocales) { - LogVerbose("Trying to load fallback translation: {}", fallbackLocale); - if (HasTranslation(fallbackLocale)) { - LogVerbose("Found matching fallback locale: {}", fallbackLocale); - CopyUtf8(szCode, fallbackLocale, sizeof(szCode)); - return; - } - } - LogVerbose("No suitable translation found"); strcpy(szCode, "en"); } diff --git a/Source/utils/language.cpp b/Source/utils/language.cpp index 0c28d8dab..13c946ca0 100644 --- a/Source/utils/language.cpp +++ b/Source/utils/language.cpp @@ -270,7 +270,8 @@ const std::string &LanguageTranslate(const char *key) bool HasTranslation(const std::string &locale) { - if (locale == "en") { + 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. return true; }