[1.2.X] Fixed #15535 -- Stopped the blocktrans template tag from raising a KeyError if an included variable can't be found in the context. Thanks, melinath.
Backport from trunk (r15709). git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@15710 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
7207481aa8
commit
b34a08e070
|
@ -83,7 +83,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
|
||||||
|
|
||||||
|
|
|
@ -1138,6 +1138,9 @@ class Templates(unittest.TestCase):
|
||||||
# translation of singular form in russian (#14126)
|
# translation of singular form in russian (#14126)
|
||||||
'i18n27': ('{% load i18n %}{% blocktrans count number as counter %}1 result{% plural %}{{ counter }} results{% endblocktrans %}', {'number': 1, 'LANGUAGE_CODE': 'ru'}, u'1 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442'),
|
'i18n27': ('{% load i18n %}{% blocktrans count number as counter %}1 result{% plural %}{{ counter }} results{% endblocktrans %}', {'number': 1, 'LANGUAGE_CODE': 'ru'}, u'1 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442'),
|
||||||
|
|
||||||
|
# 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