[Python-ideas] Fix the DRY problem (was Re: PEP 501 - i18n with marked strings)

Terry Reedy tjreedy at udel.edu
Thu Aug 13 16:04:20 CEST 2015


On 8/13/2015 12:37 AM, Guido van Rossum wrote:

> Fair enough. (Though IMO the real cost of i18n is that it introduces a
> feeling of programming in molasses.)

For some structured situations, such as gui menus, the molasses is not 
needed.  _(...) does two things: mark a string for the translator 
collector, and actually do the translation.  Idle defines 'menudefs' 
structures, which are lists of menu tuples.  The first item of each 
tuple is the string to be displayed on the menu, the second is the 
binding for that item, either a pseudoevent or a list of menu tuples for 
a submenu.  A function walks the structure to extract the names to pass 
to tk menu calls.

For internationalization, the gettext.gettext translation call could be 
added in one place, where the string is passed to tk, rather than 80 
places in the structure definition.  An altered version of the menudefs 
walker could be used to collect the menu strings for translation.

If we want to encourage multi-language tkinter apps, i18n code should be 
added somewhere public in the tkinter package (and gettext module), 
rather than hidden away in idlelib.

-- 
Terry Jan Reedy



More information about the Python-ideas mailing list