mirror of https://github.com/django/django.git
Fixed #18700 -- Added URL reversal for i18n set_language view.
This commit is contained in:
parent
b496be331c
commit
10f979fd92
|
@ -1,5 +1,5 @@
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.conf.urls import patterns
|
from django.conf.urls import patterns, url
|
||||||
from django.core.urlresolvers import LocaleRegexURLResolver
|
from django.core.urlresolvers import LocaleRegexURLResolver
|
||||||
|
|
||||||
def i18n_patterns(prefix, *args):
|
def i18n_patterns(prefix, *args):
|
||||||
|
@ -16,5 +16,5 @@ def i18n_patterns(prefix, *args):
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = patterns('',
|
urlpatterns = patterns('',
|
||||||
(r'^setlang/$', 'django.views.i18n.set_language'),
|
url(r'^setlang/$', 'django.views.i18n.set_language', name='set_language'),
|
||||||
)
|
)
|
||||||
|
|
|
@ -1272,7 +1272,7 @@ Here's example HTML template code:
|
||||||
|
|
||||||
.. code-block:: html+django
|
.. code-block:: html+django
|
||||||
|
|
||||||
<form action="/i18n/setlang/" method="post">
|
<form action="{% url 'set_language' %}" method="post">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<input name="next" type="hidden" value="{{ redirect_to }}" />
|
<input name="next" type="hidden" value="{{ redirect_to }}" />
|
||||||
<select name="language">
|
<select name="language">
|
||||||
|
|
|
@ -5,6 +5,7 @@ import gettext
|
||||||
from os import path
|
from os import path
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
from django.core.urlresolvers import reverse
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.utils.translation import override, activate, get_language
|
from django.utils.translation import override, activate, get_language
|
||||||
from django.utils.text import javascript_quote
|
from django.utils.text import javascript_quote
|
||||||
|
@ -23,6 +24,9 @@ class I18NTests(TestCase):
|
||||||
self.assertRedirects(response, 'http://testserver/views/')
|
self.assertRedirects(response, 'http://testserver/views/')
|
||||||
self.assertEqual(self.client.session['django_language'], lang_code)
|
self.assertEqual(self.client.session['django_language'], lang_code)
|
||||||
|
|
||||||
|
def test_setlang_reversal(self):
|
||||||
|
self.assertEqual(reverse('set_language'), '/views/i18n/setlang/')
|
||||||
|
|
||||||
def test_jsi18n(self):
|
def test_jsi18n(self):
|
||||||
"""The javascript_catalog can be deployed with language settings"""
|
"""The javascript_catalog can be deployed with language settings"""
|
||||||
saved_lang = get_language()
|
saved_lang = get_language()
|
||||||
|
|
Loading…
Reference in New Issue