[Python-ideas] String interpolation for all literal strings
Yury Selivanov
yselivanov.ml at gmail.com
Thu Aug 6 21:37:33 CEST 2015
Eric,
On 2015-08-05 2:56 PM, Eric V. Smith wrote:
> I've come around to this idea as well, and I'm going to propose it for
> inclusion in 3.6. Once I'm done with my f-string PEP, I'll consider
> either modifying it or creating a new (and very similar) PEP.
While reading this thread, a few messages regarding i18n
and ways to have it with new strings caught my attention.
I'm not a big fan of having all string literals "scanned",
so I'll illustrate my idea on f-strings.
What if we introduce f-strings in the following fashion:
1. ``f'string {var}'`` is equivalent to
``'string {var}'.format(**locals())`` -- no new formatting
syntax.
2. there is a 'sys.set_format_hook()' function that allows
to set a global formatting hook for all f-strings:
# pseudo-code
def i18n(str, vars):
if current_lang != 'en':
str = gettext(str, current_lang)
return str.format(vars)
sys.set_format_hook(i18n)
This would allow much more convenient way not only to format
strings, but also to integrate various i18n frameworks:
f'Welcome, {user}' instead of _('Welcome, {user}')
Yury
More information about the Python-ideas
mailing list