From eb5d482ded221f7fae03c345334318836157ce43 Mon Sep 17 00:00:00 2001 From: James Turner Date: Mon, 22 May 2017 17:50:50 +0100 Subject: [PATCH] Use GetUserDefaultLocaleName This should improve our locale detection on Windows, since it is the recommended solution according to MSDN. --- src/Main/locale.cxx | 43 ++++++++++++------------------------------- 1 file changed, 12 insertions(+), 31 deletions(-) diff --git a/src/Main/locale.cxx b/src/Main/locale.cxx index da0ff460f..15f32026b 100644 --- a/src/Main/locale.cxx +++ b/src/Main/locale.cxx @@ -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; - } - - locale[--i] = 0; - SG_LOG(SG_GENERAL, SG_WARN, "Failed to detected locale's country setting."); - result.push_back(locale); + if (GetUserDefaultLocaleName(localeNameBuf, LOCALE_NAME_MAX_LENGTH)) { + std::wstring ws(localeNameBuf); + std::string localeNameUTF8 = simgear::strutils::convertWStringToUtf8(ws); + + 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; }