X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/44c44c82a3fe5362bac5cc9536f06eeac52af00c..dd38c87578df7a24a491401c943988e2bc89b62b:/src/common/intl.cpp?ds=inline diff --git a/src/common/intl.cpp b/src/common/intl.cpp index e78a33c9d0..0d83c0db88 100644 --- a/src/common/intl.cpp +++ b/src/common/intl.cpp @@ -614,7 +614,8 @@ bool wxLocale::Init(const wxChar *szName, wxCHECK_MSG( szLocale, FALSE, _T("no locale to set in wxLocale::Init()") ); } - m_pszOldLocale = wxSetlocale(LC_ALL, szLocale); + + m_pszOldLocale = wxStrdup(wxSetlocale(LC_ALL, szLocale)); if ( m_pszOldLocale == NULL ) wxLogError(_("locale '%s' can not be set."), szLocale); @@ -696,6 +697,10 @@ bool wxLocale::Init(int language, int flags) locale = wxT("in") + locale.Mid(3); else if (mid == wxT("yi")) locale = wxT("ji") + locale.Mid(3); + else if (mid == wxT("nb")) + locale = wxT("no_NO"); + else if (mid == wxT("nn")) + locale = wxT("no_NY"); retloc = wxSetlocale(LC_ALL, locale); } @@ -711,6 +716,17 @@ bool wxLocale::Init(int language, int flags) return FALSE; } #elif defined(__WIN32__) + + #if wxUSE_UNICODE && (defined(__VISUALC__) || defined(__MINGW32__)) + // NB: setlocale() from msvcrt.dll (used by VC++ and Mingw) + // can't set locale to language that can only be written using + // Unicode. Therefore wxSetlocale call failed, but we don't want + // to report it as an error -- so that at least message catalogs + // can be used. Watch for code marked with + // #ifdef SETLOCALE_FAILS_ON_UNICODE_LANGS bellow. + #define SETLOCALE_FAILS_ON_UNICODE_LANGS + #endif + wxMB2WXbuf retloc = wxT("C"); if (language != wxLANGUAGE_DEFAULT) { @@ -721,42 +737,58 @@ bool wxLocale::Init(int language, int flags) } else { + int codepage = -1; wxUint32 lcid = MAKELCID(MAKELANGID(info->WinLang, info->WinSublang), SORT_DEFAULT); - if (SetThreadLocale(lcid)) + SetThreadLocale(lcid); + // NB: we must translate LCID to CRT's setlocale string ourselves, + // because SetThreadLocale does not modify change the + // interpretation of setlocale(LC_ALL, "") call: + wxChar buffer[256]; + buffer[0] = wxT('\0'); + GetLocaleInfo(lcid, LOCALE_SENGLANGUAGE, buffer, 256); + locale << buffer; + if (GetLocaleInfo(lcid, LOCALE_SENGCOUNTRY, buffer, 256) > 0) + locale << wxT("_") << buffer; + if (GetLocaleInfo(lcid, LOCALE_IDEFAULTANSICODEPAGE, buffer, 256) > 0) + { + codepage = wxAtoi(buffer); + if (codepage != 0) + locale << wxT(".") << buffer; + } + if (locale.IsEmpty()) { - retloc = wxSetlocale(LC_ALL, wxEmptyString); + wxLogLastError(wxT("SetThreadLocale")); + wxLogError(wxT("Cannot set locale to language %s."), name.c_str()); + return FALSE; } else { - // Windows9X doesn't support SetThreadLocale, so we must - // translate LCID to CRT's setlocale string ourselves - locale.Empty(); - if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) - { - wxChar buffer[256]; - buffer[0] = wxT('\0'); - GetLocaleInfo(lcid, LOCALE_SENGLANGUAGE, buffer, 256); - locale << buffer; - if (GetLocaleInfo(lcid, LOCALE_SENGCOUNTRY, buffer, 256) > 0) - locale << wxT("_") << buffer; - } - if (locale.IsEmpty()) - { - wxLogLastError(wxT("SetThreadLocale")); - wxLogError(wxT("Cannot set locale to language %s."), name.c_str()); - return FALSE; - } - else + retloc = wxSetlocale(LC_ALL, locale); +#ifdef SETLOCALE_FAILS_ON_UNICODE_LANGS + if (codepage == 0 && (const wxChar*)retloc == NULL) { - retloc = wxSetlocale(LC_ALL, locale); + retloc = wxT("C"); } +#endif } } } else { retloc = wxSetlocale(LC_ALL, wxEmptyString); +#ifdef SETLOCALE_FAILS_ON_UNICODE_LANGS + if ((const wxChar*)retloc == NULL) + { + wxChar buffer[16]; + if (GetLocaleInfo(LOCALE_USER_DEFAULT, + LOCALE_IDEFAULTANSICODEPAGE, buffer, 16) > 0 && + wxStrcmp(buffer, wxT("0")) == 0) + { + retloc = wxT("C"); + } + } +#endif } if ( !retloc ) @@ -772,12 +804,15 @@ bool wxLocale::Init(int language, int flags) #endif #ifndef WX_NO_LOCALE_SUPPORT - wxChar *szLocale = retloc ? wxStrdup(retloc) : NULL; + wxChar *szLocale = retloc ? wxStrdup(retloc) : NULL; bool ret = Init(name, canonical, retloc, (flags & wxLOCALE_LOAD_DEFAULT) != 0, (flags & wxLOCALE_CONV_ENCODING) != 0); - if (szLocale) - free(szLocale); + free(szLocale); + + if ( ret ) + m_language = lang; + return ret; #endif } @@ -865,10 +900,16 @@ void wxLocale::AddCatalogLookupPathPrefix(const wxString& prefix) wxString lang; if ( langOrig == wxT("iw")) lang = _T("he"); - else if ( langOrig == wxT("in") ) + else if (langOrig == wxT("in")) lang = wxT("id"); - else if ( langOrig == wxT("ji") ) + else if (langOrig == wxT("ji")) lang = wxT("yi"); + else if (langOrig == wxT("no_NO")) + lang = wxT("nb_NO"); + else if (langOrig == wxT("no_NY")) + lang = wxT("nn_NO"); + else if (langOrig == wxT("no")) + lang = wxT("nb_NO"); else lang = langOrig; @@ -964,7 +1005,7 @@ void wxLocale::AddCatalogLookupPathPrefix(const wxString& prefix) lc = wxT("fr_CA") ; break ; case verNorway: - lc = wxT("no_NO") ; + lc = wxT("nb_NO") ; break ; case verIsrael: lc = wxT("iw_IL") ; @@ -1462,6 +1503,7 @@ wxLocale::~wxLocale() // restore old locale wxSetLocale(m_pOldLocale); wxSetlocale(LC_ALL, m_pszOldLocale); + free((wxChar *)m_pszOldLocale); // const_cast } // get the translation of given string in current locale @@ -2313,7 +2355,7 @@ void wxLocale::InitLanguagesDB() LNG(wxLANGUAGE_NAURU, "na" , 0 , 0 , "Nauru") LNG(wxLANGUAGE_NEPALI, "ne" , LANG_NEPALI , SUBLANG_DEFAULT , "Nepali") LNG(wxLANGUAGE_NEPALI_INDIA, "ne_IN", LANG_NEPALI , SUBLANG_NEPALI_INDIA , "Nepali (India)") - LNG(wxLANGUAGE_NORWEGIAN_BOKMAL, "no_NO", LANG_NORWEGIAN , SUBLANG_NORWEGIAN_BOKMAL , "Norwegian (Bokmal)") + LNG(wxLANGUAGE_NORWEGIAN_BOKMAL, "nb_NO", LANG_NORWEGIAN , SUBLANG_NORWEGIAN_BOKMAL , "Norwegian (Bokmal)") LNG(wxLANGUAGE_NORWEGIAN_NYNORSK, "nn_NO", LANG_NORWEGIAN , SUBLANG_NORWEGIAN_NYNORSK , "Norwegian (Nynorsk)") LNG(wxLANGUAGE_OCCITAN, "oc" , 0 , 0 , "Occitan") LNG(wxLANGUAGE_ORIYA, "or" , LANG_ORIYA , SUBLANG_DEFAULT , "Oriya")