Handling percent-sign (%) in Django blocktrans tags

这一生的挚爱 提交于 2019-12-30 09:23:11

问题


I'm currently localizing my Django app. All other translations work fine except percent-sign inside blocktrans tags.

In my template I have {% blocktrans %}Original % blocktrans{endblocktrans %}.

django-admin makemessages produces this in django.po:

#: templates/index.html:78
#, python-format
msgid "Original %% blocktrans"
msgstr ""

I update that to msgstr "Translated %% blocktrans", run django-admin compilemessages, restart dev server and refresh the page, but I still see Original % blocktrans in the output. Other translations are shown properly.

For reference, {% trans "Original % trans" %} also works ok. After makemessages and translation I have:

#: templates/index.html:72
msgid "Original % trans"
msgstr "Translated % trans"

This works as expected - translated version is shown.

I must use blocktrans because I also need to embed variables to the strings. I'm using Django 1.2.5.

How can I make blocktrans work with percent-signs?


回答1:


Check out this ticket - it's not a solution, but it sheds light on what's going on




回答2:


Couldn't find a real solution to the problem, so I used a workaround: create a constant PERCENT_SIGN = u'%' and use that as {{ PERCENT_SIGN }} inside blocktrans-blocks.




回答3:


Another ticket has been opened for this particular issue, with a patch that fixes it. Hopefully it will be fixed for Django 1.4.

https://code.djangoproject.com/ticket/16721



来源:https://stackoverflow.com/questions/5448207/handling-percent-sign-in-django-blocktrans-tags

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!