Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handling percent-sign (%) in Django blocktrans tags

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?

like image 745
anttikoo Avatar asked Mar 27 '11 08:03

anttikoo


3 Answers

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

like image 110
Steve Jalim Avatar answered Oct 18 '22 23:10

Steve Jalim


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.

like image 43
anttikoo Avatar answered Oct 18 '22 23:10

anttikoo


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

like image 20
Claude Avatar answered Oct 18 '22 23:10

Claude