Skip to content

Added trans_default_domain tag to twig reference and some formatting #2202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 4, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions book/translation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ Translations in Templates
Most of the time, translation occurs in templates. Symfony2 provides native
support for both Twig and PHP templates.

.. _book-translation-twig:
.. _book-translation-tags:

Twig Templates
~~~~~~~~~~~~~~
Expand Down Expand Up @@ -778,6 +778,8 @@ You can also specify the message domain and pass some additional variables:
{0} There is no apples|{1} There is one apple|]1,Inf] There are %count% apples
{% endtranschoice %}

.. _book-translation-filters:

The ``trans`` and ``transchoice`` filters can be used to translate *variable
texts* and complex expressions:

Expand Down Expand Up @@ -812,16 +814,19 @@ texts* and complex expressions:
{{ message|trans|raw }}
{{ '<h3>bar</h3>'|trans|raw }}

.. versionadded:: 2.1
You can now set the translation domain for an entire Twig template with a
single tag:
.. tip::

.. code-block:: jinja
You can set the translation domain for an entire Twig template with a single tag:

{% trans_default_domain "app" %}
.. code-block:: jinja

Note that this only influences the current template, not any "included"
templates (in order to avoid side effects).
{% trans_default_domain "app" %}

Note that this only influences the current template, not any "included"
templates (in order to avoid side effects).

.. versionadded:: 2.1
The ``trans_default_domain`` tag is new in Symfony2.1

PHP Templates
~~~~~~~~~~~~~
Expand Down
41 changes: 22 additions & 19 deletions reference/twig_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ Filters
| | spaces and capitalizes the string) |
+---------------------------------------------------------------------------------+-------------------------------------------------------------------+
| ``text|trans(arguments = {}, domain = 'messages', locale = null)`` | This will translate the text into the current language, more |
| | information in :ref:`book-translation-twig`. |
| | information in :ref:`book-translation-filers`. |
+---------------------------------------------------------------------------------+-------------------------------------------------------------------+
| ``text|transchoice(count, arguments = {}, domain = 'messages', locale = null)`` | This will translate the text with pluralization, more information |
| | in :ref:`book-translation-twig`. |
| | in :ref:`book-translation-filters`. |
+---------------------------------------------------------------------------------+-------------------------------------------------------------------+
| ``variable|yaml_encode(inline = 0)`` | This will transform the variable text into a YAML syntax. |
+---------------------------------------------------------------------------------+-------------------------------------------------------------------+
Expand Down Expand Up @@ -110,23 +110,26 @@ Filters
Tags
----

+---------------------------------------------------+-------------------------------------------------------------------+
| Tag Syntax | Usage |
+===================================================+===================================================================+
| ``{% render url('route', {parameters}) %}`` | This will render the Response Content for the given controller |
| | that the URL points to. For more information, |
| | see :ref:`templating-embedding-controller`. |
+---------------------------------------------------+-------------------------------------------------------------------+
| ``{% form_theme form 'file' %}`` | This will look inside the given file for overridden form blocks, |
| | more information in :doc:`/cookbook/form/form_customization`. |
+---------------------------------------------------+-------------------------------------------------------------------+
| ``{% trans with {variables} %}...{% endtrans %}`` | This will translate and render the text, more information in |
| | :ref:`book-translation-twig` |
+---------------------------------------------------+-------------------------------------------------------------------+
| ``{% transchoice count with {variables} %}`` | This will translate and render the text with pluralization, more |
| ... | information in :ref:`book-translation-twig` |
| ``{% endtranschoice %}`` | |
+---------------------------------------------------+-------------------------------------------------------------------+
+---------------------------------------------------+--------------------------------------------------------------------+
| Tag Syntax | Usage |
+===================================================+====================================================================+
| ``{% render url('route', {parameters}) %}`` | This will render the Response Content for the given controller |
| | that the URL points to. For more information, |
| | see :ref:`templating-embedding-controller`. |
+---------------------------------------------------+--------------------------------------------------------------------+
| ``{% form_theme form 'file' %}`` | This will look inside the given file for overridden form blocks, |
| | more information in :doc:`/cookbook/form/form_customization`. |
+---------------------------------------------------+--------------------------------------------------------------------+
| ``{% trans with {variables} %}...{% endtrans %}`` | This will translate and render the text, more information in |
| | :ref:`book-translation-tags` |
+---------------------------------------------------+--------------------------------------------------------------------+
| ``{% transchoice count with {variables} %}`` | This will translate and render the text with pluralization, more |
| ... | information in :ref:`book-translation-tags` |
| ``{% endtranschoice %}`` | |
+---------------------------------------------------+--------------------------------------------------------------------+
| ``{% trans_default_domain language %}`` | This will set the default domain for message catalogues in the |
| | current template |
+---------------------------------------------------+--------------------------------------------------------------------+

Tests
-----
Expand Down