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