diff --git a/Core/Config.cpp b/Core/Config.cpp index 9faa2cdd9c..6803d81efd 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(); diff --git a/Windows/main.cpp b/Windows/main.cpp index 0d872e3b99..52c37476e6 100644 --- a/Windows/main.cpp +++ b/Windows/main.cpp @@ -15,6 +15,7 @@ // Official git repository and contact information can be found at // https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. +#include #include #include #include @@ -332,6 +333,26 @@ bool System_InputBoxGetWString(const wchar_t *title, const std::wstring &default } } +static std::string GetDefaultLangRegion() { + wchar_t lcLangName[256] = {}; + + // LOCALE_SNAME is only available in WinVista+ + if (0 != GetLocaleInfo(LOCALE_NAME_USER_DEFAULT, LOCALE_SNAME, lcLangName, ARRAY_SIZE(lcLangName))) { + std::string result = ConvertWStringToUTF8(lcLangName); + std::replace(result.begin(), result.end(), '-', '_'); + return result; + } else { + // This should work on XP, but we may get numbers for some countries. + if (0 != GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SISO639LANGNAME, lcLangName, ARRAY_SIZE(lcLangName))) { + wchar_t lcRegion[256] = {}; + if (0 != GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SISO3166CTRYNAME, lcRegion, ARRAY_SIZE(lcRegion))) { + return ConvertWStringToUTF8(lcLangName) + "_" + ConvertWStringToUTF8(lcRegion); + } + } + // Unfortunate default. We tried. + return "en_US"; + } +} std::vector GetWideCmdLine() { wchar_t **wargv; @@ -365,27 +386,14 @@ int WINAPI WinMain(HINSTANCE _hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLin #ifndef _DEBUG bool showLog = false; #else - bool showLog = false; + bool showLog = true; #endif const std::string &exePath = File::GetExeDirectory(); VFSRegister("", new DirectoryAssetReader((exePath + "/assets/").c_str())); VFSRegister("", new DirectoryAssetReader(exePath.c_str())); - wchar_t lcCountry[256]; - - // LOCALE_SNAME is only available in WinVista+ - // Really should find a way to do this in XP too :/ - if (0 != GetLocaleInfo(LOCALE_NAME_USER_DEFAULT, LOCALE_SNAME, lcCountry, 256)) { - langRegion = ConvertWStringToUTF8(lcCountry); - for (size_t i = 0; i < langRegion.size(); i++) { - if (langRegion[i] == '-') - langRegion[i] = '_'; - } - } else { - langRegion = "en_US"; - } - + langRegion = GetDefaultLangRegion(); osName = GetWindowsVersion() + " " + GetWindowsSystemArchitecture(); char configFilename[MAX_PATH] = { 0 };