Opened 3 years ago

Last modified 14 months ago

#28647 new New feature

Add support for python-brace-format for variables within {% blocktrans %}

Reported by: Aidas Bendoraitis Owned by: nobody
Component: Internationalization Version: 1.11
Severity: Normal Keywords:
Cc: Claude Paroz Triage Stage: Someday/Maybe
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Currently with gettext() function you can use both, older-style python format %(variable)s and newer style python-brace-format {variable}, for example:

gettext('Hello, %(addressee)s!') % {'addressee': 'World'}
gettext('Hello, {addressee}!').format(addressee='World')

Unfortunately, {% blocktrans %} always produces the old-style format with the % sign.

I think, it would make sense to add a parameter to the {% blocktrans %} tag by which you could define the python string format you want to produce.

According to my experience with not-so-technical translators, %(variable)s format in the django.po files is more confusing than {variable}.

Change History (4)

comment:1 Changed 3 years ago by Tim Graham

Cc: Claude Paroz added

What do you think, Claude?

comment:2 Changed 3 years ago by Claude Paroz

I'm not a fan for adding yet another parameter for that.
We could switch to the new format syntax, but that would be backwards-incompatible because po files would change. That could be doable through a from future load blocktrans transition.
Is it worth it? Should we ask on the django-developers ML?

comment:3 Changed 3 years ago by Tim Graham

Triage Stage: UnreviewedSomeday/Maybe

comment:4 Changed 14 months ago by Ole Laursen

Exactly how, I'm not sure, but this would definitely be worthwhile IMHO (I have a bunch of i18n projects, and yes, transition would be annoying, but something that could be fixed with a script). I'm sort of living with this, but today I hit a string that I have defined both in Python and in a template, and end up with two strings in the .po file:

"Some thing %(foo)s"

"Some thing {foo}"

Grrrr.

Note: See TracTickets for help on using tickets.
Back to Top