Ticket #5885: template_simple_tag_i18n_fix.diff

File template_simple_tag_i18n_fix.diff, 968 bytes (added by Dmitri Fedortchenko <zeraien@…>, 17 years ago)

The patch to fix simple_tag and i18n _() syntax. It also includes a workaround for UnicodeDecodeErrors that occur sometimes in VariableNotFound tracebacks (as a bonus)

  • django/template/__init__.py

     
    127127        self.params = params
    128128
    129129    def __str__(self):
    130         return self.msg % self.params
    131 
     130        try:
     131            return self.msg % self.params
     132        except UnicodeDecodeError:
     133            return self.msg % (self.params[0],str(self.params[1]))
     134       
    132135class InvalidTemplateLibrary(Exception):
    133136    pass
    134137
     
    692695            if var[0] in "\"'" and var[0] == var[-1]:
    693696                self.literal = var[1:-1]
    694697           
     698            elif var[0:2] == "_(" and var[-1] == ")":
     699                self.literal = _(re.match("\_\(['\"]([^'\"]+)['\"]\)",var).group(1))
     700
    695701            else:
    696702                # Otherwise we'll set self.lookups so that resolve() knows we're
    697703                # dealing with a bonafide variable
Back to Top