【发布时间】:2012-01-07 09:04:38
【问题描述】:
我正在使用 Ruby on Rails 3.1,我想知道如何正确处理与邮件程序相关的国际化。也就是……
...在我的app/views/users/mailer/_custom.html.erb 文件中:
...
<%= @test_email.to_s %>
...
...在我的app/mailers/users/mailer.rb 文件中:
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
通过使用上面的代码,@test_email.to_s 文本不会在发送的电子邮件中显示(它似乎是空白的),I18n gem 似乎没有正确完成应该做的事情。 如何解决问题,以便在“目标”电子邮件正文中正确显示语言环境消息?
更新 @volodymyr
您在答案中发布的代码对我不起作用。我还尝试将以下代码添加到我的 config/locales/defaults/en.yml 文件中:
en:
hello: Test text!!!
Test text!!! 仍然没有显示在发送的电子邮件中(它是空白的)。
【问题讨论】:
-
尝试用引号括起来。例如:你好:“测试文本”
-
@volodymyr - 问题与引号无关...请阅读答案下方的评论以获取更多信息。
标签: ruby-on-rails ruby ruby-on-rails-3 email internationalization