From 713c3f9d1b10ac25fb3c4a1ff115e23c035851db Mon Sep 17 00:00:00 2001 From: Jonathan Li Date: Sun, 27 Nov 2016 23:55:59 +0000 Subject: [PATCH] Use locale name directly for Windows Vista and later MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of combining the language, country and codepage and passing the resulting string to setlocale(), the locale name can be used instead for setlocale() on Windows Vista and onwards. Closes https://github.com/wxWidgets/wxWidgets/pull/358 This fixes a crash that occurs when switching locale from Korean to Norwegian Bokmål, since the language_country.codepage string resolves to "Norwegian Bokmål_Norway.1252" and mbstowcs trips up on the non-ASCII character. --- src/common/intl.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/common/intl.cpp b/src/common/intl.cpp index 1f6f8de543..a2e6a68a03 100644 --- a/src/common/intl.cpp +++ b/src/common/intl.cpp @@ -49,6 +49,10 @@ #ifdef __WIN32__ #include "wx/dynlib.h" #include "wx/msw/private.h" + + #ifndef LOCALE_SNAME + #define LOCALE_SNAME 0x5c + #endif #endif #include "wx/file.h" @@ -147,6 +151,19 @@ wxString wxLanguageInfo::GetLocaleName() const wxChar buffer[256]; buffer[0] = wxT('\0'); + if ( wxGetWinVersion() >= wxWinVersion_Vista ) + { + if ( ::GetLocaleInfo(lcid, LOCALE_SNAME, buffer, WXSIZEOF(buffer)) ) + { + locale << buffer; + } + else + { + wxLogLastError(wxT("GetLocaleInfo(LOCALE_SNAME)")); + } + return locale; + } + if ( !::GetLocaleInfo(lcid, LOCALE_SENGLANGUAGE, buffer, WXSIZEOF(buffer)) ) { wxLogLastError(wxT("GetLocaleInfo(LOCALE_SENGLANGUAGE)"));