Code

Opened 2 years ago

Closed 2 years ago

#17621 closed Bug (worksforme)

django.utils.translation.activate() issue

Reported by: tomasz.zawadzinski@… Owned by: nobody
Component: Internationalization Version: 1.3
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

django.utils.translation.activate() doesn't affect on form instances. Strings defined in a class of form (ex label, error_messages etc), are translated only in a result of setting a proper cookie or session key.

Attachments (0)

Change History (3)

comment:1 follow-up: Changed 2 years ago by claudep

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

Please provide us with real code so as we can judge if the problem is in Django or on your side. Did you use ugettext_lazy to mark form class strings for translation?

comment:2 in reply to: ↑ 1 Changed 2 years ago by anonymous

I'm sorry, everything is fine using ugettext_lazy. I don't know if this problem is worth solving anymore.

code looked like this (other strings were translated properly, these in templates and other helping functions):

from django.utils.translation import ugettext as _

class BookingForm(forms.Form):
   name = forms.CharField(max_length=25, label=_(u'Imię'), error_messages={'required': _(u'Proszę wpisać imię.')})
   [...]

def index(request, lang=''):
   if lang == 'en':
      translation.activate('en')
   elif lang == 'pl':
      translation.activate('pl')

   c = {'form': BookingForm()}
   [...]

comment:3 Changed 2 years ago by aaugustin

  • Resolution set to worksforme
  • Status changed from new to closed

This is exactly the reason why ugettext_lazy exists :)

https://docs.djangoproject.com/en/dev/topics/i18n/translation/#lazy-translation

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.