Active
Project:
Workbench Email
Version:
2.x-dev
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
10 Jan 2019 at 17:29 UTC
Updated:
7 Nov 2023 at 01:12 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
mbovan commentedNot sure if this is a bug...
Comment #3
larowlanIs this a duplicate of #3017022: Event subscriber should pass the entity lang code into the queue
Comment #4
jibranYes, it is duplicate.
Comment #5
lendudeTrying 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.
Comment #6
thtas commentedMy 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.