#36884: Translation of fields in admin log messages works incorrectly
------------------------+-----------------------------------------
Reporter: Meiyer | Type: Bug
Status: new | Component: contrib.admin
Version: 3.0 | Severity: Normal
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------+-----------------------------------------
The Django Admin builds the log messages using `construct_change_message`,
which looks at the fields of the change form, specifically their labels
(
https://github.com/django/django/blob/9814676ea75bfe5c5d5244c50ccfe1f652a2f058/django/contrib/admin/utils.py#L618).
The helper function turns off the translation when building the change
JSON, to apply the translation when a LogMessage is displayed. However,
there is a flaw in the logic:
* the `verbose_name` parameter of the model field would typically be
lower-cased (from the docs: ''“The convention is not to capitalize the
first letter of the verbose_name. Django will automatically capitalize the
first letter where it needs to.”'' ).
* the labels generated by the forms have the first letter capitalized
(from the docs: ''“the default label for a Field is generated from the
field name by converting all underscores to spaces and upper-casing the
first letter”'') where for Model Forms, ''“Django will fall back on that
model field’s verbose_name and then the field’s attribute name”''.
This results in translation mismatch at render time. For example, the log
message would include `"fields": ["Occupation"]` while the translation
catalog has only the key “occupation”, coming from that field’s
`verbose_name`. As a result, the field names are not properly translated.
I tracked the issue back to changes introduced in 3.0 and it persists in
all versions up to 6.0.
--
Ticket URL: <
https://code.djangoproject.com/ticket/36884>
Django <
https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.