Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django translation escape % sign

I'm trying to translate some text that contains a percent sign like so:

{% trans "100% butterfly" %}

When I run the makemessages command, I get the following output in my german .po file:

#: .\appName\templates\appName\butterflies.html:54
#, fuzzy, python-format
#| msgid ""
#| "100% butterfly"
msgid ""
"100%% butterfly"
msgstr ""
"100% shmetterling"

Which when compiled, fails to translate the text to German. I've tried doing {% trans "100%% butterfly" %}, but this causes the pages to display "100%% butterfly" when viewed in both german and english. I've also tried using blocktrans tags instead to translate the text, with the same result.

Manually erasing the extra % in the .po file, along with the #, fuzzy, python-format line works, but I'd rather not have to do this for every % sign I'm trying to translate.

How do I escape this in my HTML so that Django stops generating a fuzzy translation in the .po file and doesn't get confused thinking I'm trying to do some python formatting?

like image 375
tayden Avatar asked Oct 08 '15 18:10

tayden


1 Answers

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.

like image 176
zzheng Avatar answered Sep 24 '22 16:09

zzheng