some documentation updates
--HG--
branch : trunk
diff --git a/jinja2/environment.py b/jinja2/environment.py
index 92ab578..23e77b6 100644
--- a/jinja2/environment.py
+++ b/jinja2/environment.py
@@ -112,7 +112,8 @@
`extensions`
List of Jinja extensions to use. This can either be import paths
- as strings or extension classes.
+ as strings or extension classes. For more information have a
+ look at :ref:`the extensions documentation <jinja-extensions>`.
`optimized`
should the optimizer be enabled? Default is `True`.
@@ -282,6 +283,9 @@
tree of nodes is used by the compiler to convert the template into
executable source- or bytecode. This is useful for debugging or to
extract information from templates.
+
+ If you are :ref:`developing Jinja2 extensions <writing-extensions>`
+ this gives you a good overview of the node tree generated.
"""
try:
return Parser(self, source, filename).parse()
diff --git a/jinja2/ext.py b/jinja2/ext.py
index c35a9c2..5d2251d 100644
--- a/jinja2/ext.py
+++ b/jinja2/ext.py
@@ -15,7 +15,7 @@
from jinja2.environment import get_spontaneous_environment
from jinja2.runtime import Undefined, concat
from jinja2.exceptions import TemplateAssertionError, TemplateSyntaxError
-from jinja2.utils import import_string, Markup
+from jinja2.utils import contextfunction, import_string, Markup
# the only real useful gettext functions for a Jinja template. Note
@@ -74,14 +74,14 @@
)
-class TransExtension(Extension):
+class InternationalizationExtension(Extension):
"""This extension adds gettext support to Jinja."""
tags = set(['trans'])
def __init__(self, environment):
Extension.__init__(self, environment)
environment.globals.update({
- '_': lambda x: x,
+ '_': contextfunction(lambda c, x: c['gettext'](x)),
'gettext': lambda x: x,
'ngettext': lambda s, p, n: (s, p)[n != 1]
})
@@ -284,11 +284,11 @@
if not extension:
continue
extension = import_string(extension)
- if extension is TransExtension:
+ if extension is InternationalizationExtension:
have_trans_extension = True
extensions.append(extension)
if not have_trans_extension:
- extensions.append(TransExtension)
+ extensions.append(InternationalizationExtension)
environment = get_spontaneous_environment(
options.get('block_start_string', '{%'),
@@ -310,3 +310,8 @@
node = environment.parse(fileobj.read().decode(encoding))
for lineno, func, message in extract_from_ast(node, keywords):
yield lineno, func, message, []
+
+
+#: nicer import names
+i18n = InternationalizationExtension
+cache = CacheExtension