diff --git a/src/common/translation.cpp b/src/common/translation.cpp index d731165af0..0d58caf3a5 100644 --- a/src/common/translation.cpp +++ b/src/common/translation.cpp @@ -1346,9 +1346,27 @@ bool wxTranslations::AddCatalog(const wxString& domain, return true; const wxString msgIdLang = wxUILocale::GetLanguageCanonicalName(msgIdLanguage); - const wxString domain_lang = GetBestTranslation(domain, msgIdLang); - if ( msgIdLang == domain_lang ) + // 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'"), diff --git a/tests/intl/intltest.cpp b/tests/intl/intltest.cpp index ca3ceebdf3..9b14175fce 100644 --- a/tests/intl/intltest.cpp +++ b/tests/intl/intltest.cpp @@ -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]")