Ticket #5972: trans_understands_filter_alternate_version.diff
File trans_understands_filter_alternate_version.diff, 2.0 KB (added by , 17 years ago) |
---|
-
django/templatetags/i18n.py
34 34 return '' 35 35 36 36 class TranslateNode(Node): 37 def __init__(self, value, noop):38 self. value = Variable(value)37 def __init__(self, filter_expression, noop): 38 self.filter_expression = filter_expression 39 39 self.noop = noop 40 40 41 41 def render(self, context): 42 value = self.value.resolve(context) 43 if self.noop: 44 return value 45 else: 46 return translation.ugettext(value) 42 43 if not self.noop: 44 filter_expression = self.filter_expression.var.resolve(context) 45 translated = translation.ugettext(filter_expression) 46 self.filter_expression.var = Variable('"'+translated+'"') 47 # Filters are applied here, since this is a FilterExpression 48 return self.filter_expression.resolve(context) 47 49 48 50 class BlockTranslateNode(Node): 49 51 def __init__(self, extra_context, singular, plural=None, countervar=None, … … 171 173 class TranslateParser(TokenParser): 172 174 def top(self): 173 175 value = self.value() 176 177 if value[0] == "'" and value[-1] == "'": 178 # FilterExpression does not support single-quoted strings, so we "fix" it, 179 # in order to maintain backwards compatibility with existing 180 # uses of ``trans`` where single quote use is supported. 181 value = value.replace("'",'"') 182 174 183 if self.more(): 175 184 if self.tag() == 'noop': 176 185 noop = True … … 180 189 noop = False 181 190 return (value, noop) 182 191 value, noop = TranslateParser(token.contents).top() 183 return TranslateNode( value, noop)192 return TranslateNode(parser.compile_filter(value), noop) 184 193 185 194 def do_block_translate(parser, token): 186 195 """