1
0
Fork 0

Use GetUserDefaultLocaleName

This should improve our locale detection on Windows, since it is the recommended
solution according to MSDN.
This commit is contained in:
James Turner 2017-05-22 17:50:50 +01:00
parent 27b34182c7
commit eb5d482ded

View file

@ -49,43 +49,24 @@ FGLocale::~FGLocale()
}
#ifdef _WIN32
/**
* Determine locale/language settings on Windows.
*
* Copyright (C) 1997, 2002, 2003 Martin von Loewis
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose and without fee is hereby granted,
* provided that the above copyright notice appear in all copies.
*
* This software comes with no warranty. Use at your own risk.
*/
string_list
FGLocale::getUserLanguage()
{
string_list result;
static char locale[100] = {0};
static wchar_t localeNameBuf[LOCALE_NAME_MAX_LENGTH];
if (GetLocaleInfo(LOCALE_USER_DEFAULT,
LOCALE_SISO639LANGNAME,
locale, sizeof(locale)))
{
SG_LOG(SG_GENERAL, SG_DEBUG, "Detected locale's language setting: " << locale);
size_t i = strlen(locale);
locale[i++] = '_';
if (GetLocaleInfo(LOCALE_USER_DEFAULT,
LOCALE_SISO3166CTRYNAME,
locale+i, (int)(sizeof(locale)-i)))
{
result.push_back(locale);
return result;
}
if (GetUserDefaultLocaleName(localeNameBuf, LOCALE_NAME_MAX_LENGTH)) {
std::wstring ws(localeNameBuf);
std::string localeNameUTF8 = simgear::strutils::convertWStringToUtf8(ws);
locale[--i] = 0;
SG_LOG(SG_GENERAL, SG_WARN, "Failed to detected locale's country setting.");
result.push_back(locale);
SG_LOG(SG_GENERAL, SG_INFO, "Detected user locale:" << localeNameUTF8);
result.push_back(localeNameUTF8);
return result;
}
} else {
SG_LOG(SG_GENERAL, SG_WARN, "Failed to detected user locale");
}
return result;
}