[Python-ideas] PEP 501 - i18n with marked strings

M.-A. Lemburg mal at egenix.com
Tue Aug 11 16:06:13 CEST 2015


On 11.08.2015 15:10, Jonathan Slenders wrote:
> -1 on any approach that uses a translation hook. Many frameworks have their
> own way of translating things. So that should definitely not be a global.

The module global approach is only one way to define a
__interpolate__ function.

As I understand the PEP, the compiler would simply translate
the literal into a regular function call, which then is subject
to the usual scoping rules in Python.

It would therefore be possible to override the builtin in
a local scope to e.g. address things like context or
per-session based i18n.

You could e.g. pass in a ${context} variable to the string,
so that your __interpolate__ function can then directly
access the required translation context. Alternatively,
the __interpolate__ function could inspect the call stack
to automatically find the needed context variable.

I guess this particular use case could be made more elegant :-)

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Aug 11 2015)
>>> Python Projects, Coaching and Consulting ...  http://www.egenix.com/
>>> mxODBC Plone/Zope Database Adapter ...       http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
________________________________________________________________________

::::: Try our mxODBC.Connect Python Database Interface for free ! ::::::

   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
    D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
           Registered at Amtsgericht Duesseldorf: HRB 46611
               http://www.egenix.com/company/contact/


More information about the Python-ideas mailing list