Kaydet (Commit) 9ca0961b authored tarafından Tim Graham's avatar Tim Graham

Added headings to i18n template tags and filters.

üst 84522c0d
...@@ -816,18 +816,33 @@ Other tags ...@@ -816,18 +816,33 @@ Other tags
These tags also require a ``{% load i18n %}``. These tags also require a ``{% load i18n %}``.
* ``{% get_available_languages as LANGUAGES %}`` returns a list of tuples in .. templatetag:: get_available_languages
which the first element is the :term:`language code` and the second is the
language name (translated into the currently active locale).
* ``{% get_current_language as LANGUAGE_CODE %}`` returns the current user's ``get_available_languages``
preferred language, as a string. Example: ``en-us``. (See ~~~~~~~~~~~~~~~~~~~~~~~~~~~
:ref:`how-django-discovers-language-preference`.)
* ``{% get_current_language_bidi as LANGUAGE_BIDI %}`` returns the current ``{% get_available_languages as LANGUAGES %}`` returns a list of tuples in
locale's direction. If True, it's a right-to-left language, e.g.: Hebrew, which the first element is the :term:`language code` and the second is the
Arabic. If False it's a left-to-right language, e.g.: English, French, German language name (translated into the currently active locale).
etc.
.. templatetag:: get_current_language
``get_current_languages``
~~~~~~~~~~~~~~~~~~~~~~~~~
``{% get_current_language as LANGUAGE_CODE %}`` returns the current user's
preferred language as a string. Example: ``en-us``. See
:ref:`how-django-discovers-language-preference`.
.. templatetag:: get_current_language_bidi
``get_current_language_bidi``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
``{% get_current_language_bidi as LANGUAGE_BIDI %}`` returns the current
locale's direction. If ``True``, it's a right-to-left language, e.g. Hebrew,
Arabic. If ``False`` it's a left-to-right language, e.g. English, French,
German, etc.
If you enable the ``django.template.context_processors.i18n`` context processor If you enable the ``django.template.context_processors.i18n`` context processor
then each ``RequestContext`` will have access to ``LANGUAGES``, then each ``RequestContext`` will have access to ``LANGUAGES``,
...@@ -837,6 +852,11 @@ then each ``RequestContext`` will have access to ``LANGUAGES``, ...@@ -837,6 +852,11 @@ then each ``RequestContext`` will have access to ``LANGUAGES``,
The ``i18n`` context processor is not enabled by default for new projects. The ``i18n`` context processor is not enabled by default for new projects.
.. templatetag:: get_language_info
``get_language_info``
~~~~~~~~~~~~~~~~~~~~~
You can also retrieve information about any of the available languages using You can also retrieve information about any of the available languages using
provided template tags and filters. To get information about a single language, provided template tags and filters. To get information about a single language,
use the ``{% get_language_info %}`` tag:: use the ``{% get_language_info %}`` tag::
...@@ -851,6 +871,11 @@ You can then access the information:: ...@@ -851,6 +871,11 @@ You can then access the information::
Name in English: {{ lang.name }}<br /> Name in English: {{ lang.name }}<br />
Bi-directional: {{ lang.bidi }} Bi-directional: {{ lang.bidi }}
.. templatetag:: get_language_info_list
``get_language_info_list``
~~~~~~~~~~~~~~~~~~~~~~~~~~
You can also use the ``{% get_language_info_list %}`` template tag to retrieve You can also use the ``{% get_language_info_list %}`` template tag to retrieve
information for a list of languages (e.g. active languages as specified in information for a list of languages (e.g. active languages as specified in
:setting:`LANGUAGES`). See :ref:`the section about the set_language redirect :setting:`LANGUAGES`). See :ref:`the section about the set_language redirect
...@@ -871,6 +896,13 @@ you can iterate over those languages in the template:: ...@@ -871,6 +896,13 @@ you can iterate over those languages in the template::
{% get_language_info_list for available_languages as langs %} {% get_language_info_list for available_languages as langs %}
{% for lang in langs %} ... {% endfor %} {% for lang in langs %} ... {% endfor %}
.. templatefilter:: language_name
.. templatefilter:: language_name_local
.. templatefilter:: language_bidi
Template filters
~~~~~~~~~~~~~~~~
There are also simple filters available for convenience: There are also simple filters available for convenience:
* ``{{ LANGUAGE_CODE|language_name }}`` ("German") * ``{{ LANGUAGE_CODE|language_name }}`` ("German")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment