i18n change #14

Closed
wants to merge 3 commits into
from
Jump to file or symbol
Failed to load files and symbols.
+8 −2
Split
View
@@ -9,6 +9,7 @@
from pyramid.exceptions import ConfigurationError
from pyramid.resource import abspath_from_resource_spec
+from pyramid.i18n import get_localizer
class IJinja2Environment(Interface):
pass
@@ -51,6 +52,7 @@ def parse_extensions(extensions):
extensions = splitlines(extensions)
return [ maybe_import_string(x) for x in extensions ]
+
def renderer_factory(info):
registry = info.registry
settings = info.settings
@@ -78,14 +80,15 @@ def renderer_factory(info):
extensions=extensions)
environment.filters.update(filters)
registry.registerUtility(environment, IJinja2Environment)
- return Jinja2TemplateRenderer(info, environment)
+ return Jinja2TemplateRenderer(info, environment, 'jinja2.ext.i18n' in settings.get('jinja2.extensions',''))
class Jinja2TemplateRenderer(object):
implements(ITemplateRenderer)
template = None
- def __init__(self, info, environment):
+ def __init__(self, info, environment, i18n_enabled=False):
self.info = info
self.environment = environment
+ self.jinja2_i18n_ext = i18n_enabled
def implementation(self):
return self.template
@@ -99,6 +102,9 @@ def __call__(self, value, system):
system.update(value)
except (TypeError, ValueError):
raise ValueError('renderer was passed non-dictionary as value')
+ if self.jinja2_i18n_ext:
+ localizer = get_localizer(system['request'])
+ self.environment.install_gettext_translations(localizer.translations, newstyle=True)
result = self.template.render(system)
return result