title: Django: change app language programmatically (without /i18n/setlang/ view)
body: <p>My situation is the following:</p>
  
  <p>I'm developing a multi-language site and currently I use the Django view <strong>/i18n/setlang/</strong> to let user switch language from a dropdown menu, and all works fine… but now, I wish to set the language programmatically, specifically I have a form with a series of settings and, among these, there is a "favorite language" voice, once the user submit the form, my view saves the User model and theoretically after that it should set the application language using the saved preference, but it does not work. What I tried is:</p>
  
  <pre><code>from django.utils.translation import activate
  
  activate(lang)
  </code></pre>
  
  <p>but the result is bizarre: the UI after the redirect is still in the old language, but the message of successful update (django messages framework) is displayed back in the expected language!  </p>
  
  <p>I've also checked the source code of the Django view: <a href="https://github.com/django/django/blob/master/django/views/i18n.py" rel="nofollow">https://github.com/django/django/blob/master/django/views/i18n.py</a></p>
  
  <p>And I saw that they save the selected language in session if available (I have session activated), so I tried:</p>
  
  <pre><code>self.request.session['_language'] = form.cleaned_data['favouriteLanguage']
  </code></pre>
  
  <p>…but is not working, what should I do?</p>
  
  <p>I'm using Django 1.6 and the django middleware I did install are the following:</p>
  
  <pre><code>    'django.middleware.common.CommonMiddleware',
      'django.contrib.sessions.middleware.SessionMiddleware',
      'django.middleware.locale.LocaleMiddleware',
      'django.middleware.csrf.CsrfViewMiddleware',
      'django.contrib.auth.middleware.AuthenticationMiddleware',
      'django.contrib.messages.middleware.MessageMiddleware',
  </code></pre>
  
  <p>ps: in both my tries, {{ request.LANGUAGE_CODE }} in template prints the old language code :(</p>