X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c48908df67c6504891cccd34088cad955b1357ca..4843cdfe0f9b64aeb9e95266b69752c32322a493:/src/common/intl.cpp diff --git a/src/common/intl.cpp b/src/common/intl.cpp index 66107d6fa7..ad9d29f161 100644 --- a/src/common/intl.cpp +++ b/src/common/intl.cpp @@ -1037,6 +1037,8 @@ static wxString GetFullSearchPath(const wxChar *lang) << wxPATH_SEP; } + // TODO: use wxStandardPaths instead of all this mess!! + // LC_PATH is a standard env var containing the search path for the .mo // files #ifndef __WXWINCE__ @@ -1056,14 +1058,16 @@ static wxString GetFullSearchPath(const wxChar *lang) // then take the current directory // FIXME it should be the directory of the executable -#ifdef __WXMAC__ - wxChar cwd[512] ; - wxGetWorkingDirectory( cwd , sizeof( cwd ) ) ; - searchPath << GetAllMsgCatalogSubdirs(cwd, lang); +#if defined(__WXMAC__) + searchPath << GetAllMsgCatalogSubdirs(wxGetCwd(), lang); // generic search paths could be somewhere in the system folder preferences -#else // !Mac +#elif defined(__WXMSW__) + // look in the directory of the executable + wxString path; + wxSplitPath(wxGetFullModuleName(), &path, NULL, NULL); + searchPath << GetAllMsgCatalogSubdirs(path, lang); +#else // !Mac, !MSW searchPath << GetAllMsgCatalogSubdirs(wxT("."), lang); - #endif // platform return searchPath; @@ -1078,7 +1082,7 @@ bool wxMsgCatalogFile::Load(const wxChar *szDirPrefix, const wxChar *szName0, FIXME: UNICODE SUPPORT: must use CHARSET specifier! */ wxString szName = szName0; - if(szName.Find(wxT('.')) != -1) // contains a dot + if(szName.Find(wxT('.')) != wxNOT_FOUND) // contains a dot szName = szName.Left(szName.Find(wxT('.'))); wxString searchPath = GetFullSearchPath(szDirPrefix); @@ -1108,7 +1112,7 @@ bool wxMsgCatalogFile::Load(const wxChar *szDirPrefix, const wxChar *szName0, wxString strFullName; if ( !wxFindFileInPath(&strFullName, searchPath, strFile) ) { wxLogVerbose(_("catalog file for domain '%s' not found."), szName.c_str()); - return FALSE; + return false; } // open file @@ -1117,22 +1121,22 @@ bool wxMsgCatalogFile::Load(const wxChar *szDirPrefix, const wxChar *szName0, wxFile fileMsg(strFullName); if ( !fileMsg.IsOpened() ) - return FALSE; + return false; - // get the file size - off_t nSize = fileMsg.Length(); + // get the file size (assume it is less than 4Gb...) + wxFileOffset nSize = fileMsg.Length(); if ( nSize == wxInvalidOffset ) - return FALSE; + return false; // 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; + return false; } // examine header - bool bValid = (size_t)nSize > sizeof(wxMsgCatalogHeader); + bool bValid = nSize + (size_t)0 > sizeof(wxMsgCatalogHeader); wxMsgCatalogHeader *pHeader = (wxMsgCatalogHeader *)m_pData; if ( bValid ) { @@ -1148,7 +1152,7 @@ bool wxMsgCatalogFile::Load(const wxChar *szDirPrefix, const wxChar *szName0, wxLogWarning(_("'%s' is not a valid message catalog."), strFullName.c_str()); wxDELETEA(m_pData); - return FALSE; + return false; } // initialize @@ -1157,7 +1161,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: @@ -1222,7 +1226,7 @@ void wxMsgCatalogFile::FillHash(wxMessagesHash& hash, { #if wxUSE_WCHAR_T wxCSConv *csConv = NULL; - if ( !!m_charset ) + if ( !m_charset.empty() ) csConv = new wxCSConv(m_charset); wxMBConv& inputConv = csConv ? *((wxMBConv*)csConv) : *wxConvCurrent; @@ -1234,15 +1238,15 @@ void wxMsgCatalogFile::FillHash(wxMessagesHash& hash, #elif wxUSE_FONTMAP wxASSERT_MSG( msgIdCharset == NULL, _T("non-ASCII msgid languages only supported if wxUSE_WCHAR_T=1") ); - + wxEncodingConverter converter; if ( convertEncoding ) { wxFontEncoding targetEnc = wxFONTENCODING_SYSTEM; - wxFontEncoding enc = wxFontMapper::Get()->CharsetToEncoding(m_charset, FALSE); + wxFontEncoding enc = wxFontMapper::Get()->CharsetToEncoding(m_charset, false); if ( enc == wxFONTENCODING_SYSTEM ) { - convertEncoding = FALSE; // unknown encoding + convertEncoding = false; // unknown encoding } else { @@ -1252,10 +1256,10 @@ void wxMsgCatalogFile::FillHash(wxMessagesHash& hash, wxFontEncodingArray a = wxEncodingConverter::GetPlatformEquivalents(enc); if (a[0] == enc) // no conversion needed, locale uses native encoding - convertEncoding = FALSE; + convertEncoding = false; if (a.GetCount() == 0) // we don't know common equiv. under this platform - convertEncoding = FALSE; + convertEncoding = false; targetEnc = a[0]; } } @@ -1338,10 +1342,10 @@ bool wxMsgCatalog::Load(const wxChar *szDirPrefix, const wxChar *szName, if ( file.Load(szDirPrefix, szName, m_pluralFormsCalculator) ) { file.FillHash(m_messages, msgIdCharset, bConvertEncoding); - return TRUE; + return true; } - return FALSE; + return false; } const wxChar *wxMsgCatalog::GetString(const wxChar *sz, size_t n) const @@ -1398,6 +1402,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; @@ -1425,7 +1432,7 @@ bool wxLocale::Init(const wxChar *szName, // the argument to setlocale() szLocale = szShort; - wxCHECK_MSG( szLocale, FALSE, _T("no locale to set in wxLocale::Init()") ); + wxCHECK_MSG( szLocale, false, _T("no locale to set in wxLocale::Init()") ); } #ifdef __WXWINCE__ @@ -1455,7 +1462,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] ) @@ -1466,12 +1473,9 @@ 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; + bool bOk = true; if ( bLoadDefault ) bOk = AddCatalog(wxT("wxstd")); @@ -1479,30 +1483,30 @@ bool wxLocale::Init(const wxChar *szName, } -#if defined(__UNIX__) && wxUSE_UNICODE +#if defined(__UNIX__) && wxUSE_UNICODE && !defined(__WXMAC__) static wxWCharBuffer wxSetlocaleTryUTF(int c, const wxChar *lc) { wxMB2WXbuf l = wxSetlocale(c, lc); if ( !l && lc && lc[0] != 0 ) { - wxString buf(lc); + wxString buf(lc); wxString buf2; - buf2 = buf + wxT(".UTF-8"); - l = wxSetlocale(c, buf2.c_str()); + buf2 = buf + wxT(".UTF-8"); + l = wxSetlocale(c, buf2.c_str()); if ( !l ) { buf2 = buf + wxT(".utf-8"); - l = wxSetlocale(c, buf2.c_str()); + l = wxSetlocale(c, buf2.c_str()); } if ( !l ) { buf2 = buf + wxT(".UTF8"); - l = wxSetlocale(c, buf2.c_str()); + l = wxSetlocale(c, buf2.c_str()); } if ( !l ) { buf2 = buf + wxT(".utf8"); - l = wxSetlocale(c, buf2.c_str()); + l = wxSetlocale(c, buf2.c_str()); } } return l; @@ -1523,7 +1527,7 @@ bool wxLocale::Init(int language, int flags) // We failed to detect system language, so we will use English: if (lang == wxLANGUAGE_UNKNOWN) { - return FALSE; + return false; } const wxLanguageInfo *info = GetLanguageInfo(lang); @@ -1532,7 +1536,7 @@ bool wxLocale::Init(int language, int flags) if (info == NULL) { wxLogError(wxT("Unknown language %i."), lang); - return FALSE; + return false; } wxString name = info->Description; @@ -1580,7 +1584,7 @@ bool wxLocale::Init(int language, int flags) if ( !retloc ) { wxLogError(wxT("Cannot set locale to '%s'."), locale.c_str()); - return FALSE; + return false; } #elif defined(__WIN32__) @@ -1633,11 +1637,11 @@ 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()); - return FALSE; + return false; } else { @@ -1679,12 +1683,30 @@ bool wxLocale::Init(int language, int flags) if ( !retloc ) { wxLogError(wxT("Cannot set locale to language %s."), name.c_str()); - return FALSE; + return false; + } +#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)); } -#elif defined(__WXMAC__) || defined(__WXPM__) + 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; + return false; #define WX_NO_LOCALE_SUPPORT #endif @@ -2181,6 +2203,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) @@ -2285,11 +2310,11 @@ wxFontEncoding wxLocale::GetSystemEncoding() return wxFONTENCODING_CP950; } #elif defined(__WXMAC__) - TextEncoding encoding = 0 ; + TextEncoding encoding = 0 ; #if TARGET_CARBON - encoding = CFStringGetSystemEncoding() ; + encoding = CFStringGetSystemEncoding() ; #else - UpgradeScriptInfoToTextEncoding ( smSystemScript , kTextLanguageDontCare , kTextRegionDontCare , NULL , &encoding ) ; + UpgradeScriptInfoToTextEncoding ( smSystemScript , kTextLanguageDontCare , kTextRegionDontCare , NULL , &encoding ) ; #endif return wxMacGetFontEncFromSystemEnc( encoding ) ; #elif defined(__UNIX_LIKE__) && wxUSE_FONTMAP @@ -2297,7 +2322,7 @@ wxFontEncoding wxLocale::GetSystemEncoding() if ( !encname.empty() ) { wxFontEncoding enc = wxFontMapper::Get()-> - CharsetToEncoding(encname, FALSE /* not interactive */); + 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 @@ -2423,8 +2448,9 @@ wxLocale::~wxLocale() delete pTmpCat; } - // restore old locale + // restore old locale pointer wxSetLocale(m_pOldLocale); + // FIXME #ifndef __WXWINCE__ wxSetlocale(LC_ALL, m_pszOldLocale); @@ -2505,7 +2531,7 @@ const wxChar *wxLocale::GetString(const wxChar *szOrigString, wxString wxLocale::GetHeaderValue( const wxChar* szHeader, const wxChar* szDomain ) const { - if ( wxIsEmpty(Header) ) + if ( wxIsEmpty(szHeader) ) return wxEmptyString; wxChar const * pszTrans = NULL; @@ -2519,14 +2545,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; } @@ -2535,14 +2561,14 @@ wxString wxLocale::GetHeaderValue( const wxChar* szHeader, if ( wxIsEmpty(pszTrans) ) return wxEmptyString; - wxChar const * pszFound = wxStrstr(pszTrans, Header); + wxChar const * pszFound = wxStrstr(pszTrans, szHeader); if ( pszFound == NULL ) return wxEmptyString; - - pszFound += wxStrlen(Header) + 2 /* ': ' */; + + pszFound += wxStrlen(szHeader) + 2 /* ': ' */; // Every header is separated by \n - + wxChar const * pszEndLine = wxStrchr(pszFound, wxT('\n')); if ( pszEndLine == NULL ) pszEndLine = pszFound + wxStrlen(pszFound); @@ -2736,7 +2762,7 @@ class wxLocaleModule: public wxModule DECLARE_DYNAMIC_CLASS(wxLocaleModule) public: wxLocaleModule() {} - bool OnInit() { return TRUE; } + bool OnInit() { return true; } void OnExit() { wxLocale::DestroyLanguagesDB(); } };