]> git.saurik.com Git - wxWidgets.git/commitdiff
Shorten lang names in wxTranslations, not wxFileTranslationsLoader.
authorVáclav Slavík <vslavik@fastmail.fm>
Mon, 26 Apr 2010 20:51:16 +0000 (20:51 +0000)
committerVáclav Slavík <vslavik@fastmail.fm>
Mon, 26 Apr 2010 20:51:16 +0000 (20:51 +0000)
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

include/wx/translation.h
src/common/translation.cpp

index ee10962a72a3e93403a04c2fac8e20884f8bd7f4..3dcd97ab2a96109784ec0c53e43337f8c54eb0a0 100644 (file)
@@ -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);
index 4c841afc94a19eb6fbe9a8d10557aedc9863d1ea..6ea7c334ac17b6154774664449c02f13d7366313 100644 (file)
@@ -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());