[Zope3-dev] i18n, unicode, and the underline

Barry Warsaw barry@python.org
11 Apr 2003 15:36:44 -0400


On Fri, 2003-04-11 at 11:44, Barry Warsaw wrote:

> Ok, given this, I'm fine with allowing human readable messages in Zope's
> Python code be marked with _('str') when 'str' is us-ascii.  If it's
> anything else, you must use _(u'ustr').  If you screw up you'll get an
> exception at the earliest possible point -- a good thing.

BTW, this Just Works already!

Here's the twisty maze...

_ is usually bound to a MessageIDFactory instance.  When this instance
is called, e.g. _('str') it creates a MessageID object, and /that/ is a
subclass of unicode.  The __new__() for MessageID is essentially
equivalent to calling unicode(str) with no codec, which is exactly what
Guido suggested.

Neat!

-Barry