[Feature request][Action Mailer] Add locale support

Instead of wrapping the call to mail in I18n.with_locale inside my mailer methods like this:

  mail to: @user.email

I would like to avoid the wrapping and simply do just this:

mail to: @user.email, locale: @user.locale

or even specify the locale using default like this:

default to: -> { @user.email },  locale: -> { @user.locale }

If you agree this is a good idea, I would be happy to submit a PR.

1 Like

Currently you can simply do the following.

  before_action do
    if params
      @user = params[:user]

  around_action :with_locale_from_user

  def with_locale_from_user(&block)
    I18n.with_locale(current_locale, &block)

And then to use UserMailer.with(user: user).welcome.deliver_later?

But I agree that it would be nice to reduce this boilerplate.

1 Like

I have created a PR here: