我正在使用blocktrans标签渲染一些复数形式;以下是模板文件中相关的片段:
{% blocktrans count choice_count=choice_count %}
You have {{ choice_count }} choice:
{% plural %}
You have {{ choice_count }} choices:
{% endblocktrans %}
运行
python manage.py makemessages --all
后,这是我的例如django.po
文件中与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):"
但是当我运行python manage.py compilemessages
时,我收到了以下错误信息:
$ ./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
我知道这是由于模板文件中的换行符/空格,我知道如何“绕过”它 - 当我将模板片段更改为:
{% blocktrans count choice_count=choice_count %}You have {{ choice_count }} choice:{% plural %}You have {{ choice_count }} choices:{% endblocktrans %}
再次运行 makemessages
,从消息中删除 fuzzy
标记,然后重新运行 compilemessages
,它会成功编译。
然而,我的问题是如何保留第一个模板语法并仍能编译消息,因为它极大地提高了模板文件中代码的可读性。