def babel_localeselector(): if hasattr(g, 'current_locale'): return g.current_locale elif request.cookies.get('locale') is not None: return request.cookies.get('locale') elif current_user is not None: return current_user.get_locale() return request.accept_languages.best_match(locales.keys())