import jinja2
from werkzeug import script
-env = jinja2.Environment(extensions=['jinja2.ext.i18n', 'jinja2.ext.do'])
+env = jinja2.Environment(extensions=['jinja2.ext.i18n', 'jinja2.ext.do',
+ 'jinja2.ext.loopcontrols'])
def shell_init_func():
def _compile(x):
class ExtensionRegistry(type):
- """Gives the extension a unique identifier."""
+ """Gives the extension an unique identifier."""
def __new__(cls, name, bases, d):
rv = type.__new__(cls, name, bases, d)
dyn_args, dyn_kwargs, lineno=lineno)
+@contextfunction
+def _gettext_alias(context, string):
+ return context.resolve('gettext')(string)
+
+
class InternationalizationExtension(Extension):
"""This extension adds gettext support to Jinja2."""
tags = set(['trans'])
def __init__(self, environment):
Extension.__init__(self, environment)
- environment.globals['_'] = contextfunction(lambda c, x: c['gettext'](x))
+ environment.globals['_'] = _gettext_alias
environment.extend(
install_gettext_translations=self._install,
install_null_translations=self._install_null,
converted into types and postprocessed. For example comments are removed,
integers and floats converted, strings unescaped etc.
"""
- source = unicode(source)
def generate():
for lineno, token, value in self.tokeniter(source, name, filename):
if token in ('comment_begin', 'comment', 'comment_end',
wants. The parser uses the `tokenize` function with returns a
`TokenStream` and postprocessed tokens.
"""
- source = '\n'.join(source.splitlines())
+ source = u'\n'.join(unicode(source).splitlines())
pos = 0
lineno = 1
stack = ['root']