Sha256: 271a388de204d146e42d980c29e86c0232ad25c5e38feeb86409de62fd3f2d46

Contents?: true

Size: 917 Bytes

Versions: 48

Compression:

Stored size: 917 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. It will only
      # yield if the user has an email, thus avoiding sending emails to deleted
      # users.
      #
      # Returns nothing.
      def with_user(user)
        I18n.with_locale(user.locale || user.organization.default_locale) do
          yield if user.email.present?
        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

48 entries across 48 versions & 1 rubygems

Version Path
decidim-core-0.29.1 app/mailers/concerns/decidim/localised_mailer.rb
decidim-core-0.28.4 app/mailers/concerns/decidim/localised_mailer.rb
decidim-core-0.27.9 app/mailers/concerns/decidim/localised_mailer.rb
decidim-core-0.29.0 app/mailers/concerns/decidim/localised_mailer.rb
decidim-core-0.28.3 app/mailers/concerns/decidim/localised_mailer.rb
decidim-core-0.27.8 app/mailers/concerns/decidim/localised_mailer.rb
decidim-core-0.29.0.rc4 app/mailers/concerns/decidim/localised_mailer.rb
decidim-core-0.29.0.rc3 app/mailers/concerns/decidim/localised_mailer.rb
decidim-core-0.29.0.rc2 app/mailers/concerns/decidim/localised_mailer.rb
decidim-core-0.29.0.rc1 app/mailers/concerns/decidim/localised_mailer.rb
decidim-core-0.28.2 app/mailers/concerns/decidim/localised_mailer.rb
decidim-core-0.27.7 app/mailers/concerns/decidim/localised_mailer.rb
decidim-core-0.28.1 app/mailers/concerns/decidim/localised_mailer.rb
decidim-core-0.27.6 app/mailers/concerns/decidim/localised_mailer.rb
decidim-core-0.26.10 app/mailers/concerns/decidim/localised_mailer.rb
decidim-core-0.26.9 app/mailers/concerns/decidim/localised_mailer.rb
decidim-core-0.28.0 app/mailers/concerns/decidim/localised_mailer.rb
decidim-core-0.27.5 app/mailers/concerns/decidim/localised_mailer.rb
decidim-core-0.28.0.rc5 app/mailers/concerns/decidim/localised_mailer.rb
decidim-core-0.28.0.rc4 app/mailers/concerns/decidim/localised_mailer.rb