Perhaps somebody could explain exactly what's going on.

I have a form whose labels are translatable strings:

class MyForm(forms.Form):

   field1 = forms.CharField(label=_('Label 1'), max_length=20)

I generated the .po files, supplied the translations, generated
the .mo files, added the proper middleware etc. All of the necessary
bits for i18n are turned on and working. The odd behaviour I'll see is
that after the first translation takes place by POSTing to /i18n/
setlang/ (for example, to french) all subsequent page loads will
render the french translation instead of the language code currently
defined in request.session['django_language']. So if I switch to
spanish, I still see french labels. If I restart apache and load the
page with spanish set as the language, now the spanish translation
comes through properly, but again, from here on in, even when I switch
to french, the spanish one always shows.

I'm guessing this has to do with how python modules are loaded and the
form class is loaded once the first time, translation takes place and
that's it (until server reload). I've got around this by setting the
label in an overloaded __init__ call. For example:

def __init__(self, *args, **args):
    self.fields['field1'].label = _(self.fields['field1'].label)

Anybody else seen this before? Is my intuition right?

FWIW, django is version 1.2-pre alpha r11616, apache2/mod_wsgi.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to