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

Martin v. Loewis martin@loewis.home.cs.tu-berlin.de
Tue, 5 Sep 2000 08:44:44 +0200

> Instead of:
>     _ = locale.translator(DOMAIN)
> could we have:
>     _, _u = locale.translator(DOMAIN)

Currently, you would write

_ = locale.translator(DOMAIN).gettext

for the first one, and

cat = locale.translator(DOMAIN)
_, _u = cat.gettext, cat.ugettext

for the second one. However, I doubt many users would need both
methods. They either trust that their output channels are unicode-safe
or they don't. I'd even emagine cases where they do

def _(msg):
  return cat.ugettext(msg).encode("utf-8")

so they get UTF-8 even if the catalog uses some different encoding;
that may be useful when they write to log files. Of course, in that
case, they should really write

logfile = codecs.open("logfilename","w",encoding="utf-8")

to get a unicode-safe output channel.

> Or maybe:
>     _, _e = locale.translator(DOMAIN)

That would be

_e = cat.charset()

> But I'm not sure I like any of these things.  Maybe nicer would be
> that `_` is the class instance itself, with a __call__ method for
> implementing _(TEXT). One could then use _.charset or such to get
> then `msgstr' encoding

Maybe it's not nicer. __call__ is typically used to hide the fact that
something is an instance object, so users can treat it as if it was a
function. Now, if you say that users need to be aware that it is
indeed an instance (since it exposes additional methods), they also
need to understand how __call__ works for these instances. That is
more difficult to grasp than telling them about instances, their
methods, and the notion of bound methods.