1
0
mirror of https://github.com/django/django.git synced 2024-12-22 17:16:24 +00:00

Refs #25933 -- Fixed i18n_patterns() prefix_default_language=False with HTTP_ACCEPT_LANGUAGE header.

This commit is contained in:
Krzysztof Urbaniak 2016-03-10 15:08:53 +01:00 committed by Tim Graham
parent 34c56687ae
commit 85a4844f8a
2 changed files with 6 additions and 4 deletions

View File

@ -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)

View File

@ -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')