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

Sven R. Kunze srkunze at mail.de
Wed Aug 12 09:30:14 CEST 2015


I think I understood that.

How can I differentiate between {variables} to be translated and 
variables not to be translated?

I thought this was the intention of Mike's idea: unifying both i and f 
as they are orthogonal to each other. As I don't like the $ so much, I 
proposed using {...} as well with a special marker i18n or something.

That could be completely useless, I am unsure.


On 12.08.2015 01:22, Jonathan Slenders wrote:
> Not exactly.
>
> Take this string for instance:
>
>     f'hello {name}'
>
>
> And our FString implementation, very simple:
>
>     class FString(str):
>         def __init__(self, value, **kwargs):
>             super().__init__(value.format(**self.kwargs))
>
>             self.value = value
>
>             self.kwargs = kwargs
>
>
> What the above f-string should do is create an instance of that class. 
> This is just a compiler detail. A preprocessor step. Like this:
>
>     FString('hello {name}', name=str(name))
>
>
> FString is just an str instance, it has the actual interpolated value, 
> but it still contains the original uninterpolated string and all 
> parameters (as strings as well.)
>
> Now, what gettext can do, if we would wrap this string in the 
> underscore function, is take the "value" attribute from this string 
> FString, translate that, and apply the interpolation again.
>
> This way, we are completely compatible with the format() call. There 
> is no need at all for using globals/locals or _getframe(). The name 
> bindings are static, this is lintable.
>
> Please tell me if I'm missing something.
>
>
> 2015-08-11 19:12 GMT+02:00 Sven R. Kunze <srkunze at mail.de 
> <mailto:srkunze at mail.de>>:
>
>     I actually thought this was about a two-step process using lazy
>     evaluation.
>
>     This way {name:i18n} or {name:later} basically marks lazy evaluation.
>
>     But as it seems, i'...' is more supposed to do all (translation +
>     formatting) of this at once. My fault, sorry.
>
>
>     On 11.08.2015 10:35, Petr Viktorin wrote:
>
>         On Tue, Aug 11, 2015 at 9:36 AM, Sven R. Kunze
>         <srkunze at mail.de <mailto:srkunze at mail.de>> wrote:
>
>             Also bare with me but couldn't i18n not just be another
>             format spec?
>
>             i'Hello there, {name:i18n} {age}.'
>
>         Usually it's not the substitutions that you need to translate,
>         but the
>         surrounding text.
>
>
>     _______________________________________________
>     Python-ideas mailing list
>     Python-ideas at python.org <mailto: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/20150812/584ba467/attachment-0001.html>


More information about the Python-ideas mailing list