Opened 3 years ago

Closed 3 years ago

#33112 closed Bug (needsinfo)

BaseValidator does not localize params passed to rendered ValidationError

Reported by: Jake Urban Owned by: nobody
Component: Core (Other) Version: 3.2
Severity: Normal Keywords: validators, localization, i10n, error, message
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: yes

Description (last modified by Carlton Gibson)

django.core.validators.BaseValidator does not localize the values contained in the params dict passed to ValidatorError. The result is that error messages contain localized error messages with non-localized values.

Here is a photo of an english-style number included in a Portuguese error message:

https://code.djangoproject.com/raw-attachment/ticket/33112/Screen%20Shot%202021-09-15%20at%204.42.51%20PM.png

Attachments (1)

Screen Shot 2021-09-15 at 4.42.51 PM.png (18.0 KB ) - added by Jake Urban 3 years ago.
A Portuguese error message containing an english-style number.

Download all attachments as: .zip

Change History (2)

by Jake Urban, 3 years ago

A Portuguese error message containing an english-style number.

comment:1 by Carlton Gibson, 3 years ago

Description: modified (diff)
Resolution: needsinfo
Status: newclosed

Hi Jake — thanks for the report. It's a tricky one.

I'm not 100% clear what the correct response here should be. Can I ask you to follow up with more details to the i18n category on the Django Forum so we can get some more eyes on this?

What's the localization story we can tell for parameters in translated error messages? 🤔

e.g. limit_value in message = _('Ensure this value is greater than or equal to %(limit_value)s.')

Testing myself, I don't quite see the behaviour you're pointing to…

With es locale.

import decimal

from django import forms


class ExampleForm(forms.Form):
    value = forms.DecimalField(
        max_value=decimal.Decimal(100000.00),
        min_value=decimal.Decimal(10.00),
        max_digits=8,
        decimal_places=2,
    )

I see

>>> from forms import ExampleForm
>>> f = ExampleForm(data={'value':'1'})
>>> f.is_valid()
False
>>> f.errors
{'value': ['Asegúrese de que este valor es mayor o igual a 10.']}

Rather than 10.00 from your screenshot.

So, when you post, can you provide the full reproduce so we're all on exactly the same page? Thanks!

I'll close as needsinfo here for the moment, but we can adjust that based on the discussion.
(I hope that makes sense.)

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