From e9ea0f53f606759520fb0b600761a6ec1618a662 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 2 Mar 2021 18:14:58 +0100 Subject: [PATCH] Refactor platform checks in wxLocale::Init() Avoid the need for ugly WX_NO_LOCALE_SUPPORT macro at the cost of a couple of extra #ifs, which seems to be a worthy trade-off. This also allows making the code calling setlocale("") for the default language platform-independent. No real changes. --- src/common/intl.cpp | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/common/intl.cpp b/src/common/intl.cpp index 32191a40f0..0b0d8798f4 100644 --- a/src/common/intl.cpp +++ b/src/common/intl.cpp @@ -508,8 +508,18 @@ bool wxLocale::Init(int lang, int flags) DoInit(name, shortName, lang); // Set the locale: + +#if defined(__UNIX__) || defined(__WIN32__) + + // We prefer letting the CRT to set its locale on its own when using + // default locale, as it does a better job of it than we do. We also have + // to do this when we didn't recognize the default language at all. + const char *retloc = lang == wxLANGUAGE_DEFAULT ? wxSetlocale(LC_ALL, "") + : NULL; + #if defined(__UNIX__) - const char *retloc = wxSetlocaleTryAll(LC_ALL, shortName); + if ( !retloc ) + retloc = wxSetlocaleTryAll(LC_ALL, shortName); if ( !retloc ) { @@ -546,16 +556,12 @@ bool wxLocale::Init(int lang, int flags) #endif // __AIX__ #elif defined(__WIN32__) - const char *retloc; if ( lang == wxLANGUAGE_DEFAULT ) { ::SetThreadLocale(LOCALE_USER_DEFAULT); wxMSWSetThreadUILanguage(LANG_USER_DEFAULT); - // We're using the system language, so let setlocale() deal with it: it - // does it better than we do and we might not even know about this - // language in the first place. - retloc = wxSetlocale(LC_ALL, ""); + // CRT locale already set above. } else if ( info->WinLang == 0 ) { @@ -591,12 +597,9 @@ bool wxLocale::Init(int lang, int flags) } #endif // CRT not handling Unicode-only languages #else - wxUnusedVar(flags); - return false; - #define WX_NO_LOCALE_SUPPORT + #error "Unsupported platform" #endif -#ifndef WX_NO_LOCALE_SUPPORT return DoCommonPostInit ( retloc != NULL, @@ -604,7 +607,10 @@ bool wxLocale::Init(int lang, int flags) shortName, flags & wxLOCALE_LOAD_DEFAULT ); -#endif // !WX_NO_LOCALE_SUPPORT +#else // !(__UNIX__ || __WIN32__) + wxUnusedVar(flags); + return false; +#endif } namespace