symfony2: how to include line breaks / newlines in translations?
For me the following version did the trick:
foo: "| Hello \n this is a new line"
Twig does not convert line feeds to <br />
automatically.
Use the nl2br filter.
#template.html.twig
{{ 'foo'|trans|nl2br }}
I'm not quite sure but eventually you'll have to add \n
to the translation strings additonally.
#messages.<locale>.yml
foo: >
Hello i am a line \n
Hello i am a new line
In your YAML file use:
foo: |
first line
second line
and in your TWIG file:
<p>{{ 'foo'|trans|nl2br }}</p>
tested on:
- Symfony version 2.6.6
- twig/twig 1.x-dev 6792014