summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2010-10-29 16:48:58 +0000
committerRussell Keith-Magee <russell@keith-magee.com>2010-10-29 16:48:58 +0000
commitccc49029b8d84cf3eaaa3593df6370329f7b14e1 (patch)
tree3e88f1a774a557cae46a7095073ccf6e05e7fff8 /docs
parent269e921756371bee6d35a967bc2ffe84d1ae39eb (diff)
Fixed #14181 -- Added a template tag and filters to allow localization to be disabled in a template. Thanks to Benjamin Wohlwend for the work on the patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@14395 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'docs')
-rw-r--r--docs/ref/templates/builtins.txt9
-rw-r--r--docs/topics/i18n/localization.txt97
2 files changed, 104 insertions, 2 deletions
diff --git a/docs/ref/templates/builtins.txt b/docs/ref/templates/builtins.txt
index 8e166d802f..7bb4481904 100644
--- a/docs/ref/templates/builtins.txt
+++ b/docs/ref/templates/builtins.txt
@@ -2113,3 +2113,12 @@ Django templates. It is slightly different from the libraries described
above because you don't need to add any application to the ``INSTALLED_APPS``
setting but rather set :setting:`USE_I18N` to True, then loading it with
``{% load i18n %}``. See :ref:`specifying-translation-strings-in-template-code`.
+
+l10n
+~~~~
+
+Provides a couple of templatetags that allow control over the localization of
+values in Django templates. It is slightly different from the libraries described
+above because you don't need to add any application to the ``INSTALLED_APPS``;
+you only need to load the library using ``{% load l10n %}``. See
+:ref:`topic-l10n-templates`.
diff --git a/docs/topics/i18n/localization.txt b/docs/topics/i18n/localization.txt
index 38d74e68e3..df89851039 100644
--- a/docs/topics/i18n/localization.txt
+++ b/docs/topics/i18n/localization.txt
@@ -2,11 +2,13 @@
Localization
============
-This document covers two localization-related topics: `Creating language
-files`_ and `locale aware date, time and numbers input/output in forms`_
+This document covers three localization-related topics: `Creating language
+files`_ , `locale aware date, time and numbers input/output in forms`_,
+and `controlling localization in templates`_.
.. _`Creating language files`: how-to-create-language-files_
.. _`locale aware date, time and numbers input/output in forms`: format-localization_
+.. _`controlling localization in templates`: topic-l10n-templates
.. seealso::
@@ -315,3 +317,94 @@ where :file:`formats.py` contains custom format definitions. For example::
to use a space as a thousand separator, instead of the default for English,
a comma.
+
+.. topic-l10n-templates:
+
+Controlling localization in templates
+=====================================
+
+When you have enabled localization using :setting:`USE_L10N`, Django
+will try to use a locale specific format whenever it outputs a value
+in a template.
+
+However, it may not always be appropriate to use localized values --
+for example, if you're outputting Javascript or XML that is designed
+to be machine-readable, you will always want unlocalized values. You
+may also want to use localization in selected templates, rather than
+using localization everywhere.
+
+To allow for fine control over the use of localization, Django
+provides a the ``l10n`` template library that contains the following
+tags and filters.
+
+Template tags
+-------------
+
+.. templatetag:: localize
+
+localize
+~~~~~~~~
+
+.. versionadded:: 1.3
+
+Enables or disables localization of template variables in the
+contained block.
+
+This tag allows a more fine grained control of localization than
+:setting:`USE_L10N`.
+
+To activate or deactivate localization for a template block, use::
+
+ {% localize on %}
+ {{ value }}
+ {% endlocalize %}
+
+ {% localize off %}
+ {{ value }}
+ {% endlocalize %}
+
+.. note::
+
+ The value of :setting:`USE_L10N` is not respected inside of a
+ `{% localize %}` block.
+
+See :tfilter:`localized` and :tfilter:`unlocalized` for a template filter that will
+do the same job on a per-variable basis.
+
+Template filters
+----------------
+
+.. templatefilter:: localize
+
+localize
+~~~~~~~~
+
+.. versionadded:: 1.3
+
+Forces localization of a single value.
+
+For example::
+
+ {{ value|localize }}
+
+To disable localization on a single value, use :tfilter:`unlocalize`. To control
+localization over a large section of a template, use the :ttag:`localize` template
+tag.
+
+
+.. templatefilter:: unlocalize
+
+unlocalize
+~~~~~~~~~~
+
+.. versionadded:: 1.3
+
+Forces a single value to be printed without localization.
+
+For example::
+
+ {{ value|unlocalize }}
+
+To force localization of a single value, use :tfilter:`localize`. To
+control localization over a large section of a template, use the
+:ttag:`localize` template tag.