'Set language for the current user'

def process_request(self, request):

    lang = getattr(settings, 'HARDTREE_LANGUAGES_DEFAULT', 'en')
    if request.user.username:
        try:
            user = request.user.profile
            conf = ModuleSetting.get('language', user=user)[0]
            lang = conf.value
        except IndexError:
            pass
        except AttributeError:
            pass
    else:
        try:
            conf = ModuleSetting.get('language', user__isnull=True, strict=True)[0]
            lang = conf.value
        except IndexError:
            pass
    lang = to_language(lang)
    request.session['django_language'] = lang
