[I18n-sig] Re: gettext in the standard library

Martin von Loewis loewis@informatik.hu-berlin.de
Mon, 4 Sep 2000 23:00:13 +0200 (MET DST)

> > > def _(s):
> > >     return unicode(s, "utf-8")

> That was just an example of how you could add the decoding
> functionality to the _ function.
> You would of course also add a gettext.gettext call
> somewhere in there which translates the string first
> (possibly recoding it to some other encoding for the
> table lookup first).

So it would be

def _(s):

then??? There is no reason to do such a thing. First, you take a good
UTF-8 string, transform it into a Unicode object; then gettext must
encode the Unicode object into some byte string (possibly using
UTF-8), as there msgids are stored as bytes on the disk (i.e. using
some encoding).

If you put UTF-8 in your source as msgid, you can *directly* invoking
gettext, without needing to create a temporary Unicode object first.

Even if there is some pragma utf-8 some day, it would be still more
straight-forward to write

  _("<utf-8 bytes>")


  _(u"<utf-8 bytes>")

as gettext would need some clue what byte encoding it needs to use,
whereas the byte encoding is obvious in the first case.