Sha256: bf4b00751d936486424e0519312d75b4dda37ff62f5a81898277f38338adc02a

Contents?: true

Size: 786 Bytes

Versions: 21

Compression:

Stored size: 786 Bytes

Contents

# frozen_string_literal: true

require "active_support/concern"

module Decidim
  # A module to be included in mailers that changes the default behaviour so
  # the emails are rendered in the user's locale instead of the default one.
  module LocalisedMailer
    extend ActiveSupport::Concern

    included do
      # Yields with the I18n locale changed to the user's one.
      #
      # Returns nothing.
      def with_user(user)
        I18n.with_locale(user.locale || user.organization.default_locale) do
          yield
        end
      end

      # Overwrite default devise_mail method to always render the email with
      # the user's locale.
      def devise_mail(record, action, opts = {})
        with_user(record) do
          super
        end
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
decidim-core-0.23.6 app/mailers/concerns/decidim/localised_mailer.rb
decidim-core-0.23.5 app/mailers/concerns/decidim/localised_mailer.rb
decidim-core-0.24.0.rc2 app/mailers/concerns/decidim/localised_mailer.rb
decidim-core-0.23.4 app/mailers/concerns/decidim/localised_mailer.rb
decidim-core-0.24.0.rc1 app/mailers/concerns/decidim/localised_mailer.rb
decidim-core-0.23.3 app/mailers/concerns/decidim/localised_mailer.rb
decidim-core-0.23.2 app/mailers/concerns/decidim/localised_mailer.rb
decidim-core-0.23.1 app/mailers/concerns/decidim/localised_mailer.rb
decidim-core-0.23.1.rc1 app/mailers/concerns/decidim/localised_mailer.rb
decidim-core-0.23.0 app/mailers/concerns/decidim/localised_mailer.rb
decidim-core-0.22.0 app/mailers/concerns/decidim/localised_mailer.rb
decidim-core-0.21.0 app/mailers/concerns/decidim/localised_mailer.rb
decidim-core-0.20.1 app/mailers/concerns/decidim/localised_mailer.rb
decidim-core-0.20.0 app/mailers/concerns/decidim/localised_mailer.rb
decidim-core-0.19.1 app/mailers/concerns/decidim/localised_mailer.rb
decidim-core-0.18.1 app/mailers/concerns/decidim/localised_mailer.rb
decidim-core-0.19.0 app/mailers/concerns/decidim/localised_mailer.rb
decidim-core-0.17.2 app/mailers/concerns/decidim/localised_mailer.rb
decidim-core-0.18.0 app/mailers/concerns/decidim/localised_mailer.rb
decidim-core-0.17.1 app/mailers/concerns/decidim/localised_mailer.rb