Hi,
I've developed a custom i18n system based on the following filter:
@contextfilter
def render(context, value):
"""
Renders the filtered value as a string template, using the context and
environment of the caller template.
"""
mini_template = _environment.from_string(value)
return mini_template.render(context)
This allows me, for example, to create the following context:
context = {
'user': {
'name': 'Joel',
'locale': 'es'
}
'greetings': {
'en': 'Hi {{user.name}}!',
'es': '¡Hola {{user.name}}!'
}
}
And use it like this in my templates:
{{ greetings[user.locale]|render() }}
That works perfectly.
Now imagine that I've an array of users. I was doing the following in
Django Templates, but it doesn't work in Jinja because the variable 'user'
is not in the context:
{% for user in list_of_users %}
{{ greeting[user.locale]|render() }}
{% endfor %}
Is there anything I could do to get that variable's value at the
contextfilter? I've thousands of translation strings, so I would do
anything to avoid touching them.
Thank you very much for your help.
--
You received this message because you are subscribed to the Google Groups
"pocoo-libs" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/pocoo-libs/-/GHFs5FRQ5H8J.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/pocoo-libs?hl=en.