Use GetUserDefaultLocaleName
This should improve our locale detection on Windows, since it is the recommended solution according to MSDN.
This commit is contained in:
parent
27b34182c7
commit
eb5d482ded
1 changed files with 12 additions and 31 deletions
|
@ -49,43 +49,24 @@ FGLocale::~FGLocale()
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _WIN32
|
#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
|
string_list
|
||||||
FGLocale::getUserLanguage()
|
FGLocale::getUserLanguage()
|
||||||
{
|
{
|
||||||
string_list result;
|
string_list result;
|
||||||
static char locale[100] = {0};
|
static wchar_t localeNameBuf[LOCALE_NAME_MAX_LENGTH];
|
||||||
|
|
||||||
if (GetLocaleInfo(LOCALE_USER_DEFAULT,
|
if (GetUserDefaultLocaleName(localeNameBuf, LOCALE_NAME_MAX_LENGTH)) {
|
||||||
LOCALE_SISO639LANGNAME,
|
std::wstring ws(localeNameBuf);
|
||||||
locale, sizeof(locale)))
|
std::string localeNameUTF8 = simgear::strutils::convertWStringToUtf8(ws);
|
||||||
{
|
|
||||||
SG_LOG(SG_GENERAL, SG_DEBUG, "Detected locale's language setting: " << locale);
|
SG_LOG(SG_GENERAL, SG_INFO, "Detected user locale:" << localeNameUTF8);
|
||||||
size_t i = strlen(locale);
|
result.push_back(localeNameUTF8);
|
||||||
locale[i++] = '_';
|
|
||||||
if (GetLocaleInfo(LOCALE_USER_DEFAULT,
|
|
||||||
LOCALE_SISO3166CTRYNAME,
|
|
||||||
locale+i, (int)(sizeof(locale)-i)))
|
|
||||||
{
|
|
||||||
result.push_back(locale);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
locale[--i] = 0;
|
|
||||||
SG_LOG(SG_GENERAL, SG_WARN, "Failed to detected locale's country setting.");
|
|
||||||
result.push_back(locale);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
} else {
|
||||||
|
SG_LOG(SG_GENERAL, SG_WARN, "Failed to detected user locale");
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue