I'm using flask, pybabel for i18n. Sometimes I need to send emails to my users. And I want to send email in their own language. Language code stores in databases so the problem is to translate template with right language. Here is part of my sending function:
lang = user.get_lang()
subject = _('Subject')
for user in users:
if user.email:
body = render_template('emails/template.eml', user=user)
recipients = [user.email]
msg = Message(subject, html=body, recipients=recipients)
conn.send(msg)
And example of template:
{{ _('Hi {name}. How are you?').format(user.name) }}
All I need is something like set_langauge(lang)
which I can call before each template render. How can I do it?
Thanks.