I am using Ruby on Rails 3.1.1 and I am trying to translate email messages body. I created/stated all necessary "things" (YAML files, key/value pairs, ...) to make the I18n gem to work: email messages are sent without problems using the default language (:en
).
Then I added a new language and made all that had to be done to make the I18n gem to work with another language and to get always a locale=de
parameter in URLs.
class ApplicationController < ActionController::Base
before_filter :set_locale
def set_locale
if params[:locale] && I18n.available_locales.include?(params[:locale].to_sym)
I18n.locale = params[:locale]
end
end
...
end
However when I sent an email, even if the locale is properly set (eg: locale=de
), sent email message are not translated (those still use the default :en
language).
How can I make the I18n to translate email messages body?
- I read the Localized ActionMailer Templates for Rails blog post but it is old and I have not tested that...
- I read the Rails I18n and emails blog post and I tested that. It works, but how can handle translation in my case (I am using the
params
method...)? Is there a better solution?