[Python-Dev] Re: [I18n-sig] Changes to gettext.py for Python 2.3

Barry Warsaw barry@python.org
11 Apr 2003 16:37:56 -0400


On Fri, 2003-04-11 at 15:54, "Martin v. L÷wis" wrote:

> To avoid breakage, you could define ugettext as
> 
>    def ugettext(self, message):
>        if isinstance(message, unicode):
>           tmsg = self._catalog.get(message.encode(self._charset))
>           if tmsg is None:
>              return message
>        else:
>           tmsg = self._catalog.get(message, message)
>        return unicode(tmsg, self._charset)

I suppose we could cache the conversion to make the next lookup more
efficient.  Alternatively, if we always convert internally to Unicode we
could encode on .gettext().  Then we could just pick One Way and do away
with the coerce flag.

-Barry