summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArmin Ronacher <armin.ronacher@active-4.com>2008-09-15 14:35:01 +0200
committerArmin Ronacher <armin.ronacher@active-4.com>2008-09-15 14:35:01 +0200
commit3213355aef195818c282dabe51dfd5694c26d5f6 (patch)
treefdb7445914a223acd11c9e834ef3afcfc33a6a47
parent57c9b6dcf51371c597a92869e7583b169d53d292 (diff)
downloadjinja2-3213355aef195818c282dabe51dfd5694c26d5f6.tar.gz
Fixed a confusing edge case (thanks apollo13)
--HG-- branch : trunk
-rw-r--r--CHANGES8
-rw-r--r--jinja2/compiler.py6
-rw-r--r--jinja2/ext.py11
3 files changed, 18 insertions, 7 deletions
diff --git a/CHANGES b/CHANGES
index eb730f1..14ee198 100644
--- a/CHANGES
+++ b/CHANGES
@@ -18,6 +18,14 @@ Version 2.1
undefined object now instead of raising an index error. This was a bug
caused by eager optimizing.
+- the i18n extension looks up `foo.ugettext` now followed by `foo.gettext`
+ if an translations object is installed. This makes dealing with custom
+ translations classes easier.
+
+- fixed a confusing behavior with conditional extending. loops were partially
+ executed under some conditions even though they were not part of a visible
+ area.
+
Version 2.0
-----------
(codename jinjavitus, released on July 17th 2008)
diff --git a/jinja2/compiler.py b/jinja2/compiler.py
index 6bd9428..c63044a 100644
--- a/jinja2/compiler.py
+++ b/jinja2/compiler.py
@@ -1051,7 +1051,7 @@ class CodeGenerator(NodeVisitor):
def visit_Output(self, node, frame):
# if we have a known extends statement, we don't output anything
- if self.has_known_extends and frame.toplevel:
+ if self.has_known_extends and frame.block is None:
return
if self.environment.finalize:
@@ -1061,11 +1061,11 @@ class CodeGenerator(NodeVisitor):
self.newline(node)
- # if we are in the toplevel scope and there was already an extends
+ # if we are not in a block and there was already an extends
# statement we have to add a check that disables our yield(s) here
# so that they don't appear in the output.
outdent_later = False
- if frame.toplevel and self.extends_so_far != 0:
+ if frame.block is None and self.extends_so_far != 0:
self.writeline('if parent_template is None:')
self.indent()
outdent_later = True
diff --git a/jinja2/ext.py b/jinja2/ext.py
index e140fbc..a666d77 100644
--- a/jinja2/ext.py
+++ b/jinja2/ext.py
@@ -142,10 +142,13 @@ class InternationalizationExtension(Extension):
)
def _install(self, translations):
- self.environment.globals.update(
- gettext=translations.ugettext,
- ngettext=translations.ungettext
- )
+ gettext = getattr(translations, 'ugettext', None)
+ if gettext is None:
+ gettext = translations.gettext
+ ngettext = getattr(translations, 'ungettext', None)
+ if ngettext is None:
+ ngettext = translations.ngettext
+ self.environment.globals.update(gettext=gettext, ngettext=ngettext)
def _install_null(self):
self.environment.globals.update(