Load catalogs for all preferred languages, if they exist
This way the first and only fallback language isn't necessarily the msgid language (which is English most often). This is how GNU gettext works -- it uses multiple fallback languages when multiple preferred languages are set. As a side effect, fixes #18227 in one possible way.
This commit is contained in:
parent
5d08e404c7
commit
2d784da2ee
@ -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,
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user