          The set_language view can be used to change the session language.
  
          The user is redirected to the 'next' argument if provided.
          """
          for lang_code, lang_name in settings.LANGUAGES:
              post_data = dict(language=lang_code, next='/')
              response = self.client.post('/i18n/setlang/', data=post_data)
              self.assertRedirects(response, '/')
              self.assertEqual(self.client.session[LANGUAGE_SESSION_KEY], lang_code)
  
      def test_setlang_unsafe_next(self):
          """
          The set_language view only redirects to the 'next' argument if it is
          "safe".
 
</s> remove         lang_code, lang_name = settings.LANGUAGES[0]
 </s> add         lang_code = self._get_inactive_language_code() </s> remove After setting the language choice, Django redirects the user, following this
algorithm:

* Django looks for a ``next`` parameter in the ``POST`` data.
* If that doesn't exist, or is empty, Django tries the URL in the
  ``Referrer`` header.
* If that's empty -- say, if a user's browser suppresses that header --
  then the user will be redirected to ``/`` (the site root) as a fallback.
 </s> add After setting the language choice, Django looks for a ``next`` parameter in the
``POST`` or ``GET`` data. If that is found and Django considers it to be a safe
URL (i.e. it doesn't point to a different host and uses a safe scheme), a
redirect to that URL will be performed. Otherwise, Django may fall back to
redirecting the user to the URL from the ``Referer`` header or, if it is not
set, to ``/``, depending on the nature of the request:

* For AJAX requests, the fallback will be performed only if the ``next``
  parameter was set. Otherwise a 204 status code (No Content) will be returned.
* For non-AJAX requests, the fallback will always be performed.

.. versionchanged:: 1.10

    Returning a 204 status code for AJAX requests when no redirect is specified
    is new. </s> remove     if not is_safe_url(url=next, host=request.get_host()):
 </s> add     if (next or not request.is_ajax()) and not is_safe_url(url=next, host=request.get_host()): </s> remove             next_trans = translate_url(next, lang_code)
            if next_trans != next:
                response = http.HttpResponseRedirect(next_trans)
 </s> add             if next:
                next_trans = translate_url(next, lang_code)
                if next_trans != next:
                    response = http.HttpResponseRedirect(next_trans)
        lang_code = self._get_inactive_language_code()
        post_data = dict(language=lang_code, next='/')
        response = self.client.post('/i18n/setlang/', post_data, HTTP_REFERER='/i_should_not_be_used/')
        self.assertRedirects(response, '/')
        self.assertEqual(self.client.session[LANGUAGE_SESSION_KEY], lang_code)
          The set_language view can be used to change the session language.
  
          The user is redirected to the 'next' argument if provided.
          """
        lang_code = self._get_inactive_language_code()
        post_data = dict(language=lang_code, next='/')
        response = self.client.post('/i18n/setlang/', post_data, HTTP_REFERER='/i_should_not_be_used/')
        self.assertRedirects(response, '/')
        self.assertEqual(self.client.session[LANGUAGE_SESSION_KEY], lang_code)
        lang_code = self._get_inactive_language_code()
        post_data = dict(language=lang_code, next='/')
        response = self.client.post('/i18n/setlang/', post_data, HTTP_REFERER='/i_should_not_be_used/')
        self.assertRedirects(response, '/')
        self.assertEqual(self.client.session[LANGUAGE_SESSION_KEY], lang_code)
        lang_code = self._get_inactive_language_code()
        post_data = dict(language=lang_code, next='/')
        response = self.client.post('/i18n/setlang/', post_data, HTTP_REFERER='/i_should_not_be_used/')
        self.assertRedirects(response, '/')
        self.assertEqual(self.client.session[LANGUAGE_SESSION_KEY], lang_code)
        lang_code = self._get_inactive_language_code()
        post_data = dict(language=lang_code, next='/')
        response = self.client.post('/i18n/setlang/', post_data, HTTP_REFERER='/i_should_not_be_used/')
        self.assertRedirects(response, '/')
        self.assertEqual(self.client.session[LANGUAGE_SESSION_KEY], lang_code)
        lang_code = self._get_inactive_language_code()
        post_data = dict(language=lang_code, next='/')
        response = self.client.post('/i18n/setlang/', post_data, HTTP_REFERER='/i_should_not_be_used/')
        self.assertRedirects(response, '/')
        self.assertEqual(self.client.session[LANGUAGE_SESSION_KEY], lang_code)
  
      def test_setlang_unsafe_next(self):
          """
          The set_language view only redirects to the 'next' argument if it is
          "safe".
keep keep keep keep replace replace replace replace replace keep keep keep keep keep
 Fixed #21446 -- Allowed not performing redirect in set_language view

Thanks Claude Paroz and Tim Graham for polishing the patch. 
tests/view_tests/tests/test_i18n.py