Skip to content
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

Conversation

xijo
Copy link
Contributor

@xijo xijo commented Jul 2, 2015

Fixes #20774

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.

@kaspth
Copy link
Contributor

kaspth commented Jul 4, 2015

Can you add a changelog entry for Action Mailer at the top of the file? Otherwise LGTM 😄

@xijo
Copy link
Contributor Author

xijo commented Jul 5, 2015

@kaspth I added the changelog entry, thanks for the review. 👍

@kaspth
Copy link
Contributor

kaspth commented Jul 5, 2015

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`.
@xijo xijo force-pushed the action_mailer_message_delivery_respects_i18n_locale branch from 15df5e2 to ca2387e Compare July 5, 2015 18:22
@xijo
Copy link
Contributor Author

xijo commented Jul 5, 2015

@kaspth Right, done. Thanks for the reminder! :)

@kaspth
Copy link
Contributor

kaspth commented Jul 5, 2015

Thanks ❤️

kaspth added a commit that referenced this pull request Jul 5, 2015
…spects_i18n_locale

ActionMailer::MessageDelivery respects current I18n.locale
@kaspth kaspth merged commit f2a8c23 into rails:master Jul 5, 2015
@matthewd
Copy link
Member

matthewd commented Jul 6, 2015

@kaspth it seems undesirable (and impractical) to require everyone to drain their AJ queue prior to upgrade... thoughts?

@xijo
Copy link
Contributor Author

xijo commented Jul 6, 2015

@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
Copy link
Contributor

kaspth commented Jul 6, 2015

@matthewd nice catch, I missed that.

@xijo can we extend the existing class to be more resilient i.e. don't break if the locale isn't there?

@xijo
Copy link
Contributor Author

xijo commented Jul 6, 2015

@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?

kaspth added a commit to kaspth/rails that referenced this pull request Jul 7, 2015
…e_delivery_respects_i18n_locale"

This reverts commit f2a8c23, reversing
changes made to 3046c9b.
@kaspth
Copy link
Contributor

kaspth commented Jul 7, 2015

@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.
Though I'm confident we'll figure this out ❤️

@xijo
Copy link
Contributor Author

xijo commented Jul 7, 2015

@kaspth Thanks for reverting. 👍
I created a new PR #20800 to fix this issue inside of ActiveJob itself. Would you take a look at it?

@matthewd Thanks again for pointing the compatibility issue out. I think in #20800 I found a good way to work around it and I'd love to hear your opinion as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants