Return true from AddCatalog() if message ID matches language
When the original messages language matches the language of the locale
being used, these strings can be used directly and so AddCatalog()
should still return true for them but it didn't do it any more after the
changes of 94b1a17aeb (Add AddAvailableCatalog() and use it in
AddStdCatalog(), 2023-09-30).
See #18227.
Closes #24019.
Closes #24037.
This commit is contained in:
parent
6fbb504955
commit
39079cbf23
2 changed files with 36 additions and 3 deletions
|
|
@ -1346,9 +1346,27 @@ bool wxTranslations::AddCatalog(const wxString& domain,
|
|||
return true;
|
||||
|
||||
const wxString msgIdLang = wxUILocale::GetLanguageCanonicalName(msgIdLanguage);
|
||||
|
||||
// Check if the original strings can be used directly.
|
||||
bool canUseUntranslated = false;
|
||||
if ( m_lang.empty() )
|
||||
{
|
||||
// If we are using the default language, check if the message ID
|
||||
// language is acceptable for this system.
|
||||
const wxString domain_lang = GetBestTranslation(domain, msgIdLang);
|
||||
|
||||
if ( msgIdLang == domain_lang )
|
||||
canUseUntranslated = true;
|
||||
}
|
||||
else // But if we have a fixed language, we should just check it instead.
|
||||
{
|
||||
// Consider message IDs for another region using the same language
|
||||
// acceptable.
|
||||
if ( msgIdLang.BeforeFirst('_') == m_lang.BeforeFirst('_') )
|
||||
canUseUntranslated = true;
|
||||
}
|
||||
|
||||
if ( canUseUntranslated )
|
||||
{
|
||||
wxLogTrace(TRACE_I18N,
|
||||
wxS("not using translations for domain '%s' with msgid language '%s'"),
|
||||
|
|
|
|||
|
|
@ -239,7 +239,7 @@ void IntlTestCase::IsAvailable()
|
|||
CPPUNIT_ASSERT_EQUAL( origLocale, setlocale(LC_ALL, nullptr) );
|
||||
}
|
||||
|
||||
TEST_CASE("wxTranslations::Available", "[translations]")
|
||||
TEST_CASE("wxTranslations::AddCatalog", "[translations]")
|
||||
{
|
||||
// We currently have translations for French and Japanese in this test
|
||||
// directory, check that loading those succeeds but loading others doesn't.
|
||||
|
|
@ -270,6 +270,21 @@ TEST_CASE("wxTranslations::Available", "[translations]")
|
|||
trans.SetLanguage(wxLANGUAGE_ITALIAN);
|
||||
CHECK_FALSE( trans.AddAvailableCatalog(domain) );
|
||||
}
|
||||
|
||||
// And loading catalog using the same language as message IDs should
|
||||
// "succeed" too, even if there is no such file, as in this case the
|
||||
// message IDs themselves can be used directly.
|
||||
SECTION("Untranslated")
|
||||
{
|
||||
trans.SetLanguage(wxLANGUAGE_GERMAN);
|
||||
CHECK( trans.AddCatalog(domain, wxLANGUAGE_GERMAN) );
|
||||
|
||||
// Using a different region should still work.
|
||||
CHECK( trans.AddCatalog(domain, wxLANGUAGE_GERMAN_SWISS) );
|
||||
|
||||
// But using a completely different language should not.
|
||||
CHECK_FALSE( trans.AddCatalog(domain, wxLANGUAGE_DUTCH) );
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("wxLocale::Default", "[locale]")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue