Always succeed in CreateForLanguage(wxLANGUAGE_ENGLISH)

This is required for wxLocale compatibility, as using wxLANGUAGE_ENGLISH
is supposed to be the same as using "C" locale (even if it isn't,
really) at wxLocale level.
This commit is contained in:
Vadim Zeitlin
2021-08-31 03:25:50 +02:00
parent c835d1afa6
commit 5bf11d94a7
2 changed files with 18 additions and 2 deletions

View File

@@ -50,7 +50,9 @@ public:
// The language passed to this function is a valid language, i.e. neither
// wxLANGUAGE_UNKNOWN nor wxLANGUAGE_DEFAULT.
//
// It may return NULL in case of failure.
// It may return NULL in case of failure, but never does so for English
// languages because wxLocale(wxLANGUAGE_ENGLISH) is always supposed to
// work, so it just falls back on CreateStdC() if it fails to create it.
static wxUILocaleImpl* CreateForLanguage(const wxLanguageInfo& info);
// Use this locale in the UI.

View File

@@ -22,6 +22,10 @@
#include "wx/uilocale.h"
#ifndef __WINDOWS__
#include "wx/language.h"
#endif
#include "wx/private/uilocale.h"
// ----------------------------------------------------------------------------
@@ -57,7 +61,17 @@ wxUILocaleImpl* wxUILocaleImpl::CreateForLanguage(const wxLanguageInfo& info)
locId.Modifier(mod);
}
return CreateForLocale(locId);
wxUILocaleImpl* impl = CreateForLocale(locId);
if ( !impl &&
(info.Language == wxLANGUAGE_ENGLISH ||
info.Language == wxLANGUAGE_ENGLISH_US) )
{
// For compatibility, never fail creating locale for neutral or US
// English, even if it's unavailable on the current system somehow.
impl = CreateStdC();
}
return impl;
}
#endif // !__WINDOWS__