def translation_set_language(
    request: HttpRequest, select_language: str
) -> Optional[HttpResponseRedirect]:
    """
    Set and activate a language, if that language is available.
    """

    select_language = translation_allowed_language(select_language)

    if translation.check_for_language(select_language):
        fallback = False
    else:
        # The page is in a language that Django has no messages for.
        # We display anyhow, but fall back to primary language for
        # other messages and other applications. It is *highly* recommended to
        # create a new django.po for the language instead of
        # using this behaviour.
        select_language = PRIMARY_LANGUAGE
        fallback = True

    translation.activate(select_language)
    request.LANGUAGE_CODE = translation.get_language()  # type: ignore

    if hasattr(request, "session"):
        # User has a session, then set this language there
        current_session_language = request.session.get(
            LANGUAGE_SESSION_KEY, PRIMARY_LANGUAGE
        )

        if select_language != current_session_language:
            request.session[LANGUAGE_SESSION_KEY] = select_language
    elif request.method == "GET" and not fallback:
        # No session is active. We need to set a cookie for the language
        # so that it persists when users change their location to somewhere
        # not under the control of the CMS.
        # Only do this when request method is GET (mainly, do not abort
        # POST requests)
        response = HttpResponseRedirect(request.get_full_path())
        response.set_cookie(str(LANGUAGE_COOKIE_NAME), select_language, samesite="Lax")
        return response

    Set and activate a language, if that language is available.
    
feincms/extensions/translations.py