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

Barry Warsaw barry@python.org
10 Apr 2003 17:58:48 -0400


On Thu, 2003-04-10 at 17:05, Gary Poster wrote:
> (This is Casey Duncan's idea btw :-)
> 
> Having to write
> 
>      _(u"Name")
> 
> when I mean
> 
>      "Name"
> 
> for user presentation strings everywhere does not look good at all, and 
> has a significant-barrier-of-entry-to-newbies feel to it.  I understand 
> the rationale for each of the marks, but could we at least make the _ 
> function automatically convert strings to unicode?
> 
> Ever-so-slightly better:
> 
>      _("Name")

As long as ever character in the normal string is a 7-bit ascii
character, sure you're fine.  As soon as you put some 8-bit data in
there you'll get a UnicodeError upon conversion unless you specify the
codec you want to use to decode it to Unicode.  Since there's no
opportunity to specify the codec in the underscore function call, you
will lose.

Summary: for 7-bit us-ascii, sure go ahead.  For anything else, use
_(u'Name').  We have to change _() though.

-Barry