私は一部をレンダリングしていますpluralization using the blocktrans tag;ここでは関係スニペットは、テンプレートファイルにあります:msgfmtエラーを引き起こさずに{%blocktrans%}タグと{%plural%}タグの間に空白を入れたいのですが?
{% blocktrans count choice_count=choice_count %}
You have {{ choice_count }} choice:
{% plural %}
You have {{ choice_count }} choices:
{% endblocktrans %}
python manage.py makemessages --all
を実行した後、これが私の、例えば内の関連するスニペットですen
ためdjango.po
ファイル:
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
を再実行しても問題ありません。
しかし、私の質問は、テンプレートファイルのコードの可読性を大幅に向上させるため、最初のテンプレート構文を維持してメッセージをコンパイルする方法です。
['{%spaceless%}'タグを使用してみましたか(https://docs.djangoproject.com/en/1.10/ref/templates/builtins/#spaceless)? – guival