X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f8a586e08eef0a5d09612f26f0e0c687cfac9963..6143d3b61e311ae647577c284eaf41dded4e2b3c:/src/common/intl.cpp diff --git a/src/common/intl.cpp b/src/common/intl.cpp index 34e2fc3938..8aeb57fbe9 100644 --- a/src/common/intl.cpp +++ b/src/common/intl.cpp @@ -72,6 +72,7 @@ #endif #include "wx/file.h" +#include "wx/filename.h" #include "wx/tokenzr.h" #include "wx/module.h" #include "wx/fontmap.h" @@ -99,9 +100,6 @@ typedef wxUint32 size_t32; const size_t32 MSGCATALOG_MAGIC = 0x950412de; const size_t32 MSGCATALOG_MAGIC_SW = 0xde120495; -// extension of ".mo" files -#define MSGCATALOG_EXTENSION _T(".mo") - // the constants describing the format of lang_LANG locale string static const size_t LEN_LANG = 2; static const size_t LEN_SUBLANG = 2; @@ -498,7 +496,6 @@ public: ~wxPluralFormsCalculator() {} void init(wxPluralFormsToken::Number nplurals, wxPluralFormsNode* plural); - wxString getString() const; private: wxPluralFormsToken::Number m_nplurals; @@ -1074,16 +1071,14 @@ static wxString GetFullSearchPath(const wxChar *lang) } // open disk file and read in it's contents -bool wxMsgCatalogFile::Load(const wxChar *szDirPrefix, const wxChar *szName0, +bool wxMsgCatalogFile::Load(const wxChar *szDirPrefix, const wxChar *szName, wxPluralFormsCalculatorPtr& rPluralFormsCalculator) { - /* We need to handle locales like de_AT.iso-8859-1 - For this we first chop off the .CHARSET specifier and ignore it. - FIXME: UNICODE SUPPORT: must use CHARSET specifier! - */ - wxString szName = szName0; - if(szName.Find(wxT('.')) != wxNOT_FOUND) // contains a dot - szName = szName.Left(szName.Find(wxT('.'))); + /* + We need to handle locales like de_AT.iso-8859-1 + For this we first chop off the .CHARSET specifier and ignore it. + FIXME: UNICODE SUPPORT: must use CHARSET specifier! + */ wxString searchPath = GetFullSearchPath(szDirPrefix); const wxChar *sublocale = wxStrchr(szDirPrefix, wxT('_')); @@ -1097,9 +1092,6 @@ bool wxMsgCatalogFile::Load(const wxChar *szDirPrefix, const wxChar *szName0, << wxPATH_SEP; } - wxString strFile = szName; - strFile += MSGCATALOG_EXTENSION; - // don't give translation errors here because the wxstd catalog might // not yet be loaded (and it's normal) // @@ -1107,17 +1099,18 @@ bool wxMsgCatalogFile::Load(const wxChar *szDirPrefix, const wxChar *szName0, NoTransErr noTransErr; wxLogVerbose(_("looking for catalog '%s' in path '%s'."), - szName.c_str(), searchPath.c_str()); + szName, searchPath.c_str()); + wxFileName fn(szName); + fn.SetExt(_T("mo")); wxString strFullName; - if ( !wxFindFileInPath(&strFullName, searchPath, strFile) ) { - wxLogVerbose(_("catalog file for domain '%s' not found."), szName.c_str()); + if ( !wxFindFileInPath(&strFullName, searchPath, fn.GetFullPath()) ) { + wxLogVerbose(_("catalog file for domain '%s' not found."), szName); return false; } // open file - wxLogVerbose(_("using catalog '%s' from '%s'."), - szName.c_str(), strFullName.c_str()); + wxLogVerbose(_("using catalog '%s' from '%s'."), szName, strFullName.c_str()); wxFile fileMsg(strFullName); if ( !fileMsg.IsOpened() ) @@ -1130,7 +1123,7 @@ bool wxMsgCatalogFile::Load(const wxChar *szDirPrefix, const wxChar *szName0, // read the whole file in memory m_pData = new size_t8[nSize]; - if ( fileMsg.Read(m_pData, nSize) != nSize ) { + if ( fileMsg.Read(m_pData, (size_t)nSize) != nSize ) { wxDELETEA(m_pData); return false; } @@ -1161,7 +1154,7 @@ bool wxMsgCatalogFile::Load(const wxChar *szDirPrefix, const wxChar *szName0, Swap(pHeader->ofsOrigTable)); m_pTransTable = (wxMsgTableEntry *)(m_pData + Swap(pHeader->ofsTransTable)); - m_nSize = nSize; + m_nSize = (size_t32)nSize; // now parse catalog's header and try to extract catalog charset and // plural forms formula from it: @@ -1226,7 +1219,7 @@ void wxMsgCatalogFile::FillHash(wxMessagesHash& hash, { #if wxUSE_WCHAR_T wxCSConv *csConv = NULL; - if ( !m_charset.IsEmpty() ) + if ( !m_charset.empty() ) csConv = new wxCSConv(m_charset); wxMBConv& inputConv = csConv ? *((wxMBConv*)csConv) : *wxConvCurrent; @@ -1243,7 +1236,7 @@ void wxMsgCatalogFile::FillHash(wxMessagesHash& hash, if ( convertEncoding ) { wxFontEncoding targetEnc = wxFONTENCODING_SYSTEM; - wxFontEncoding enc = wxFontMapper::Get()->CharsetToEncoding(m_charset, false); + wxFontEncoding enc = wxFontMapperBase::Get()->CharsetToEncoding(m_charset, false); if ( enc == wxFONTENCODING_SYSTEM ) { convertEncoding = false; // unknown encoding @@ -1402,6 +1395,9 @@ wxLanguageInfoArray *wxLocale::ms_languagesDB = NULL; void wxLocale::DoCommonInit() { m_pszOldLocale = NULL; + + m_pOldLocale = wxSetLocale(this); + m_pMsgCat = NULL; m_language = wxLANGUAGE_UNKNOWN; m_initialized = false; @@ -1459,7 +1455,7 @@ bool wxLocale::Init(const wxChar *szName, // the short name will be used to look for catalog files as well, // so we need something here - if ( m_strShort.IsEmpty() ) { + if ( m_strShort.empty() ) { // FIXME I don't know how these 2 letter abbreviations are formed, // this wild guess is surely wrong if ( szLocale && szLocale[0] ) @@ -1470,9 +1466,6 @@ bool wxLocale::Init(const wxChar *szName, } } - // save the old locale to be able to restore it later - m_pOldLocale = wxSetLocale(this); - // load the default catalog with wxWidgets standard messages m_pMsgCat = NULL; bool bOk = true; @@ -1637,7 +1630,7 @@ bool wxLocale::Init(int language, int flags) if (codepage != 0) locale << wxT(".") << buffer; } - if (locale.IsEmpty()) + if (locale.empty()) { wxLogLastError(wxT("SetThreadLocale")); wxLogError(wxT("Cannot set locale to language %s."), name.c_str()); @@ -1685,7 +1678,25 @@ bool wxLocale::Init(int language, int flags) wxLogError(wxT("Cannot set locale to language %s."), name.c_str()); return false; } -#elif defined(__WXMAC__) || defined(__WXPM__) +#elif defined(__WXMAC__) + if (lang == wxLANGUAGE_DEFAULT) + locale = wxEmptyString; + else + locale = info->CanonicalName; + + wxMB2WXbuf retloc = wxSetlocale(LC_ALL, locale); + + 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 ) + { + wxLogError(wxT("Cannot set locale to '%s'."), locale.c_str()); + return false; + } +#elif defined(__WXPM__) wxMB2WXbuf retloc = wxSetlocale(LC_ALL , wxEmptyString); #else return false; @@ -1780,7 +1791,7 @@ void wxLocale::AddCatalogLookupPathPrefix(const wxString& prefix) (langFull.Len() == LEN_FULL && langFull[LEN_LANG] == wxT('_')) ) { // 0. Make sure the lang is according to latest ISO 639 - // (this is neccessary because glibc uses iw and in instead + // (this is necessary because glibc uses iw and in instead // of he and id respectively). // the language itself (second part is the dialect/sublang) @@ -2185,6 +2196,9 @@ wxString wxLocale::GetSystemEncodingName() // FIXME: what is the error return value for GetACP()? UINT codepage = ::GetACP(); encname.Printf(_T("windows-%u"), codepage); +#elif defined(__WXMAC__) + // default is just empty string, this resolves to the default system + // encoding later #elif defined(__UNIX_LIKE__) #if defined(HAVE_LANGINFO_H) && defined(CODESET) @@ -2263,12 +2277,17 @@ wxFontEncoding wxLocale::GetSystemEncoding() #if defined(__WIN32__) && !defined(__WXMICROWIN__) UINT codepage = ::GetACP(); - // wxWidgets only knows about CP1250-1257, 932, 936, 949, 950 + // wxWidgets only knows about CP1250-1257, 874, 932, 936, 949, 950 if ( codepage >= 1250 && codepage <= 1257 ) { return (wxFontEncoding)(wxFONTENCODING_CP1250 + codepage - 1250); } + if ( codepage == 874 ) + { + return wxFONTENCODING_CP874; + } + if ( codepage == 932 ) { return wxFONTENCODING_CP932; @@ -2300,7 +2319,7 @@ wxFontEncoding wxLocale::GetSystemEncoding() wxString encname = GetSystemEncodingName(); if ( !encname.empty() ) { - wxFontEncoding enc = wxFontMapper::Get()-> + wxFontEncoding enc = (wxFontMapperBase::Get())-> CharsetToEncoding(encname, false /* not interactive */); // on some modern Linux systems (RedHat 8) the default system locale @@ -2427,8 +2446,9 @@ wxLocale::~wxLocale() delete pTmpCat; } - // restore old locale + // restore old locale pointer wxSetLocale(m_pOldLocale); + // FIXME #ifndef __WXWINCE__ wxSetlocale(LC_ALL, m_pszOldLocale); @@ -2523,14 +2543,14 @@ wxString wxLocale::GetHeaderValue( const wxChar* szHeader, if ( pMsgCat == NULL ) return wxEmptyString; - pszTrans = pMsgCat->GetString(wxT(""), (size_t)-1); + pszTrans = pMsgCat->GetString(wxEmptyString, (size_t)-1); } else { // search in all domains for ( pMsgCat = m_pMsgCat; pMsgCat != NULL; pMsgCat = pMsgCat->m_pNext ) { - pszTrans = pMsgCat->GetString(wxT(""), (size_t)-1); + pszTrans = pMsgCat->GetString(wxEmptyString, (size_t)-1); if ( pszTrans != NULL ) // take the first found break; }