Skip to content
Myr

Fixed a bug in the i18n extension that caused the explicit pluralization block to look up the wrong variable.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

--HG-- branch : trunk

authored by Armin Ronacher · committed by Armin Ronacher · parent ce67710 · Browse files · 3 files+26 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+26 added−1 removed

  • tests:+10 added−0 removed
  • other:+16 added−1 removed

3 files+26 added−1 removed

modified:jinja2/ext.py+13 added-1 removed
122 unmodified lines
123class InternationalizationExtension(Extension):124 """This extension adds gettext support to Jinja2."""125 tags = set(['trans'])126127 # TODO: the i18n extension is currently reevaluating values in a few128 # situations. Take this example:129 # {% trans count=something() %}{{ count }} foo{% pluralize130 # %}{{ count }} fooss{% endtrans %}131 # something is called twice here. One time for the gettext value and132 # the other time for the n-parameter of the ngettext function.133134 def __init__(self, environment):135 Extension.__init__(self, environment)136 environment.globals['_'] = _gettext_alias137 environment.extend(
73 unmodified lines
211 if parser.stream.current.test('name:pluralize'):212 have_plural = True213 parser.stream.next()214 if parser.stream.current.type is not 'block_end':208 plural_expr = parser.parse_expression()215 name = parser.stream.expect('name')216 if name.value not in variables:217 parser.fail('unknown variable %r for pluralization' %218 name.value, name.lineno,219 exc=TemplateAssertionError)220 plural_expr = variables[name.value]221 parser.stream.expect('block_end')222 plural_names, plural = self._parse_block(parser, False)223 parser.stream.next()224 referenced.update(plural_names)
228 unmodified lines
modified:tests/test_i18n.py+10 added
4 unmodified lines
56 :copyright: 2007 by Armin Ronacher.7 :license: BSD, see LICENSE for more details.8"""9from py.test import raises10from jinja2 import Environment, DictLoader, contextfunction11from jinja2.exceptions import TemplateAssertionError1213templates = {14 'master.html': '<title>{{ page_title|default(_("missing")) }}</title>'15 '{% block body %}{% endblock %}',
51 unmodified lines
67 assert tmpl.render(LANGUAGE='de', user_count=1) == 'Ein Benutzer online'68 assert tmpl.render(LANGUAGE='de', user_count=2) == '2 Benutzer online'697071def test_complex_plural():72 tmpl = i18n_env.from_string('{% trans foo=42, count=2 %}{{ count }} item{% '73 'pluralize count %}{{ count }} items{% endtrans %}')74 assert tmpl.render() == '2 items'75 raises(TemplateAssertionError, i18n_env.from_string,76 '{% trans foo %}...{% pluralize bar %}...{% endtrans %}')777879def test_trans_stringformatting():80 tmpl = i18n_env.get_template('stringformat.html')81 assert tmpl.render(LANGUAGE='de', user_count=5) == 'Benutzer: 5'82
14 unmodified lines
modified:CHANGES+3 added
7 unmodified lines
8- fixed a bug with nested loops and the special loop variable. Before the9 change an inner loop overwrote the loop variable from the outer one after10 iteration.1112- fixed a bug with the i18n extension that caused the explicit pluralization13 block to look up the wrong variable.1415Version 2.016-----------17(codename jinjavitus, released on July 17th 2008)18
32 unmodified lines