You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ _('Accessing a global variable works: (some_global_var)%s') }}
{% for x in [1, 2, 3] %}
{% _('Accessing a local variable does not: (x)%s' %}
{% endfor %}
In my_gettext, I can access some_global_var via context, but I have no way of accessing the local variable x. I could do this:
{% _('Accessing a local variable does not: (x)%s', x=x %}
...and then access x via kwargs, but I would prefer not to, as in a real template this would introduce a lot of redundancy (especially if global variable access is also done this way).
My goal is to continue to implement the gettext API so that I can use tools like extraction, but I want template authors to be able to refer to variables without passing them in, as this adds verbosity and an opportunity for template author error. Are there any good solutions here?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello!
I'm writing a
gettext
wrapper for various reasons. My wrapper function is defined on the template globals like so:The jinja template looks like this:
In
my_gettext
, I can accesssome_global_var
viacontext
, but I have no way of accessing the local variablex
. I could do this:...and then access
x
viakwargs
, but I would prefer not to, as in a real template this would introduce a lot of redundancy (especially if global variable access is also done this way).My goal is to continue to implement the
gettext
API so that I can use tools like extraction, but I want template authors to be able to refer to variables without passing them in, as this adds verbosity and an opportunity for template author error. Are there any good solutions here?Thank you!
Beta Was this translation helpful? Give feedback.
All reactions