我用Flask Appbuilder编写了一个简单的应用程序,view.py
如下所示。它是http://flask-appbuilder.readthedocs.io/en/latest/views.html中exmaple的一部分,在method1
中我用我想找到的函数替换了{
我们可以在app(en,fr,ru,…)中更改语言并进行翻译。是否有一个获取当前语言的函数?(当前的_Language())。在
from flask_appbuilder import AppBuilder, BaseView, expose, has_access, ModelView
from app import appbuilder, db
from flask import render_template, g
from flask_babel import Babel
from flask_babel import lazy_gettext as _
from flask_appbuilder.models.sqla.interface import SQLAInterface
class MyView(BaseView):
default_view = 'method1'
@expose('/method1/')
@has_access
def method1(self):
return Current_Language()
appbuilder.add_view(MyView, "Method1", category='My View')
你的问题有点模棱两可。你指的是当前的服务器端语言还是客户端语言。在
前者:
后者:
^{pr2}$您感兴趣的标题是
Accept-Language
。但是当涉及到以这种方式推断客户机语言时,也有一些警告。见https://www.w3.org/International/questions/qa-accept-lang-localesappbuilder
实例有一个bm
属性,它是BabelManager
类的一个实例。在这个类有一个
get_locale
方法,它返回应用程序使用的当前语言。在您可以检查project repository.上的
BabelManager
类的代码相关问题 更多 >
编程相关推荐