Ticket #5972: trans_understands_filter_alternate_version.3.diff
File trans_understands_filter_alternate_version.3.diff, 2.2 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 translated = translation.ugettext(self.filter_expression.var.resolve(context)) 45 self.filter_expression.var = Variable('"'+translated+'"') 46 # Filters are applied here 47 return self.filter_expression.resolve(context) 47 48 48 49 class BlockTranslateNode(Node): 49 50 def __init__(self, extra_context, singular, plural=None, countervar=None, … … 171 172 class TranslateParser(TokenParser): 172 173 def top(self): 173 174 value = self.value() 175 176 # Backwards Compatiblity fix: 177 # FilterExpression does not support single-quoted strings, 178 # so we make a cheap localized fix in order to maintain 179 # backwards compatibility with existing uses of ``trans`` 180 # where single quote use is supported. 181 if value[0] == "'": 182 pos = None 183 m = re.match("^'([^']+)'(\|.*$)",value) 184 if m: 185 value = '"%s"%s' % (m.group(1),m.group(2)) 186 elif value[-1] == "'": 187 value = '"%s"' % value[1:-1] 188 174 189 if self.more(): 175 190 if self.tag() == 'noop': 176 191 noop = True … … 180 195 noop = False 181 196 return (value, noop) 182 197 value, noop = TranslateParser(token.contents).top() 183 return TranslateNode( value, noop)198 return TranslateNode(parser.compile_filter(value), noop) 184 199 185 200 def do_block_translate(parser, token): 186 201 """