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

Wichert Akkerman wichert at wiggy.net
Fri Feb 13 09:22:24 CET 2015


> On 13 Feb 2015, at 01:01, Terry Reedy <tjreedy at udel.edu> wrote:
> 
> On 2/11/2015 10:33 PM, 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').
>> 
>> Since () has equal precedence with . while + and - are lower, we would
>> have the following equivalences for mixed expressions with '.':
>> 
>> _(snake.format()) == -snake.format()  # format, then translate
>>                # or -(snake.lower())
>> _(snake).format() == (-snake).format()  # translate, then format
> 
> The core idea of this proposal is to add a single prefix symbol as an alternative to _(...).  Summarizing the alternate proposals:
> 
> Zero Piraeus suggests that ~ (.__invert__ (normally bitwise)) would be better.  I agree.
> 
> M.-A. Lemburg points out that neither of
>  label = +'I like' + +'Python'
>  label = -'I like' + -'Python'
> do not 'read well'.  I do not know how common such concatentions are, but I agree that they do not look good.

Please note that concatenating translatable strings like that is a really bad practice, and will lead to impossible situations. If you translate “I like” and “Python” separately, and then concatenate the results you are likely to get something that is quite awful, if not impossible, in many languages.

There are also other areas in which Python i18n support is currently lacking, and which would only get worse with this proposal: support for message contexts and plural forms. Both are critical for any non-trivial application. For what’s worth I am toying with the idea of spending pycon sprint time on that topic (unless the pyramid folks manage to grab all my attention again!).

Wichert.


More information about the Python-ideas mailing list