-
Notifications
You must be signed in to change notification settings - Fork 461
Description
PEP 750 has been accepted and it would be great to have support for this ready once Python 3.14 gets released!
Writing translatable strings like this would be much more natural than the current way of using .format() or % on them, and also much less error-prone (people accidentally calling .format() inside _() instead of outside):
_(t'Hello {user}: {message}')
ngettext(t'{n} user', t'{n} users', n)Unfortunately certain case are trickier, since you'd need to generate placeholder names from somewhat arbitrary python expressions:
_(t'Hello {user.name}: {get_message(user)}')However, I think anything besides simple attribute accesses are probably somewhat of an edge case, and generating something like user_name and get_message_user, or failing in more complex cases (or when two different expressions would be turned into the same placeholder string) would not be too bad. In fact, Jinja's i18n tag already does that (you can use simple variables directly, but have to bind anything else to a simple variable name).