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?
Asked
Active
Viewed 4,969 times
2

daveoncode
- 18,900
- 15
- 104
- 159
-
{% blocktrans %} Translate this string {% plural %} And this plural string {% endblocktrans %} – catherine Feb 12 '13 at 13:52
3 Answers
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
-
Yes, I want html output... but honestly I don't like to embed html tags in localized strings :P – daveoncode Feb 12 '13 at 14:12
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
character both in django template file and your .po
files
Like this .po
:
msgid "Psycological aid"
msgstr "Психологическая помощь"
django template:
{% trans 'Psycological aid' %}
Containing block should have white-space: pre-line;
css rule

Unicorn
- 1,397
- 1
- 15
- 24