Why is solid i18n redirecting back to the previous language?

I am on an old Django version (1.8) and using solid-i18n==1.3.0 to support having the default language like English as / instead of /en.

My problem is that, in production, a page whose sessions is set to Spanish, if you select any other language, redirects twice: first to the selected language and then back to Spanish.

This is the session in Spanish:

>>> from django.contrib.sessions.models import Session as Sess
>>> s = Sess.objects.get(pk='f2l3drtob4ox797ohcwantp4xfrb4r5u')
>>> s.get_decoded()['_language']

And this is the request chain:

enter image description here

The POST body of the selectlang/ request is:


My confusion is about the third request: why is it going back to the /es/edit/xxxxxxxx page?

My i18n settings are as follows:

# SOLID_I18N_DEFAULT_PREFIX_REDIRECT = True  # not working, redirects to "en" back again

And the view the selectlang/ URL points to is a custom one:

def select_language(request):
    Just like `django.views.i18n.set_language` but adds `translation.activate(lang_code)` because of an issue
    with solid_i18n not redirecting to the default language (no path) when selected.
    next = request.POST.get('next', request.GET.get('next'))
    if not is_safe_url(url=next, host=request.get_host()):
        next = request.META.get('HTTP_REFERER')
        if not is_safe_url(url=next, host=request.get_host()):
            next = '/'
    response = http.HttpResponseRedirect(next)
    if request.method == 'POST':
        lang_code = request.POST.get('language', None)
        if lang_code and check_for_language(lang_code):
            if hasattr(request, 'session'):
                request.session[LANGUAGE_SESSION_KEY] = lang_code
                request.session['user_lang'] = lang_code  # to override association default language
                response.set_cookie(_settings.LANGUAGE_COOKIE_NAME, lang_code,
            translation.activate(lang_code)  # added so that it redirects properly to the selected language
    return response

You can find the solid i18n middleware class SolidLocaleMiddleware here, just in case you can't find the source for the 1.3.0.

I haven't been able to debug this locally, where I am able to switch languages correctly and it never fires that second "redirect" back to the original language.

Please refer from comments like "just upgrade your versions already". Not up to me.

Back to Top