Reuse Unix branch of wxLocale::Init() for macOS too
There doesn't seem to be any reason to partially duplicate Unix-specific code in a separate Mac branch when we can just use the same code. Parts of it which are not necessary under Mac, such as trying ".UTF-8" locales in wxSetlocaleTryUTF8(), can be separately disabled there (even though they are harmless), but other parts are probably needed, e.g. setting Norwegian locale failed under macOS before because we didn't translate nb_NO that we use to no_NO actually supported under macOS.
This commit is contained in:
@@ -385,14 +385,16 @@ bool wxLocale::DoCommonPostInit(bool success,
|
|||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(__UNIX__) && wxUSE_UNICODE && !defined(__WXMAC__)
|
#if defined(__UNIX__)
|
||||||
static const char *wxSetlocaleTryUTF8(int c, const wxString& lc)
|
static const char *wxSetlocaleTryUTF8(int c, const wxString& lc)
|
||||||
{
|
{
|
||||||
const char *l = NULL;
|
const char *l = NULL;
|
||||||
|
|
||||||
// NB: We prefer to set UTF-8 locale if it's possible and only fall back to
|
// NB: We prefer to set UTF-8 locale if it's possible and only fall back to
|
||||||
// non-UTF-8 locale if it fails
|
// non-UTF-8 locale if it fails, but this is not necessary under the
|
||||||
|
// supported macOS versions where xx_YY locales are just aliases to
|
||||||
|
// xx_YY.UTF-8 anyhow.
|
||||||
|
#if wxUSE_UNICODE && !defined(__WXMAC__)
|
||||||
if ( !lc.empty() )
|
if ( !lc.empty() )
|
||||||
{
|
{
|
||||||
wxString buf(lc);
|
wxString buf(lc);
|
||||||
@@ -418,13 +420,12 @@ static const char *wxSetlocaleTryUTF8(int c, const wxString& lc)
|
|||||||
|
|
||||||
// if we can't set UTF-8 locale, try non-UTF-8 one:
|
// if we can't set UTF-8 locale, try non-UTF-8 one:
|
||||||
if ( !l )
|
if ( !l )
|
||||||
|
#endif // wxUSE_UNICODE && !__WXMAC__
|
||||||
l = wxSetlocale(c, lc);
|
l = wxSetlocale(c, lc);
|
||||||
|
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
#else
|
#endif // __UNIX__
|
||||||
#define wxSetlocaleTryUTF8(c, lc) wxSetlocale(c, lc)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
bool wxLocale::Init(int language, int flags)
|
bool wxLocale::Init(int language, int flags)
|
||||||
{
|
{
|
||||||
@@ -459,7 +460,7 @@ bool wxLocale::Init(int language, int flags)
|
|||||||
DoInit(name, info->CanonicalName, lang);
|
DoInit(name, info->CanonicalName, lang);
|
||||||
|
|
||||||
// Set the locale:
|
// Set the locale:
|
||||||
#if defined(__UNIX__) && !defined(__WXMAC__)
|
#if defined(__UNIX__)
|
||||||
const wxString& locale = info->CanonicalName;
|
const wxString& locale = info->CanonicalName;
|
||||||
|
|
||||||
const char *retloc = wxSetlocaleTryUTF8(LC_ALL, locale);
|
const char *retloc = wxSetlocaleTryUTF8(LC_ALL, locale);
|
||||||
@@ -552,16 +553,6 @@ bool wxLocale::Init(int language, int flags)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif // CRT not handling Unicode-only languages
|
#endif // CRT not handling Unicode-only languages
|
||||||
#elif defined(__WXMAC__)
|
|
||||||
const wxString& locale = info->CanonicalName;
|
|
||||||
|
|
||||||
const char *retloc = wxSetlocale(LC_ALL, locale);
|
|
||||||
|
|
||||||
if ( !retloc )
|
|
||||||
{
|
|
||||||
// Some C libraries don't like xx_YY form and require xx only
|
|
||||||
retloc = wxSetlocale(LC_ALL, ExtractLang(locale));
|
|
||||||
}
|
|
||||||
#else
|
#else
|
||||||
wxUnusedVar(flags);
|
wxUnusedVar(flags);
|
||||||
return false;
|
return false;
|
||||||
|
Reference in New Issue
Block a user