Skip to content

Adaptation of action mailer to include localisation of templates and the availability of translation methods

License

Notifications You must be signed in to change notification settings

Hermanverschooten/actionmailer_i18n

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

I came across the need to have actionmailer send out localized versions of e-mails, so I made the necessary changes to make this work for me...

I was using version 2.3.2 of Rails.

Herman verschooten


Example:

class Notification < ActionMailer::Base
  def user_created(from, user)
    @locale       = 'en'
    @from         = from
    @recipients   = user.email
    @bcc          = "[email protected]"
    @subject      = t("user_created_email")
    @body[:user]  = user
  end
end

given that a .yml under config/locales/ contains:

:nl
  user_created_email: "Uw nieuwe gebruiker werd aangemaakt!"
:en
  user_created_email: "Your new account was created!"

and

app/views/notification contains:

user_created_en.html.erb

Dear <%= @user.name %>,

Your account has been created.

You can sign in with:

Login: <%= @user.login %>
Password: <%= @user.password %>

Sincerely,

The team

user_created.html.erb

Geachte <%= @user.name %>,

Je account werd aangemaakt.

Je kan vanaf nu aanmelden met volgende gegevens:

Gebruiker: <%= @user.login %>
Paswoord: <%= @user.password %>

Met vriendelijke groeten,

Het Team

Then when the locale is set to 'en' as in the above example,
the recipient will receive the enlish e-mail, all others
will receive the dutch e-mail.


About

Adaptation of action mailer to include localisation of templates and the availability of translation methods

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published