symfony2: how to include line breaks / newlines in translations?
internationalization, symfony, twig, yaml
Solution
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
Problem
how am I supposed to get line breaks working in Symfony 2.4? ``` #messages.de.yml foo: | Hello i am a line Hello i am a new line ``` and ``` #messages.de.yml foo: > Hello i am a line Hello i am a new line ``` twig ``` #template.html.twig {{ 'foo'|trans }} ``` The translation is working but line breaks aren't. The documentation isn't really clear to me. Hints will be highly appreciated.