July 2017
Intermediate to advanced
456 pages
11h 32m
English
Content in Twig templates can translate content either in small sets by using the t or trans filter, or the {% trans %} block. For instance, you can run text through the translate function using either of the following:
{{ 'Hello world' | t }}
{{ 'Hello world' | trans }}
Placing output within a {% trans %} block runs text through the translation function, including handling variables. For example:
{% trans %}
Submitted by {{ author.username }} on {{ node.created }}
{% endtrans %}
This is the same as running t('Submitted by @username on @created') and passing the appropriate variables. The default variable handling is to escape the values, but you are also able to avoid this escaping or wrapping it in an <em> tag by using ...
Read now
Unlock full access