X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/b78a78f779b95dc46b66e07fddac87ffb0aed1dc..0e878cfcc6486c7903ae89b316bc71700320199d:/src/common/intl.cpp diff --git a/src/common/intl.cpp b/src/common/intl.cpp index 98bc6dcc07..9fbde46e7c 100644 --- a/src/common/intl.cpp +++ b/src/common/intl.cpp @@ -768,15 +768,18 @@ bool wxLocale::Init(int language, int flags) wxMB2WXbuf retloc = wxSetlocale(LC_ALL , wxEmptyString); #else return FALSE; + #define WX_NO_LOCALE_SUPPORT #endif - wxChar *szLocale = retloc ? wxStrdup(retloc) : NULL; +#ifndef WX_NO_LOCALE_SUPPORT + 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); return ret; +#endif } @@ -1392,7 +1395,7 @@ const wxLanguageInfo *wxLocale::GetLanguageInfo(int lang) { CreateLanguagesDB(); - size_t count = ms_languagesDB->GetCount(); + const size_t count = ms_languagesDB->GetCount(); for ( size_t i = 0; i < count; i++ ) { if ( ms_languagesDB->Item(i).Language == lang ) @@ -1404,6 +1407,42 @@ const wxLanguageInfo *wxLocale::GetLanguageInfo(int lang) return NULL; } +/* static */ +const wxLanguageInfo *wxLocale::FindLanguageInfo(const wxString& locale) +{ + CreateLanguagesDB(); + + const wxLanguageInfo *infoRet = NULL; + + const size_t count = ms_languagesDB->GetCount(); + for ( size_t i = 0; i < count; i++ ) + { + const wxLanguageInfo *info = &ms_languagesDB->Item(i); + + if ( wxStricmp(locale, info->CanonicalName) == 0 || + wxStricmp(locale, info->Description) == 0 ) + { + // exact match, stop searching + infoRet = info; + break; + } + + if ( wxStricmp(locale, info->CanonicalName.BeforeFirst(_T('_'))) == 0 ) + { + // a match -- but maybe we'll find an exact one later, so continue + // looking + // + // OTOH, maybe we had already found a language match and in this + // case don't overwrite it becauce the entry for the default + // country always appears first in ms_languagesDB + if ( !infoRet ) + infoRet = info; + } + } + + return infoRet; +} + wxString wxLocale::GetSysName() const { return wxSetlocale(LC_ALL, NULL);