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

Ron Adam ron3200 at gmail.com
Thu Feb 12 14:34:52 CET 2015



On 02/12/2015 03:00 AM, M.-A. Lemburg wrote:
> On 12.02.2015 04:33, Terry Reedy wrote:
>> >A possible solution would be to give 3.x str a __pos__ or __neg__ method, so +'python' or -'python'
>> >would mean the translation of 'python' (the snake).  This would be even*less*  intrusive and easier
>> >to write than _('python').
> Doesn't read well:
>
> label = +'I like' + +'Python'
>
> and this is even worse, IMO:
>
> label = -'I like' + -'Python'
>
>
> 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'.

Another option may be to add a '_' property to the string type as an 
alternate interface to Gettext, and possibly for use with other 
translators.  The '_' property would still access a global function, but it 
could have a much longer and more meaningful name like __string_translator__.

    label = 'I like'._ + 'Python'._

Then in cases where '_' is used locally as a temp name, like with lambda, 
you can use the '_' property instead of the global '_' function.


An advantage of the 'i' prefix notation is the translation could be done at 
parse time instead of run time.  But that may be hard to do because all the 
parts may not be available at parse time. (?)

-Ron



More information about the Python-ideas mailing list