mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-16 00:34:19 +00:00
Windows: replace deprecated OS calls in SystemStats::getDisplayLanguage()
The previously used getUserDefaultUILanguage() was based on the deprecated LCID/LANGID concept. It had an increasing number of corner cases as not every locale had associated LCIDs. The new solution is based on locale names (string based) and will return reasonable names in more situations.
This commit is contained in:
parent
1ee106d730
commit
fbc1a51a67
1 changed files with 25 additions and 9 deletions
|
|
@ -554,20 +554,36 @@ String SystemStats::getUserRegion() { return getLocaleValue (LOCALE_USER_D
|
|||
String SystemStats::getDisplayLanguage()
|
||||
{
|
||||
DynamicLibrary dll ("kernel32.dll");
|
||||
JUCE_LOAD_WINAPI_FUNCTION (dll, GetUserDefaultUILanguage, getUserDefaultUILanguage, LANGID, (void))
|
||||
JUCE_LOAD_WINAPI_FUNCTION (dll,
|
||||
GetUserPreferredUILanguages,
|
||||
getUserPreferredUILanguages,
|
||||
BOOL,
|
||||
(DWORD, PULONG, PZZWSTR, PULONG))
|
||||
|
||||
if (getUserDefaultUILanguage == nullptr)
|
||||
return "en";
|
||||
constexpr auto defaultResult = "en";
|
||||
|
||||
auto langID = MAKELCID (getUserDefaultUILanguage(), SORT_DEFAULT);
|
||||
if (getUserPreferredUILanguages == nullptr)
|
||||
return defaultResult;
|
||||
|
||||
auto mainLang = getLocaleValue (langID, LOCALE_SISO639LANGNAME, "en");
|
||||
auto region = getLocaleValue (langID, LOCALE_SISO3166CTRYNAME, nullptr);
|
||||
ULONG numLanguages = 0;
|
||||
ULONG numCharsInLanguagesBuffer = 0;
|
||||
|
||||
if (region.isNotEmpty())
|
||||
mainLang << '-' << region;
|
||||
// Retrieving the necessary buffer size for storing the list of languages
|
||||
if (! getUserPreferredUILanguages (MUI_LANGUAGE_NAME, &numLanguages, nullptr, &numCharsInLanguagesBuffer))
|
||||
return defaultResult;
|
||||
|
||||
return mainLang;
|
||||
std::vector<WCHAR> languagesBuffer (numCharsInLanguagesBuffer);
|
||||
const auto success = getUserPreferredUILanguages (MUI_LANGUAGE_NAME,
|
||||
&numLanguages,
|
||||
languagesBuffer.data(),
|
||||
&numCharsInLanguagesBuffer);
|
||||
|
||||
if (! success || numLanguages == 0)
|
||||
return defaultResult;
|
||||
|
||||
// The buffer contains a zero delimited list of languages, the first being
|
||||
// the currently displayed language.
|
||||
return languagesBuffer.data();
|
||||
}
|
||||
|
||||
} // namespace juce
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue