module documentation

Undocumented

Variable register Undocumented
Class ​Block​Translate​Node Undocumented
Class ​Get​Available​Languages​Node Undocumented
Class ​Get​Current​Language​Bidi​Node Undocumented
Class ​Get​Current​Language​Node Undocumented
Class ​Get​Language​Info​List​Node Undocumented
Class ​Get​Language​Info​Node Undocumented
Class ​Language​Node Undocumented
Class ​Translate​Node Undocumented
Function do​_block​_translate Translate a block of text with parameters.
Function do​_get​_available​_languages Store a list of available languages in the context.
Function do​_get​_current​_language Store the current language in the context.
Function do​_get​_current​_language​_bidi Store the current language layout in the context.
Function do​_get​_language​_info Store the language information dictionary for the given language code in a context variable.
Function do​_get​_language​_info​_list No summary
Function do​_translate Mark a string for translation and translate the string for the current language.
Function language Enable the given language just for this block.
Function language​_bidi Undocumented
Function language​_name Undocumented
Function language​_name​_local Undocumented
Function language​_name​_translated Undocumented
register =

Undocumented

@register.tag('blocktranslate')
@register.tag('blocktrans')
def do_block_translate(parser, token):

Translate a block of text with parameters.

Usage:

{% blocktranslate with bar=foo|filter boo=baz|filter %}
This is {{ bar }} and {{ boo }}.
{% endblocktranslate %}

Additionally, this supports pluralization:

{% blocktranslate count count=var|length %}
There is {{ count }} object.
{% plural %}
There are {{ count }} objects.
{% endblocktranslate %}

This is much like ngettext, only in template syntax.

The "var as value" legacy format is still supported:

{% blocktranslate with foo|filter as bar and baz|filter as boo %}
{% blocktranslate count var|length as count %}

The translated string can be stored in a variable using asvar:

{% blocktranslate with bar=foo|filter boo=baz|filter asvar var %}
This is {{ bar }} and {{ boo }}.
{% endblocktranslate %}
{{ var }}

Contextual translations are supported:

{% blocktranslate with bar=foo|filter context "greeting" %}
    This is {{ bar }}.
{% endblocktranslate %}

This is equivalent to calling pgettext/npgettext instead of (u)gettext/(u)ngettext.

@register.tag('get_available_languages')
def do_get_available_languages(parser, token):

Store a list of available languages in the context.

Usage:

{% get_available_languages as languages %}
{% for language in languages %}
...
{% endfor %}

This puts settings.LANGUAGES into the named variable.

@register.tag('get_current_language')
def do_get_current_language(parser, token):

Store the current language in the context.

Usage:

{% get_current_language as language %}

This fetches the currently active language and puts its value into the language context variable.

@register.tag('get_current_language_bidi')
def do_get_current_language_bidi(parser, token):

Store the current language layout in the context.

Usage:

{% get_current_language_bidi as bidi %}

This fetches the currently active language's layout and puts its value into the bidi context variable. True indicates right-to-left layout, otherwise left-to-right.

@register.tag('get_language_info')
def do_get_language_info(parser, token):

Store the language information dictionary for the given language code in a context variable.

Usage:

{% get_language_info for LANGUAGE_CODE as l %}
{{ l.code }}
{{ l.name }}
{{ l.name_translated }}
{{ l.name_local }}
{{ l.bidi|yesno:"bi-directional,uni-directional" }}
@register.tag('get_language_info_list')
def do_get_language_info_list(parser, token):

Store a list of language information dictionaries for the given language codes in a context variable. The language codes can be specified either as a list of strings or a settings.LANGUAGES style list (or any sequence of sequences whose first items are language codes).

Usage:

{% get_language_info_list for LANGUAGES as langs %}
{% for l in langs %}
  {{ l.code }}
  {{ l.name }}
  {{ l.name_translated }}
  {{ l.name_local }}
  {{ l.bidi|yesno:"bi-directional,uni-directional" }}
{% endfor %}
@register.tag('translate')
@register.tag('trans')
def do_translate(parser, token):

Mark a string for translation and translate the string for the current language.

Usage:

{% translate "this is a test" %}

This marks the string for translation so it will be pulled out by makemessages into the .po files and runs the string through the translation engine.

There is a second form:

{% translate "this is a test" noop %}

This marks the string for translation, but returns the string unchanged. Use it when you need to store values into forms that should be translated later on.

You can use variables instead of constant strings to translate stuff you marked somewhere else:

{% translate variable %}

This tries to translate the contents of the variable variable. Make sure that the string in there is something that is in the .po file.

It is possible to store the translated string into a variable:

{% translate "this is a test" as var %}
{{ var }}

Contextual translations are also supported:

{% translate "this is a test" context "greeting" %}

This is equivalent to calling pgettext instead of (u)gettext.

@register.tag
def language(parser, token):

Enable the given language just for this block.

Usage:

{% language "de" %}
    This is {{ bar }} and {{ boo }}.
{% endlanguage %}
@register.filter
def language_bidi(lang_code):

Undocumented

@register.filter
def language_name(lang_code):

Undocumented

@register.filter
def language_name_local(lang_code):

Undocumented

@register.filter
def language_name_translated(lang_code):

Undocumented