Skip to content

Commit b408349

Browse files
committed
Merge pull request #2202 from WouterJ/trans_domain_twig
Added trans_default_domain tag to twig reference and some formatting
2 parents f239d0e + d337e76 commit b408349

File tree

2 files changed

+35
-27
lines changed

2 files changed

+35
-27
lines changed

book/translation.rst

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ Translations in Templates
741741
Most of the time, translation occurs in templates. Symfony2 provides native
742742
support for both Twig and PHP templates.
743743

744-
.. _book-translation-twig:
744+
.. _book-translation-tags:
745745

746746
Twig Templates
747747
~~~~~~~~~~~~~~
@@ -778,6 +778,8 @@ You can also specify the message domain and pass some additional variables:
778778
{0} There is no apples|{1} There is one apple|]1,Inf] There are %count% apples
779779
{% endtranschoice %}
780780
781+
.. _book-translation-filters:
782+
781783
The ``trans`` and ``transchoice`` filters can be used to translate *variable
782784
texts* and complex expressions:
783785

@@ -812,16 +814,19 @@ texts* and complex expressions:
812814
{{ message|trans|raw }}
813815
{{ '<h3>bar</h3>'|trans|raw }}
814816
815-
.. versionadded:: 2.1
816-
You can now set the translation domain for an entire Twig template with a
817-
single tag:
817+
.. tip::
818818

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

821-
{% trans_default_domain "app" %}
821+
.. code-block:: jinja
822822
823-
Note that this only influences the current template, not any "included"
824-
templates (in order to avoid side effects).
823+
{% trans_default_domain "app" %}
824+
825+
Note that this only influences the current template, not any "included"
826+
templates (in order to avoid side effects).
827+
828+
.. versionadded:: 2.1
829+
The ``trans_default_domain`` tag is new in Symfony2.1
825830

826831
PHP Templates
827832
~~~~~~~~~~~~~

reference/twig_reference.rst

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ Filters
7777
| | spaces and capitalizes the string) |
7878
+---------------------------------------------------------------------------------+-------------------------------------------------------------------+
7979
| ``text|trans(arguments = {}, domain = 'messages', locale = null)`` | This will translate the text into the current language, more |
80-
| | information in :ref:`book-translation-twig`. |
80+
| | information in :ref:`book-translation-filers`. |
8181
+---------------------------------------------------------------------------------+-------------------------------------------------------------------+
8282
| ``text|transchoice(count, arguments = {}, domain = 'messages', locale = null)`` | This will translate the text with pluralization, more information |
83-
| | in :ref:`book-translation-twig`. |
83+
| | in :ref:`book-translation-filters`. |
8484
+---------------------------------------------------------------------------------+-------------------------------------------------------------------+
8585
| ``variable|yaml_encode(inline = 0)`` | This will transform the variable text into a YAML syntax. |
8686
+---------------------------------------------------------------------------------+-------------------------------------------------------------------+
@@ -110,23 +110,26 @@ Filters
110110
Tags
111111
----
112112

113-
+---------------------------------------------------+-------------------------------------------------------------------+
114-
| Tag Syntax | Usage |
115-
+===================================================+===================================================================+
116-
| ``{% render url('route', {parameters}) %}`` | This will render the Response Content for the given controller |
117-
| | that the URL points to. For more information, |
118-
| | see :ref:`templating-embedding-controller`. |
119-
+---------------------------------------------------+-------------------------------------------------------------------+
120-
| ``{% form_theme form 'file' %}`` | This will look inside the given file for overridden form blocks, |
121-
| | more information in :doc:`/cookbook/form/form_customization`. |
122-
+---------------------------------------------------+-------------------------------------------------------------------+
123-
| ``{% trans with {variables} %}...{% endtrans %}`` | This will translate and render the text, more information in |
124-
| | :ref:`book-translation-twig` |
125-
+---------------------------------------------------+-------------------------------------------------------------------+
126-
| ``{% transchoice count with {variables} %}`` | This will translate and render the text with pluralization, more |
127-
| ... | information in :ref:`book-translation-twig` |
128-
| ``{% endtranschoice %}`` | |
129-
+---------------------------------------------------+-------------------------------------------------------------------+
113+
+---------------------------------------------------+--------------------------------------------------------------------+
114+
| Tag Syntax | Usage |
115+
+===================================================+====================================================================+
116+
| ``{% render url('route', {parameters}) %}`` | This will render the Response Content for the given controller |
117+
| | that the URL points to. For more information, |
118+
| | see :ref:`templating-embedding-controller`. |
119+
+---------------------------------------------------+--------------------------------------------------------------------+
120+
| ``{% form_theme form 'file' %}`` | This will look inside the given file for overridden form blocks, |
121+
| | more information in :doc:`/cookbook/form/form_customization`. |
122+
+---------------------------------------------------+--------------------------------------------------------------------+
123+
| ``{% trans with {variables} %}...{% endtrans %}`` | This will translate and render the text, more information in |
124+
| | :ref:`book-translation-tags` |
125+
+---------------------------------------------------+--------------------------------------------------------------------+
126+
| ``{% transchoice count with {variables} %}`` | This will translate and render the text with pluralization, more |
127+
| ... | information in :ref:`book-translation-tags` |
128+
| ``{% endtranschoice %}`` | |
129+
+---------------------------------------------------+--------------------------------------------------------------------+
130+
| ``{% trans_default_domain language %}`` | This will set the default domain for message catalogues in the |
131+
| | current template |
132+
+---------------------------------------------------+--------------------------------------------------------------------+
130133

131134
Tests
132135
-----

0 commit comments

Comments
 (0)