Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #21417 -- Expanded TEMPLATE_STRING_IF_INVALID in blocktrans

Thanks keturn for the reporti, Chris Medrela for details and
Tim Graham for the review.
Refs #19915.
  • Loading branch information...
commit 02add43568b694ef25afeae474b5b1da883826c6 1 parent 8847a0c
@claudep claudep authored
Showing with 10 additions and 2 deletions.
  1. +8 −2 django/templatetags/i18n.py
  2. +2 −0  tests/template_tests/tests.py
View
10 django/templatetags/i18n.py
@@ -150,8 +150,14 @@ def render(self, context, nested=False):
else:
result = translation.ugettext(singular)
default_value = settings.TEMPLATE_STRING_IF_INVALID
- render_value = lambda v: render_value_in_context(
- context.get(v, default_value), context)
+
+ def render_value(key):
+ if key in context:
+ val = context[key]
+ else:
+ val = default_value % key if '%s' in default_value else default_value
+ return render_value_in_context(val, context)
+
data = dict((v, render_value(v)) for v in vars)
context.pop()
try:
View
2  tests/template_tests/tests.py
@@ -1507,6 +1507,8 @@ def get_template_tests(self):
'invalidstr04_2': ('{% if var|default:"Foo" %}Yes{% else %}No{% endif %}', {}, 'Yes'),
'invalidstr05': ('{{ var }}', {}, ('', ('INVALID %s', 'var'))),
'invalidstr06': ('{{ var.prop }}', {'var': {}}, ('', ('INVALID %s', 'var.prop'))),
+ 'invalidstr07': ('{% load i18n %}{% blocktrans %}{{ var }}{% endblocktrans %}',
+ {}, ('', ('INVALID %s', 'var'))),
### MULTILINE #############################################################
Please sign in to comment.
Something went wrong with that request. Please try again.