#29623 closed Bug (fixed)
DurationField's overflow error message fails to translate
Reported by: | Jannis Leidel | Owned by: | Markus Holtermann |
---|---|---|---|
Component: | Forms | Version: | 2.1 |
Severity: | Release blocker | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
In https://github.com/django/django/commit/55b5393bd235aa6c55ea9a7da6f0e8b75b204084 a new ValidationError message was added that isn't using the common pattern of using string substitution variables but instead a format string.
I noticed this while updating the German translation for 2.1 and found Transifex to not display the variables correctly which could prevent translators to correctly set the variables in the translated string.
In my experience translators can mistake "{variables}" in text as something to translate as well, which effectively can lead to either KeyError (because the expected format variable weren't found) or empty fill-ins.
Either way, this is a possible breaking change.
Change History (10)
comment:1 by , 6 years ago
Component: | Internationalization → Forms |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 6 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:3 by , 6 years ago
Easy pickings: | set |
---|---|
Has patch: | set |
comment:4 by , 6 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
Patch seems fine.
(Slight niggle: Isn't %-style string formatting discouraged now? Does this kind of consideration block moving away from it, assuming that's desirable?)
follow-up: 6 comment:5 by , 6 years ago
I don't think the .format()
option works with gettext though, does it?
comment:6 by , 6 years ago
Replying to Markus Holtermann:
I don't think the
.format()
option works with gettext though, does it?
It does. I don't recall the exact gettext version the support was added to, but it works.
Sorry Jannis, but I don't think this is a bug. Even if the older %()s
syntax is not deprecated, I see more and more Python code using the 'string'.format()
syntax. Translators have to get used to the new syntax anyway. Moreover, if the content is mistakenly translated, msgfmt -c
will notice it as an error (the string is marked #, python-brace-format
in the po files) and we will not accept the file in Django. The fact that Transifex accepts the wrong translation is a bug in Transifex.
comment:7 by , 6 years ago
Needs tests: | set |
---|---|
Triage Stage: | Ready for checkin → Accepted |
In fact, regardless of the placeholder style, there might be a bug about the translation happening partially at import time instead of validation time. Anyway, a test is required.
comment:8 by , 6 years ago
Needs tests: | unset |
---|---|
Summary: | DurationField ValidationError message should use proper gettext variables → DurationField's overflow error message fails to translate |
I confirmed Claude's suspicion and updated the PR.
PR: https://github.com/django/django/pull/10255/files