X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f48a115976827701bb7b4bab7333f7512de08ab2..08670ea85abf4b4946a9ce64971b591d7b1ee30b:/src/common/intl.cpp diff --git a/src/common/intl.cpp b/src/common/intl.cpp index 7499eb5447..97cb520a39 100644 --- a/src/common/intl.cpp +++ b/src/common/intl.cpp @@ -293,7 +293,7 @@ bool wxLocale::DoInit(const wxString& name, if ( m_pszOldLocale == NULL ) { - wxLogError(_("locale '%s' can not be set."), szLocale); + wxLogError(_("locale '%s' cannot be set."), szLocale); } // the short name will be used to look for catalog files as well, @@ -1045,16 +1045,21 @@ bool wxLocale::IsAvailable(int lang) #elif defined(__UNIX__) // Test if setting the locale works, then set it back. - const char *oldLocale = wxSetlocaleTryUTF8(LC_ALL, info->CanonicalName); - if ( !oldLocale ) - { - // Some C libraries don't like xx_YY form and require xx only - oldLocale = wxSetlocaleTryUTF8(LC_ALL, ExtractLang(info->CanonicalName)); - if ( !oldLocale ) - return false; - } + char * const oldLocale = wxStrdupA(setlocale(LC_ALL, NULL)); + + // Some platforms don't like xx_YY form and require xx only so test for + // it too. + const bool + available = wxSetlocaleTryUTF8(LC_ALL, info->CanonicalName) || + wxSetlocaleTryUTF8(LC_ALL, ExtractLang(info->CanonicalName)); + // restore the original locale wxSetlocale(LC_ALL, oldLocale); + + free(oldLocale); + + if ( !available ) + return false; #endif return true; @@ -1407,7 +1412,7 @@ LCTYPE GetLCTYPEFormatFromLocalInfo(wxLocaleInfo index) } // anonymous namespace /* static */ -wxString wxLocale::GetInfo(wxLocaleInfo index, wxLocaleCategory WXUNUSED(cat)) +wxString wxLocale::GetInfo(wxLocaleInfo index, wxLocaleCategory cat) { wxUint32 lcid = LOCALE_USER_DEFAULT; if ( wxGetLocale() ) @@ -1425,9 +1430,35 @@ wxString wxLocale::GetInfo(wxLocaleInfo index, wxLocaleCategory WXUNUSED(cat)) switch ( index ) { + case wxLOCALE_THOUSANDS_SEP: + if ( ::GetLocaleInfo(lcid, LOCALE_STHOUSAND, buf, WXSIZEOF(buf)) ) + str = buf; + break; + case wxLOCALE_DECIMAL_POINT: - if ( ::GetLocaleInfo(lcid, LOCALE_SDECIMAL, buf, WXSIZEOF(buf)) ) + if ( ::GetLocaleInfo(lcid, + cat == wxLOCALE_CAT_MONEY + ? LOCALE_SMONDECIMALSEP + : LOCALE_SDECIMAL, + buf, + WXSIZEOF(buf)) ) + { str = buf; + + // As we get our decimal point separator from Win32 and not the + // CRT there is a possibility of mismatch between them and this + // can easily happen if the user code called setlocale() + // instead of using wxLocale to change the locale. And this can + // result in very strange bugs elsewhere in the code as the + // assumptions that formatted strings do use the decimal + // separator actually fail, so check for it here. + wxASSERT_MSG + ( + wxString::Format("%.3f", 1.23).find(str) != wxString::npos, + "Decimal separator mismatch -- did you use setlocale()?" + "If so, use wxLocale to change the locale instead." + ); + } break; case wxLOCALE_SHORT_DATE_FMT: