From: Václav Slavík Date: Mon, 26 Apr 2010 20:51:16 +0000 (+0000) Subject: Shorten lang names in wxTranslations, not wxFileTranslationsLoader. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/076c0a8ee8c9238af2037b66ef97bda7cede4e4a 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 --- diff --git a/include/wx/translation.h b/include/wx/translation.h index ee10962a72..3dcd97ab2a 100644 --- a/include/wx/translation.h +++ b/include/wx/translation.h @@ -111,6 +111,9 @@ public: static const wxString& GetUntranslatedString(const wxString& str); private: + // perform loading of the catalog via m_loader + bool LoadCatalog(const wxString& domain, const wxString& lang); + // find best translation for given domain wxString ChooseLanguageForDomain(const wxString& domain, const wxString& msgIdLang); diff --git a/src/common/translation.cpp b/src/common/translation.cpp index 4c841afc94..6ea7c334ac 100644 --- a/src/common/translation.cpp +++ b/src/common/translation.cpp @@ -1359,8 +1359,48 @@ bool wxTranslations::AddCatalog(const wxString& domain, if ( msgIdLang == domain_lang ) 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" ); - 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, "invalid language specification" ); - wxString searchPath; - -#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)); - } + wxString searchPath = GetFullSearchPath(lang); wxLogTrace(TRACE_I18N, wxS("Looking for \"%s.mo\" in search path \"%s\""), domain, searchPath); @@ -1703,11 +1719,7 @@ bool wxFileTranslationsLoader::LoadCatalog(wxTranslations *translations, wxString strFullName; 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; - } // open file and read its data wxLogVerbose(_("using catalog '%s' from '%s'."), domain, strFullName.c_str());