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.
This commit is contained in:
parent
8847a0c601
commit
02add43568
|
@ -150,8 +150,14 @@ class BlockTranslateNode(Node):
|
||||||
else:
|
else:
|
||||||
result = translation.ugettext(singular)
|
result = translation.ugettext(singular)
|
||||||
default_value = settings.TEMPLATE_STRING_IF_INVALID
|
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)
|
data = dict((v, render_value(v)) for v in vars)
|
||||||
context.pop()
|
context.pop()
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -1507,6 +1507,8 @@ class TemplateTests(TestCase):
|
||||||
'invalidstr04_2': ('{% if var|default:"Foo" %}Yes{% else %}No{% endif %}', {}, 'Yes'),
|
'invalidstr04_2': ('{% if var|default:"Foo" %}Yes{% else %}No{% endif %}', {}, 'Yes'),
|
||||||
'invalidstr05': ('{{ var }}', {}, ('', ('INVALID %s', 'var'))),
|
'invalidstr05': ('{{ var }}', {}, ('', ('INVALID %s', 'var'))),
|
||||||
'invalidstr06': ('{{ var.prop }}', {'var': {}}, ('', ('INVALID %s', 'var.prop'))),
|
'invalidstr06': ('{{ var.prop }}', {'var': {}}, ('', ('INVALID %s', 'var.prop'))),
|
||||||
|
'invalidstr07': ('{% load i18n %}{% blocktrans %}{{ var }}{% endblocktrans %}',
|
||||||
|
{}, ('', ('INVALID %s', 'var'))),
|
||||||
|
|
||||||
### MULTILINE #############################################################
|
### MULTILINE #############################################################
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue