Problem/Motivation

As of now, the email notifications emails are sent in the current user interface language and not in the default language of the recipient.

As an example, publishing an article with FR user interface language will sent out an email in FR (in case there is a translation).

Proposed resolution

One option would be to use a preferred admin language of the recipient as a default email notification language?

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Comments

mbovan created an issue. See original summary.

mbovan’s picture

Category: Bug report » Task

Not sure if this is a bug...

larowlan’s picture

Status: Active » Postponed (maintainer needs more info)
jibran’s picture

Status: Postponed (maintainer needs more info) » Closed (duplicate)

Yes, it is duplicate.

lendude’s picture

Version: 8.x-1.x-dev » 2.x-dev
Status: Closed (duplicate) » Active

Trying to figure this out now, but this is not the same thing as #3017022: Event subscriber should pass the entity lang code into the queue or #3017273: Recipient Type Email Field does not work for translated content, always uses original language value..

So what we need is that the email that gets send uses the 'Site language' setting of the user that gets the email (which state: 'This account's preferred language for emails.', so adhering to that promise makes sense).

Obviously, that only makes sense for RecipientType plugins that actually load users, so we need a fallback for other RecipientType plugins.

So the setup is as follows:
* Apply #2951261: There is no way to add transaltion for email body. since otherwise this makes little sense (well you get a translated subject so you could do without this)
* Use something like the "roles_with_access" RecipientType that loads users to find the email addresses
* Now we want to send the email in the language specified by that user
* To do that we would need to load the correct template translation in \Drupal\workbench_email\EventSubscriber\WorkbenchTransitionEventSubscriber::onContentModerationTransition before it gets send to the mail
* The RecipientType plugin needs to be aware of the need to only load the users matching the language of the template getting passed

I can sorta see a way to hack this into the module for our use case, but currently don't really see a way to do so in a generic way without some major breaking API changes.

thtas’s picture

StatusFileSize
new2.19 KB

My solution for this was to override the queue processor class with our own.

As it's processing each item, we check if a user exists with that email, then re-load the template in the users preferred language.

It would might be better if the queue items included the user being notified rather than the email address. This would also catch the case of a user changing email addresses before the queue item was processed.

Attached is my override in case anybody else finds it useful.