Skip to content
Myr

translate.py

This file

Path

examples/basic/translate.py

18 lines · 544 bytes · Python

Last changed by

Not known.

History of this file

Take it

The walk stopped after 200 commits: lines older than c580dd0 point at it.

update building docs instructions in contributing guide (#1235)sixtyfathomsbefore adoptionc580dd0

lines 1–18why, one step back
1from jinja2 import Environment
23env = 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 }} users15{% endtrans %}16"""17 ).render(user="someone", users=[1, 2, 3])18)