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

Chris Angelico rosuav at gmail.com
Tue Aug 18 15:38:16 CEST 2015


On Tue, Aug 18, 2015 at 8:32 PM, Petr Viktorin <encukou at gmail.com> wrote:
> On Tue, Aug 18, 2015 at 10:08 AM, Jonathan Slenders
> <jonathan at slenders.be> wrote:
>> 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.
>
> Or it would need to return a lazy translation, which would get
> translated when the request is available (e.g. when inserted into a
> template).

How hard would this be to implement? Something that isn't a string,
retains all the necessary information, and then collapses to a string
when someone looks at it? This "quantum string interpolation" model
(string theory??) would work well for logging too, as it'd be lazy
enough to be efficient - it needn't do the actual interpolation or
translation work until later on.

ChrisA


More information about the Python-ideas mailing list