Problem:

When using Mimemail templates, themes, preprocess functions to add localized strings into the email then recipient's preferred language is not respected. This is the case when email is being triggered by another user with different language, for example an admin or cron running actions which send emails. The content is translated, but when adding strings in preprocess or templates, the strings are printed in English.

Solution:

Switch global $language to user's preferred language when running the theme function. Then switch it back to the original. Patch attached.

This patch is D6. Not sure if the problem exists in D7.

Comments

sgabe’s picture

StatusFileSize
new2.68 KB

I did some testing with your patch.

  • It seems sometimes(?) Simplenews uses an empty user object as recipient with just the mail set, even when the recipient is a registered user. So we need to cover the scenario when though $recipient is an object but without language and additional settings.
  • Since we need the user object to determine the preferred language, we should try to get it anyway and remove this part of the Plain text only preference checking.

The attached patch seems to work for me but needs some more testing since overwriting the recipients user object may break something.

sgabe’s picture

StatusFileSize
new2.76 KB

Seems safer to check the initial mail address with which the user registered.

richsky’s picture

I feel like there is a problem with mail language in D7 also. Tested with core contact form.

tr’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev
Issue summary: View changes
Status: Needs review » Postponed (maintainer needs more info)

D6 is long past its end-of-life.

But #3 indicates there might be some similar problem in D7.
However, no details are given so I can't confirm.

It's possible this patch can still be useful in D7, but first I need someone to update this issue and try to confirm if the problem still exists on D7. I also need steps to reproduce the problem.