X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/0d28a1f9271606b5a38b4b7b2a78bd869bb7d520..eea4d01c65f9b29baa1193db762b4c6b8144af24:/src/common/intl.cpp diff --git a/src/common/intl.cpp b/src/common/intl.cpp index d27fc4899d..9b38ffbf14 100644 --- a/src/common/intl.cpp +++ b/src/common/intl.cpp @@ -79,11 +79,6 @@ // constants // ---------------------------------------------------------------------------- -// the constants describing the format of ll_CC locale string -static const size_t LEN_LANG = 2; -static const size_t LEN_SUBLANG = 2; -static const size_t LEN_FULL = LEN_LANG + 1 + LEN_SUBLANG; // 1 for '_' - #define TRACE_I18N wxS("i18n") // ============================================================================ @@ -99,10 +94,10 @@ static wxLocale *wxSetLocale(wxLocale *pLocale); namespace { -// get just the language part +// get just the language part ("en" in "en_GB") inline wxString ExtractLang(const wxString& langFull) { - return langFull.Left(LEN_LANG); + return langFull.BeforeFirst('_'); } // helper functions of GetSystemLanguage() @@ -111,7 +106,11 @@ inline wxString ExtractLang(const wxString& langFull) // get everything else (including the leading '_') inline wxString ExtractNotLang(const wxString& langFull) { - return langFull.Mid(LEN_LANG); + size_t pos = langFull.find('_'); + if ( pos != wxString::npos ) + return langFull.substr(pos); + else + return wxString(); } #endif // __UNIX__ @@ -201,8 +200,7 @@ wxLanguageInfoArray *wxLocale::ms_languagesDB = NULL; /*static*/ void wxLocale::DestroyLanguagesDB() { - delete ms_languagesDB; - ms_languagesDB = NULL; + wxDELETE(ms_languagesDB); } @@ -240,7 +238,7 @@ bool wxLocale::Init(const wxString& name, const wxString& locale, bool bLoadDefault #if WXWIN_COMPATIBILITY_2_8 - ,bool bConvertEncoding + ,bool WXUNUSED_UNLESS_DEBUG(bConvertEncoding) #endif ) { @@ -295,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, @@ -642,94 +640,92 @@ bool wxLocale::Init(int language, int flags) langFull.Truncate(posEndLang); } - // in addition to the format above, we also can have full language names - // in LANG env var - for example, SuSE is known to use LANG="german" - so - // check for this - // do we have just the language (or sublang too)? - bool justLang = langFull.length() == LEN_LANG; - if ( justLang || - (langFull.length() == LEN_FULL && langFull[LEN_LANG] == wxS('_')) ) - { - // 0. Make sure the lang is according to latest ISO 639 - // (this is necessary because glibc uses iw and in instead - // of he and id respectively). - - // the language itself (second part is the dialect/sublang) - wxString langOrig = ExtractLang(langFull); - - wxString lang; - if ( langOrig == wxS("iw")) - lang = wxS("he"); - else if (langOrig == wxS("in")) - lang = wxS("id"); - else if (langOrig == wxS("ji")) - lang = wxS("yi"); - else if (langOrig == wxS("no_NO")) - lang = wxS("nb_NO"); - else if (langOrig == wxS("no_NY")) - lang = wxS("nn_NO"); - else if (langOrig == wxS("no")) - lang = wxS("nb_NO"); - else - lang = langOrig; + const bool justLang = langFull.find('_') == wxString::npos; + + // 0. Make sure the lang is according to latest ISO 639 + // (this is necessary because glibc uses iw and in instead + // of he and id respectively). + + // the language itself (second part is the dialect/sublang) + wxString langOrig = ExtractLang(langFull); + + wxString lang; + if ( langOrig == wxS("iw")) + lang = wxS("he"); + else if (langOrig == wxS("in")) + lang = wxS("id"); + else if (langOrig == wxS("ji")) + lang = wxS("yi"); + else if (langOrig == wxS("no_NO")) + lang = wxS("nb_NO"); + else if (langOrig == wxS("no_NY")) + lang = wxS("nn_NO"); + else if (langOrig == wxS("no")) + lang = wxS("nb_NO"); + else + lang = langOrig; - // did we change it? - if ( lang != langOrig ) - { - langFull = lang + ExtractNotLang(langFull); - } + // did we change it? + if ( lang != langOrig ) + { + langFull = lang + ExtractNotLang(langFull); + } - // 1. Try to find the language either as is: - // a) With modifier if set - if ( !modifier.empty() ) + // 1. Try to find the language either as is: + // a) With modifier if set + if ( !modifier.empty() ) + { + wxString langFullWithModifier = langFull + modifier; + for ( i = 0; i < count; i++ ) { - wxString langFullWithModifier = langFull + modifier; - for ( i = 0; i < count; i++ ) - { - if ( ms_languagesDB->Item(i).CanonicalName == langFullWithModifier ) - break; - } + if ( ms_languagesDB->Item(i).CanonicalName == langFullWithModifier ) + break; } + } - // b) Without modifier - if ( modifier.empty() || i == count ) + // b) Without modifier + if ( modifier.empty() || i == count ) + { + for ( i = 0; i < count; i++ ) { - for ( i = 0; i < count; i++ ) - { - if ( ms_languagesDB->Item(i).CanonicalName == langFull ) - break; - } + if ( ms_languagesDB->Item(i).CanonicalName == langFull ) + break; } + } - // 2. If langFull is of the form xx_YY, try to find xx: - if ( i == count && !justLang ) + // 2. If langFull is of the form xx_YY, try to find xx: + if ( i == count && !justLang ) + { + for ( i = 0; i < count; i++ ) { - for ( i = 0; i < count; i++ ) + if ( ms_languagesDB->Item(i).CanonicalName == lang ) { - if ( ms_languagesDB->Item(i).CanonicalName == lang ) - { - break; - } + break; } } + } - // 3. If langFull is of the form xx, try to find any xx_YY record: - if ( i == count && justLang ) + // 3. If langFull is of the form xx, try to find any xx_YY record: + if ( i == count && justLang ) + { + for ( i = 0; i < count; i++ ) { - for ( i = 0; i < count; i++ ) + if ( ExtractLang(ms_languagesDB->Item(i).CanonicalName) + == langFull ) { - if ( ExtractLang(ms_languagesDB->Item(i).CanonicalName) - == langFull ) - { - break; - } + break; } } } - else // not standard format + + + if ( i == count ) { - // try to find the name in verbose description + // In addition to the format above, we also can have full language + // names in LANG env var - for example, SuSE is known to use + // LANG="german" - so check for use of non-standard format and try to + // find the name in verbose description. for ( i = 0; i < count; i++ ) { if (ms_languagesDB->Item(i).Description.CmpNoCase(langFull) == 0) @@ -1028,7 +1024,7 @@ wxLocale::~wxLocale() wxSetLocale(m_pOldLocale); wxSetlocale(LC_ALL, m_pszOldLocale); - free((wxChar *)m_pszOldLocale); // const_cast + free(const_cast(m_pszOldLocale)); } @@ -1049,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; @@ -1411,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() ) @@ -1429,8 +1430,18 @@ 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; break;