Don't forget the i18n use case
Don't forget the i18n use case
Posted Jan 24, 2025 14:48 UTC (Fri) by mgedmin (guest, #34497)Parent article: A revamped Python string-formatting proposal
from gettext import gettext as _
name = 'world'
print(_(f"Hello, {name.capitalize()}!")) # WRONG: interpolates first, calls gettext on the result
from gettext import gettext as _
name = 'world'
print(_("Hello, {name}").format(name=name.capitalize())) # what you have to use today
from sometranslationhelper import _ # I'll probably have to write it
name = 'world'
print(_(t"Hello, {name.capitalize()}") # now it's possible to glue back the original template string and pass it to gettext, then interpolate afterwards
