def __init__(self): loaders = {} for resource in ctx.get_implementations(IResourceManager, instances=True): loaders[resource.resource_name] = FileSystemLoader(resource.templates_path) loader = ChoiceLoader([FileSystemLoader(ctx.cfg['templates.path']), PrefixLoader(loaders)]) cache_obj = None if ctx.cfg['templates.use_cache']: if ctx.cfg['templates.use_memcached_cache']: cache_obj = MemcachedBytecodeCache( client=inyoka_cache, timeout=ctx.cfg['caching.timeout'] ) elif ctx.cfg['templates.use_filesystem_cache']: cache_obj = FileSystemBytecodeCache( directory=ctx.cfg['caching.filesystem_cache_path'], ) Environment.__init__(self, loader=loader, extensions=['jinja2.ext.i18n', 'jinja2.ext.do', 'jinja2.ext.with_', 'jinja2.ext.autoescape'], auto_reload=ctx.cfg['templates.auto_reload'], undefined=StrictUndefined, cache_size=-1, bytecode_cache=cache_obj, autoescape=True ) self.globals.update( INYOKA_REVISION=INYOKA_REVISION, PYTHON_VERSION='%d.%d.%d' % sys.version_info[:3], DEBUG=ctx.cfg['debug'], href=href, ) self.filters.update( jsonencode=json.dumps, datetimeformat=l10n.format_datetime, dateformat=l10n.format_date, timeformat=l10n.format_time, timedelta=l10n.timedeltaformat, monthformat=l10n.format_month, dayformatshort=l10n.format_day_short, humanize=l10n.humanize_number, ) self.install_gettext_translations( i18n.get_translations(), newstyle=True )
def _get_translations(self): """Hook our translations into wtforms""" return get_translations()
def reload_environment(sender): get_environment().install_gettext_translations( i18n.get_translations(), newstyle=True )