Ticket #12104: blocktrans_variable_attribute_works.diff

File blocktrans_variable_attribute_works.diff, 1.1 KB (added by philipn, 15 years ago)

normal-like variable reference in blocktrans

  • django/templatetags/i18n.py

     
    11import re
    22
    3 from django.template import Node, Variable, VariableNode, _render_value_in_context
     3from django.template import Node, Variable, VariableDoesNotExist, VariableNode, _render_value_in_context
    44from django.template import TemplateSyntaxError, TokenParser, Library
    55from django.template import TOKEN_TEXT, TOKEN_VAR
    66from django.utils import translation
     
    8282            result = translation.ugettext(singular)
    8383        # Escape all isolated '%' before substituting in the context.
    8484        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            try:
     88                data.append((v, Variable(v).resolve(context)))
     89            except VariableDoesNotExist:
     90                data.append((v, ''))
     91        data = dict(data)
    8692        context.pop()
    8793        return result % data
    8894
Back to Top