X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/4be927a2d0af07be3554e18726681289c192f4c9..28999ba6310e9c110a963223fd38e1f340e60568:/src/common/intl.cpp?ds=sidebyside diff --git a/src/common/intl.cpp b/src/common/intl.cpp index 4b164126f3..d9dd83410c 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; @@ -1119,20 +1123,20 @@ bool wxMsgCatalogFile::Load(const wxChar *szDirPrefix, const wxChar *szName0, if ( !fileMsg.IsOpened() ) return false; - // get the file size + // get the file size (assume it is less than 4Gb...) wxFileOffset nSize = fileMsg.Length(); if ( nSize == wxInvalidOffset ) return false; // read the whole file in memory m_pData = new size_t8[nSize]; - if ( fileMsg.Read(m_pData, nSize) != (size_t)nSize ) { + if ( fileMsg.Read(m_pData, (size_t)nSize) != nSize ) { wxDELETEA(m_pData); 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 ) { @@ -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: @@ -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; @@ -1466,9 +1473,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; @@ -1681,7 +1685,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; @@ -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) @@ -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);