From 5bf11d94a79c016a91f895b1cca015a526bc3ea3 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 31 Aug 2021 03:25:50 +0200 Subject: [PATCH] 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. --- include/wx/private/uilocale.h | 4 +++- src/common/uilocale.cpp | 16 +++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/include/wx/private/uilocale.h b/include/wx/private/uilocale.h index 9df8bb6d42..abe4f13b14 100644 --- a/include/wx/private/uilocale.h +++ b/include/wx/private/uilocale.h @@ -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. diff --git a/src/common/uilocale.cpp b/src/common/uilocale.cpp index 6bf54e6710..cb3f115518 100644 --- a/src/common/uilocale.cpp +++ b/src/common/uilocale.cpp @@ -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__