Fixed #25933 -- Allowed an unprefixed default language in i18n_patterns().

This commit is contained in:
Krzysztof Urbaniak 2016-02-29 09:24:19 +01:00 committed by Tim Graham
parent 4b129ac81f
commit 839a955d08
7 changed files with 112 additions and 30 deletions

View file

@ -248,6 +248,10 @@ Internationalization
used in a root URLConf specified using :attr:`request.urlconf
<django.http.HttpRequest.urlconf>`.
* By setting the new ``prefix_default_language`` parameter for
:func:`~django.conf.urls.i18n.i18n_patterns` to ``False``, you can allow
accessing the default language without a URL prefix.
Management Commands
~~~~~~~~~~~~~~~~~~~

View file

@ -1326,11 +1326,17 @@ Django provides two mechanisms to internationalize URL patterns:
Language prefix in URL patterns
-------------------------------
.. function:: i18n_patterns(*pattern_list)
.. function:: i18n_patterns(*urls, prefix_default_language=True)
This function can be used in a root URLconf and Django will automatically
prepend the current active language code to all url patterns defined within
:func:`~django.conf.urls.i18n.i18n_patterns`. Example URL patterns::
:func:`~django.conf.urls.i18n.i18n_patterns`.
Setting ``prefix_default_language`` to ``False`` removes the prefix from the
default language (:setting:`LANGUAGE_CODE`). This can be useful when adding
translations to existing site so that the current URLs won't change.
Example URL patterns::
from django.conf.urls import include, url
from django.conf.urls.i18n import i18n_patterns
@ -1371,6 +1377,21 @@ function. Example::
>>> reverse('news:detail', kwargs={'slug': 'news-slug'})
'/nl/news/news-slug/'
With ``prefix_default_language=False`` and ``LANGUAGE_CODE='en'``, the URLs
will be::
>>> activate('en')
>>> reverse('news:index')
'/news/'
>>> activate('nl')
>>> reverse('news:index')
'/nl/news/'
.. versionadded:: 1.10
The ``prefix_default_language`` parameter was added.
.. warning::
:func:`~django.conf.urls.i18n.i18n_patterns` is only allowed in a root