@babel.localeselector def get_locale(): # if a user is logged in, use the locale from the user settings user = getattr(g, 'user', None) if user is not None and hasattr(user, 'locale'): print "get_locale: user.locale %s" % user.locale return user.locale # otherwise try to guess the language from the user accept header # we support en/da/de print "get_locale: request.accept_languages.best_match: %s" % (request.accept_languages.best_match(LANGUAGES.keys())) return request.accept_languages.best_match(LANGUAGES.keys())