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

Terry Reedy tjreedy at udel.edu
Fri Feb 13 02:39:33 CET 2015


On 2/12/2015 11:09 AM, Barry Warsaw wrote:

> [alternate syntax] is really unnecessary.
 > These days, I believe standard GNU xgettext can
> parse Python code and can be told to use an alternative marker function.

My current interest in gettext is due to (incomplete) proposals (such as 
#17776) to internationalize parts of Idle.  There are no instances of 
'_,' in idlelib, and probably no other use of '_' as an identifier, so 
injection of '_' into builtins is not my concern for batch (production) 
mode running.

But I don't like turning code like this (idlelib/Binding.py)

(_'file', [
    ('_New File', '<<open-new-window>>'),
    ('_Open...', '<<open-window-from-file>>'),
    ('Open _Module...', '<<open-module>>'),
    ('Class _Browser', '<<open-class-browser>>'),
    ('_Path Browser', '<<open-path-browser>>'),
    ... and so on for another 59 lines

loaded with tuple parens and _Hotkey markers into the following with () 
and _ doing double duty and doubled in number.

  (_('file'), [
    (_('_New File'), '<<open-new-window>>'),
    (_('_Open...'), '<<open-window-from-file>>'),
    (_('Open _Module...'), '<<open-module>>'),
    (_('Class _Browser'), '<<open-class-browser>>'),
    (_('_Path Browser'), '<<open-path-browser>>'),
    ... and so on for another 59 lines

> Tools/i18n/pygettext.py certainly can.

Are there any tests of this script, especially for 3.x, other than the 
two examples at the end?

> I might as well use this opportunity to plug my flufl.i18n package:
> http://pythonhosted.org/flufl.i18n/
> It provides a nice, higher level API for doing i18n.

The short "Single language context" doc section is certainly a lot 
simpler and clearer than the gettext doc.  But I cannot use your package 
for Idle.  I might, however, use your idea of using rot13 for testing.

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.

-- 
Terry Jan Reedy



More information about the Python-ideas mailing list