[Solved]-Django translation escape % sign

8👍

According to this comment in Django’s Trac, adding a translator comment to deactivate python format above the string that you want to translate can fix / workaround this issue.

If the text to translate is in your Python code, use:

# Translator: xgettext:no-python-format
_('100% butterfly')

For trans template tag, you can try:

{# Translators: xgettext:no-python-format #}
{% trans "100% butterfly" %}

as explained in the doc.

👤zzheng

2👍

I think the better way is to use the html code : %

It is the most elegant way for dealing with django translation for example.

1👍

Turns out this is a Django problem with a fix possibly coming in Django 1.9.
One workaround is to do:

{% blocktrans with percent="%" %}100{{percent}} butterfly{% endblocktrans %}

Which essentially embraces the python formatting it thinks you’re trying to do when you put a % symbol in your trans text. It’s verbose and sucks, but it works.

👤tayden

Leave a comment