From 019e9d041fba2544831ef653b8aeaee123ef22e6 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 14 Jul 2017 20:05:01 +0200 Subject: [PATCH] Fix setting locale under MSW when using locale name Previously, all MSW-specific stuff like calling SetThreadLocale() and SetThreadUILanguage() was only done when initializing wxLocale from a wxLanguage value, but not when using a string name for it. Fix this by implicitly calling Init(wxLanguage) from Init(wxString) if we can find the language corresponding to the given name, and if the other parameter is not incompatible with it. --- src/common/intl.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/common/intl.cpp b/src/common/intl.cpp index 4386df0bd4..eee34aae76 100644 --- a/src/common/intl.cpp +++ b/src/common/intl.cpp @@ -299,6 +299,23 @@ bool wxLocale::Init(const wxString& name, wxS("no locale to set in wxLocale::Init()") ); } + if ( const wxLanguageInfo* langInfo = FindLanguageInfo(szLocale) ) + { + // Prefer to use Init(wxLanguage) overload if possible as it will + // correctly set our m_language and also set the locale correctly under + // MSW, where just calling wxSetLocale() as we do below is not enough. + // + // However don't do it if the parameters are incompatible with this + // language, e.g. if we are called with something like ("French", "de") + // to use French locale but German translations: this seems unlikely to + // happen but, in principle, it could. + if ( langInfo->CanonicalName.StartsWith(shortName) ) + { + return Init(langInfo->Language, + bLoadDefault ? wxLOCALE_LOAD_DEFAULT : 0); + } + } + // the short name will be used to look for catalog files as well, // so we need something here wxString strShort(shortName);