diff options
author | David Lord <davidism@gmail.com> | 2021-12-26 11:29:39 -0700 |
---|---|---|
committer | David Lord <davidism@gmail.com> | 2021-12-26 11:51:54 -0700 |
commit | b6f50df85b7b26f7e79d26b455db9b55d2a21d0c (patch) | |
tree | 9cef366d29b3435e20fc78941cbab8acdea94d96 /tests | |
parent | 896a62135bcc151f2997e028c5125bec2cb2431f (diff) | |
download | jinja2-b6f50df85b7b26f7e79d26b455db9b55d2a21d0c.tar.gz |
specify context for translation block
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_ext.py | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/tests/test_ext.py b/tests/test_ext.py index b54e905..2e842e0 100644 --- a/tests/test_ext.py +++ b/tests/test_ext.py @@ -43,6 +43,9 @@ newstyle_i18n_templates = { "pgettext.html": '{{ pgettext("fruit", "Apple") }}', "npgettext.html": '{{ npgettext("fruit", "%(num)s apple", "%(num)s apples",' " apples) }}", + "pgettext_block": "{% trans 'fruit' num=apples %}Apple{% endtrans %}", + "npgettext_block": "{% trans 'fruit' num=apples %}{{ num }} apple" + "{% pluralize %}{{ num }} apples{% endtrans %}", "transvars1.html": "{% trans %}User: {{ num }}{% endtrans %}", "transvars2.html": "{% trans num=count %}User: {{ num }}{% endtrans %}", "transvars3.html": "{% trans count=num %}User: {{ count }}{% endtrans %}", @@ -593,11 +596,20 @@ class TestNewstyleInternationalization: tmpl = newstyle_i18n_env.get_template("pgettext.html") assert tmpl.render(LANGUAGE="de") == "Apple" - def test_context_newstyle_plural(self): + def test_context_plural(self): tmpl = newstyle_i18n_env.get_template("npgettext.html") assert tmpl.render(LANGUAGE="de", apples=1) == "1 Apple" assert tmpl.render(LANGUAGE="de", apples=5) == "5 Apples" + def test_context_block(self): + tmpl = newstyle_i18n_env.get_template("pgettext_block") + assert tmpl.render(LANGUAGE="de") == "Apple" + + def test_context_plural_block(self): + tmpl = newstyle_i18n_env.get_template("npgettext_block") + assert tmpl.render(LANGUAGE="de", apples=1) == "1 Apple" + assert tmpl.render(LANGUAGE="de", apples=5) == "5 Apples" + class TestAutoEscape: def test_scoped_setting(self): |