From: Václav Slavík Date: Fri, 16 Apr 2010 11:29:22 +0000 (+0000) Subject: Remove wxLOCALE_CONV_ENCODING flag. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/3acf8a8d9b31ca97d21627d6f6c82fd4a9ed04b5 Remove wxLOCALE_CONV_ENCODING flag. This doesn't affect Unicode builds, only the legacy ANSI one. PO files are now always converted to the appropriate charset according to current locale. This was the default behavior for long time; not doing the conversion was always a fragile hack that didn't work well. Removing this flag simplifies wxLocale code. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@63993 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/docs/changes.txt b/docs/changes.txt index 233ce6f6e5..345b69cc82 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -165,6 +165,10 @@ Changes in behaviour not resulting in compilation errors, please read this! indentation instead of being its double. Its default value was changed accordingly, to 2. +- wxLOCALE_CONV_ENCODING flag has no effect now, catalogs are converted + regardless of whether the flag was specified or not. This only affects + legacy ANSI builds. + Changes in behaviour which may result in compilation errors ----------------------------------------------------------- diff --git a/docs/doxygen/overviews/nonenglish.h b/docs/doxygen/overviews/nonenglish.h index 5c49fc4513..e62b9098ed 100644 --- a/docs/doxygen/overviews/nonenglish.h +++ b/docs/doxygen/overviews/nonenglish.h @@ -102,9 +102,7 @@ Windows). How is this done? When you tell the wxLocale class to load a message catalog that contains a correct header, it checks the charset. The catalog is then converted to the charset used (see wxLocale::GetSystemEncoding and -wxLocale::GetSystemEncodingName) by the user's operating system. This is the -default behaviour of the wxLocale class; you can disable it by @b not passing -@c wxLOCALE_CONV_ENCODING to wxLocale::Init. +wxLocale::GetSystemEncodingName) by the user's operating system. @section overview_nonenglish_strings Non-English Strings or 8-bit Characters in Source diff --git a/include/wx/intl.h b/include/wx/intl.h index 5572139112..4ee062a2ec 100644 --- a/include/wx/intl.h +++ b/include/wx/intl.h @@ -409,8 +409,11 @@ enum wxLocaleInfo enum wxLocaleInitFlags { wxLOCALE_DONT_LOAD_DEFAULT = 0x0000, // don't load wxwin.mo - wxLOCALE_LOAD_DEFAULT = 0x0001, // load wxwin.mo? - wxLOCALE_CONV_ENCODING = 0x0002 // convert encoding on the fly? + wxLOCALE_LOAD_DEFAULT = 0x0001 // load wxwin.mo? +#if WXWIN_COMPATIBILITY_2_8 + ,wxLOCALE_CONV_ENCODING = 0x0002 // no longer used, simply remove + // it from the existing code +#endif }; class WXDLLIMPEXP_BASE wxLocale @@ -426,8 +429,11 @@ public: wxLocale(const wxString& name, // name (for messages) const wxString& shortName = wxEmptyString, // dir prefix (for msg files) const wxString& locale = wxEmptyString, // locale (for setlocale) - bool bLoadDefault = true, // preload wxstd.mo? - bool bConvertEncoding = false) // convert Win<->Unix if necessary? + bool bLoadDefault = true // preload wxstd.mo? +#if WXWIN_COMPATIBILITY_2_8 + ,bool bConvertEncoding = true // convert Win<->Unix if necessary? +#endif + ) { DoCommonInit(); @@ -435,7 +441,7 @@ public: } wxLocale(int language, // wxLanguage id or custom language - int flags = wxLOCALE_LOAD_DEFAULT | wxLOCALE_CONV_ENCODING) + int flags = wxLOCALE_LOAD_DEFAULT) { DoCommonInit(); @@ -446,12 +452,15 @@ public: bool Init(const wxString& name, const wxString& shortName = wxEmptyString, const wxString& locale = wxEmptyString, - bool bLoadDefault = true, - bool bConvertEncoding = false); + bool bLoadDefault = true +#if WXWIN_COMPATIBILITY_2_8 + ,bool bConvertEncoding = true +#endif + ); // same as second ctor (returns true on success) bool Init(int language = wxLANGUAGE_DEFAULT, - int flags = wxLOCALE_LOAD_DEFAULT | wxLOCALE_CONV_ENCODING); + int flags = wxLOCALE_LOAD_DEFAULT); // restores old locale virtual ~wxLocale(); @@ -592,8 +601,6 @@ private: wxMsgCatalog *m_pMsgCat; // pointer to linked list of catalogs - bool m_bConvertEncoding; - bool m_initialized; static wxLanguageInfoArray *ms_languagesDB; diff --git a/interface/wx/intl.h b/interface/wx/intl.h index 0345f2cf69..31255ff190 100644 --- a/interface/wx/intl.h +++ b/interface/wx/intl.h @@ -479,8 +479,7 @@ public: /** See Init() for parameters description. */ - wxLocale(int language, - int flags = wxLOCALE_LOAD_DEFAULT | wxLOCALE_CONV_ENCODING); + wxLocale(int language, int flags = wxLOCALE_LOAD_DEFAULT); /** See Init() for parameters description. @@ -495,8 +494,7 @@ public: wxLocale(const wxString& name, const wxString& short = wxEmptyString, const wxString& locale = wxEmptyString, - bool bLoadDefault = true, - bool bConvertEncoding = false); + bool bLoadDefault = true); /** The destructor, like the constructor, also has global side effects: the @@ -763,17 +761,11 @@ public: containing the translations of standard wxWidgets messages automatically. - wxLOCALE_DONT_LOAD_DEFAULT: Negation of wxLOCALE_LOAD_DEFAULT. - - wxLOCALE_CONV_ENCODING: Automatically convert message catalogs to - platform's default encoding. Note that it will do only basic - conversion between well-known pair like iso8859-1 and windows-1252 or - iso8859-2 and windows-1250. See @ref overview_nonenglish for - detailed description of this behaviour. - Note that this flag is meaningless in Unicode build. @return @true on success or @false if the given locale couldn't be set. */ bool Init(int language = wxLANGUAGE_DEFAULT, - int flags = wxLOCALE_LOAD_DEFAULT | wxLOCALE_CONV_ENCODING); + int flags = wxLOCALE_LOAD_DEFAULT); /** @deprecated @@ -791,16 +783,9 @@ public: May be set to @false to prevent loading of the message catalog for the given locale containing the translations of standard wxWidgets messages. This parameter would be rarely used in normal circumstances. - @param bConvertEncoding - May be set to @true to do automatic conversion of message catalogs to - platform's native encoding. Note that it will do only basic conversion - between well-known pair like iso8859-1 and windows-1252 or iso8859-2 - and windows-1250. - See @ref overview_nonenglish for detailed description of this behaviour. */ bool Init(const wxString& name, const wxString& short = wxEmptyString, - const wxString& locale = wxEmptyString, bool bLoadDefault = true, - bool bConvertEncoding = false); + const wxString& locale = wxEmptyString, bool bLoadDefault = true); /** Check whether the operating system and/or C run time environment supports diff --git a/samples/internat/internat.cpp b/samples/internat/internat.cpp index ba9b735ad9..c2ffd69059 100644 --- a/samples/internat/internat.cpp +++ b/samples/internat/internat.cpp @@ -229,7 +229,7 @@ bool MyApp::OnInit() // don't use wxLOCALE_LOAD_DEFAULT flag so that Init() doesn't return // false just because it failed to load wxstd catalog - if ( !m_locale.Init(m_lang, wxLOCALE_DONT_LOAD_DEFAULT | wxLOCALE_CONV_ENCODING) ) + if ( !m_locale.Init(m_lang, wxLOCALE_DONT_LOAD_DEFAULT) ) { wxLogWarning(_("This language is not supported by the system.")); diff --git a/src/common/intl.cpp b/src/common/intl.cpp index fa97d94990..67bf71f86f 100644 --- a/src/common/intl.cpp +++ b/src/common/intl.cpp @@ -858,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 @@ -951,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; } @@ -1305,43 +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 - - // 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 @@ -1433,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; @@ -1442,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; } @@ -1532,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) @@ -1645,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; @@ -1833,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; } @@ -2491,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 diff --git a/tests/intl/intltest.cpp b/tests/intl/intltest.cpp index 0e6b8948b4..02b98472ed 100644 --- a/tests/intl/intltest.cpp +++ b/tests/intl/intltest.cpp @@ -75,7 +75,7 @@ void IntlTestCase::setUp() CPPUNIT_ASSERT( m_locale ); // don't load default catalog, it may be unavailable: - bool loaded = m_locale->Init(wxLANGUAGE_FRENCH, wxLOCALE_DONT_LOAD_DEFAULT | wxLOCALE_CONV_ENCODING); + bool loaded = m_locale->Init(wxLANGUAGE_FRENCH, wxLOCALE_DONT_LOAD_DEFAULT); CPPUNIT_ASSERT( loaded ); m_locale->AddCatalog("internat"); diff --git a/tests/strings/strings.cpp b/tests/strings/strings.cpp index cdba4098bc..a925df605e 100644 --- a/tests/strings/strings.cpp +++ b/tests/strings/strings.cpp @@ -720,7 +720,7 @@ void StringTestCase::ToDouble() wxLocale *locale = new wxLocale; // don't load default catalog, it may be unavailable: - CPPUNIT_ASSERT( locale->Init(wxLANGUAGE_FRENCH, wxLOCALE_DONT_LOAD_DEFAULT | wxLOCALE_CONV_ENCODING) ); + CPPUNIT_ASSERT( locale->Init(wxLANGUAGE_FRENCH, wxLOCALE_DONT_LOAD_DEFAULT) ); static const struct ToDoubleData doubleData2[] = {