From 85a4844f8a8e628b90fa30ba7074f162a2d188ef Mon Sep 17 00:00:00 2001 From: Krzysztof Urbaniak Date: Thu, 10 Mar 2016 15:08:53 +0100 Subject: [PATCH] Refs #25933 -- Fixed i18n_patterns() prefix_default_language=False with HTTP_ACCEPT_LANGUAGE header. --- django/middleware/locale.py | 6 ++---- tests/i18n/tests.py | 4 ++++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/django/middleware/locale.py b/django/middleware/locale.py index 44dec75a54..c8cbd58685 100644 --- a/django/middleware/locale.py +++ b/django/middleware/locale.py @@ -22,7 +22,8 @@ class LocaleMiddleware(object): urlconf = getattr(request, 'urlconf', settings.ROOT_URLCONF) i18n_patterns_used, prefixed_default_language = is_language_prefix_patterns_used(urlconf) language = translation.get_language_from_request(request, check_path=i18n_patterns_used) - if not language and i18n_patterns_used and not prefixed_default_language: + language_from_path = translation.get_language_from_path(request.path_info) + if not language_from_path and i18n_patterns_used and not prefixed_default_language: language = settings.LANGUAGE_CODE translation.activate(language) request.LANGUAGE_CODE = translation.get_language() @@ -33,9 +34,6 @@ class LocaleMiddleware(object): urlconf = getattr(request, 'urlconf', settings.ROOT_URLCONF) i18n_patterns_used, prefixed_default_language = is_language_prefix_patterns_used(urlconf) - if not language_from_path and i18n_patterns_used and not prefixed_default_language: - language_from_path = settings.LANGUAGE_CODE - if response.status_code == 404 and not language_from_path and i18n_patterns_used: language_path = '/%s%s' % (language, request.path_info) path_valid = is_valid_path(language_path, urlconf) diff --git a/tests/i18n/tests.py b/tests/i18n/tests.py index ba5127f2ea..d365f3be6d 100644 --- a/tests/i18n/tests.py +++ b/tests/i18n/tests.py @@ -1808,6 +1808,10 @@ class UnprefixedDefaultLanguageTests(SimpleTestCase): response = self.client.get('/fr/simple/') self.assertEqual(response.content, b'Oui') + def test_unprefixed_language_other_than_accept_language(self): + response = self.client.get('/simple/', HTTP_ACCEPT_LANGUAGE='fr') + self.assertEqual(response.content, b'Yes') + def test_unexpected_kwarg_to_i18n_patterns(self): with self.assertRaisesMessage(AssertionError, "Unexpected kwargs for i18n_patterns(): {'foo':"): i18n_patterns(object(), foo='bar')