I am using Ruby on Rails 3.1 and I would like to know how to correctly handle internationalization related to the mailer. That is, …
… in my app/views/users/mailer/_custom.html.erb file I have:
...
<%= @test_email.to_s %>
...
… in my app/mailers/users/mailer.rb file I have:
class Users::Mailer < ActionMailer::Base
def custom(user)
...
@test_email = t('test_email')
# I also tried to use '@test_email = I18n.t('test_email')'
end
end
By using the above code the @test_email.to_s text is not displayed (it seems to be blank) in the sent email and the I18n gem seems don’t accomplish correctly what should be done. How can I solve the problem so to properly display the locale message in the “aimed” email body?
UPDATE for @volodymyr
The code you posted in your answer doesn’t work for me. I tried also to add the following code to my config/locales/defaults/en.yml file:
en:
hello: Test text!!!
The Test text!!! is still not displayed in the sent email (it is blank).
Here is example of working code(I`m using Rails 3.1.0 and ruby 1.9.3p0 (2011-10-30 revision 33570)):
For testing I used Rails console:
So you need to check if:
UPDATE: Try to enclose string with quotes in localization file: