Always use active wxTranslations instance via wxLocale.
Don't use m_translations directly, if the user made changes to wxTranslations instance, it would be too confusing if calls through wxLocale compat API did nothing. Also don't change active wxTranslations object from wxLocale if already done by user, only call wxTranslations::Set() from wxLocale constructor if it wasn't already set by the user. Still do if wxTranslations instance currently in use was set by previous wxLocale on the locale stack. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64165 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -247,10 +247,8 @@ public:
|
|||||||
// The loaded catalog will be used for message lookup by GetString().
|
// The loaded catalog will be used for message lookup by GetString().
|
||||||
//
|
//
|
||||||
// Returns 'true' if it was successfully loaded
|
// Returns 'true' if it was successfully loaded
|
||||||
bool AddCatalog(const wxString& domain)
|
bool AddCatalog(const wxString& domain);
|
||||||
{ return m_translations.AddCatalog(domain); }
|
bool AddCatalog(const wxString& domain, wxLanguage msgIdLanguage);
|
||||||
bool AddCatalog(const wxString& domain, wxLanguage msgIdLanguage)
|
|
||||||
{ return m_translations.AddCatalog(domain, msgIdLanguage); }
|
|
||||||
bool AddCatalog(const wxString& domain,
|
bool AddCatalog(const wxString& domain,
|
||||||
wxLanguage msgIdLanguage, const wxString& msgIdCharset);
|
wxLanguage msgIdLanguage, const wxString& msgIdCharset);
|
||||||
|
|
||||||
@@ -258,8 +256,7 @@ public:
|
|||||||
static bool IsAvailable(int lang);
|
static bool IsAvailable(int lang);
|
||||||
|
|
||||||
// check if the given catalog is loaded
|
// check if the given catalog is loaded
|
||||||
bool IsLoaded(const wxString& domain) const
|
bool IsLoaded(const wxString& domain) const;
|
||||||
{ return m_translations.IsLoaded(domain); }
|
|
||||||
|
|
||||||
// Retrieve the language info struct for the given language
|
// Retrieve the language info struct for the given language
|
||||||
//
|
//
|
||||||
@@ -300,7 +297,7 @@ public:
|
|||||||
const wxString& GetString(const wxString& origString,
|
const wxString& GetString(const wxString& origString,
|
||||||
const wxString& domain = wxEmptyString) const
|
const wxString& domain = wxEmptyString) const
|
||||||
{
|
{
|
||||||
return m_translations.GetString(origString, domain);
|
return wxGetTranslation(origString, domain);
|
||||||
}
|
}
|
||||||
// plural form version of the same:
|
// plural form version of the same:
|
||||||
const wxString& GetString(const wxString& origString,
|
const wxString& GetString(const wxString& origString,
|
||||||
@@ -308,7 +305,7 @@ public:
|
|||||||
size_t n,
|
size_t n,
|
||||||
const wxString& domain = wxEmptyString) const
|
const wxString& domain = wxEmptyString) const
|
||||||
{
|
{
|
||||||
return m_translations.GetString(origString, origString2, n, domain);
|
return wxGetTranslation(origString, origString2, n, domain);
|
||||||
}
|
}
|
||||||
|
|
||||||
// this is hack to work around a problem with wxGetTranslation() which
|
// this is hack to work around a problem with wxGetTranslation() which
|
||||||
@@ -322,10 +319,7 @@ public:
|
|||||||
|
|
||||||
// return the contents of .po file header
|
// return the contents of .po file header
|
||||||
wxString GetHeaderValue(const wxString& header,
|
wxString GetHeaderValue(const wxString& header,
|
||||||
const wxString& domain = wxEmptyString) const
|
const wxString& domain = wxEmptyString) const;
|
||||||
{
|
|
||||||
return m_translations.GetHeaderValue(header, domain);
|
|
||||||
}
|
|
||||||
|
|
||||||
// These two methods are for internal use only. First one creates
|
// These two methods are for internal use only. First one creates
|
||||||
// ms_languagesDB if it doesn't already exist, second one destroys
|
// ms_languagesDB if it doesn't already exist, second one destroys
|
||||||
|
@@ -211,7 +211,24 @@ void wxLocale::DoCommonInit()
|
|||||||
m_pszOldLocale = NULL;
|
m_pszOldLocale = NULL;
|
||||||
|
|
||||||
m_pOldLocale = wxSetLocale(this);
|
m_pOldLocale = wxSetLocale(this);
|
||||||
|
|
||||||
|
// Set translations object, but only if the user didn't do so yet.
|
||||||
|
// This is to preserve compatibility with wx-2.8 where wxLocale was
|
||||||
|
// the only API for translations. wxLocale works as a stack, with
|
||||||
|
// latest-created one being the active one:
|
||||||
|
// wxLocale loc_fr(wxLANGUAGE_FRENCH);
|
||||||
|
// // _() returns French
|
||||||
|
// {
|
||||||
|
// wxLocale loc_cs(wxLANGUAGE_CZECH);
|
||||||
|
// // _() returns Czech
|
||||||
|
// }
|
||||||
|
// // _() returns French again
|
||||||
|
wxTranslations *oldTrans = wxTranslations::Get();
|
||||||
|
if ( !oldTrans ||
|
||||||
|
(m_pOldLocale && oldTrans == &m_pOldLocale->m_translations) )
|
||||||
|
{
|
||||||
wxTranslations::SetNonOwned(&m_translations);
|
wxTranslations::SetNonOwned(&m_translations);
|
||||||
|
}
|
||||||
|
|
||||||
m_language = wxLANGUAGE_UNKNOWN;
|
m_language = wxLANGUAGE_UNKNOWN;
|
||||||
m_initialized = false;
|
m_initialized = false;
|
||||||
@@ -235,10 +252,14 @@ bool wxLocale::Init(const wxString& name,
|
|||||||
bool ret = DoInit(name, shortName, locale);
|
bool ret = DoInit(name, shortName, locale);
|
||||||
|
|
||||||
// NB: don't use 'lang' here, 'language' may be wxLANGUAGE_DEFAULT
|
// NB: don't use 'lang' here, 'language' may be wxLANGUAGE_DEFAULT
|
||||||
m_translations.SetLanguage(shortName);
|
wxTranslations *t = wxTranslations::Get();
|
||||||
|
if ( t )
|
||||||
|
{
|
||||||
|
t->SetLanguage(shortName);
|
||||||
|
|
||||||
if ( bLoadDefault )
|
if ( bLoadDefault )
|
||||||
m_translations.AddStdCatalog();
|
t->AddStdCatalog();
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@@ -538,10 +559,14 @@ bool wxLocale::Init(int language, int flags)
|
|||||||
m_language = lang;
|
m_language = lang;
|
||||||
|
|
||||||
// NB: don't use 'lang' here, 'language'
|
// NB: don't use 'lang' here, 'language'
|
||||||
m_translations.SetLanguage(wx_static_cast(wxLanguage, language));
|
wxTranslations *t = wxTranslations::Get();
|
||||||
|
if ( t )
|
||||||
|
{
|
||||||
|
t->SetLanguage(static_cast<wxLanguage>(language));
|
||||||
|
|
||||||
if ( flags & wxLOCALE_LOAD_DEFAULT )
|
if ( flags & wxLOCALE_LOAD_DEFAULT )
|
||||||
m_translations.AddStdCatalog();
|
t->AddStdCatalog();
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
#endif // !WX_NO_LOCALE_SUPPORT
|
#endif // !WX_NO_LOCALE_SUPPORT
|
||||||
@@ -988,7 +1013,9 @@ wxString wxLocale::GetSysName() const
|
|||||||
// clean up
|
// clean up
|
||||||
wxLocale::~wxLocale()
|
wxLocale::~wxLocale()
|
||||||
{
|
{
|
||||||
// restore old translations object
|
// Restore old translations object.
|
||||||
|
// See DoCommonInit() for explanation of why this is needed for backward
|
||||||
|
// compatibility.
|
||||||
if ( wxTranslations::Get() == &m_translations )
|
if ( wxTranslations::Get() == &m_translations )
|
||||||
{
|
{
|
||||||
if ( m_pOldLocale )
|
if ( m_pOldLocale )
|
||||||
@@ -1037,19 +1064,56 @@ bool wxLocale::IsAvailable(int lang)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool wxLocale::AddCatalog(const wxString& domain)
|
||||||
|
{
|
||||||
|
wxTranslations *t = wxTranslations::Get();
|
||||||
|
if ( !t )
|
||||||
|
return false;
|
||||||
|
return t->AddCatalog(domain);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxLocale::AddCatalog(const wxString& domain, wxLanguage msgIdLanguage)
|
||||||
|
{
|
||||||
|
wxTranslations *t = wxTranslations::Get();
|
||||||
|
if ( !t )
|
||||||
|
return false;
|
||||||
|
return t->AddCatalog(domain, msgIdLanguage);
|
||||||
|
}
|
||||||
|
|
||||||
// add a catalog to our linked list
|
// add a catalog to our linked list
|
||||||
bool wxLocale::AddCatalog(const wxString& szDomain,
|
bool wxLocale::AddCatalog(const wxString& szDomain,
|
||||||
wxLanguage msgIdLanguage,
|
wxLanguage msgIdLanguage,
|
||||||
const wxString& msgIdCharset)
|
const wxString& msgIdCharset)
|
||||||
{
|
{
|
||||||
|
wxTranslations *t = wxTranslations::Get();
|
||||||
|
if ( !t )
|
||||||
|
return false;
|
||||||
#if wxUSE_UNICODE
|
#if wxUSE_UNICODE
|
||||||
wxUnusedVar(msgIdCharset);
|
wxUnusedVar(msgIdCharset);
|
||||||
return m_translations.AddCatalog(szDomain, msgIdLanguage);
|
return t->AddCatalog(szDomain, msgIdLanguage);
|
||||||
#else
|
#else
|
||||||
return m_translations.AddCatalog(szDomain, msgIdLanguage, msgIdCharset);
|
return t->AddCatalog(szDomain, msgIdLanguage, msgIdCharset);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool wxLocale::IsLoaded(const wxString& domain) const
|
||||||
|
{
|
||||||
|
wxTranslations *t = wxTranslations::Get();
|
||||||
|
if ( !t )
|
||||||
|
return false;
|
||||||
|
return t->IsLoaded(domain);
|
||||||
|
}
|
||||||
|
|
||||||
|
wxString wxLocale::GetHeaderValue(const wxString& header,
|
||||||
|
const wxString& domain) const
|
||||||
|
{
|
||||||
|
wxTranslations *t = wxTranslations::Get();
|
||||||
|
if ( !t )
|
||||||
|
return wxEmptyString;
|
||||||
|
return t->GetHeaderValue(header, domain);
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// accessors for locale-dependent data
|
// accessors for locale-dependent data
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
Reference in New Issue
Block a user