X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/978af864269a739e77d9431c8465435e3f8f7407..63e02796620637b50a96d74a2264f3dea8def866:/src/common/intl.cpp diff --git a/src/common/intl.cpp b/src/common/intl.cpp index ccc1418e29..95eb80b3e1 100644 --- a/src/common/intl.cpp +++ b/src/common/intl.cpp @@ -18,12 +18,6 @@ // headers // ---------------------------------------------------------------------------- -#if defined(__BORLAND__) && !defined(__WXDEBUG__) - // There's a bug in Borland's compiler that breaks wxLocale with -O2, - // so make sure that flag is not used for this file: - #pragma option -O1 -#endif - #ifdef __EMX__ // The following define is needed by Innotek's libc to // make the definition of struct localeconv available. @@ -1017,20 +1011,26 @@ wxMsgCatalogFile::~wxMsgCatalogFile() delete [] m_pData; } -// return the directory to search for message catalogs under the given prefix +// return the directories to search for message catalogs under the given +// prefix, separated by wxPATH_SEP static -wxString GetMsgCatalogSubdir(const wxChar *prefix, const wxChar *lang) +wxString GetMsgCatalogSubdirs(const wxChar *prefix, const wxChar *lang) { wxString searchPath; searchPath << prefix << wxFILE_SEP_PATH << lang; - // under Unix, the message catalogs are supposed to go into LC_MESSAGES - // subdirectory so look there too -#ifdef __UNIX__ + // Under Unix, the message catalogs are supposed to go into LC_MESSAGES + // subdirectory so look there too. Note that we do it on all platforms + // and not just Unix, because it doesn't cost much to look into one more + // directory and doing it this way has two important benefits: + // a) we don't break compatibility with wx-2.6 and older by stopping to + // look in a directory where the catalogs used to be and thus silently + // breaking apps after they are recompiled against the latest wx + // b) it makes it possible to package app's support files in the same + // way on all target platforms const wxString searchPathOrig(searchPath); searchPath << wxFILE_SEP_PATH << wxT("LC_MESSAGES") << wxPATH_SEP << searchPathOrig; -#endif // __UNIX__ return searchPath; } @@ -1045,7 +1045,7 @@ static wxString GetFullSearchPath(const wxChar *lang) count = gs_searchPrefixes.size(); for ( n = 0; n < count; n++ ) { - paths.Add(GetMsgCatalogSubdir(gs_searchPrefixes[n], lang)); + paths.Add(GetMsgCatalogSubdirs(gs_searchPrefixes[n], lang)); } @@ -1065,7 +1065,7 @@ static wxString GetFullSearchPath(const wxChar *lang) const wxChar *pszLcPath = wxGetenv(wxT("LC_PATH")); if ( pszLcPath ) { - const wxString lcp = GetMsgCatalogSubdir(pszLcPath, lang); + const wxString lcp = GetMsgCatalogSubdirs(pszLcPath, lang); if ( paths.Index(lcp) == wxNOT_FOUND ) paths.Add(lcp); } @@ -1074,7 +1074,7 @@ static wxString GetFullSearchPath(const wxChar *lang) wxString wxp = wxGetInstallPrefix(); if ( !wxp.empty() ) { - wxp = GetMsgCatalogSubdir(wxp + _T("/share/locale"), lang); + wxp = GetMsgCatalogSubdirs(wxp + _T("/share/locale"), lang); if ( paths.Index(wxp) == wxNOT_FOUND ) paths.Add(wxp); } @@ -1585,7 +1585,7 @@ bool wxLocale::Init(const wxChar *szName, // an error if this does not exist if ( bOk ) { - wxString port(wxPlatformInfo().GetPortIdName()); + wxString port(wxPlatformInfo::Get().GetPortIdName()); if ( !port.empty() ) { AddCatalog(port.BeforeFirst(wxT('/')).MakeLower()); @@ -1713,7 +1713,7 @@ bool wxLocale::Init(int language, int flags) { retloc = wxSetlocaleTryUTF(LC_ALL, localeAlt); if ( !retloc ) - retloc = wxSetlocaleTryUTF(LC_ALL, locale.Left(2)); + retloc = wxSetlocaleTryUTF(LC_ALL, localeAlt.Left(2)); } } @@ -1898,14 +1898,14 @@ void wxLocale::AddCatalogLookupPathPrefix(const wxString& prefix) !wxGetEnv(wxT("LC_MESSAGES"), &langFull) && !wxGetEnv(wxT("LANG"), &langFull)) { - // no language specified, threat it as English - return wxLANGUAGE_ENGLISH; + // no language specified, treat it as English + return wxLANGUAGE_ENGLISH_US; } if ( langFull == _T("C") || langFull == _T("POSIX") ) { - // default C locale - return wxLANGUAGE_ENGLISH; + // default C locale is English too + return wxLANGUAGE_ENGLISH_US; } // the language string has the following form @@ -2499,7 +2499,9 @@ const wxLanguageInfo *wxLocale::GetLanguageInfo(int lang) { if ( ms_languagesDB->Item(i).Language == lang ) { - return &ms_languagesDB->Item(i); + // We need to create a temporary here in order to make this work with BCC in final build mode + wxLanguageInfo *ptr = &ms_languagesDB->Item(i); + return ptr; } } @@ -2711,6 +2713,44 @@ wxMsgCatalog *wxLocale::FindCatalog(const wxChar *szDomain) const return NULL; } +// check if the given locale is provided by OS and C run time +/* static */ +bool wxLocale::IsAvailable(int lang) +{ + const wxLanguageInfo *info = wxLocale::GetLanguageInfo(lang); + wxCHECK_MSG( info, false, _T("invalid language") ); + +#if defined(__WIN32__) + if ( !info->WinLang ) + return false; + + if ( !::IsValidLocale + ( + MAKELCID(MAKELANGID(info->WinLang, info->WinSublang), + SORT_DEFAULT), + LCID_INSTALLED + ) ) + return false; + +#elif defined(__UNIX__) + + // Test if setting the locale works, then set it back. + wxMB2WXbuf oldLocale = wxSetlocale(LC_ALL, wxEmptyString); + wxMB2WXbuf tmp = wxSetlocaleTryUTF(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)); + if ( !tmp ) + return false; + } + // restore the original locale + wxSetlocale(LC_ALL, oldLocale); +#endif + + return true; +} + // check if the given catalog is loaded bool wxLocale::IsLoaded(const wxChar *szDomain) const { @@ -2720,7 +2760,7 @@ bool wxLocale::IsLoaded(const wxChar *szDomain) const // add a catalog to our linked list bool wxLocale::AddCatalog(const wxChar *szDomain) { - return AddCatalog(szDomain, wxLANGUAGE_ENGLISH, NULL); + return AddCatalog(szDomain, wxLANGUAGE_ENGLISH_US, NULL); } // add a catalog to our linked list