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

Jonathan Slenders jonathan at slenders.be
Tue Aug 18 10:08:46 CEST 2015


But how would you determine the current active language? Is that a thread
local?
This would probably not work to make an asyncio or Twisted applications
translatable.

For an asyncio web application for instance, the translate function needs
to know the request object.

2015-08-17 23:37 GMT+02:00 Ned Batchelder <ned at nedbatchelder.com>:

>
> On 8/17/15 11:51 AM, Barry Warsaw wrote:
>
>> One of the things I've mentioned to Nick about PEP 501 is the difference
>> between i"foo" and iu"foo".  The former gets mapped to __interpolate__()
>> while
>> the latter gets mapped to __interpolateu__().  Nick makes the case for
>> this
>> distinction based on the ability to override __interpolate__() in the
>> local
>> namespace to implement i18n, whereas __interpolateu__() - while
>> technically
>> still able to override - would generally just be left to the "normal"
>> non-i18n
>> interpolation.
>>
>> I countered with a proposal that a context manager could be used, but Nick
>> points out that you can't really *unbind* __interpolate__() when the
>> context
>> manager exits.
>>
>> This still seems weird to me.  There's no distinction in Python 3 between
>> "foo" and u"foo" with the latter having been re-added to aid in migrations
>> between Python 2 and 3.  But with PEP 501, this introduces a functional
>> distinction between i"foo" and iu"foo" (and ui"foo"?).  It's handy, but
>> seems
>> to be a fairly significant difference from the current use if
>> u-prefixes.  I'm
>> sympathetic but still skeptical. ;)
>>
>
> I agree that this "one weird trick" of distinguishing between i"" and iu""
> is really unfortunate. As you say, in Python 3, "foo" and u"foo" are the
> same, so why should i"" and iu"" be different?
>
> I understand the appeal of interpolated strings, but can we retain some
> measure of "explicit is better than implicit"?  If i18n considerations are
> this important (and I agree that they are), let's take them seriously
> enough to give them real syntax.
>
> --Ned.
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150818/86d5dd43/attachment.html>


More information about the Python-ideas mailing list