Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #387 (closed defect: fixed)

Opened 13 years ago

Last modified 12 years ago

[PATCH] lazy_gettext doesn't work for non-ascii encodings

Reported by: ischenko@… Owned by: anonymous
Priority: normal Milestone: 0.9
Component: TurboGears Version:
Severity: major Keywords:
Cc:

Description (last modified by kevin) (diff)

As it is, lazy_gettext function will not work for non-ascii encodings because it calls str() on unicode string. Moreover, it breaks the contract because docstring for gettext() clearly says that a Unicode string is returned.

Simple fix is to replace str() call with unicode().

Here is the patch, inline:

--- turbogears/i18n/tg_gettext.py (revision 491) +++ turbogears/i18n/tg_gettext.py (working copy) @@ -94,7 +94,7 @@

def str(self):

  • return str(self.eval())

+ return unicode(self.eval())

def mod(self, other):

return self.eval() % other

Change History

comment:1 Changed 13 years ago by anonymous

  • Milestone set to 0.9

comment:2 Changed 13 years ago by ischenko@…

It turns out more tricker than I described. E.g. it doesn't work for text in attributes .

class lazystring need to modified to:

class lazystring(object):
    ...
    def __unicode__(self):
        return unicode(self.eval())

    def __str__(self):
        return str(self.eval())

PLUS, Kid itself need to be patched. pull.py:180:

def to_unicode(value, encoding):
    try:
        return unicode(value) # use __unicode__ if defined
    except TypeError:
        pass
    
    if not isinstance(value, str):
        value = str(value)
    
    return unicode(value, encoding)

comment:3 Changed 13 years ago by dstanek

  • Status changed from new to closed
  • Resolution set to fixed

comment:4 Changed 13 years ago by ischenko@…

  • Status changed from closed to reopened
  • Resolution fixed deleted

It's not really done yet, because the patch to lazystring still need to be applied.

Here it is:

+    def __unicode__(self):
+        return unicode(self.eval())

comment:5 Changed 13 years ago by kevin

  • Status changed from reopened to closed
  • Resolution set to fixed
  • Description modified (diff)

committed in [536]

Note: See TracTickets for help on using tickets.