[Python-ideas] Gettext syntax (was Re: Allow "assigning" to ...)
Terry Reedy
tjreedy at udel.edu
Thu Feb 12 23:41:24 CET 2015
On 2/12/2015 10:53 AM, Barry Warsaw wrote:
> On Feb 12, 2015, at 02:40 PM, Ben Finney wrote:
>
>> Gettext has been using the name ‘_’ since 1995, which was in Python's
>> infancy. The name ‘_’ is pretty obvious, I'm sure it was in use before
>> Python came along.
>
> Exactly. All this was designed for compatibility with GNU gettext conventions
> such as in i18n'd C programs. It was especially useful to interoperate with
> source text extraction tools.
Are you referring to then existing tools that would pull out string
literals inside _(...) and put them in a file for translation? I can
see how you (all) would not want to break them.
> We were aware of the collision with the
> interactive interpreter convenience but that wasn't deemed enough to buck
> established convention.
It leads to this
>>> import gettext
>>> gettext.install('foo')
>>> _
<bound method NullTranslations.gettext of <gettext.NullTranslations
object at 0x000000000361E978>>
>>> _('abc')
'abc'
>>> _
'abc' # whoops
of
>>> _('cat')
...
TypeError: 'str' object is not callable
Of course, one can learn to forgo the '_' convenience and test or
experiment with explicit assignments.
>>> s = _('cat')
>>> s
'gato' # for instance
I presume you decided then that this was less evil that bucking the
external convention.
> Using _ to imply "ignore this value" came along afterward.
Since interactive _ is usually ignored, I do not see this usage as all
that different, except that it extends the conflict to batch made --
which is, of course, an important difference.
--
Terry Jan Reedy
More information about the Python-ideas
mailing list