diff --git a/docs/translation.txt b/docs/translation.txt index adac134c61..21d947d1d6 100644 --- a/docs/translation.txt +++ b/docs/translation.txt @@ -120,45 +120,41 @@ A standard problem with translations is pluralization of strings. Use Using translations in templates =============================== -Using translations in Django templates works much like translations in Python -code. The ``{% i18n %}`` template tag lets you use the same ``_()`` helper -function as in your Python code:: +Using translations in Django templates uses two template tags and a slightly +different syntax than standard gettext. The ``{% trans %}`` template tag +translates a constant string or a variable content:: - -
{% i18n _('Hello %(name)s, welcome at %(site)s!') %}
-{% i18n ngettext('There is %(count)d file', 'There are %(count)d files', files|count) %}
- - +{{ _('Hello, world!') }}
- - + {% blocktrans count list|counted as counter %} + There is only one {{ name }} object. + {% plural %} + There are {{ counter }} {{ name }} objects. + {% endblocktrans %} -This syntax is much shorter, but it doesn't allow you to use ``gettext_noop`` -or ``ngettext``. +Internally all block translations and inline translations are translated into +the actual gettext/ngettext call. Each ``DjangoContext`` has access to two translation-specific variables: @@ -167,6 +163,15 @@ Each ``DjangoContext`` has access to two translation-specific variables: * ``LANGUAGE_CODE`` is the current user's preferred language, as a string. Example: ``en-us``. (See "How language preference is discovered", below.) +If you don't use the ``DjangoContext`` extension, you can get those values with +two tags:: + + {% get_current_language as LANGUAGE_CODE %} + {% get_available_languages as LANGUAGES %} + +All tags live in the ``i18n`` tag library, so you need to specify +``{% load i18n %}`` in the head of your template to make use of them. + The ``setlang`` redirect view -----------------------------