Merge pull request #8306 from unknownbrackets/lang-fuzzy

Fuzzy match lang when user locale doesn't exist + XP support
This commit is contained in:
Henrik Rydgård committed 2015-12-28 19:44:32 +01:00
commit d5121cd974
2 files changed
+44 -19

No files matched your search

+21 -4
View File
@@ -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<std::string> 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();
+23 -15
View File
@@ -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 <algorithm>
#include <WinNls.h>
#include <math.h>
#include <Wbemidl.h>
@@ -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<std::wstring> 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 };