I have a django view communicate the user's preferred locale to a form in forms.py. However, that form seems to get initialized before I even call it.
Class SurveyForm() seems to load before my call from views.py and even before the SurveyForms() init function becomes active.
Here is the code:
class SurveyForm(forms.Form):
questions = Question.objects.all()
Q1 = questions.get(identifier='Q1')
question1 = forms.CharField(required=False, label=Q1.name)
def __init__(self, *args, **kwargs):
translation.activate('nl')
When I put translation.activate('nl')
in the SurveyForm
class, it does work.
When I put translation.activate('nl')
in the __init__
, or in views.py
, it does not work. How can this be changed?
Note: I use modeltranslation, so Q1.name
will get the Dutch translation when Dutch language is active.