diff --git a/interface/wx/translation.h b/interface/wx/translation.h index a57c9930d0..fd39fd6b18 100644 --- a/interface/wx/translation.h +++ b/interface/wx/translation.h @@ -190,9 +190,10 @@ public: bool AddStdCatalog(); /** - Add a catalog for use with the current locale. + Add a catalog for the preferred UI language. In case of multiple + preferences, add catalog for each language, if available. - By default, it is searched for in standard places (see + By default, the catalog is searched for in standard places (see wxFileTranslationsLoader), but you may also prepend additional directories to the search path with wxFileTranslationsLoader::AddCatalogLookupPathPrefix(). @@ -216,8 +217,9 @@ public: code are used instead. @return - @true if catalog was successfully loaded, @false otherwise (which might - mean that the catalog is not found or that it isn't in the correct format). + @true if catalog in the most preferred language was successfully loaded, + @false otherwise (which might mean that the catalog is not found or that + it isn't in the correct format). */ bool AddCatalog(const wxString& domain, wxLanguage msgIdLanguage = wxLANGUAGE_ENGLISH_US); @@ -243,8 +245,9 @@ public: in case they use 8-bit characters (e.g. German or French strings). @return - @true if catalog was successfully loaded, @false otherwise (which might - mean that the catalog is not found or that it isn't in the correct format). + @true if catalog in the most preferred language was successfully loaded, + @false otherwise (which might mean that the catalog is not found or that + it isn't in the correct format). */ bool AddCatalog(const wxString& domain, wxLanguage msgIdLanguage, diff --git a/src/common/translation.cpp b/src/common/translation.cpp index a64327eaef..377dc533f1 100644 --- a/src/common/translation.cpp +++ b/src/common/translation.cpp @@ -1555,9 +1555,9 @@ bool wxTranslations::AddCatalog(const wxString& domain, wxLanguage msgIdLanguage) { const wxString msgIdLang = wxLocale::GetLanguageCanonicalName(msgIdLanguage); - const wxString domain_lang = GetBestTranslation(domain, msgIdLang); + const wxArrayString domain_langs = GetAllGoodTranslations(domain, msgIdLanguage); - if ( domain_lang.empty() ) + if ( domain_langs.empty() ) { wxLogTrace(TRACE_I18N, wxS("no suitable translation for domain '%s' found"), @@ -1565,11 +1565,30 @@ bool wxTranslations::AddCatalog(const wxString& domain, return false; } - wxLogTrace(TRACE_I18N, - wxS("adding '%s' translation for domain '%s' (msgid language '%s')"), - domain_lang, domain, msgIdLang); + bool success = false; + for ( wxArrayString::const_iterator lang = domain_langs.begin(); + lang != domain_langs.end(); + ++lang ) + { + wxLogTrace(TRACE_I18N, + wxS("adding '%s' translation for domain '%s' (msgid language '%s')"), + *lang, domain, msgIdLang); - return LoadCatalog(domain, domain_lang, msgIdLang); + // No use loading languages that are less preferred than the + // msgid language, as by definition it contains all the strings + // in the msgid language. + if ( msgIdLang == *lang ) + break; + + // We determine success by the success of loading/failing to load + // the most preferred (i.e. the first one) language's catalog: + if ( lang == domain_langs.begin() ) + success = LoadCatalog(domain, *lang, msgIdLang); + else + LoadCatalog(domain, *lang, msgIdLang); + } + + return success; }