X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/31b7522e2bc5a058e75bd710471198fb384e500b..d2b23b67301bd2d286366d4326a21da3132558fa:/src/common/intl.cpp?ds=sidebyside diff --git a/src/common/intl.cpp b/src/common/intl.cpp index 0dcec79652..f8129005d8 100644 --- a/src/common/intl.cpp +++ b/src/common/intl.cpp @@ -1534,7 +1534,8 @@ bool wxLocale::Init(const wxString& name, // the argument to setlocale() szLocale = shortName; - wxCHECK_MSG( szLocale, false, _T("no locale to set in wxLocale::Init()") ); + wxCHECK_MSG( !szLocale.empty(), false, + _T("no locale to set in wxLocale::Init()") ); } #ifdef __WXWINCE__ @@ -1599,10 +1600,14 @@ bool wxLocale::Init(const wxString& name, #if defined(__UNIX__) && wxUSE_UNICODE && !defined(__WXMAC__) -static wxWCharBuffer wxSetlocaleTryUTF(int c, const wxChar *lc) +static wxWCharBuffer wxSetlocaleTryUTF8(int c, const wxChar *lc) { - wxMB2WXbuf l = wxSetlocale(c, lc); - if ( !l && lc && lc[0] != 0 ) + wxMB2WXbuf l; + + // NB: We prefer to set UTF-8 locale if it's possible and only fall back to + // non-UTF-8 locale if it fails + + if ( lc && lc[0] != 0 ) { wxString buf(lc); wxString buf2; @@ -1624,10 +1629,15 @@ static wxWCharBuffer wxSetlocaleTryUTF(int c, const wxChar *lc) l = wxSetlocale(c, buf2.c_str()); } } + + // if we can't set UTF-8 locale, try non-UTF-8 one: + if ( !l ) + l = wxSetlocale(c, lc); + return l; } #else -#define wxSetlocaleTryUTF(c, lc) wxSetlocale(c, lc) +#define wxSetlocaleTryUTF8(c, lc) wxSetlocale(c, lc) #endif bool wxLocale::Init(int language, int flags) @@ -1665,13 +1675,13 @@ bool wxLocale::Init(int language, int flags) if (language != wxLANGUAGE_DEFAULT) locale = info->CanonicalName; - wxMB2WXbuf retloc = wxSetlocaleTryUTF(LC_ALL, locale); + wxMB2WXbuf retloc = wxSetlocaleTryUTF8(LC_ALL, locale); const wxString langOnly = locale.Left(2); if ( !retloc ) { // Some C libraries don't like xx_YY form and require xx only - retloc = wxSetlocaleTryUTF(LC_ALL, langOnly); + retloc = wxSetlocaleTryUTF8(LC_ALL, langOnly); } #if wxUSE_FONTMAP @@ -1712,9 +1722,9 @@ bool wxLocale::Init(int language, int flags) if ( !localeAlt.empty() ) { - retloc = wxSetlocaleTryUTF(LC_ALL, localeAlt); + retloc = wxSetlocaleTryUTF8(LC_ALL, localeAlt); if ( !retloc ) - retloc = wxSetlocaleTryUTF(LC_ALL, localeAlt.Left(2)); + retloc = wxSetlocaleTryUTF8(LC_ALL, localeAlt.Left(2)); } } @@ -2740,11 +2750,11 @@ bool wxLocale::IsAvailable(int lang) // Test if setting the locale works, then set it back. wxMB2WXbuf oldLocale = wxSetlocale(LC_ALL, wxEmptyString); - wxMB2WXbuf tmp = wxSetlocaleTryUTF(LC_ALL, info->CanonicalName); + wxMB2WXbuf tmp = wxSetlocaleTryUTF8(LC_ALL, info->CanonicalName); if ( !tmp ) { // Some C libraries don't like xx_YY form and require xx only - tmp = wxSetlocaleTryUTF(LC_ALL, info->CanonicalName.Left(2)); + tmp = wxSetlocaleTryUTF8(LC_ALL, info->CanonicalName.Left(2)); if ( !tmp ) return false; }