我们从Python开源项目中,提取了以下22个代码示例,用于说明如何使用babel.support()。
def _get_translations(): """Returns the correct gettext translations. Copy from flask-babel with some modifications. """ ctx = _request_ctx_stack.top if ctx is None: return None # babel should be in extensions for get_locale if 'babel' not in ctx.app.extensions: return None translations = getattr(ctx, 'wtforms_translations', None) if translations is None: dirname = messages_path() translations = support.Translations.load( dirname, [get_locale()], domain='wtforms' ) ctx.wtforms_translations = translations return translations
def get_translations(): """Returns the correct gettext translations that should be used for this request. This will never fail and return a dummy translation object if used outside of the request or if a translation cannot be found. """ ctx = _request_ctx_stack.top if ctx is None: return None translations = getattr(ctx, 'babel_translations', None) if translations is None: dirname = os.path.join(ctx.app.root_path, 'translations') translations = support.Translations.load(dirname, [get_locale()]) ctx.babel_translations = translations return translations