Skip to content

Commit 6b26f95

Browse files
committed
[book][translation] Adding a little more clarification to translation and escaping
1 parent 7951513 commit 6b26f95

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

book/translation.rst

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -738,18 +738,21 @@ texts* and complex expressions:
738738
variables translated using a filter. In other words, if you need to
739739
be sure that your translated variable is *not* output escaped, you must
740740
apply the raw filter after the translation filter:
741-
741+
742742
.. code-block:: jinja
743743
744744
{% message = '<h3>foo</h3>' %}
745745
746-
{# no change is needed - the translated text is never escaped #}
746+
{# text translated between tags is never escaped #}
747747
{% trans %}
748748
{{ message }}
749749
{% endtrans %}
750750
751-
{# With filters, you must unescape the translated text #}
752-
{{ message | trans | raw }}
751+
{# a variable translated via a filter must be escaped #}
752+
{{ message | trans | raw }}
753+
754+
{# but static strings are never escaped #}
755+
{{ '<h3>foo</h3>' | trans }}
753756
754757
PHP Templates
755758
~~~~~~~~~~~~~

0 commit comments

Comments
 (0)