• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1from jinja2 import Environment
2
3env = Environment(extensions=["jinja2.ext.i18n"])
4env.globals["gettext"] = {"Hello %(user)s!": "Hallo %(user)s!"}.__getitem__
5env.globals["ngettext"] = lambda s, p, n: {
6    "%(count)s user": "%(count)d Benutzer",
7    "%(count)s users": "%(count)d Benutzer",
8}[s if n == 1 else p]
9print(
10    env.from_string(
11        """\
12{% trans %}Hello {{ user }}!{% endtrans %}
13{% trans count=users|count -%}
14{{ count }} user{% pluralize %}{{ count }} users
15{% endtrans %}
16"""
17    ).render(user="someone", users=[1, 2, 3])
18)
19