How can I send emails in Rails 3 using the recipient's locale?

后端 未结 7 1806
说谎
说谎 2021-02-03 23:44

How can I send mails in a mailer using the recipient\'s locale. I have the preferred locale for each user in the database. Notice this is different from the current locale (I18n

7条回答
  •  北荒
    北荒 (楼主)
    2021-02-04 00:01

    This simple plugin was developed for rails 2 but seems to work in rails 3 too.

    http://github.com/Bertg/i18n_action_mailer

    With it you can do the following:

    def new_follower(user, follower)
      @follower = follower
      @user = user
      set_locale user.locale
      mail :to => @user.email, :subject => t(:new_follower_subject)
    end
    

    The subject and mail templates are then translated using the user's locale.

提交回复
热议问题