background: The view is called when a payment service pings back a payment outcome behind the scenes - afterwhich I need to send an email in the right langu
If just want to get the translated strings for a language for whatever reason, you can use override as a decorator like this:
from django.utils import translation
from django.utils.translation import ugettext as _
with translation.override(language):
welcome = _('welcome')
If you are using django 1.10 or higher, there's a new syntax for custom middleware:
from django.utils import translation
class LocaleMiddleware(object):
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
language_code = 'en' #TODO, your logic
translation.activate(language_code)
response = self.get_response(request)
translation.deactivate()
return response