[Python-ideas] Combine f-strings with i18n - How about using PEP 501?

Hans Polak hpolak at polak.es
Tue Sep 18 03:59:34 EDT 2018


>> I don't see how this immediately helps the OP, who wants a *literal*
>> expression that automatically invokes the translation machinery as
>> well as the interpolation machinery.
Actually, no, I do not want the expression to be automatically 
translated at compile time. It should be translated at run-time. There 
are three situations.

1. No translation, just a regular f-string.
2. App translation. The f-string gets translated to the configured language.
3. On the fly translation. The string gets translated to the language 
passed as an argument as required.

In code, this would be.
1. f'Hi {user}'
2. f'{!g}Hi {user}'
3. f'{lang!g}Hi {user}'

Cases 2 and 3 need some additional code, just like with gettext.

I'm sorry if that wasn't clear from the start. All I want is the code to 
be simpler to write and maintain. I do not want to have complicated 
parsing for the compiler.

>> Another way forward could be a preprocessor. All this can be done with a fairly simple script using parso.
This is probably the idea.

Cheers,
Hans



More information about the Python-ideas mailing list