Example:
{{{
price_adjust = models.DecimalField(max_digits=5, decimal_places=2,
default=1, choices=(('0.90', _('10% discount'), ))
}}}
will generate:
{{{
#, python-format
msgid "10% discount"
msgstr ""
}}}
When this is translated to German escaping the %, like:
{{{
#, python-format
msgid "10% discount"
msgstr "10%% Rabatt"
}}}
This results in an error message:
{{{
Execution of msgfmt failed:
/vagrant/src/locale_files/en/LC_MESSAGES/django.po:xxx: number of format
specifications in 'msgid' and 'msgstr' does not match
}}}
On the other hand, when it's not escaped, the error becomes:
{{{
Execution of msgfmt failed:
/vagrant/src/locale_files/en/LC_MESSAGES/django.po:xxx: 'msgstr' is not a
valid Python format string, unlike 'msgid'. Reason: In the directive
number 1, the character 'R' is not a valid conversion specifier.
}}}
Also, while trying to find a solution for this, I've found this
suggestion: https://code.djangoproject.com/ticket/24257#comment:2 - which
doesn't work for me at all. The only way I found is to use %(percent)s in
the string, which is awkward and difficult to read by the actual
translators.
--
Ticket URL: <https://code.djangoproject.com/ticket/27221>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Comment:
Not sure about the correct resolution. All I could find was
[http://stackoverflow.com/questions/5651182/how-to-escape-modulo-in-
django-translation-strings-ugettext-lazy a workaround on Stackoverflow].
--
Ticket URL: <https://code.djangoproject.com/ticket/27221#comment:1>
* version: 1.8 => master
* type: Bug => Cleanup/optimization
* stage: Unreviewed => Accepted
Comment:
This is not Django specific and this is a documentation issue. There are
two solutions that I know of:
- Escape the literal `%` by doubling it in the string yourself.
- Add a comment on the line before the translatable string containing
`xgettext:no-python-format`.
--
Ticket URL: <https://code.djangoproject.com/ticket/27221#comment:2>
* component: Internationalization => Documentation
--
Ticket URL: <https://code.djangoproject.com/ticket/27221#comment:3>
* status: new => assigned
* owner: nobody => Henry Dang
--
Ticket URL: <https://code.djangoproject.com/ticket/27221#comment:4>
Comment (by Henry Dang):
[https://github.com/django/django/pull/7533 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/27221#comment:5>
* needs_better_patch: 0 => 1
* has_patch: 0 => 1
Comment:
The explanation in the patch is not correct. The fix must happen in the
original file, not in the .po file.
--
Ticket URL: <https://code.djangoproject.com/ticket/27221#comment:6>
* needs_better_patch: 1 => 0
Comment:
Ah, you're right. I've made the changes, can you check if it's correct?
--
Ticket URL: <https://code.djangoproject.com/ticket/27221#comment:7>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/27221#comment:8>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"b1a9041535db5d03dab7f205669f0ab7a47de854" b1a90415]:
{{{
#!CommitTicketReference repository=""
revision="b1a9041535db5d03dab7f205669f0ab7a47de854"
Fixed #27221 -- Doc'd how to escape a percent symbol in ugettext().
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/27221#comment:9>
Comment (by Tim Graham <timograham@…>):
In [changeset:"047a62b3f7ddb4f0a3bd72dce46a47ee4a847273" 047a62b3]:
{{{
#!CommitTicketReference repository=""
revision="047a62b3f7ddb4f0a3bd72dce46a47ee4a847273"
[1.10.x] Fixed #27221 -- Doc'd how to escape a percent symbol in
ugettext().
Backport of b1a9041535db5d03dab7f205669f0ab7a47de854 from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/27221#comment:10>