def localeselector ( ) : # if a user is logged in, use the locale from the user settings user = getattr ( g , "user" , None ) if user is not None : locale = getattr ( user , "locale" , None ) if locale : return locale # Otherwise, try to guess the language from the user accept header the browser # transmits.  By default we support en/fr. The best match wins. return request . accept_languages . best_match ( current_app . config [ "BABEL_ACCEPT_LANGUAGES" ] )
python requests browser language accept en
Default locale selector used in abilian applications .
def localeselector():
    """Default locale selector used in abilian applications."""
    # if a user is logged in, use the locale from the user settings
    user = getattr(g, "user", None)
    if user is not None:
        locale = getattr(user, "locale", None)
        if locale:
            return locale

    # Otherwise, try to guess the language from the user accept header the browser
    # transmits.  By default we support en/fr. The best match wins.
    return request.accept_languages.best_match(
        current_app.config["BABEL_ACCEPT_LANGUAGES"]
    )