我已经设置了 Flask + Babel + Flask Security。
像这样创建所有翻译:
在 main.py 中,有一部分设置语言执行:
@babel.localeselector
def get_locale():
user = getattr(g, 'user', None)
if user is not None:
print("User locale {}".format(user.locale))
return user.locale
# I put here constant to test
return 'ru'
But http://localhost/登录 http://localhost/login保持未翻译。您能建议一下还有哪里可以挖吗?即使使用,日志中也没有错误调试=真
我发现Flask-安全不支持 Babel 开箱即用!这个 Pull Request 部分修复了它 https://github.com/mattupstate/flask-security/pull/520从 WTF 处理的角度来看。
为了能够翻译 Jinja2 模板,还需要修改以下内容core.py
def render_template(self, *args, **kwargs):
# Provide i18n support even if flask-babel is not installed
# or enabled.
kwargs['gettext'] = gettext
kwargs['ngettext'] = ngettext
kwargs['_'] = _
return render_template(*args, **kwargs)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)