On Mon, 2008-12-08 at 07:11 -0800, Kresimir Tonkovic wrote:
> Hi!
> 
> I'm using templetes to generate the HTML body for some reports I send
> daily by email. I do it like this:
> 
>     context = Context()
>     context["some_var"] = some_value
>     ....
> 
>     resp = render_to_string("daily_report.html", context)
> 
>     msg = EmailMultiAlternatives(
>         _(u'Daily report'), _('Please use a html-emabled mail
> reader'),
>         _('[EMAIL PROTECTED]'), ['[EMAIL PROTECTED]'])
>     msg.attach_alternative(resp, "text/html")
>     msg.send()
> 
> The template is i18n-ized and is actually created from a page template
> that works correctly. But these reports are never translated to the
> langauge set in settings.py LANGUAGE_CODE, nor have I found any other
> way to control i18n of this template's rendering. I guess this has to
> do with me using Context instead of RequestContext. Obviously there is
> no request here and thus no RequestContext.
> 
> Any ideas how I could control 18n in this scenario?

Look at what the LocaleMiddleware does for a clue.

The "active" locale, which is stored in the per-thread environment is
what is used when rendering. So it has to be set somehow.

        from django.utils import translation
        
        translation.activate(language)
        
Regards,
Malcolm



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
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/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to