[Python-ideas] Draft PEP on string interpolation

Petr Viktorin encukou at gmail.com
Mon Aug 24 20:15:45 CEST 2015


On Mon, Aug 24, 2015 at 7:38 PM, Guido van Rossum <guido at python.org> wrote:
> On Mon, Aug 24, 2015 at 10:12 AM, Barry Warsaw <barry at python.org> wrote:
>>
>> On Aug 21, 2015, at 10:52 PM, Mike Miller wrote:
>>
>> >Which syntax would you rather have for translation?  (Knowing that you
>> > might
>> >give a different answer for standard interpolation.)
>>
>> For i18n, $-strings (aka PEP 292, string.Template) is by far the best
>> choice.
>> Translators are very familiar with the syntax, having used it now for many
>> years (and not just in a Python context), and it's very difficult for
>> non-technical folks to get wrong.
>>
>> I don't see any advantages to springing yet another i18n interpolation
>> syntax
>> on translators, and I definitely don't see the advantage of introducing a
>> *second* i18n syntax to translators of Python programs.
>>
>> If that means PEP 498/501 isn't appropriate for Python i18n, so be it.
>> What
>> we have now works, even if its implementation requires the use of some
>> frowned-upon APIs, and the use of function syntax for marking and
>> invocation.
>
>
> That's fair, and I'm glad we have this clear position on the table.
>
> I cannot accept $ interpolation in the language definition. I also don't
> want PEP 498 and 501 to use different interpolation syntaxes. So to me, this
> means that i18n is off the table as a motivation for PEP 501 (it never was
> on the table for 498), and Nick can focus on motivational examples from
> html/sql/shell code injection for PEP 501 (but only if he can live with the
> PEP 498 surface syntax for interpolation).

The $ syntax might be a requirement for Barry, but it's definitely not
required for translations at large.
I agree that it *is* hard to introduce a new marker syntax in a
project, since any change in a string will generally require
re-translation in all languages. For flufl.i18n, $ is definitely best.
But it might not be best new projects/libraries.
Translators can get familiar with lots of things; the projects I
helped translate used %1 (Qt/KDE) or %s (C/printf).

Many Python projects (e.g. Django [0]) use "%(name)s" markers, where
translators often leave off the "s". The brace syntax would be a big
improvement.

[0] https://github.com/django/django/blob/master/django/conf/locale/en/LC_MESSAGES/django.po


More information about the Python-ideas mailing list