-
Notifications
You must be signed in to change notification settings - Fork 21.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ActionMailer::MessageDelivery respects current I18n.locale #20758
ActionMailer::MessageDelivery respects current I18n.locale #20758
Conversation
Can you add a changelog entry for Action Mailer at the top of the file? Otherwise LGTM 😄 |
@kaspth I added the changelog entry, thanks for the review. 👍 |
Great, now you just have to squash your commits down to one 😄 |
When #deliver_now is called all translations within the generated email will be looked up for the current I18n locale. I18n.locale = ‘de’ mail.deliver_now # Generates german email, correct In #enqueue_delivery the locale was not considered and the resulting job uses the default locale. I18n.locale = ‘de’ mail.deliver_later # Generate english email, incorrect In order to achieve a consistent behaviour the current locale is now always passed to `ActionMailer::DeliveryJob`.
15df5e2
to
ca2387e
Compare
@kaspth Right, done. Thanks for the reminder! :) |
Thanks ❤️ |
…spects_i18n_locale ActionMailer::MessageDelivery respects current I18n.locale
@kaspth it seems undesirable (and impractical) to require everyone to drain their AJ queue prior to upgrade... thoughts? |
@matthewd You're right, it'd be a breaking change if there are still mails on the queue. One solution would be to implement a new job class that expects the locale parameter and leave the old one untouched. This way it can still send out the remaining jobs on the queue. It could then safely be removed later. @kaspth What do you think? I'd make a second PR if both of you agree that this is the better solution. |
@kaspth I don't see how. Can't use default parameters because of the splat, can't move it into the optional parameters, because it would still be missing for those jobs that were stored before the update. But maybe this job is the wrong point to implement it in anyway. I wonder if this behaviour shouldn't be part of ActiveJob::Base itself, since all enqueued jobs lose their current locale atm. What do you think? |
@xijo I've reverted this for now, until we figure out a better upgrade path. Sorry for merging too soon, I'm still new at this. |
Fixes #20774
When #deliver_now is called all translations within the
generated email will be looked up for the current I18n
locale.
In #enqueue_delivery the locale was not considered and
the resulting job uses the default locale.
In order to achieve a consistent behaviour the current locale
is now always passed to
ActionMailer::DeliveryJob
.