Loading django/utils/translation/trans_real.py +3 −5 Original line number Diff line number Diff line Loading @@ -169,11 +169,9 @@ class DjangoTranslation(gettext_module.GNUTranslations): def _add_fallback(self): """Sets the GNUTranslations() fallback with the default language.""" # Don't set a fallback for the default language or for # en-us (as it's empty, so it'll ALWAYS fall back to the default # language; found this as part of #21498, as we set en-us for # management commands) if self.__language == settings.LANGUAGE_CODE or self.__language == "en-us": # Don't set a fallback for the default language or any English variant # (as it's empty, so it'll ALWAYS fall back to the default language) if self.__language == settings.LANGUAGE_CODE or self.__language.startswith('en'): return default_translation = translation(settings.LANGUAGE_CODE) self.add_fallback(default_translation) Loading tests/i18n/tests.py +15 −0 Original line number Diff line number Diff line Loading @@ -902,6 +902,21 @@ class MiscTests(TestCase): super(MiscTests, self).setUp() self.rf = RequestFactory() @override_settings(LANGUAGE_CODE='de') def test_english_fallback(self): """ With a non-English LANGUAGE_CODE and if the active language is English or one of its variants, the untranslated string should be returned (instead of falling back to LANGUAGE_CODE) (See #24413). """ self.assertEqual(ugettext("Image"), "Bild") with translation.override('en'): self.assertEqual(ugettext("Image"), "Image") with translation.override('en-us'): self.assertEqual(ugettext("Image"), "Image") with translation.override('en-ca'): self.assertEqual(ugettext("Image"), "Image") def test_parse_spec_http_header(self): """ Testing HTTP header parsing. First, we test that we can parse the Loading Loading
django/utils/translation/trans_real.py +3 −5 Original line number Diff line number Diff line Loading @@ -169,11 +169,9 @@ class DjangoTranslation(gettext_module.GNUTranslations): def _add_fallback(self): """Sets the GNUTranslations() fallback with the default language.""" # Don't set a fallback for the default language or for # en-us (as it's empty, so it'll ALWAYS fall back to the default # language; found this as part of #21498, as we set en-us for # management commands) if self.__language == settings.LANGUAGE_CODE or self.__language == "en-us": # Don't set a fallback for the default language or any English variant # (as it's empty, so it'll ALWAYS fall back to the default language) if self.__language == settings.LANGUAGE_CODE or self.__language.startswith('en'): return default_translation = translation(settings.LANGUAGE_CODE) self.add_fallback(default_translation) Loading
tests/i18n/tests.py +15 −0 Original line number Diff line number Diff line Loading @@ -902,6 +902,21 @@ class MiscTests(TestCase): super(MiscTests, self).setUp() self.rf = RequestFactory() @override_settings(LANGUAGE_CODE='de') def test_english_fallback(self): """ With a non-English LANGUAGE_CODE and if the active language is English or one of its variants, the untranslated string should be returned (instead of falling back to LANGUAGE_CODE) (See #24413). """ self.assertEqual(ugettext("Image"), "Bild") with translation.override('en'): self.assertEqual(ugettext("Image"), "Image") with translation.override('en-us'): self.assertEqual(ugettext("Image"), "Image") with translation.override('en-ca'): self.assertEqual(ugettext("Image"), "Image") def test_parse_spec_http_header(self): """ Testing HTTP header parsing. First, we test that we can parse the Loading