Skip to content
Myr

translate.py

This file

Path

examples/basic/translate.py

14 lines · 524 bytes · Python

Last changed by

Not known.

History of this file

Take it

1from jinja2 import Environment23env = Environment(extensions=['jinja2.ext.i18n'])4env.globals['gettext'] = {5    'Hello %(user)s!': 'Hallo %(user)s!'6}.__getitem__7env.globals['ngettext'] = lambda s, p, n: {8    '%(count)s user': '%(count)d Benutzer',9    '%(count)s users': '%(count)d Benutzer'10}[n == 1 and s or p]11print env.from_string("""\12{% trans %}Hello {{ user }}!{% endtrans %}13{% trans count=users|count %}{{ count }} user{% pluralize %}{{ count }} users{% endtrans %}14""").render(user="someone", users=[1, 2, 3])