Ticket #12104: blocktrans_display_error.diff
File blocktrans_display_error.diff, 1.5 KB (added by , 15 years ago) |
---|
-
django/templatetags/i18n.py
1 1 import re 2 2 3 from django.template import Node, Variable, Variable Node, _render_value_in_context3 from django.template import Node, Variable, VariableDoesNotExist, VariableNode, _render_value_in_context 4 4 from django.template import TemplateSyntaxError, TokenParser, Library 5 5 from django.template import TOKEN_TEXT, TOKEN_VAR 6 6 from django.utils import translation … … 82 82 result = translation.ugettext(singular) 83 83 # Escape all isolated '%' before substituting in the context. 84 84 result = re.sub(u'%(?!\()', u'%%', result) 85 data = dict([(v, _render_value_in_context(context[v], context)) for v in vars]) 85 data = [] 86 for v in vars: 87 if not context.has_key(v): 88 try: 89 Variable(v).resolve(context) 90 except VariableDoesNotExist: 91 # This is what should happen 92 pass 93 else: 94 raise TemplateSyntaxError, ("'blocktrans' doesn't allow " 95 "variable.attribute lookup. " 96 "Use {% blocktrans variable.attr as foo .. %} instead") 97 data.append((v, _render_value_in_context(context[v], context))) 98 data = dict(data) 86 99 context.pop() 87 100 return result % data 88 101