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.
This commit is contained in:
Vadim Zeitlin 2017-07-14 20:05:01 +02:00
parent 8cb4e70064
commit 019e9d041f

View File

@ -299,6 +299,23 @@ bool wxLocale::Init(const wxString& name,
wxS("no locale to set in wxLocale::Init()") ); 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, // the short name will be used to look for catalog files as well,
// so we need something here // so we need something here
wxString strShort(shortName); wxString strShort(shortName);