How do I enable the 'trimmed' policy in Jinja2?

Viewed 64

I am trying to enable the trimmed keyword for all {% trans %} blocks in Jinja2. I have added env.policies['ext.i18n.trimmed'] = True (found here: https://jinja.palletsprojects.com/en/3.0.x/api/#policies) in my environment configuration, but nothing happens. In my project I am using Babel with Jinja2 and Django to extract messages.

Here is my environment configuration:

def environment(**options):
     env = Environment(
         **options,
         extensions=[
             'compressor.contrib.jinja2ext.CompressorExtension',
             'jinja2.ext.autoescape',
             'sass_processor.jinja2.ext.SassSrc',
             'jinja2.ext.i18n',
         ]
     }

     env.policies['ext.i18n.trimmed'] = True
     env.install_gettext_callables(gettext=gettext, ngettext=ngettext)

     env.globals.update(globals)
     env.filters.update(filters)
     return env
0 Answers
Related