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
This commit is contained in:
Václav Slavík
2010-04-16 11:29:22 +00:00
parent f30bd8f262
commit 3acf8a8d9b
8 changed files with 63 additions and 90 deletions

View File

@@ -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 indentation instead of being its double. Its default value was changed
accordingly, to 2. 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 Changes in behaviour which may result in compilation errors
----------------------------------------------------------- -----------------------------------------------------------

View File

@@ -102,9 +102,7 @@ Windows).
How is this done? When you tell the wxLocale class to load a message catalog 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 that contains a correct header, it checks the charset. The catalog is then
converted to the charset used (see wxLocale::GetSystemEncoding and converted to the charset used (see wxLocale::GetSystemEncoding and
wxLocale::GetSystemEncodingName) by the user's operating system. This is the wxLocale::GetSystemEncodingName) by the user's operating system.
default behaviour of the wxLocale class; you can disable it by @b not passing
@c wxLOCALE_CONV_ENCODING to wxLocale::Init.
@section overview_nonenglish_strings Non-English Strings or 8-bit Characters in Source @section overview_nonenglish_strings Non-English Strings or 8-bit Characters in Source

View File

@@ -409,8 +409,11 @@ enum wxLocaleInfo
enum wxLocaleInitFlags enum wxLocaleInitFlags
{ {
wxLOCALE_DONT_LOAD_DEFAULT = 0x0000, // don't load wxwin.mo wxLOCALE_DONT_LOAD_DEFAULT = 0x0000, // don't load wxwin.mo
wxLOCALE_LOAD_DEFAULT = 0x0001, // load wxwin.mo? wxLOCALE_LOAD_DEFAULT = 0x0001 // load wxwin.mo?
wxLOCALE_CONV_ENCODING = 0x0002 // convert encoding on the fly? #if WXWIN_COMPATIBILITY_2_8
,wxLOCALE_CONV_ENCODING = 0x0002 // no longer used, simply remove
// it from the existing code
#endif
}; };
class WXDLLIMPEXP_BASE wxLocale class WXDLLIMPEXP_BASE wxLocale
@@ -426,8 +429,11 @@ public:
wxLocale(const wxString& name, // name (for messages) wxLocale(const wxString& name, // name (for messages)
const wxString& shortName = wxEmptyString, // dir prefix (for msg files) const wxString& shortName = wxEmptyString, // dir prefix (for msg files)
const wxString& locale = wxEmptyString, // locale (for setlocale) const wxString& locale = wxEmptyString, // locale (for setlocale)
bool bLoadDefault = true, // preload wxstd.mo? bool bLoadDefault = true // preload wxstd.mo?
bool bConvertEncoding = false) // convert Win<->Unix if necessary? #if WXWIN_COMPATIBILITY_2_8
,bool bConvertEncoding = true // convert Win<->Unix if necessary?
#endif
)
{ {
DoCommonInit(); DoCommonInit();
@@ -435,7 +441,7 @@ public:
} }
wxLocale(int language, // wxLanguage id or custom language wxLocale(int language, // wxLanguage id or custom language
int flags = wxLOCALE_LOAD_DEFAULT | wxLOCALE_CONV_ENCODING) int flags = wxLOCALE_LOAD_DEFAULT)
{ {
DoCommonInit(); DoCommonInit();
@@ -446,12 +452,15 @@ public:
bool Init(const wxString& name, bool Init(const wxString& name,
const wxString& shortName = wxEmptyString, const wxString& shortName = wxEmptyString,
const wxString& locale = wxEmptyString, const wxString& locale = wxEmptyString,
bool bLoadDefault = true, bool bLoadDefault = true
bool bConvertEncoding = false); #if WXWIN_COMPATIBILITY_2_8
,bool bConvertEncoding = true
#endif
);
// same as second ctor (returns true on success) // same as second ctor (returns true on success)
bool Init(int language = wxLANGUAGE_DEFAULT, bool Init(int language = wxLANGUAGE_DEFAULT,
int flags = wxLOCALE_LOAD_DEFAULT | wxLOCALE_CONV_ENCODING); int flags = wxLOCALE_LOAD_DEFAULT);
// restores old locale // restores old locale
virtual ~wxLocale(); virtual ~wxLocale();
@@ -592,8 +601,6 @@ private:
wxMsgCatalog *m_pMsgCat; // pointer to linked list of catalogs wxMsgCatalog *m_pMsgCat; // pointer to linked list of catalogs
bool m_bConvertEncoding;
bool m_initialized; bool m_initialized;
static wxLanguageInfoArray *ms_languagesDB; static wxLanguageInfoArray *ms_languagesDB;

View File

@@ -479,8 +479,7 @@ public:
/** /**
See Init() for parameters description. See Init() for parameters description.
*/ */
wxLocale(int language, wxLocale(int language, int flags = wxLOCALE_LOAD_DEFAULT);
int flags = wxLOCALE_LOAD_DEFAULT | wxLOCALE_CONV_ENCODING);
/** /**
See Init() for parameters description. See Init() for parameters description.
@@ -495,8 +494,7 @@ public:
wxLocale(const wxString& name, wxLocale(const wxString& name,
const wxString& short = wxEmptyString, const wxString& short = wxEmptyString,
const wxString& locale = wxEmptyString, const wxString& locale = wxEmptyString,
bool bLoadDefault = true, bool bLoadDefault = true);
bool bConvertEncoding = false);
/** /**
The destructor, like the constructor, also has global side effects: the The destructor, like the constructor, also has global side effects: the
@@ -763,17 +761,11 @@ public:
containing the translations of standard wxWidgets messages containing the translations of standard wxWidgets messages
automatically. automatically.
- wxLOCALE_DONT_LOAD_DEFAULT: Negation of wxLOCALE_LOAD_DEFAULT. - 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. @return @true on success or @false if the given locale couldn't be set.
*/ */
bool Init(int language = wxLANGUAGE_DEFAULT, bool Init(int language = wxLANGUAGE_DEFAULT,
int flags = wxLOCALE_LOAD_DEFAULT | wxLOCALE_CONV_ENCODING); int flags = wxLOCALE_LOAD_DEFAULT);
/** /**
@deprecated @deprecated
@@ -791,16 +783,9 @@ public:
May be set to @false to prevent loading of the message catalog for the May be set to @false to prevent loading of the message catalog for the
given locale containing the translations of standard wxWidgets messages. given locale containing the translations of standard wxWidgets messages.
This parameter would be rarely used in normal circumstances. 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, bool Init(const wxString& name, const wxString& short = wxEmptyString,
const wxString& locale = wxEmptyString, bool bLoadDefault = true, const wxString& locale = wxEmptyString, bool bLoadDefault = true);
bool bConvertEncoding = false);
/** /**
Check whether the operating system and/or C run time environment supports Check whether the operating system and/or C run time environment supports

View File

@@ -229,7 +229,7 @@ bool MyApp::OnInit()
// don't use wxLOCALE_LOAD_DEFAULT flag so that Init() doesn't return // don't use wxLOCALE_LOAD_DEFAULT flag so that Init() doesn't return
// false just because it failed to load wxstd catalog // 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.")); wxLogWarning(_("This language is not supported by the system."));

View File

@@ -858,9 +858,7 @@ public:
wxPluralFormsCalculatorPtr& rPluralFormsCalculator); wxPluralFormsCalculatorPtr& rPluralFormsCalculator);
// fills the hash with string-translation pairs // fills the hash with string-translation pairs
bool FillHash(wxMessagesHash& hash, bool FillHash(wxMessagesHash& hash, const wxString& msgIdCharset) const;
const wxString& msgIdCharset,
bool convertEncoding) const;
// return the charset of the strings in this catalog or empty string if // return the charset of the strings in this catalog or empty string if
// none/unknown // none/unknown
@@ -951,7 +949,7 @@ public:
// load the catalog from disk (szDirPrefix corresponds to language) // load the catalog from disk (szDirPrefix corresponds to language)
bool Load(const wxString& dirPrefix, const wxString& name, bool Load(const wxString& dirPrefix, const wxString& name,
const wxString& msgIdCharset, bool bConvertEncoding = false); const wxString& msgIdCharset);
// get name of the catalog // get name of the catalog
wxString GetName() const { return m_name; } wxString GetName() const { return m_name; }
@@ -1305,33 +1303,23 @@ bool wxMsgCatalogFile::Load(const wxString& szDirPrefix, const wxString& szName,
} }
bool wxMsgCatalogFile::FillHash(wxMessagesHash& hash, bool wxMsgCatalogFile::FillHash(wxMessagesHash& hash,
const wxString& msgIdCharset, const wxString& msgIdCharset) const
bool convertEncoding) 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 )
{
// determine if we need any conversion at all
wxFontEncoding encCat = wxFontMapperBase::GetEncodingFromName(m_charset);
if ( encCat == wxLocale::GetSystemEncoding() )
{
// no need to convert
convertEncoding = false;
}
}
#endif // wxUSE_UNICODE/wxUSE_FONTMAP
// conversion to use to convert catalog strings to the GUI encoding // conversion to use to convert catalog strings to the GUI encoding
wxMBConv *inputConv, wxMBConv *inputConv,
*inputConvPtr = NULL; // same as inputConv but safely deleteable *inputConvPtr = NULL; // same as inputConv but safely deleteable
if ( convertEncoding && !m_charset.empty() )
if ( !m_charset.empty() )
{ {
inputConvPtr = #if !wxUSE_UNICODE && wxUSE_FONTMAP
inputConv = new wxCSConv(m_charset); // determine if we need any conversion at all
wxFontEncoding encCat = wxFontMapperBase::GetEncodingFromName(m_charset);
if ( encCat != wxLocale::GetSystemEncoding() )
#endif
{
inputConvPtr =
inputConv = new wxCSConv(m_charset);
}
} }
else // no need or not possible to convert the encoding else // no need or not possible to convert the encoding
{ {
@@ -1339,9 +1327,7 @@ bool wxMsgCatalogFile::FillHash(wxMessagesHash& hash,
// we must somehow convert the narrow strings in the message catalog to // we must somehow convert the narrow strings in the message catalog to
// wide strings, so use the default conversion if we have no charset // wide strings, so use the default conversion if we have no charset
inputConv = wxConvCurrent; inputConv = wxConvCurrent;
#else // !wxUSE_UNICODE #endif
inputConv = NULL;
#endif // wxUSE_UNICODE/!wxUSE_UNICODE
} }
// conversion to apply to msgid strings before looking them up: we only // conversion to apply to msgid strings before looking them up: we only
@@ -1433,7 +1419,7 @@ wxMsgCatalog::~wxMsgCatalog()
#endif // !wxUSE_UNICODE #endif // !wxUSE_UNICODE
bool wxMsgCatalog::Load(const wxString& dirPrefix, const wxString& name, bool wxMsgCatalog::Load(const wxString& dirPrefix, const wxString& name,
const wxString& msgIdCharset, bool bConvertEncoding) const wxString& msgIdCharset)
{ {
wxMsgCatalogFile file; wxMsgCatalogFile file;
@@ -1442,27 +1428,9 @@ bool wxMsgCatalog::Load(const wxString& dirPrefix, const wxString& name,
if ( !file.Load(dirPrefix, name, m_pluralFormsCalculator) ) if ( !file.Load(dirPrefix, name, m_pluralFormsCalculator) )
return false; return false;
if ( !file.FillHash(m_messages, msgIdCharset, bConvertEncoding) ) if ( !file.FillHash(m_messages, msgIdCharset) )
return false; 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; return true;
} }
@@ -1532,16 +1500,23 @@ void wxLocale::DoCommonInit()
bool wxLocale::Init(const wxString& name, bool wxLocale::Init(const wxString& name,
const wxString& shortName, const wxString& shortName,
const wxString& locale, const wxString& locale,
bool bLoadDefault, bool bLoadDefault
bool bConvertEncoding) #if WXWIN_COMPATIBILITY_2_8
,bool bConvertEncoding
#endif
)
{ {
wxASSERT_MSG( !m_initialized, wxASSERT_MSG( !m_initialized,
wxS("you can't call wxLocale::Init more than once") ); 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_initialized = true;
m_strLocale = name; m_strLocale = name;
m_strShort = shortName; m_strShort = shortName;
m_bConvertEncoding = bConvertEncoding;
m_language = wxLANGUAGE_UNKNOWN; m_language = wxLANGUAGE_UNKNOWN;
// change current locale (default: same as long name) // 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) 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; bool ret = true;
int lang = language; int lang = language;
@@ -1833,8 +1813,7 @@ bool wxLocale::Init(int language, int flags)
} }
if ( !Init(name, canonical, retloc, if ( !Init(name, canonical, retloc,
(flags & wxLOCALE_LOAD_DEFAULT) != 0, (flags & wxLOCALE_LOAD_DEFAULT) != 0) )
(flags & wxLOCALE_CONV_ENCODING) != 0) )
{ {
ret = false; ret = false;
} }
@@ -2491,7 +2470,7 @@ bool wxLocale::AddCatalog(const wxString& szDomain,
wxMsgCatalog *pMsgCat = new wxMsgCatalog; 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 // add it to the head of the list so that in GetString it will
// be searched before the catalogs added earlier // be searched before the catalogs added earlier

View File

@@ -75,7 +75,7 @@ void IntlTestCase::setUp()
CPPUNIT_ASSERT( m_locale ); CPPUNIT_ASSERT( m_locale );
// don't load default catalog, it may be unavailable: // 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 ); CPPUNIT_ASSERT( loaded );
m_locale->AddCatalog("internat"); m_locale->AddCatalog("internat");

View File

@@ -720,7 +720,7 @@ void StringTestCase::ToDouble()
wxLocale *locale = new wxLocale; wxLocale *locale = new wxLocale;
// don't load default catalog, it may be unavailable: // 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[] = static const struct ToDoubleData doubleData2[] =
{ {