[Python-ideas] String interpolation for all literal strings

Terry Reedy tjreedy at udel.edu
Thu Aug 6 11:31:43 CEST 2015


On 8/6/2015 1:23 AM, Nick Coghlan wrote:

I prefer a symbol over an 'f' that is too similar to other prefix letters.

> Pondering the fact that "\N{GREEK LETTER ALPHA}",
> "{ref}".format_map(data), f"\{ref}" and string.Template("${ref}") all
> overload on "{}" as their parenthetical pair gave me an idea.
>
> Since we're effectively defining a "string display" (which will
> hopefully remain clearly independent of normal string literals), what
> if we were to bake internationalisation and localisation directly into
> this PEP, such that, by default, these new strings would be flagged
> for translation, and translations could change the *order* in which
> subexpressions were displayed, but not the *content* of those
> subexpressions?

For internationalising Idle's menu, lines like

  (!'file', [
    (!'_New File', '<<open-new-window>>'),
    (!'_Open...', '<<open-window-from-file>>'),
    (!'Open _Module...', '<<open-module>>'),
    (!'Class _Browser', '<<open-class-browser>>'),
    (!'_Path Browser', '<<open-path-browser>>'),
   ...
    + another 50 lines of menu definition

are *much* easier to type, read, and proofread than

  (_('file'), [
    (_('_New File'), '<<open-new-window>>'),
    (_('_Open...'), '<<open-window-from-file>>'),
    (_('Open _Module...'), '<<open-module>>'),
    (_('Class _Browser'), '<<open-class-browser>>'),
    (_('_Path Browser'), '<<open-path-browser>>'),--
    ... + 50 similar lines

The obnoxiousness of the latter, which literally makes me dizzy to read, 
was half my opposition to 'preparing' Idle for a use that might or might 
not ever happen.  If there were a switch to just ignore the ! prefix, 
leaving no runtime cost, then I would be even happier with adding the !s 
and telling people, 'ok, go ahead and prepare translations and Idle is 
ready to go'.

Terry Jan Reedy



More information about the Python-ideas mailing list