1. Simon Meers
  2. django-dbgettext
  3. Issues
Issue #6 new

Attributes with percent (%) signs need no-python-format comment.

Doug Van Horn
created an issue

When outputting an attribute with a percent sign in it:

{{{

-- coding: utf-8 --

gettext("""10% discount""") }}}

xgettext will incorrectly guess that this is a python-format string and add a flag comment to the .po file:

{{{

, python-format

msgid "10% discount" msgstr "" }}}

If the msgstr doesn't match the percent sign, or if the letter following it isn't a valid conversion specifier, compilemessages will break:

{{{

, python-format

msgid "10% discount" msgstr "10% pour vous" }}}

{{{ $ django-admin.py compilemessages

... 'msgstr' is not a valid Python format string, unlike 'msgid'. Reason: In the directive number 1, the character 'p' is not a valid conversion specifier. }}}

I have a patch to modify the output to handle this edge case:

https://bitbucket.org/dougvanhorn/django-dbgettext.patch/changeset/58e2d91000ca

This will result in attribute files that look like this:

{{{

-- coding: utf-8 --

xgettext:no-python-format

gettext("""10% discount""") }}}

The gettext flags behavior is discussed here (along with the workaround):

http://www.gnu.org/s/hello/manual/gettext/c_002dformat-Flag.html

Comments (2)

  1. Anonymous

    I have the same issue, but on the HTML side. The following does not seem to work as I would expect. Actually. I found no information in the Django documentation about how to pass special comments to xgettext in HTML pages.

    {% comment %} xgettext:no-python-format {% endcomment %}
    {% trans "10% discount." %}
    
  2. Log in to comment