2

How can I use line breaks in translation strings inside .po files? Currently I added "\n" and used {{msg|linebreaks}} in my template, but the string is printed in one single line... how can I print it on multiple lines?

daveoncode
  • 18,900
  • 15
  • 104
  • 159

3 Answers3

2

I assume you want HTML output. In such case, it would be better to include HTML tags in the string:

{% blocktrans %}
First line<br/>
Second line
{% endblocktrans %}

If you are looking for something else, please describe better what you are actually trying to achieve.

Update:

If the lines are independent, it might be even better to actually split them up:

{% trans "First line" %}
<br/>
{% trans "Second line" %}
Michal Čihař
  • 9,799
  • 6
  • 49
  • 87
0

bit late, but maybe helps someone, add your translation like this:

po file

msgid "_your_msgid"
msgstr "first line\nsecond line"

template

{% trans '_your_msgid' as local_var %}
{{ local_var|linebreaksbr }}
0

You can use &#10; character both in django template file and your .po files

Like this .po:

msgid "Psycological&#10;aid"
msgstr "Психологическая&#10;помощь"

django template:

{% trans 'Psycological&#10;aid' %}

Containing block should have white-space: pre-line; css rule

Unicorn
  • 1,397
  • 1
  • 15
  • 24