From 0dee5c691ba6d61f1fc1e2e732b08a95060effab Mon Sep 17 00:00:00 2001 From: WouterJ Date: Thu, 31 Jan 2013 23:36:01 +0100 Subject: [PATCH 1/3] Added trans_default_domain tag to twig reference --- reference/twig_reference.rst | 37 +++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/reference/twig_reference.rst b/reference/twig_reference.rst index 404b9b1dc2f..6981ad57eac 100644 --- a/reference/twig_reference.rst +++ b/reference/twig_reference.rst @@ -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-twig` | ++---------------------------------------------------+--------------------------------------------------------------------+ +| ``{% transchoice count with {variables} %}`` | This will translate and render the text with pluralization, more | +| ... | information in :ref:`book-translation-twig` | +| ``{% endtranschoice %}`` | | ++---------------------------------------------------+--------------------------------------------------------------------+ +| ``{% trans_default_domain language %}`` | This will set the default domain for message catalogues in the | +| | current template | ++---------------------------------------------------+--------------------------------------------------------------------+ Tests ----- From c1eddf7938be8681efc03e850650e92cecdde459 Mon Sep 17 00:00:00 2001 From: WouterJ Date: Thu, 31 Jan 2013 23:36:39 +0100 Subject: [PATCH 2/3] Reformatted trans_default_domain versionadded block --- book/translation.rst | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/book/translation.rst b/book/translation.rst index ebd5e62096b..1000bf1b4f4 100644 --- a/book/translation.rst +++ b/book/translation.rst @@ -812,16 +812,19 @@ texts* and complex expressions: {{ message|trans|raw }} {{ '

bar

'|trans|raw }} -.. versionadded:: 2.1 - You can now set the translation domain for an entire Twig template with a - single tag: +.. tip:: + + You can set the translation domain for an entire Twig template with a single tag: - .. code-block:: jinja + .. code-block:: jinja + + {% trans_default_domain "app" %} - {% trans_default_domain "app" %} + Note that this only influences the current template, not any "included" + templates (in order to avoid side effects). - 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 ~~~~~~~~~~~~~ From d337e76d20697b925d70414e55ca7ba23b988a53 Mon Sep 17 00:00:00 2001 From: WouterJ Date: Thu, 31 Jan 2013 23:37:00 +0100 Subject: [PATCH 3/3] Reformatted references for translation in twig --- book/translation.rst | 4 +++- reference/twig_reference.rst | 8 ++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/book/translation.rst b/book/translation.rst index 1000bf1b4f4..dcc6dd33290 100644 --- a/book/translation.rst +++ b/book/translation.rst @@ -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 ~~~~~~~~~~~~~~ @@ -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: diff --git a/reference/twig_reference.rst b/reference/twig_reference.rst index 6981ad57eac..9686dd16593 100644 --- a/reference/twig_reference.rst +++ b/reference/twig_reference.rst @@ -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. | +---------------------------------------------------------------------------------+-------------------------------------------------------------------+ @@ -121,10 +121,10 @@ Tags | | 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` | +| | :ref:`book-translation-tags` | +---------------------------------------------------+--------------------------------------------------------------------+ | ``{% transchoice count with {variables} %}`` | This will translate and render the text with pluralization, more | -| ... | information in :ref:`book-translation-twig` | +| ... | information in :ref:`book-translation-tags` | | ``{% endtranschoice %}`` | | +---------------------------------------------------+--------------------------------------------------------------------+ | ``{% trans_default_domain language %}`` | This will set the default domain for message catalogues in the |