Thursday, July 1, 2010

Translation problem

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

--
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 django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment