Shorten lang names in wxTranslations, not wxFileTranslationsLoader.
If a catalog with full language name ("fr_BE") doesn't exist, wxFileTranslationsLoader tries to look for just the base language ("fr") too. This isn't something specific to wxFileTranslationsLoader, it makes sense to do it regardless of the loader. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64154 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -111,6 +111,9 @@ public:
|
|||||||
static const wxString& GetUntranslatedString(const wxString& str);
|
static const wxString& GetUntranslatedString(const wxString& str);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// perform loading of the catalog via m_loader
|
||||||
|
bool LoadCatalog(const wxString& domain, const wxString& lang);
|
||||||
|
|
||||||
// find best translation for given domain
|
// find best translation for given domain
|
||||||
wxString ChooseLanguageForDomain(const wxString& domain,
|
wxString ChooseLanguageForDomain(const wxString& domain,
|
||||||
const wxString& msgIdLang);
|
const wxString& msgIdLang);
|
||||||
|
@@ -1359,8 +1359,48 @@ bool wxTranslations::AddCatalog(const wxString& domain,
|
|||||||
if ( msgIdLang == domain_lang )
|
if ( msgIdLang == domain_lang )
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
return LoadCatalog(domain, domain_lang);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool wxTranslations::LoadCatalog(const wxString& domain, const wxString& lang)
|
||||||
|
{
|
||||||
wxCHECK_MSG( m_loader, false, "loader can't be NULL" );
|
wxCHECK_MSG( m_loader, false, "loader can't be NULL" );
|
||||||
return m_loader->LoadCatalog(this, domain, domain_lang);
|
|
||||||
|
#if wxUSE_FONTMAP
|
||||||
|
// first look for the catalog for this language and the current locale:
|
||||||
|
// notice that we don't use the system name for the locale as this would
|
||||||
|
// force us to install catalogs in different locations depending on the
|
||||||
|
// system but always use the canonical name
|
||||||
|
wxFontEncoding encSys = wxLocale::GetSystemEncoding();
|
||||||
|
if ( encSys != wxFONTENCODING_SYSTEM )
|
||||||
|
{
|
||||||
|
wxString fullname(lang);
|
||||||
|
fullname << wxS('.') << wxFontMapperBase::GetEncodingName(encSys);
|
||||||
|
|
||||||
|
if ( m_loader->LoadCatalog(this, domain, fullname) )
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
#endif // wxUSE_FONTMAP
|
||||||
|
|
||||||
|
// Next try: use the provided name language name:
|
||||||
|
if ( m_loader->LoadCatalog(this, domain, lang) )
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// Also try just base locale name: for things like "fr_BE" (Belgium
|
||||||
|
// French) we should use fall back on plain "fr" if no Belgium-specific
|
||||||
|
// message catalogs exist
|
||||||
|
if ( lang.length() > LEN_LANG && lang[LEN_LANG] == wxS('_') )
|
||||||
|
{
|
||||||
|
if ( m_loader->LoadCatalog(this, domain, ExtractLang(lang)) )
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Nothing worked, the catalog just isn't there
|
||||||
|
wxLogTrace(TRACE_I18N,
|
||||||
|
"Catalog \"%s.mo\" not found for language \"%s\".",
|
||||||
|
domain, lang);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1669,31 +1709,7 @@ bool wxFileTranslationsLoader::LoadCatalog(wxTranslations *translations,
|
|||||||
wxCHECK_MSG( lang.length() >= LEN_LANG, false,
|
wxCHECK_MSG( lang.length() >= LEN_LANG, false,
|
||||||
"invalid language specification" );
|
"invalid language specification" );
|
||||||
|
|
||||||
wxString searchPath;
|
wxString searchPath = GetFullSearchPath(lang);
|
||||||
|
|
||||||
#if wxUSE_FONTMAP
|
|
||||||
// first look for the catalog for this language and the current locale:
|
|
||||||
// notice that we don't use the system name for the locale as this would
|
|
||||||
// force us to install catalogs in different locations depending on the
|
|
||||||
// system but always use the canonical name
|
|
||||||
wxFontEncoding encSys = wxLocale::GetSystemEncoding();
|
|
||||||
if ( encSys != wxFONTENCODING_SYSTEM )
|
|
||||||
{
|
|
||||||
wxString fullname(lang);
|
|
||||||
fullname << wxS('.') << wxFontMapperBase::GetEncodingName(encSys);
|
|
||||||
searchPath << GetFullSearchPath(fullname) << wxPATH_SEP;
|
|
||||||
}
|
|
||||||
#endif // wxUSE_FONTMAP
|
|
||||||
|
|
||||||
searchPath += GetFullSearchPath(lang);
|
|
||||||
if ( lang.length() > LEN_LANG && lang[LEN_LANG] == wxS('_') )
|
|
||||||
{
|
|
||||||
// also add just base locale name: for things like "fr_BE" (Belgium
|
|
||||||
// French) we should use fall back on plain "fr" if no Belgium-specific
|
|
||||||
// message catalogs exist
|
|
||||||
searchPath << wxPATH_SEP
|
|
||||||
<< GetFullSearchPath(ExtractLang(lang));
|
|
||||||
}
|
|
||||||
|
|
||||||
wxLogTrace(TRACE_I18N, wxS("Looking for \"%s.mo\" in search path \"%s\""),
|
wxLogTrace(TRACE_I18N, wxS("Looking for \"%s.mo\" in search path \"%s\""),
|
||||||
domain, searchPath);
|
domain, searchPath);
|
||||||
@@ -1703,11 +1719,7 @@ bool wxFileTranslationsLoader::LoadCatalog(wxTranslations *translations,
|
|||||||
|
|
||||||
wxString strFullName;
|
wxString strFullName;
|
||||||
if ( !wxFindFileInPath(&strFullName, searchPath, fn.GetFullPath()) )
|
if ( !wxFindFileInPath(&strFullName, searchPath, fn.GetFullPath()) )
|
||||||
{
|
|
||||||
wxLogVerbose(_("catalog file for domain '%s' not found."), domain);
|
|
||||||
wxLogTrace(TRACE_I18N, wxS("Catalog \"%s.mo\" not found"), domain);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
// open file and read its data
|
// open file and read its data
|
||||||
wxLogVerbose(_("using catalog '%s' from '%s'."), domain, strFullName.c_str());
|
wxLogVerbose(_("using catalog '%s' from '%s'."), domain, strFullName.c_str());
|
||||||
|
Reference in New Issue
Block a user