Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #15535 -- Stopped the blocktrans template tag from raising a Ke…

…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...
commit 93cd8442fc6a1b4838ccc6609b6771d697958c05 1 parent cff4ee5
Jannis Leidel authored March 02, 2011
2  django/templatetags/i18n.py
@@ -113,7 +113,7 @@ def render(self, context):
113 113
             result = translation.ugettext(singular)
114 114
         # Escape all isolated '%' before substituting in the context.
115 115
         result = re.sub(u'%(?!\()', u'%%', result)
116  
-        data = dict([(v, _render_value_in_context(context[v], context)) for v in vars])
  116
+        data = dict([(v, _render_value_in_context(context.get(v, ''), context)) for v in vars])
117 117
         context.pop()
118 118
         return result % data
119 119
 
3  tests/regressiontests/templates/tests.py
@@ -1245,6 +1245,9 @@ def get_template_tests(self):
1245 1245
             'i18n32': ('{% load i18n %}{{ "hu"|language_name }} {{ "hu"|language_name_local }} {{ "hu"|language_bidi }}', {}, u'Hungarian Magyar False'),
1246 1246
             'i18n33': ('{% load i18n %}{{ langcode|language_name }} {{ langcode|language_name_local }} {{ langcode|language_bidi }}', {'langcode': 'nl'}, u'Dutch Nederlands False'),
1247 1247
 
  1248
+            # blocktrans handling of variables which are not in the context.
  1249
+            'i18n34': ('{% load i18n %}{% blocktrans %}{{ missing }}{% endblocktrans %}', {}, u''),
  1250
+
1248 1251
             ### HANDLING OF TEMPLATE_STRING_IF_INVALID ###################################
1249 1252
 
1250 1253
             'invalidstr01': ('{{ var|default:"Foo" }}', {}, ('Foo','INVALID')),

0 notes on commit 93cd844

Please sign in to comment.
Something went wrong with that request. Please try again.