X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/14f8fa9d7fa07b02c276981d135ce73cf6818879..c4f4cf895c1576d2c474a8ebec5d3ee01b98d5f7:/src/common/intl.cpp diff --git a/src/common/intl.cpp b/src/common/intl.cpp index 3b26983d77..e2a7299f7a 100644 --- a/src/common/intl.cpp +++ b/src/common/intl.cpp @@ -147,7 +147,7 @@ static inline wxString ExtractNotLang(const wxString& langFull) // This is a "low-level" class and is used only by wxMsgCatalog // ---------------------------------------------------------------------------- -WX_DECLARE_EXPORTED_STRING_HASH_MAP(wxString, wxMessagesHash) +WX_DECLARE_EXPORTED_STRING_HASH_MAP(wxString, wxMessagesHash); class wxMsgCatalogFile { @@ -202,6 +202,8 @@ private: inline size_t32 Swap(size_t32 ui) const; bool m_bSwapped; // wrong endianness? + + DECLARE_NO_COPY_CLASS(wxMsgCatalogFile) }; @@ -506,7 +508,7 @@ wxString wxMsgCatalogFile::GetCharset() const return wxEmptyString; } - wxString header(StringAtOfs(m_pTransTable, 0)); + wxString header = wxString::FromAscii( StringAtOfs(m_pTransTable, 0)); wxString charset; int pos = header.Find(wxT("Content-Type: text/plain; charset=")); if ( pos == wxNOT_FOUND ) @@ -609,6 +611,8 @@ bool wxLocale::Init(const wxChar *szName, { // the argument to setlocale() szLocale = szShort; + + wxCHECK_MSG( szLocale, FALSE, _T("no locale to set in wxLocale::Init()") ); } m_pszOldLocale = wxSetlocale(LC_ALL, szLocale); if ( m_pszOldLocale == NULL ) @@ -666,7 +670,6 @@ bool wxLocale::Init(int language, int flags) wxString name = info->Description; wxString canonical = info->CanonicalName; wxString locale; - const wxChar *retloc; // Set the locale: #if defined(__UNIX__) && !defined(__WXMAC__) @@ -675,48 +678,55 @@ bool wxLocale::Init(int language, int flags) else locale = info->CanonicalName; - retloc = wxSetlocale(LC_ALL, locale); + wxMB2WXbuf retloc = wxSetlocale(LC_ALL, locale); - if (retloc == NULL) + if ( !retloc ) { // Some C libraries don't like xx_YY form and require xx only retloc = wxSetlocale(LC_ALL, locale.Mid(0,2)); } - if (retloc == NULL) + if ( !retloc ) { // Some C libraries (namely glibc) still use old ISO 639, // so will translate the abbrev for them wxString mid = locale.Mid(0,2); - if (mid == wxT("he")) locale = wxT("iw") + locale.Mid(3); - else if (mid == wxT("id")) locale = wxT("in") + locale.Mid(3); - else if (mid == wxT("yi")) locale = wxT("ji") + locale.Mid(3); + if (mid == wxT("he")) + locale = wxT("iw") + locale.Mid(3); + else if (mid == wxT("id")) + locale = wxT("in") + locale.Mid(3); + else if (mid == wxT("yi")) + locale = wxT("ji") + locale.Mid(3); + retloc = wxSetlocale(LC_ALL, locale); } - if (retloc == NULL) + if ( !retloc ) { // (This time, we changed locale in previous if-branch, so try again.) // Some C libraries don't like xx_YY form and require xx only retloc = wxSetlocale(LC_ALL, locale.Mid(0,2)); } - if (retloc == NULL) + if ( !retloc ) { wxLogError(wxT("Cannot set locale to '%s'."), locale.c_str()); return FALSE; } #elif defined(__WIN32__) + wxMB2WXbuf retloc = wxT("C"); if (language != wxLANGUAGE_DEFAULT) { if (info->WinLang == 0) { wxLogWarning(wxT("Locale '%s' not supported by OS."), name.c_str()); - retloc = wxT("C"); + // retloc already set to "C" } else { wxUint32 lcid = MAKELCID(MAKELANGID(info->WinLang, info->WinSublang), SORT_DEFAULT); if (SetThreadLocale(lcid)) + { retloc = wxSetlocale(LC_ALL, wxEmptyString); + } else { // Windows9X doesn't support SetThreadLocale, so we must @@ -738,27 +748,38 @@ bool wxLocale::Init(int language, int flags) return FALSE; } else + { retloc = wxSetlocale(LC_ALL, locale); + } } } } else + { retloc = wxSetlocale(LC_ALL, wxEmptyString); + } - if (retloc == NULL) + if ( !retloc ) { wxLogError(wxT("Cannot set locale to language %s."), name.c_str()); return FALSE; } -#elif defined(__WXMAC__) - retloc = wxSetlocale(LC_ALL , wxEmptyString); +#elif defined(__WXMAC__) || defined(__WXPM__) + wxMB2WXbuf retloc = wxSetlocale(LC_ALL , wxEmptyString); #else return FALSE; + #define WX_NO_LOCALE_SUPPORT #endif - return Init(name, canonical, wxString(retloc), - (flags & wxLOCALE_LOAD_DEFAULT) != 0, - (flags & wxLOCALE_CONV_ENCODING) != 0); +#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 } @@ -1334,6 +1355,17 @@ wxFontEncoding wxLocale::GetSystemEncoding() wxFontEncoding enc = wxFontMapper::Get()-> CharsetToEncoding(encname, FALSE /* not interactive */); + // on some modern Linux systems (RedHat 8) the default system locale + // is UTF8 -- but it isn't supported by wxGTK in ANSI build at all so + // don't even try to use it in this case +#if !wxUSE_UNICODE + if ( enc == wxFONTENCODING_UTF8 ) + { + // the most similar supported encoding... + enc = wxFONTENCODING_ISO8859_1; + } +#endif // !wxUSE_UNICODE + // this should probably be considered as a bug in CharsetToEncoding(): // it shouldn't return wxFONTENCODING_DEFAULT at all - but it does it // for US-ASCII charset @@ -2095,7 +2127,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxLocaleModule, wxModule) #define LNG(wxlang, canonical, winlang, winsublang, desc) \ info.Language = wxlang; \ info.CanonicalName = wxT(canonical); \ - info.Description = desc; \ + info.Description = wxT(desc); \ SETWINLANG(info, winlang, winsublang) \ AddLanguage(info); @@ -2151,7 +2183,7 @@ void wxLocale::InitLanguagesDB() LNG(wxLANGUAGE_CHINESE_HONGKONG, "zh_HK", LANG_CHINESE , SUBLANG_CHINESE_HONGKONG , "Chinese (Hongkong)") LNG(wxLANGUAGE_CHINESE_MACAU, "zh_MO", LANG_CHINESE , SUBLANG_CHINESE_MACAU , "Chinese (Macau)") LNG(wxLANGUAGE_CHINESE_SINGAPORE, "zh_SG", LANG_CHINESE , SUBLANG_CHINESE_SINGAPORE , "Chinese (Singapore)") - LNG(wxLANGUAGE_CHINESE_TAIWAN, "zh_TW", 0 , 0 , "Chinese (Taiwan)") + LNG(wxLANGUAGE_CHINESE_TAIWAN, "zh_TW", LANG_CHINESE , SUBLANG_CHINESE_TRADITIONAL , "Chinese (Taiwan)") LNG(wxLANGUAGE_CORSICAN, "co" , 0 , 0 , "Corsican") LNG(wxLANGUAGE_CROATIAN, "hr_HR", LANG_CROATIAN , SUBLANG_DEFAULT , "Croatian") LNG(wxLANGUAGE_CZECH, "cs_CZ", LANG_CZECH , SUBLANG_DEFAULT , "Czech")