当前位置: 首页>>代码示例>>Python>>正文


Python flask_babel.Babel方法代码示例

本文整理汇总了Python中flask_babel.Babel方法的典型用法代码示例。如果您正苦于以下问题:Python flask_babel.Babel方法的具体用法?Python flask_babel.Babel怎么用?Python flask_babel.Babel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在flask_babel的用法示例。


在下文中一共展示了flask_babel.Babel方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init_babel

# 需要导入模块: import flask_babel [as 别名]
# 或者: from flask_babel import Babel [as 别名]
def __init_babel(self):
        self.babel = Babel(self.app)
        # translations = Translations.load('translations')
        # translations.merge(Translations.load())
        # todo: support for multiple plugins
        supported_languages = []
        for supported_lang in self.cfg_engine.get('appkernel.i18n.languages', ['en-US']):
            supported_languages.append(supported_lang)
            if '-' in supported_lang:
                supported_languages.append(supported_lang.split('-')[0])

        def get_current_locale():
            with self.app.app_context():
                best_match = request.accept_languages.best_match(supported_languages, default='en')
                return best_match.replace('-', '_')

        self.babel.localeselector(get_current_locale)
        # catalogs = gettext.find('locale', 'locale', all=True)
        # self.logger.info('Using message catalogs: {}'.format(catalogs)) 
开发者ID:accelero-cloud,项目名称:appkernel,代码行数:21,代码来源:engine.py

示例2: create_app

# 需要导入模块: import flask_babel [as 别名]
# 或者: from flask_babel import Babel [as 别名]
def create_app():
    app = Flask(__name__)
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    from docassemble.base.config import daconfig
    import docassemble.webapp.database
    import docassemble.webapp.db_object
    connect_string = docassemble.webapp.database.connection_string()
    alchemy_connect_string = docassemble.webapp.database.alchemy_connection_string()
    app.config['SQLALCHEMY_DATABASE_URI'] = alchemy_connect_string
    app.secret_key = daconfig.get('secretkey', '38ihfiFehfoU34mcq_4clirglw3g4o87')
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    db = docassemble.webapp.db_object.init_flask()
    db.init_app(app)
    csrf = CSRFProtect()
    csrf.init_app(app)
    babel = Babel()
    babel.init_app(app)
    if daconfig.get('behind https load balancer', False):
        if proxyfix_version >= 15:
            app.wsgi_app = ProxyFix(app.wsgi_app, x_proto=1, x_host=1)
        else:
            app.wsgi_app = ProxyFix(app.wsgi_app)
    if 'cross site domains' in daconfig:
        CORS(app, origins=daconfig['cross site domains'], supports_credentials=True)
    return app, csrf, babel 
开发者ID:jhpyle,项目名称:docassemble,代码行数:27,代码来源:app_object.py

示例3: __init__

# 需要导入模块: import flask_babel [as 别名]
# 或者: from flask_babel import Babel [as 别名]
def __init__(self, import_name: str) -> None:
        shared_web_path = os.path.abspath(os.path.dirname(__file__))
        static_folder = os.path.join(shared_web_path, 'static')
        super().__init__(import_name, static_folder=static_folder)
        super().register_error_handler(DoesNotExistException, self.not_found)
        super().register_error_handler(exceptions.NotFound, self.not_found)
        super().register_error_handler(exceptions.InternalServerError, self.internal_server_error)
        super().route('/unauthorized/')(self.unauthorized)
        super().route('/logout/')(self.logout)
        super().route('/authenticate/')(self.authenticate)
        super().route('/authenticate/callback/')(self.authenticate_callback)
        super().route('/api/gitpull', methods=['POST'])(api.process_github_webhook)
        super().route('/api/commit')(api.commit_id)
        super().route('/robots.txt')(self.robots_txt)
        super().route('/favicon<rest>')(self.favicon)
        self.url_build_error_handlers.append(self.external_url_handler)
        if self.config.get('SERVER_NAME') is None:
            self.config['SERVER_NAME'] = configuration.get_optional_str('flask_server_name')
        self.config['menu'] = []
        self.config['js_url'] = ''
        self.config['css_url'] = ''
        self.config['commit-id'] = subprocess.check_output(['git', 'rev-parse', 'HEAD']).strip().decode()
        self.config['branch'] = subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD']).strip().decode()
        self.config['SESSION_COOKIE_DOMAIN'] = configuration.get_optional_str('flask_cookie_domain')

        translations = os.path.abspath(os.path.join(shared_web_path, 'translations'))
        self.config['BABEL_TRANSLATION_DIRECTORIES'] = translations
        self.babel = Babel(self)
        localization.init(self.babel)
        self.api_root = Blueprint('api', import_name, url_prefix='/api/')
        self.api = Api(self.api_root, title=f'{import_name} API')
        self.register_blueprint(self.api_root) 
