@register.tag('trans')
def do_translate(parser, token):
 class TranslateParser(TokenParser, ):
  def top(self):
   value = self.value()
   if (value[0] == "'"):
    m = re.match("^'([^']+)'(\\|.*$)", value)
    if m:
     value = ('"%s"%s' % (m.group(1).replace('"', '\\"'), m.group(2)))
    elif (value[(-1)] == "'"):
     value = ('"%s"' % value[1:(-1)].replace('"', '\\"'))
   noop = False
   asvar = None
   message_context = None
   while self.more():
    tag = self.tag()
    if (tag == 'noop'):
     noop = True
    elif (tag == 'context'):
     message_context = parser.compile_filter(self.value())
    elif (tag == 'as'):
     asvar = self.tag()
    else:
     raise TemplateSyntaxError('Only options for \'trans\' are \'noop\', \'context "xxx"\', and \'as VAR\'.')
   return (value, noop, asvar, message_context)
 (value, noop, asvar, message_context) = TranslateParser(token.contents).top()
 return TranslateNode(parser.compile_filter(value), noop, asvar, message_context)

@ register . tag ( 'trans' ) def do_translate ( parser , token ) : class TranslateParser ( TokenParser , ) : def top ( self ) : value = self . value ( ) if ( value [ 0 ] == "'" ) : m = re . match ( "^'([^']+)'(\\|.*$)" , value ) if m : value = ( '"%s"%s' % ( m . group ( 1 ) . replace ( '"' , '\\"' ) , m . group ( 2 ) ) ) elif ( value [ ( - 1 ) ] == "'" ) : value = ( '"%s"' % value [ 1 : ( - 1 ) ] . replace ( '"' , '\\"' ) ) noop = False asvar = None message_context = None while self . more ( ) : tag = self . tag ( ) if ( tag == 'noop' ) : noop = True elif ( tag == 'context' ) : message_context = parser . compile_filter ( self . value ( ) ) elif ( tag == 'as' ) : asvar = self . tag ( ) else : raise TemplateSyntaxError ( 'Only options for \'trans\' are \'noop\', \'context "xxx"\', and \'as VAR\'.' ) return ( value , noop , asvar , message_context ) ( value , noop , asvar , message_context ) = TranslateParser ( token . contents ) . top ( ) return TranslateNode ( parser . compile_filter ( value ) , noop , asvar , message_context )
translates message using the given translation_function name -- which will be either gettext or ugettext .