On Thu, Jul 1, 2010 at 2:33 PM, Daniel Baron <daniel.ba...@ggom.de> wrote: > Hi all, > > I have a problem getting the correct translation using gettext in the > following situation: > > I have a view which calls a custom function to send an email. This functions > takes three arguments > - subject of the email (string) > - the language of the email > - the template to render the content of the email: > > e.g: my_mail(ugettext_lazy('This is the subject'), 'es', 'invitation') > > Now, my_mail looks basically like this: > > def my_mail(subject, lang, tpl): > translation.activate(lang) > content = render_to_string(....) > email = EmailMessage(subject, content, from_addr, to_addr) > email.send() > > Now my problem is, that the content of the email is always sent in the > desired language given by the "lang" variable. While the subject of the > email is always sent in the language of the user calling the view. > > What am I doing wrong? And how can I tell my function to translate the > subject correctly? I thought that is exactly what ugettext_lazy is for, but > obviously I misunderstood the concept. > > Thanks, > Daniel >
I'm guessing my_mail doesn't look exactly like that. ugettext_lazy is translated to a unicode string when certain operations happen on it, one of those must be happening. I have a mail function that looks very similar to that, and it works correctly. Cheers Tom -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.