diff --git a/django/middleware/locale.py b/django/middleware/locale.py
index 87f904d..413561c 100644
a
|
b
|
from collections import OrderedDict
|
4 | 4 | |
5 | 5 | from django.conf import settings |
6 | 6 | from django.core.urlresolvers import (is_valid_path, get_resolver, |
7 | | LocaleRegexURLResolver) |
| 7 | LocaleRegexURLResolver, get_script_prefix) |
8 | 8 | from django.http import HttpResponseRedirect |
9 | 9 | from django.utils.cache import patch_vary_headers |
10 | 10 | from django.utils import translation |
… |
… |
class LocaleMiddleware(object):
|
50 | 50 | path_valid = is_valid_path("%s/" % language_path, urlconf) |
51 | 51 | |
52 | 52 | if path_valid: |
53 | | language_url = "%s://%s/%s%s" % ( |
54 | | request.scheme, request.get_host(), language, |
55 | | request.get_full_path()) |
| 53 | script_prefix = get_script_prefix() |
| 54 | language_url = "%s://%s%s" % ( |
| 55 | request.scheme, request.get_host(), |
| 56 | request.get_full_path().replace(script_prefix, |
| 57 | '%s%s/' % (script_prefix, language), 1)) |
56 | 58 | return self.response_redirect_class(language_url) |
57 | 59 | |
58 | 60 | # Store language back into session if it is not present |
diff --git a/tests/i18n/patterns/tests.py b/tests/i18n/patterns/tests.py
index 78f5a46..e1af856 100644
a
|
b
|
from __future__ import unicode_literals
|
3 | 3 | import os |
4 | 4 | |
5 | 5 | from django.core.exceptions import ImproperlyConfigured |
6 | | from django.core.urlresolvers import reverse, clear_url_caches |
| 6 | from django.core.urlresolvers import (reverse, clear_url_caches, |
| 7 | set_script_prefix) |
7 | 8 | from django.http import HttpResponsePermanentRedirect |
8 | 9 | from django.middleware.locale import LocaleMiddleware |
9 | 10 | from django.test import TestCase |
… |
… |
class URLResponseTests(URLTestCaseBase):
|
291 | 292 | self.assertEqual(response.context['LANGUAGE_CODE'], 'pt-br') |
292 | 293 | |
293 | 294 | |
| 295 | class URLRedirectWithScriptAliasTests(URLTestCaseBase): |
| 296 | """ |
| 297 | Tests if the response has the right language-code. |
| 298 | """ |
| 299 | def setUp(self): |
| 300 | super(URLRedirectWithScriptAliasTests, self).setUp() |
| 301 | self.script_prefix = '/script_prefix' |
| 302 | set_script_prefix(self.script_prefix) |
| 303 | |
| 304 | def tearDown(self): |
| 305 | super(URLRedirectWithScriptAliasTests, self).tearDown() |
| 306 | # reset script prefix |
| 307 | set_script_prefix('') |
| 308 | |
| 309 | def test_language_prefix_with_script_prefix(self): |
| 310 | response = self.client.get('/prefixed/', HTTP_ACCEPT_LANGUAGE='en', |
| 311 | SCRIPT_NAME=self.script_prefix) |
| 312 | |
| 313 | self.assertRedirects(response, '%s/en/prefixed/' % self.script_prefix, |
| 314 | target_status_code=404) |
| 315 | |
| 316 | |
294 | 317 | class URLTagTests(URLTestCaseBase): |
295 | 318 | """ |
296 | 319 | Test if the language tag works. |