[Python-ideas] Gettext syntax (was Re: Allow "assigning" to ...)

Chris Angelico rosuav at gmail.com
Thu Feb 12 11:59:35 CET 2015


On Thu, Feb 12, 2015 at 8:00 PM, M.-A. Lemburg <mal at egenix.com> wrote:
> I think the proper way of doing this would be to add a string
> literal modifier like we have with r'' for raw strings,
> e.g. i'Internationalized String'.
>
> The Python compiler would then map this to a call to
> sys.i18n like so:
>
> i'Internationalized String' -> sys.i18n('Internationalized String')
>
> and applications could set sys.i18n to whatever they use for
> internationalization.

While the syntax is very cute, it seems unnecessary to have compiler
support for something that could just be done with a library. It'd be
impossible to backport code that uses this notation, so you'd have to
either require Python 3.5 (or whatever version), or maintain two
different codebases, or have a 2to3-style precompiler.

Hmm. How hard is it to write a parser for Python code that extends the
grammar in some way? I know there've been a lot of proposals around
the place for decimal.Decimal literals and empty set literals and
such; is there an elegant way to do a proof-of-concept without
touching the C code at all?

ChrisA


More information about the Python-ideas mailing list