Skip to content

Commit

Permalink
doc: add documentation for new trans with variable substitution
Browse files Browse the repository at this point in the history
  • Loading branch information
mworrell committed Sep 23, 2016
1 parent c4e4641 commit 9d4b38b
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 23 deletions.
4 changes: 2 additions & 2 deletions doc/developer-guide/translation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ Translate tag::

{_ Translate me _}

Extended translate tag::
Interpolation trans tag::

{% _ "Example" nl="Voorbeeld" fr="Exemple" %}
{% trans "Hello {foo} World" foo=_"happy" %}

As part of a tag parameter::

Expand Down
4 changes: 4 additions & 0 deletions doc/ref/dispatch/dispatch_mod_import_csv-dispatch.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

.. include:: meta-mod_import_csv-dispatch.rst

.. Not yet documented. (no todo item, as this is not a major issue)
18 changes: 0 additions & 18 deletions doc/ref/tags/tag__.rst

This file was deleted.

6 changes: 4 additions & 2 deletions doc/ref/tags/tag_trans.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ Example::

{_ translate me _}

If the active language is “nl” then this will output “vertaal mij”. Of course depending on the available translations. When a translation is not available then the text is output as-is without any translation.
If the active language is “nl” then this will output “vertaal mij”. Of course depending on the available translations.

.. seealso:: :ref:`tag-_`.
If a translation is not available then the text is output as-is without any translation.

.. seealso:: :ref:`tag-trans_ext`.

27 changes: 27 additions & 0 deletions doc/ref/tags/tag_trans_ext.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

.. index:: tag; translate
.. _tag-trans_ext:

translate with variable substitution
====================================

Translate a text value using gettext and substitute variables.

Example::

{% trans "Hello {foo} World" foo=1234 %}

This translates the text using the available po files. The variables in the translated text will
be substituted with the value of the arguments.

If the active language is “en” then the example above will output “Hello 1234 World”, in “nl” it will be “Hallo 1234 wereld”. Of course depending on the available translations.

If a translation is not available then the text is output as-is without any translation.

If a “{” is needed in the string, then repeat it:

{% trans "Hello {{foo}}, and this is {foo}." foo=1234 %}

Will echo “Hello {foo}, and this is 1234.”

.. seealso:: :ref:`tag-trans`.
2 changes: 1 addition & 1 deletion rebar.lock
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
0},
{<<"template_compiler">>,
{git,"https://github.com/zotonic/template_compiler.git",
{ref,"f5c8e1827540f513ca1756cd06a9c98f52f21b92"}},
{ref,"14fae262a80340a5a4f10257ddb52fd943e783e5"}},
0},
{<<"twerl">>,
{git,"https://github.com/mworrell/twerl.git",
Expand Down

0 comments on commit 9d4b38b

Please sign in to comment.