Skip to content

Commit e826265

Browse files
authored
Use both language and country code for auto language detection
1 parent 6c5631c commit e826265

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/DesktopPlusUI/TranslationManager.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -760,9 +760,19 @@ void TranslationManager::LoadTranslationFromFile(const std::string& filename)
760760
{
761761
wchar_t buffer[16] = {0};
762762
::GetLocaleInfoEx(LOCALE_NAME_USER_DEFAULT, LOCALE_SISO639LANGNAME, buffer, sizeof(buffer) / sizeof(wchar_t));
763-
764-
//ISO 639 code ideally matches the file names used, so this works as auto-detection
765-
std::string lang_filename = StringConvertFromUTF16(buffer) + ".ini";
763+
std::string lang = StringConvertFromUTF16(buffer);
764+
::GetLocaleInfoEx(LOCALE_NAME_USER_DEFAULT, LOCALE_SISO3166CTRYNAME, buffer, sizeof(buffer) / sizeof(wchar_t));
765+
std::string ctry = StringConvertFromUTF16(buffer);
766+
767+
// ISO 639 code ideally matches the file names used, so this works as auto-detection
768+
// try to detect the language file with the country code first (e.g. en_US.ini)
769+
std::string lang_filename = lang + "_" + ctry + ".ini";
770+
if (!FileExists(WStringConvertFromUTF8((ConfigManager::Get().GetApplicationPath() + "lang/" + lang_filename).c_str()).c_str()))
771+
{
772+
// if the country code file does not exist, try to load the language file without the country code (e.g. en.ini)
773+
lang_filename = lang + ".ini";
774+
}
775+
766776
ConfigManager::SetValue(configid_str_interface_language_file, lang_filename);
767777
LoadTranslationFromFile(lang_filename);
768778

0 commit comments

Comments
 (0)