python-babel/flask-babel

Translation not changing inside jinja2 array.

thilojaeggi opened this issue · 2 comments

I have the following array for generating my navigation items but when I change the language on my site (by changing the cookie) all the pages translate but the navigation items stay in the previous language.

I assume jinja2 is caching something here?

This is my array:
{% set navigation_bar = [
('user.dash', _('Dash')),
('user.stats', _('Statistics')),
('user.automations', _('Automations')),
] -%}

I'm going to suggest you post on the Jinja tracker. This isn't a flask-babel bug (we're just the glue). You may be able to work around this issue by using our lazy_gettext instead of _, since in theory even if Jinja is caching this set the string should proxy at display time.

How do I use lazy_gettext in Jinja though?
Do I need to add it manually?