From: Armin Ronacher Date: Mon, 15 Sep 2008 12:35:01 +0000 (+0200) Subject: Fixed a confusing edge case (thanks apollo13) X-Git-Tag: 2.1~33 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=3213355aef195818c282dabe51dfd5694c26d5f6;p=jinja2.git Fixed a confusing edge case (thanks apollo13) --HG-- branch : trunk --- 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(