Opened 5 years ago

Closed 5 years ago

Last modified 4 years ago

#13583 closed (invalid)

Invalid localization of error_messages in form fields

Reported by: dmitry_nosov Owned by: nobody
Component: Core (Other) Version: 1.2
Severity: Keywords: error_messages
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description (last modified by kmtracey)

If I use this construction:

forms.IntegerField(min_value=1, max_value=5,                                   
                                 error_messages = {
                                    'max_value': u'Ошибка!',
                                 })

The error message output is
u'u041e\u0448\u0438\u0431\u043a\u0430!'

Instead of

u'Ошибка!'

Change History (3)

comment:1 Changed 5 years ago by phxx

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

I cannot confirm this.
The following code generates the expected output:

class A(forms.Form):
    value = forms.IntegerField(min_value=1, max_value=10,
    error_messages = {
        'max_value': u'Ошибка!',
    })

print A({'value':'12'}).errors['value'][0]

outputs

Ошибка!

Your confusion might be resulting of python's behaviour how unicode strings are handled. If you use a character like б in a string it will be converted into its unicode number which is \u0431 in this case.

comment:2 Changed 5 years ago by kmtracey

  • Description modified (diff)
  • Resolution set to invalid
  • Status changed from new to closed

There is not enough information here to figure out what's going on....the error message output where? In a template, the snippet provided does produce correct output by default (for example if {{ form }} is used in the template for display). I suspect the observed problem is due to some incorrect way of outputting the error information in the template, or, if the "output" being referred to is some debugging information, then a misunderstanding about how Python displays unicode string representations (as phxx notes), not a bug in Django. A better place to ask for help in either case would be django-users.

comment:3 Changed 4 years ago by jacob

  • milestone 1.2 deleted

Milestone 1.2 deleted

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