I'm rendering some pluralization using the blocktrans tag; here's the relevant snippet in the template file:
{% blocktrans count choice_count=choice_count %}
You have {{ choice_count }} choice:
{% plural %}
You have {{ choice_count }} choices:
{% endblocktrans %}
After running python manage.py makemessages --all
, this is the relevant snippet in my, e.g. django.po
file for en
:
msgid ""
"\n"
" You have %(choice_count)s choice:\n"
msgid_plural ""
"\n"
" You have %(choice_count)s choices:\n"
msgstr[0] "You have one choices:"
msgstr[1] "You have %(choice_count)s choice(s):"
But when I run python manage.py compilemessages
, this is the error message I get:
$ ./manage.py compilemessages
processing file django.po in /home/yiqing/repos/training/site/training/locale/en/LC_MESSAGES
/home/yiqing/repos/training/site/training/locale/en/LC_MESSAGES/django.po:60: `msgid' and `msgstr[0]' entries do not both begin with '\n'
msgfmt: found 4 fatal errors
I know that it's because of the newlines/spaces in the template file, and I know how to get "around" it -- when I change the the template snippet to, e.g., this:
{% blocktrans count choice_count=choice_count %}You have {{ choice_count }} choice:{% plural %}You have {{ choice_count }} choices:{% endblocktrans %}
And rerun makemessages
, remove the fuzzy
marker from the messages and then rerun compilemessages
, it compiles just fine.
However, my question is how to keep the first template syntax and still be able to compile the messages, because it drastically improves the readability of the code in the template files.
The documentation mentions the "trimmed" keyword for blocktrans, quoting: