Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#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 Tim Graham, 6 years ago

Component: InternationalizationForms
Triage Stage: UnreviewedAccepted

comment:2 by Markus Holtermann, 6 years ago

Owner: changed from nobody to Markus Holtermann
Status: newassigned

comment:3 by Markus Holtermann, 6 years ago

Easy pickings: set
Has patch: set

comment:4 by Carlton Gibson, 6 years ago

Triage Stage: AcceptedReady 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?)

Version 0, edited 6 years ago by Carlton Gibson (next)

comment:5 by Markus Holtermann, 6 years ago

I don't think the .format() option works with gettext though, does it?

in reply to:  5 comment:6 by Claude Paroz, 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 Claude Paroz, 6 years ago

Needs tests: set
Triage Stage: Ready for checkinAccepted

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 Tim Graham, 6 years ago

Needs tests: unset
Summary: DurationField ValidationError message should use proper gettext variablesDurationField's overflow error message fails to translate

I confirmed Claude's suspicion and updated the PR.

comment:9 by Tim Graham <timograham@…>, 6 years ago

Resolution: fixed
Status: assignedclosed

In 730173d1:

Fixed #29623 -- Fixed translation failure of DurationField's "overflow" error message.

comment:10 by Tim Graham <timograham@…>, 6 years ago

In e3be4e9:

[2.1.x] Fixed #29623 -- Fixed translation failure of DurationField's "overflow" error message.

Backport of 730173d1c5cf210d8e3bd951fa49f64b9bc561ca from master

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