X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/8fbd067d3cf19ad8c4fe6c3b1005e770f5ac6405..75504144d2ee5ce2bc62d186f04b2d445c2048c5:/src/common/intl.cpp diff --git a/src/common/intl.cpp b/src/common/intl.cpp index 978b4b41e5..67bf71f86f 100644 --- a/src/common/intl.cpp +++ b/src/common/intl.cpp @@ -65,12 +65,10 @@ #include "wx/filename.h" #include "wx/tokenzr.h" #include "wx/fontmap.h" -#include "wx/encconv.h" #include "wx/scopedptr.h" #include "wx/apptrait.h" #include "wx/stdpaths.h" #include "wx/hashset.h" -#include "wx/filesys.h" #if defined(__WXOSX__) #include "wx/osx/core/cfref.h" @@ -860,9 +858,7 @@ public: wxPluralFormsCalculatorPtr& rPluralFormsCalculator); // fills the hash with string-translation pairs - bool FillHash(wxMessagesHash& hash, - const wxString& msgIdCharset, - bool convertEncoding) const; + bool FillHash(wxMessagesHash& hash, const wxString& msgIdCharset) const; // return the charset of the strings in this catalog or empty string if // none/unknown @@ -953,7 +949,7 @@ public: // load the catalog from disk (szDirPrefix corresponds to language) bool Load(const wxString& dirPrefix, const wxString& name, - const wxString& msgIdCharset, bool bConvertEncoding = false); + const wxString& msgIdCharset); // get name of the catalog wxString GetName() const { return m_name; } @@ -1005,7 +1001,7 @@ static wxString wxGetANSICodePageForLocale(LCID lcid) if ( ::GetLocaleInfo(lcid, LOCALE_IDEFAULTANSICODEPAGE, buffer, WXSIZEOF(buffer)) > 0 ) { - if ( buffer[0] != _T('0') || buffer[1] != _T('\0') ) + if ( buffer[0] != wxT('0') || buffer[1] != wxT('\0') ) cp = buffer; //else: this locale doesn't use ANSI code page } @@ -1025,10 +1021,10 @@ wxString wxLanguageInfo::GetLocaleName() const const LCID lcid = GetLCID(); wxChar buffer[256]; - buffer[0] = _T('\0'); + buffer[0] = wxT('\0'); if ( !::GetLocaleInfo(lcid, LOCALE_SENGLANGUAGE, buffer, WXSIZEOF(buffer)) ) { - wxLogLastError(_T("GetLocaleInfo(LOCALE_SENGLANGUAGE)")); + wxLogLastError(wxT("GetLocaleInfo(LOCALE_SENGLANGUAGE)")); return locale; } @@ -1036,13 +1032,13 @@ wxString wxLanguageInfo::GetLocaleName() const if ( ::GetLocaleInfo(lcid, LOCALE_SENGCOUNTRY, buffer, WXSIZEOF(buffer)) > 0 ) { - locale << _T('_') << buffer; + locale << wxT('_') << buffer; } const wxString cp = wxGetANSICodePageForLocale(lcid); if ( !cp.empty() ) { - locale << _T('.') << cp; + locale << wxT('.') << cp; } return locale; @@ -1190,12 +1186,7 @@ bool wxMsgCatalogFile::Load(const wxString& szDirPrefix, const wxString& szName, fn.SetExt(wxS("mo")); wxString strFullName; -#if wxUSE_FILESYSTEM - wxFileSystem fileSys; - if ( !fileSys.FindFileInPath(&strFullName, searchPath, fn.GetFullPath()) ) -#else // !wxUSE_FILESYSTEM if ( !wxFindFileInPath(&strFullName, searchPath, fn.GetFullPath()) ) -#endif // wxUSE_FILESYSTEM/!wxUSE_FILESYSTEM { wxLogVerbose(_("catalog file for domain '%s' not found."), szName); wxLogTrace(TRACE_I18N, wxS("Catalog \"%s.mo\" not found"), szName); @@ -1206,22 +1197,6 @@ bool wxMsgCatalogFile::Load(const wxString& szDirPrefix, const wxString& szName, wxLogVerbose(_("using catalog '%s' from '%s'."), szName, strFullName.c_str()); wxLogTrace(TRACE_I18N, wxS("Using catalog \"%s\"."), strFullName.c_str()); -#if wxUSE_FILESYSTEM - wxFSFile * const fileMsg = fileSys.OpenFile(strFullName); - if ( !fileMsg ) - return false; - - wxInputStream *fileStream = fileMsg->GetStream(); - m_data.SetDataLen(0); - - static const size_t chunkSize = 4096; - while ( !fileStream->Eof() ) { - fileStream->Read(m_data.GetAppendBuf(chunkSize), chunkSize); - m_data.UngetAppendBuf(fileStream->LastRead()); - } - - delete fileMsg; -#else // !wxUSE_FILESYSTEM wxFile fileMsg(strFullName); if ( !fileMsg.IsOpened() ) return false; @@ -1239,7 +1214,6 @@ bool wxMsgCatalogFile::Load(const wxString& szDirPrefix, const wxString& szName, return false; m_data.UngetWriteBuf(nSize); -#endif // wxUSE_FILESYSTEM/!wxUSE_FILESYSTEM // examine header @@ -1329,44 +1303,31 @@ bool wxMsgCatalogFile::Load(const wxString& szDirPrefix, const wxString& szName, } bool wxMsgCatalogFile::FillHash(wxMessagesHash& hash, - const wxString& msgIdCharset, - bool convertEncoding) const + const wxString& msgIdCharset) const { -#if wxUSE_UNICODE - // this parameter doesn't make sense, we always must convert encoding in - // Unicode build - convertEncoding = true; -#elif wxUSE_FONTMAP - if ( convertEncoding ) + // conversion to use to convert catalog strings to the GUI encoding + wxMBConv *inputConv, + *inputConvPtr = NULL; // same as inputConv but safely deleteable + + if ( !m_charset.empty() ) { +#if !wxUSE_UNICODE && wxUSE_FONTMAP // determine if we need any conversion at all wxFontEncoding encCat = wxFontMapperBase::GetEncodingFromName(m_charset); - if ( encCat == wxLocale::GetSystemEncoding() ) + if ( encCat != wxLocale::GetSystemEncoding() ) +#endif { - // no need to convert - convertEncoding = false; + inputConvPtr = + inputConv = new wxCSConv(m_charset); } } -#endif // wxUSE_UNICODE/wxUSE_FONTMAP - -#if wxUSE_WCHAR_T - // conversion to use to convert catalog strings to the GUI encoding - wxMBConv *inputConv, - *inputConvPtr = NULL; // same as inputConv but safely deleteable - if ( convertEncoding && !m_charset.empty() ) - { - inputConvPtr = - inputConv = new wxCSConv(m_charset); - } else // no need or not possible to convert the encoding { #if wxUSE_UNICODE // we must somehow convert the narrow strings in the message catalog to // wide strings, so use the default conversion if we have no charset inputConv = wxConvCurrent; -#else // !wxUSE_UNICODE - inputConv = NULL; -#endif // wxUSE_UNICODE/!wxUSE_UNICODE +#endif } // conversion to apply to msgid strings before looking them up: we only @@ -1376,43 +1337,6 @@ bool wxMsgCatalogFile::FillHash(wxMessagesHash& hash, ? NULL : new wxCSConv(msgIdCharset); -#elif wxUSE_FONTMAP - wxASSERT_MSG( msgIdCharset.empty(), - wxS("non-ASCII msgid languages only supported if wxUSE_WCHAR_T=1") ); - - wxEncodingConverter converter; - if ( convertEncoding ) - { - wxFontEncoding targetEnc = wxFONTENCODING_SYSTEM; - wxFontEncoding enc = wxFontMapperBase::Get()->CharsetToEncoding(m_charset, false); - if ( enc == wxFONTENCODING_SYSTEM ) - { - convertEncoding = false; // unknown encoding - } - else - { - targetEnc = wxLocale::GetSystemEncoding(); - if (targetEnc == wxFONTENCODING_SYSTEM) - { - wxFontEncodingArray a = wxEncodingConverter::GetPlatformEquivalents(enc); - if (a[0] == enc) - // no conversion needed, locale uses native encoding - convertEncoding = false; - if (a.GetCount() == 0) - // we don't know common equiv. under this platform - convertEncoding = false; - targetEnc = a[0]; - } - } - - if ( convertEncoding ) - { - converter.Init(enc, targetEnc); - } - } -#endif // wxUSE_WCHAR_T/!wxUSE_WCHAR_T - (void)convertEncoding; // get rid of warnings about unused parameter - for (size_t32 i = 0; i < m_numStrings; i++) { const char *data = StringAtOfs(m_pOrigTable, i); @@ -1423,12 +1347,10 @@ bool wxMsgCatalogFile::FillHash(wxMessagesHash& hash, #if wxUSE_UNICODE msgid = wxString(data, *inputConv); #else // ASCII - #if wxUSE_WCHAR_T - if ( inputConv && sourceConv ) - msgid = wxString(inputConv->cMB2WC(data), *sourceConv); - else - #endif - msgid = data; + if ( inputConv && sourceConv ) + msgid = wxString(inputConv->cMB2WC(data), *sourceConv); + else + msgid = data; #endif // wxUSE_UNICODE data = StringAtOfs(m_pTransTable, i); @@ -1445,19 +1367,12 @@ bool wxMsgCatalogFile::FillHash(wxMessagesHash& hash, wxString msgstr; #if wxUSE_UNICODE msgstr = wxString(str, *inputConv); -#elif wxUSE_WCHAR_T +#else if ( inputConv ) msgstr = wxString(inputConv->cMB2WC(str), *wxConvUI); else msgstr = str; -#else // !wxUSE_WCHAR_T - #if wxUSE_FONTMAP - if ( bConvertEncoding ) - msgstr = wxString(converter.Convert(str)); - else - #endif - msgstr = str; -#endif // wxUSE_WCHAR_T/!wxUSE_WCHAR_T +#endif // wxUSE_UNICODE/!wxUSE_UNICODE if ( !msgstr.empty() ) { @@ -1475,10 +1390,8 @@ bool wxMsgCatalogFile::FillHash(wxMessagesHash& hash, } } -#if wxUSE_WCHAR_T delete sourceConv; delete inputConvPtr; -#endif // wxUSE_WCHAR_T return true; } @@ -1506,7 +1419,7 @@ wxMsgCatalog::~wxMsgCatalog() #endif // !wxUSE_UNICODE bool wxMsgCatalog::Load(const wxString& dirPrefix, const wxString& name, - const wxString& msgIdCharset, bool bConvertEncoding) + const wxString& msgIdCharset) { wxMsgCatalogFile file; @@ -1515,27 +1428,9 @@ bool wxMsgCatalog::Load(const wxString& dirPrefix, const wxString& name, if ( !file.Load(dirPrefix, name, m_pluralFormsCalculator) ) return false; - if ( !file.FillHash(m_messages, msgIdCharset, bConvertEncoding) ) + if ( !file.FillHash(m_messages, msgIdCharset) ) return false; -#if !wxUSE_UNICODE - // we should use a conversion compatible with the message catalog encoding - // in the GUI if we don't convert the strings to the current conversion but - // as the encoding is global, only change it once, otherwise we could get - // into trouble if we use several message catalogs with different encodings - // - // this is, of course, a hack but it at least allows the program to use - // message catalogs in any encodings without asking the user to change his - // locale - if ( !bConvertEncoding && - !file.GetCharset().empty() && - wxConvUI == &wxConvLocal ) - { - wxConvUI = - m_conv = new wxCSConv(file.GetCharset()); - } -#endif // !wxUSE_UNICODE - return true; } @@ -1605,16 +1500,23 @@ void wxLocale::DoCommonInit() bool wxLocale::Init(const wxString& name, const wxString& shortName, const wxString& locale, - bool bLoadDefault, - bool bConvertEncoding) + bool bLoadDefault +#if WXWIN_COMPATIBILITY_2_8 + ,bool bConvertEncoding +#endif + ) { wxASSERT_MSG( !m_initialized, wxS("you can't call wxLocale::Init more than once") ); +#if WXWIN_COMPATIBILITY_2_8 + wxASSERT_MSG( bConvertEncoding, + wxS("wxLocale::Init with bConvertEncoding=false is no longer supported, add charset to your catalogs") ); +#endif + m_initialized = true; m_strLocale = name; m_strShort = shortName; - m_bConvertEncoding = bConvertEncoding; m_language = wxLANGUAGE_UNKNOWN; // change current locale (default: same as long name) @@ -1635,7 +1537,9 @@ bool wxLocale::Init(const wxString& name, m_pszOldLocale = NULL; if ( m_pszOldLocale == NULL ) + { wxLogError(_("locale '%s' can not be set."), szLocale); + } // the short name will be used to look for catalog files as well, // so we need something here @@ -1716,6 +1620,11 @@ static const char *wxSetlocaleTryUTF8(int c, const wxString& lc) bool wxLocale::Init(int language, int flags) { +#if WXWIN_COMPATIBILITY_2_8 + wxASSERT_MSG( !(flags & wxLOCALE_CONV_ENCODING), + wxS("wxLOCALE_CONV_ENCODING is no longer supported, add charset to your catalogs") ); +#endif + bool ret = true; int lang = language; @@ -1904,8 +1813,7 @@ bool wxLocale::Init(int language, int flags) } if ( !Init(name, canonical, retloc, - (flags & wxLOCALE_LOAD_DEFAULT) != 0, - (flags & wxLOCALE_CONV_ENCODING) != 0) ) + (flags & wxLOCALE_LOAD_DEFAULT) != 0) ) { ret = false; } @@ -2562,7 +2470,7 @@ bool wxLocale::AddCatalog(const wxString& szDomain, wxMsgCatalog *pMsgCat = new wxMsgCatalog; - if ( pMsgCat->Load(m_strShort, szDomain, msgIdCharset, m_bConvertEncoding) ) + if ( pMsgCat->Load(m_strShort, szDomain, msgIdCharset) ) { // add it to the head of the list so that in GetString it will // be searched before the catalogs added earlier @@ -2612,8 +2520,8 @@ static wxString TranslateFromUnicodeFormat(const wxString& fmt) char chLast = '\0'; size_t lastCount = 0; - - const char* formatchars = + + const char* formatchars = "dghHmMsSy" #ifdef __WXMSW__ "t" @@ -2809,7 +2717,7 @@ static wxString TranslateFromUnicodeFormat(const wxString& fmt) // strftime() doesn't have era string, // ignore this format wxASSERT_MSG( lastCount <= 2, "too many 'g's" ); - + break; #ifndef __WXMSW__ case 'a': @@ -2842,10 +2750,10 @@ static wxString TranslateFromUnicodeFormat(const wxString& fmt) break; // not a special character so must be just a separator, treat as is - if ( *p == _T('%') ) + if ( *p == wxT('%') ) { // this one needs to be escaped - fmtWX += _T('%'); + fmtWX += wxT('%'); } fmtWX += *p; @@ -3095,6 +3003,8 @@ wxString GetDateFormatFromLangInfo(wxLocaleInfo index) return fmtDateOnly; #else // !HAVE_LANGINFO_H + wxUnusedVar(index); + // no fallback, let the application deal with unavailability of // nl_langinfo() itself as there is no good way for us to do it (well, we // could try to reverse engineer the format from strftime() output but this