Code

Ticket #15535: ticket15535_r15708.diff

File ticket15535_r15708.diff, 1.6 KB (added by melinath, 3 years ago)
Line 
1diff --git a/django/templatetags/i18n.py b/django/templatetags/i18n.py
2index 0cb7e6a..e6b3b61 100644
3--- a/django/templatetags/i18n.py
4+++ b/django/templatetags/i18n.py
5@@ -113,7 +113,7 @@ class BlockTranslateNode(Node):
6             result = translation.ugettext(singular)
7         # Escape all isolated '%' before substituting in the context.
8         result = re.sub(u'%(?!\()', u'%%', result)
9-        data = dict([(v, _render_value_in_context(context[v], context)) for v in vars])
10+        data = dict([(v, _render_value_in_context(context.get(v, ''), context)) for v in vars])
11         context.pop()
12         return result % data
13 
14diff --git a/tests/regressiontests/templates/tests.py b/tests/regressiontests/templates/tests.py
15index 54c97ce..fb47b27 100644
16--- a/tests/regressiontests/templates/tests.py
17+++ b/tests/regressiontests/templates/tests.py
18@@ -1245,6 +1245,9 @@ class Templates(unittest.TestCase):
19             'i18n32': ('{% load i18n %}{{ "hu"|language_name }} {{ "hu"|language_name_local }} {{ "hu"|language_bidi }}', {}, u'Hungarian Magyar False'),
20             'i18n33': ('{% load i18n %}{{ langcode|language_name }} {{ langcode|language_name_local }} {{ langcode|language_bidi }}', {'langcode': 'nl'}, u'Dutch Nederlands False'),
21 
22+            # blocktrans handling of variables which are not in the context.
23+            'i18n34': ('{% load i18n %}{% blocktrans %}{{ missing }}{% endblocktrans %}', {}, u''),
24+
25             ### HANDLING OF TEMPLATE_STRING_IF_INVALID ###################################
26 
27             'invalidstr01': ('{{ var|default:"Foo" }}', {}, ('Foo','INVALID')),