[Python-ideas] String interpolation for all literal strings

Barry Warsaw barry at python.org
Fri Aug 7 18:09:58 CEST 2015


On Aug 07, 2015, at 05:33 PM, Nick Coghlan wrote:

>When you're mixing translation with interpolation, you really want the
>translation lookup to happen first, when the placeholders are still
>present in the format string:

It just doesn't work otherwise.

>sys._getframe() usage is what I meant by stack walking. It's not
>*really* based on walking the stack, but you're relying on poking
>around in runtime state to do dynamic scoping, rather than being able
>to do lexical analysis at compile time (and hence why static analysers
>get confused about apparently unused local variables).

Sure, yep.

One other word about i18n based on experience.  The escape format *really*
matters.  Keep in mind that we've always had positional interpolation, via
'%(foo)s', but we found that to be very highly error prone.  I can't tell you
how many times a translator would accidentally leave off the trailing 's',
thus breaking the translation.  It's exactly the reason for string.Template --
$-strings are familiar to almost all translators, and really hard to screw up.
I fear that something like \{ (and especially if \} is required) will be as
error prone as %(foo)s.

Cheers,
-Barry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150807/d3d3533c/attachment.sig>


More information about the Python-ideas mailing list