Is there a preferred way to make a Flask application multilingual? Ideally, the solution would enable to @app.route
the same view to use different urls for each languages, like @app.route(en='/staff/', fr='/equipe/)
. I'm pretty confident I could hack something like that together, but an existing library would sure save me some time. Thanks.
问问题
12499 次
2 回答
24
我相信Flask-Babel就是你要找的。
于 2010-08-06T20:34:03.077 回答
1
您可以通过创建一个决定使用哪个路由的装饰器来实现这一点。
def lang_route(en, fr, *args, **kwargs):
# Find out the user's language
lang = "en"
if lang == "en":
return app.route(en, *args, **kwargs)
if lang == "fr":
return app.route(fr, *args, **kwargs)
@lang_route(en="/staff", fr="/equipe")
def staff():
return "staff"
于 2020-09-24T17:35:16.160 回答