Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #19915 - Made blocktrans tag honor TEMPLATE_STRING_IF_INVALID.

Thanks Natalia Bidart for the report and Matías Bordese for the fix.
  • Loading branch information...
commit 804366327d728d23a9f7a25ff77a6eed3c9f9323 1 parent 2047865
Matias Bordese authored February 27, 2013 ramiro committed March 03, 2013
7  django/templatetags/i18n.py
... ...
@@ -1,6 +1,7 @@
1 1
 from __future__ import unicode_literals
2 2
 import re
3 3
 
  4
+from django.conf import settings
4 5
 from django.template import (Node, Variable, TemplateSyntaxError,
5 6
     TokenParser, Library, TOKEN_TEXT, TOKEN_VAR)
6 7
 from django.template.base import render_value_in_context
@@ -17,7 +18,6 @@ def __init__(self, variable):
17 18
         self.variable = variable
18 19
 
19 20
     def render(self, context):
20  
-        from django.conf import settings
21 21
         context[self.variable] = [(k, translation.ugettext(v)) for k, v in settings.LANGUAGES]
22 22
         return ''
23 23
 
@@ -143,7 +143,10 @@ def render(self, context, nested=False):
143 143
                 result = translation.pgettext(message_context, singular)
144 144
             else:
145 145
                 result = translation.ugettext(singular)
146  
-        data = dict([(v, render_value_in_context(context.get(v, ''), context)) for v in vars])
  146
+        default_value = settings.TEMPLATE_STRING_IF_INVALID
  147
+        render_value = lambda v: render_value_in_context(
  148
+            context.get(v, default_value), context)
  149
+        data = dict([(v, render_value(v)) for v in vars])
147 150
         context.pop()
148 151
         try:
149 152
             result = result % data
5  tests/template_tests/tests.py
@@ -1392,7 +1392,10 @@ def get_template_tests(self):
1392 1392
             'i18n33': ('{% load i18n %}{{ langcode|language_name }} {{ langcode|language_name_local }} {{ langcode|language_bidi }}', {'langcode': 'nl'}, 'Dutch Nederlands False'),
1393 1393
 
1394 1394
             # blocktrans handling of variables which are not in the context.
1395  
-            'i18n34': ('{% load i18n %}{% blocktrans %}{{ missing }}{% endblocktrans %}', {}, ''),
  1395
+            # this should work as if blocktrans was not there (bug #19915)
  1396
+            'i18n34': ('{% load i18n %}{% blocktrans %}{{ missing }}{% endblocktrans %}', {}, ('', 'INVALID')),
  1397
+            'i18n34_2': ("{% load i18n %}{% blocktrans with a='α' %}{{ missing }}{% endblocktrans %}", {}, ('', 'INVALID')),
  1398
+            'i18n34_3': ('{% load i18n %}{% blocktrans with a=anton %}{{ missing }}{% endblocktrans %}', {'anton': 'α'}, ('', 'INVALID')),
1396 1399
 
1397 1400
             # trans tag with as var
1398 1401
             'i18n35': ('{% load i18n %}{% trans "Page not found" as page_not_found %}{{ page_not_found }}', {'LANGUAGE_CODE': 'de'}, "Seite nicht gefunden"),

0 notes on commit 8043663

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