开发者ID:PennyDreadfulMTG,项目名称:Penny-Dreadful-Tools,代码行数:34,代码来源:flask_app.py

示例4: init

# 需要导入模块: import flask_babel [as 别名]
# 或者: from flask_babel import Babel [as 别名]
def init(babel: Babel) -> None:
    LANGUAGES.extend([str(locale) for locale in babel.list_translations()])
    babel.localeselector(get_locale) 
开发者ID:PennyDreadfulMTG,项目名称:Penny-Dreadful-Tools,代码行数:5,代码来源:localization.py

示例5: configure_coverage

# 需要导入模块: import flask_babel [as 别名]
# 或者: from flask_babel import Babel [as 别名]
def configure_coverage(app):
    """Setup coverage related extensions."""
    # setup chanjo report
    app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = True if app.debug else False
    if chanjo_api:
        chanjo_api.init_app(app)
        configure_template_filters(app)
        # register chanjo report blueprint
        app.register_blueprint(report_bp, url_prefix="/reports")

    babel = Babel(app)

    @babel.localeselector
    def get_locale():
        """Determine locale to use for translations."""
        accept_languages = current_app.config.get("ACCEPT_LANGUAGES", ["en"])

        # first check request args
        session_language = request.args.get("lang")
        if session_language in accept_languages:
            current_app.logger.info("using session language: %s", session_language)
            return session_language

        # language can be forced in config
        user_language = current_app.config.get("REPORT_LANGUAGE")
        if user_language:
            return user_language

        # try to guess the language from the user accept header that
        # the browser transmits.  We support de/fr/en in this example.
        # The best match wins.
        return request.accept_languages.best_match(accept_languages) 
开发者ID:Clinical-Genomics,项目名称:scout,代码行数:34,代码来源:app.py

示例6: init

# 需要导入模块: import flask_babel [as 别名]
# 或者: from flask_babel import Babel [as 别名]
def init():
        # Do init once
        app = Flask(__name__)

        # Read and override configs
        app.config.from_pyfile('config_main.py')
        app.config.from_pyfile('../instance/config_site.py')
        app.config.from_envvar('GHC_SETTINGS', silent=True)

        # Global Logging config
        logging.basicConfig(level=int(app.config['GHC_LOG_LEVEL']),
                            format=app.config['GHC_LOG_FORMAT'])

        app.config['GHC_SITE_URL'] = \
            app.config['GHC_SITE_URL'].rstrip('/')

        app.secret_key = app.config['SECRET_KEY']

        App.db_instance = SQLAlchemy(app)
        App.babel_instance = Babel(app)

        # Plugins (via Docker ENV) must be list, but may have been
        # specified as comma-separated string, or older set notation
        app.config['GHC_PLUGINS'] = to_list(app.config['GHC_PLUGINS'])
        app.config['GHC_USER_PLUGINS'] = \
            to_list(app.config['GHC_USER_PLUGINS'])

        # Concatenate core- and user-Plugins
        App.plugins_instance = \
            app.config['GHC_PLUGINS'] + app.config['GHC_USER_PLUGINS']

        # Needed to find Plugins
        home_dir = os.path.dirname(os.path.abspath(__file__))
        App.home_dir = sys.path.append('%s/..' % home_dir)

        # Finally assign app-instance
        App.app_instance = app
        App.count += 1
        LOGGER.info("created GHC App instance #%d" % App.count) 
开发者ID:geopython,项目名称:GeoHealthCheck,代码行数:41,代码来源:init.py


注:本文中的flask_babel.Babel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。