Django

Code

Ticket #4982 (closed: fixed)

Opened 1 year ago

Last modified 1 year ago

{% blocktrans %} does not escape % in text

Reported by: nostgard <nostgard@yahoo.com> Assigned to: permon
Milestone: Component: Internationalization
Version: SVN Keywords: sprintsept14
Cc: permonik@mesias.brnonet.cz Triage Stage: Ready for checkin
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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.'

Attachments

patch.diff (1.0 kB) - added by permonik@mesias.brnonet.cz on 09/12/07 09:23:32.

Change History

07/26/07 21:53:45 changed by SmileyChris

  • needs_better_patch changed.
  • stage changed from Unreviewed to Accepted.
  • needs_tests changed.
  • needs_docs changed.

07/30/07 21:54:34 changed by John Shaffer <jshaffer2112@gmail.com>

  • component changed from Translations to Internationalization.

09/12/07 09:23:32 changed by permonik@mesias.brnonet.cz

  • attachment patch.diff added.

09/12/07 09:26:06 changed by permonik@mesias.brnonet.cz

  • has_patch set to 1.

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.

09/12/07 09:28:41 changed by anonymous

  • cc set to permonik@mesias.brnonet.cz.

09/14/07 09:58:24 changed by permon

  • owner changed from nobody to permon.
  • status changed from new to assigned.

09/14/07 14:45:55 changed by permon

  • keywords set to sprintsept14.

09/14/07 15:37:13 changed by permon

  • stage changed from Accepted to Ready for checkin.

10/20/07 07:29:57 changed by mtredinnick

  • status changed from assigned to closed.
  • resolution set to fixed.

(In [6565]) Fixed #4982 -- Fixed handling of '%' symbols in 'blocktrans' blocks. Thanks, permonik@mesias.brnonet.cz.


Add/Change #4982 ({% blocktrans %} does not escape % in text)




Change Properties
Action