[Django] #27221: ugettext does not escape percent symbol

19 views
Skip to first unread message

Django

unread,
Sep 14, 2016, 6:35:54 AM9/14/16
to django-...@googlegroups.com
#27221: ugettext does not escape percent symbol
--------------------------------------+------------------------------
Reporter: pgcd | Owner: nobody
Type: Bug | Status: new
Component: Internationalization | Version: 1.8
Severity: Normal | Keywords: ugettext percent
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------
While {% trans %} and {% blocktrans %} correctly escape '%' with '%%' in
templates, using ugettext or ugettext_lazy does not; this results in
errors with compilemessages.

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.

Django

unread,
Sep 14, 2016, 9:05:44 PM9/14/16
to django-...@googlegroups.com
#27221: ugettext does not escape percent symbol
-------------------------------------+-------------------------------------

Reporter: pgcd | Owner: nobody
Type: Bug | Status: new
Component: | Version: 1.8
Internationalization |
Severity: Normal | Resolution:

Keywords: ugettext percent | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* 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>

Django

unread,
Sep 15, 2016, 4:08:58 AM9/15/16
to django-...@googlegroups.com
#27221: ugettext does not escape percent symbol
--------------------------------------+------------------------------------
Reporter: pgcd | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Internationalization | Version: master
Severity: Normal | Resolution:
Keywords: ugettext percent | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by claudep):

* 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>

Django

unread,
Sep 15, 2016, 7:41:05 AM9/15/16
to django-...@googlegroups.com
#27221: Document how to escape a percent symbol in ugettext
--------------------------------------+------------------------------------
Reporter: pgcd | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Documentation | Version: master

Severity: Normal | Resolution:
Keywords: ugettext percent | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by timgraham):

* component: Internationalization => Documentation


--
Ticket URL: <https://code.djangoproject.com/ticket/27221#comment:3>

Django

unread,
Nov 4, 2016, 8:03:29 PM11/4/16
to django-...@googlegroups.com
#27221: Document how to escape a percent symbol in ugettext
-------------------------------------+-------------------------------------
Reporter: pgcd | Owner: Henry
Type: | Dang
Cleanup/optimization | Status: assigned

Component: Documentation | Version: master
Severity: Normal | Resolution:
Keywords: ugettext percent | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Henry Dang):

* status: new => assigned
* owner: nobody => Henry Dang


--
Ticket URL: <https://code.djangoproject.com/ticket/27221#comment:4>

Django

unread,
Nov 9, 2016, 10:31:00 PM11/9/16
to django-...@googlegroups.com
#27221: Document how to escape a percent symbol in ugettext
-------------------------------------+-------------------------------------
Reporter: pgcd | Owner: Henry
Type: | Dang
Cleanup/optimization | Status: assigned
Component: Documentation | Version: master
Severity: Normal | Resolution:
Keywords: ugettext percent | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Henry Dang):

[https://github.com/django/django/pull/7533 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/27221#comment:5>

Django

unread,
Nov 10, 2016, 4:28:16 AM11/10/16
to django-...@googlegroups.com
#27221: Document how to escape a percent symbol in ugettext
-------------------------------------+-------------------------------------
Reporter: pgcd | Owner: Henry
Type: | Dang
Cleanup/optimization | Status: assigned
Component: Documentation | Version: master
Severity: Normal | Resolution:
Keywords: ugettext percent | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Claude Paroz):

* 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>

Django

unread,
Nov 12, 2016, 1:25:32 PM11/12/16
to django-...@googlegroups.com
#27221: Document how to escape a percent symbol in ugettext
-------------------------------------+-------------------------------------
Reporter: pgcd | Owner: Henry
Type: | Dang
Cleanup/optimization | Status: assigned
Component: Documentation | Version: master
Severity: Normal | Resolution:
Keywords: ugettext percent | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Henry Dang):

* 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>

Django

unread,
Nov 22, 2016, 11:42:45 AM11/22/16
to django-...@googlegroups.com
#27221: Document how to escape a percent symbol in ugettext
-------------------------------------+-------------------------------------
Reporter: pgcd | Owner: Henry
Type: | Dang
Cleanup/optimization | Status: assigned
Component: Documentation | Version: master
Severity: Normal | Resolution:
Keywords: ugettext percent | Triage Stage: Ready for
| checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/27221#comment:8>

Django

unread,
Nov 22, 2016, 1:58:12 PM11/22/16
to django-...@googlegroups.com
#27221: Document how to escape a percent symbol in ugettext
-------------------------------------+-------------------------------------
Reporter: pgcd | Owner: Henry
Type: | Dang
Cleanup/optimization | Status: closed
Component: Documentation | Version: master
Severity: Normal | Resolution: fixed

Keywords: ugettext percent | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* 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>

Django

unread,
Nov 22, 2016, 1:58:52 PM11/22/16
to django-...@googlegroups.com
#27221: Document how to escape a percent symbol in ugettext
-------------------------------------+-------------------------------------
Reporter: pgcd | Owner: Henry
Type: | Dang
Cleanup/optimization | Status: closed
Component: Documentation | Version: master
Severity: Normal | Resolution: fixed
Keywords: ugettext percent | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Reply all
Reply to author
Forward
0 new messages