def METHOD_NAME(request, language):
    referer = get_referer(request, default='/')
    # set the new language
    translation.activate(language)
    # get the response, set the cookie and return
    response = HttpResponseRedirect(referer)
    response.set_cookie(settings.LANGUAGE_COOKIE_NAME, language)
    return response