Skip to content

Support t-strings in Python 3.14Β #1206

@ThiefMaster

Description

@ThiefMaster

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).

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions