summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorJannis Leidel <jannis@leidel.info>2011-07-04 09:52:06 +0000
committerJannis Leidel <jannis@leidel.info>2011-07-04 09:52:06 +0000
commit286a1cad8839da3219dc3901540fb9422686e5ab (patch)
tree4c44fd1979e1a97c66c128fb6f17df9bdd2d9274 /docs
parenta34e67031a09e69a50d748e5b493edbd6effb1ff (diff)
Fixed #16332 -- Added language template tag that switches the activate language for the enclosed template section, e.g. to allow translation of URLs as added in r16405. Many thanks to Florian Apolloner and Orne Brocaar.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16501 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'docs')
-rw-r--r--docs/topics/http/urls.txt6
-rw-r--r--docs/topics/i18n/internationalization.txt26
2 files changed, 32 insertions, 0 deletions
diff --git a/docs/topics/http/urls.txt b/docs/topics/http/urls.txt
index 1f880262fa..f06dbe1506 100644
--- a/docs/topics/http/urls.txt
+++ b/docs/topics/http/urls.txt
@@ -28,6 +28,12 @@ This mapping can be as short or as long as needed. It can reference other
mappings. And, because it's pure Python code, it can be constructed
dynamically.
+.. versionadded:: 1.4
+
+ Django also allows to translate URLs according to the active language.
+ This process is described in the
+ :ref:`internationalization docs <url-internationalization>`.
+
.. _how-django-processes-a-request:
How Django processes a request
diff --git a/docs/topics/i18n/internationalization.txt b/docs/topics/i18n/internationalization.txt
index 4850f7e7bc..5e9c1cd3b0 100644
--- a/docs/topics/i18n/internationalization.txt
+++ b/docs/topics/i18n/internationalization.txt
@@ -887,6 +887,32 @@ return the URL in the active language. Example::
that a carelessly translated URL causes a collision with a non-translated
URL pattern.
+.. _reversing_in_templates:
+
+.. templatetag:: language
+
+Reversing in templates
+----------------------
+
+If localized URLs get reversed in templates they always use the current
+language. To link to a URL in another language use the ``language``
+template tag. It enables the given language in the enclosed template section:
+
+.. code-block:: html+django
+
+ {% load i18n %}
+
+ {% get_available_languages as languages %}
+
+ {% trans "View this category in:" %}
+ {% for lang_code, lang_name in languages %}
+ {% language lang_code %}
+ <a href="{% url category slug=category.slug %}">{{ lang_name }}</a>
+ {% endlanguage %}
+ {% endfor %}
+
+The :ttag:`language` tag expects the language code as the only argument.
+
.. _set_language-redirect-view:
The ``set_language`` redirect view