Fixed #15535 -- Stopped the blocktrans template tag from raising a KeyError if an included variable can't be found in the context. Thanks, melinath.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@15709 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
cff4ee5cba
commit
93cd8442fc
|
@ -113,7 +113,7 @@ class BlockTranslateNode(Node):
|
||||||
result = translation.ugettext(singular)
|
result = translation.ugettext(singular)
|
||||||
# Escape all isolated '%' before substituting in the context.
|
# Escape all isolated '%' before substituting in the context.
|
||||||
result = re.sub(u'%(?!\()', u'%%', result)
|
result = re.sub(u'%(?!\()', u'%%', result)
|
||||||
data = dict([(v, _render_value_in_context(context[v], context)) for v in vars])
|
data = dict([(v, _render_value_in_context(context.get(v, ''), context)) for v in vars])
|
||||||
context.pop()
|
context.pop()
|
||||||
return result % data
|
return result % data
|
||||||
|
|
||||||
|
|
|
@ -1245,6 +1245,9 @@ class Templates(unittest.TestCase):
|
||||||
'i18n32': ('{% load i18n %}{{ "hu"|language_name }} {{ "hu"|language_name_local }} {{ "hu"|language_bidi }}', {}, u'Hungarian Magyar False'),
|
'i18n32': ('{% load i18n %}{{ "hu"|language_name }} {{ "hu"|language_name_local }} {{ "hu"|language_bidi }}', {}, u'Hungarian Magyar False'),
|
||||||
'i18n33': ('{% load i18n %}{{ langcode|language_name }} {{ langcode|language_name_local }} {{ langcode|language_bidi }}', {'langcode': 'nl'}, u'Dutch Nederlands False'),
|
'i18n33': ('{% load i18n %}{{ langcode|language_name }} {{ langcode|language_name_local }} {{ langcode|language_bidi }}', {'langcode': 'nl'}, u'Dutch Nederlands False'),
|
||||||
|
|
||||||
|
# blocktrans handling of variables which are not in the context.
|
||||||
|
'i18n34': ('{% load i18n %}{% blocktrans %}{{ missing }}{% endblocktrans %}', {}, u''),
|
||||||
|
|
||||||
### HANDLING OF TEMPLATE_STRING_IF_INVALID ###################################
|
### HANDLING OF TEMPLATE_STRING_IF_INVALID ###################################
|
||||||
|
|
||||||
'invalidstr01': ('{{ var|default:"Foo" }}', {}, ('Foo','INVALID')),
|
'invalidstr01': ('{{ var|default:"Foo" }}', {}, ('Foo','INVALID')),
|
||||||
|
|
Loading…
Reference in New Issue