Re: i18n and l10n of templates for emails
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 django-users@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: i18n and l10n of templates for emails
On 8 pro, 18:16, "R. Gorman" <[EMAIL PROTECTED]> wrote: > I ran into the same issue, but different encoding. I found that > adding a special comment line to the beginning of the python file > allowed for the desired encoding (source: 2.2.3 > fromhttp://www.python.org/doc/2.5.2/tut/node4.html). > > Hope that helps, Thanks R, but this has nothing to do with python code character set. It's all about template translations. Regards, Krešimir --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: i18n and l10n of templates for emails
I ran into the same issue, but different encoding. I found that adding a special comment line to the beginning of the python file allowed for the desired encoding (source: 2.2.3 from http://www.python.org/doc/2.5.2/tut/node4.html). Hope that helps, R. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com 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 -~--~~~~--~~--~--~---
i18n and l10n of templates for emails
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? Regards, Krešimir Tonković --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com 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 -~--~~~~--~~--~--~---