diff --git a/django/middleware/locale.py b/django/middleware/locale.py index 44dec75a542..c8cbd58685e 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 ba5127f2ea5..d365f3be6d9 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')