How to include inline br tag within a translation string

360 views Asked by At

Hi we're using the Twig templating system within our site along with the twig i18n extension to handle our language translations.

As per the documentation, all of our template strings are wrapped in the trans block to be translated by the extension as shown below:

{% trans "Text to be <br>translated" %}

The issue is that within some of our template strings we have inline <br> tags for text formatting. In all the instances where these <br> tags exist, the strings don't translate and remain in English. Is there any way to 'escape' the <br> tags within a trans block, so that all the strings are read and translated properly?

1

There are 1 answers

0
Andrew Chernauskas On

You can run it through a nl2br filter as well as the trans filter:

{{ "Company Name\nAll Rights Reserved."|nl2br|t }}