Replace en_US code with en when searching for user preferred languages (#3859)

This commit is contained in:
Andrew James 2021-12-30 14:12:17 +11:00 committed by GitHub
commit e1d01aad7c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 3 deletions

View file

@ -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) {

View file

@ -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;
}