#4982 closed Uncategorized (fixed)
{% blocktrans %} does not escape % in text
Reported by: | Owned by: | Tomáš Kopeček | |
---|---|---|---|
Component: | Internationalization | Version: | dev |
Severity: | Normal | Keywords: | sprintsept14 |
Cc: | permonik@… | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
Description ¶
When you try to use a blocktrans with a percent sign in it. When the percent is escaped (%%) it renders fine. It does not occur when using a trans tag.
>>> from django.template import Context, Template >>> t1 = Template('{% load i18n %}{% blocktrans %}We lost 5% today.{% endblocktrans %}') >>> t2 = Template('{% load i18n %}{% blocktrans %}We lost 5%% today.{% endblocktrans %}') >>> t3 = Template('{% load i18n %}{% trans "We lost 5% today." %}') >>> c = Context() >>> t1.render(c) Traceback (most recent call last): File "<console>", line 1, in <module> File "D:\Python\lib\site-packages\django\template\__init__.py", line 181, in render return self.nodelist.render(context) File "D:\Python\lib\site-packages\django\template\__init__.py", line 736, in render bits.append(self.render_node(node, context)) File "D:\Python\lib\site-packages\django\template\__init__.py", line 764, in render_node raise wrapped TemplateSyntaxError: Caught an exception while rendering: unsupported format character 't' (0x74) at index 11 Original Traceback (most recent call last): File "D:\Python\lib\site-packages\django\template\__init__.py", line 754, in render_node result = node.render(context) File "D:\Python\lib\site-packages\django\templatetags\i18n.py", line 73, in render result = translation.ugettext(singular) % context ValueError: unsupported format character 't' (0x74) at index 11 >>> t2.render(c) u'We lost 5% today.' >>> t3.render(c) u'We lost 5% today.'
Change History (14)
comment:1 by , 18 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 18 years ago
Component: | Translations → Internationalization |
---|
by , 17 years ago
Attachment: | patch.diff added |
---|
comment:3 by , 17 years ago
Has patch: | set |
---|
comment:4 by , 17 years ago
Cc: | added |
---|
comment:5 by , 17 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:6 by , 17 years ago
Keywords: | sprintsept14 added |
---|
comment:7 by , 17 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
comment:8 by , 17 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
follow-up: 10 comment:9 by , 15 years ago
Patch needs improvement: | set |
---|---|
Resolution: | fixed |
Status: | closed → reopened |
On Django 1.2.1:
When using single % inside blocktrans, "django-admin.py makemessages" won't work and as %% inside the template, the output still is %%, due to the patch above. When removing the patch line, everything works ok.
comment:10 by , 15 years ago
Cc: | added; removed |
---|
Replying to nasmon:
On Django 1.2.1:
When using single % inside blocktrans, "django-admin.py makemessages" won't work and as %% inside the template, the output still is %%, due to the patch above. When removing the patch line, everything works ok.
Can you attach some working example? For me is everything working ok with 1.2.1 tree.
comment:11 by , 14 years ago
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
Triage Stage: | Ready for checkin → Accepted |
I can't repeat this problem, either. Closing for now. Please open a new ticket if there's a specific failure case, because we're not going to revert this change -- at the time it was applied, it fixed a concrete problem -- so it's a matter of tweaking the current code to fix things if there's a concrete failure case.
Reclosing as "fixed" to restore previous state.
comment:12 by , 14 years ago
Easy pickings: | unset |
---|---|
Severity: | → Normal |
Type: | → Uncategorized |
UI/UX: | unset |
FYI, I've reopened the issue with patch/test case in #16721.
Blocktrans creates template string with %()s, but doesn't correctly escape % signs in original text. Patch attached, make-messages.py works as intended - so no other harm in i18n machinery.