Possible Duplicate:
Django switching, for a block of code, switch the language so translations are done in one language
Is there an easy way to get Django to switch language for a single template rendering operation?
In my case the user may trigger an event that will require to message a person that is not speaking the same language.
For instance - user is English speaker but invokes an action that messages a Spanish speaking person - thus I need to generate the outgoing content in Spanish language.
I am aware that it is possible by faking the Request and using RequestContext, however I would prefer a shorter/cleaner solution.
Are you looking for something like the following:
from django.utils import translation
language_code = 'xx'
template_body = Template(some_text_var)
translation.activate(language_code)
r = template_body.render(context)
translation.deactivate()
For better code reuse, you can refactor this as a context manager.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With