diff --git a/django/utils/translation/trans_real.py b/django/utils/translation/trans_real.py index 7dcc77b46c..f4e35eabbc 100644 --- a/django/utils/translation/trans_real.py +++ b/django/utils/translation/trans_real.py @@ -43,7 +43,7 @@ language_code_re = _lazy_re_compile( re.IGNORECASE ) -language_code_prefix_re = _lazy_re_compile(r'^/(\w+([@-]\w+)?)(/|$)') +language_code_prefix_re = _lazy_re_compile(r'^/(\w+([@-]\w+){0,2})(/|$)') @receiver(setting_changed) diff --git a/docs/releases/4.1.txt b/docs/releases/4.1.txt index cc412bebfa..543c9caf6e 100644 --- a/docs/releases/4.1.txt +++ b/docs/releases/4.1.txt @@ -183,7 +183,8 @@ Generic Views Internationalization ~~~~~~~~~~~~~~~~~~~~ -* ... +* The :func:`~django.conf.urls.i18n.i18n_patterns` function now supports + languages with both scripts and regions. Logging ~~~~~~~ diff --git a/tests/i18n/tests.py b/tests/i18n/tests.py index dfceaa5381..0b419d426c 100644 --- a/tests/i18n/tests.py +++ b/tests/i18n/tests.py @@ -1593,11 +1593,15 @@ class MiscTests(SimpleTestCase): @override_settings( LANGUAGES=[ ('en', 'English'), + ('en-latn-us', 'Latin English'), + ('en-Latn-US', 'BCP 47 case format'), ('de', 'German'), ('de-1996', 'German, orthography of 1996'), ('de-at', 'Austrian German'), + ('de-ch-1901', 'German, Swiss variant, traditional orthography'), ('i-mingo', 'Mingo'), ('kl-tunumiit', 'Tunumiisiut'), + ('nan-hani-tw', 'Hanji'), ('pl', 'Polish'), ], ) @@ -1609,13 +1613,17 @@ class MiscTests(SimpleTestCase): ('/xyz/', None), ('/en/', 'en'), ('/en-gb/', 'en'), + ('/en-latn-us/', 'en-latn-us'), + ('/en-Latn-US/', 'en-Latn-US'), ('/de/', 'de'), ('/de-1996/', 'de-1996'), ('/de-at/', 'de-at'), ('/de-ch/', 'de'), - ('/de-simple-page/', None), + ('/de-ch-1901/', 'de-ch-1901'), + ('/de-simple-page-test/', None), ('/i-mingo/', 'i-mingo'), ('/kl-tunumiit/', 'kl-tunumiit'), + ('/nan-hani-tw/', 'nan-hani-tw'), ] for path, language in tests: with self.subTest(path=path): @@ -1824,7 +1832,7 @@ class UnprefixedDefaultLanguageTests(SimpleTestCase): def test_page_with_dash(self): # A page starting with /de* shouldn't match the 'de' language code. - response = self.client.get('/de-simple-page/') + response = self.client.get('/de-simple-page-test/') self.assertEqual(response.content, b'Yes') def test_no_redirect_on_404(self):