From 5fdc72f893ad68069b51982f585006179c735feb Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Fri, 25 Dec 2015 19:15:03 -0800 Subject: [PATCH] Fuzzy match lang when user locale doesn't exist. So for example, fr_CA would select fr_FR rather than en_US. Wrong dialect can sometimes be pretty far off, but it's still likely a better default. --- Core/Config.cpp | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/Core/Config.cpp b/Core/Config.cpp index 3b5607fd65..0a671fa4b2 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -233,11 +233,28 @@ struct ReportedConfigSetting : public ConfigSetting { }; const char *DefaultLangRegion() { + // Unfortunate default. There's no need to use bFirstRun, since this is only a default. static std::string defaultLangRegion = "en_US"; - if (g_Config.bFirstRun) { - std::string langRegion = System_GetProperty(SYSPROP_LANGREGION); - if (i18nrepo.IniExists(langRegion)) - defaultLangRegion = langRegion; + std::string langRegion = System_GetProperty(SYSPROP_LANGREGION); + if (i18nrepo.IniExists(langRegion)) { + defaultLangRegion = langRegion; + } else if (langRegion.length() >= 3) { + // Don't give up. Let's try a fuzzy match - so nl_BE can match nl_NL. + IniFile mapping; + mapping.LoadFromVFS("langregion.ini"); + std::vector keys; + mapping.GetKeys("LangRegionNames", keys); + + for (std::string key : keys) { + if (startsWithNoCase(key, langRegion)) { + // Exact submatch, or different case. Let's use it. + defaultLangRegion = key; + break; + } else if (startsWithNoCase(key, langRegion.substr(0, 3))) { + // Best so far. + defaultLangRegion = key; + } + } } return defaultLangRegion.c_str();