Skip to content

Commit

Permalink
Fixed #15535 -- Stopped the blocktrans template tag from raising a Ke…
Browse files Browse the repository at this point in the history
…yError 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
  • Loading branch information
jezdez committed Mar 2, 2011
1 parent cff4ee5 commit 93cd844
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion django/templatetags/i18n.py
Expand Up @@ -113,7 +113,7 @@ def render(self, context):
result = translation.ugettext(singular)
# Escape all isolated '%' before substituting in the context.
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()
return result % data

Expand Down
3 changes: 3 additions & 0 deletions tests/regressiontests/templates/tests.py
Expand Up @@ -1245,6 +1245,9 @@ def get_template_tests(self):
'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'),

# blocktrans handling of variables which are not in the context.
'i18n34': ('{% load i18n %}{% blocktrans %}{{ missing }}{% endblocktrans %}', {}, u''),

### HANDLING OF TEMPLATE_STRING_IF_INVALID ###################################

'invalidstr01': ('{{ var|default:"Foo" }}', {}, ('Foo','INVALID')),
Expand Down

0 comments on commit 93cd844

Please sign in to comment.