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

Andrew Barnert abarnert at yahoo.com
Fri Feb 13 03:28:46 CET 2015


On Feb 12, 2015, at 17:39, Terry Reedy <tjreedy at udel.edu> wrote:

> I18n of existing code would be easier if Tools/i18n had a stringmark.py script that would either mark all strings with _() (or alternative) or interactively let one say yes or no to each.

One nice thing about the existing idiom is that you can use tools designed for perl or C and they do the right thing. Except, of course, that they don't handle triple quotes.

At a job around 10-12 years ago, we used this horrible commercial Windows tool for internationalization that did this, among other things. When I wanted to write some new server code in Python, management objected that it wouldn't work with our existing i18n tools. I was able to whip up a pre- and post-processor to deal with the triple quotes, and integrate it into the toolchain, in half a day. If I couldn't have done that, I probably wouldn't have been able to use Python.

By the way the injecting _ into builtins thing was actually a (tiny) problem. In C, only files that include the header have _, so the rest can be skipped; in Python, they all get _ without an import, so you have to assume they all need to be handled. (I solved that by actually importing gettext in all the modules even though it wasn't necessary, so the preprocessor could turn that import into the include the tool expected.)

Hopefully things aren't quite as bad as they were back then, but there must still be some nice gettext-style tools that either work, or can be hacked around easily, with Python gettext with the _ idiom, and I have no idea what fraction of them would be lost if we used a different idiom.

Of course there's be nothing stopping anyone from using the old _ idiom even if we added a new one, so don't take this as a vote against coming up with something better.


More information about the Python-ideas mailing list