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

Barry Warsaw barry at python.org
Fri Feb 13 17:26:10 CET 2015


On Feb 12, 2015, at 08:39 PM, Terry Reedy wrote:

>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

I agree it looks cluttered, but I'm not sure how you could improve things.
You have to be able to mark some strings as translatable, while other strings
are not.  E.g. I never translate log output because that is typically not
consumed by the end user, and if it were me-as-developer trying to parse
Russian log output to find a bug, I wouldn't get very far. :)  Plus, there are
plenty of strings in a typical program that also aren't for consumption by the
end user.

>> 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?

Probably not.  I think once GNU xgettext learned how to parse Python, our
script hasn't seen much love.

>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.

I'm not sure what you're asking for; do you want something you could point at
a Python file and it would rewrite it after interactively asking for
translatability or not?  Hmm, maybe that would be cool.  I look forward to the
contribution. <wink>

Cheers,
-Barry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150213/0a939966/attachment.sig>


More information about the Python-ideas mailing list