【问题标题】:I18n using wrong locale in emails, why?I18n 在电子邮件中使用错误的语言环境,为什么?
【发布时间】:2011-06-01 13:37:21
【问题描述】:

我使用的是 Rails 2.3.6 和 I18n。一切正常,除了 I18n 在发送电子邮件时使用了错误的语言环境。事实上,它使用 en.yml 而不是 it.yml 呈现以下代码,尽管我的默认语言环境是它。

你能帮帮我吗?

class UserMailer < ActionMailer::Base

  default_url_options[:host] = GAME_CONFIG["domain"]

  def password_reset_instructions(user)  
    subject       I18n.translate("email_messages.lost_password.subject")  
    from  "#{GAME_CONFIG["name"]} <no-reply@#{GAME_CONFIG["domain"]}>"
    recipients    user.email  
    sent_on       Time.now  
    body          :edit_password_reset_url => edit_password_reset_url(user.perishable_token)
  end

end

在我的生产服务器中,如果我尝试检查我得到的当前语言环境:

I18n.default_locale
:it
I18n.locale
:it

【问题讨论】:

    标签: ruby-on-rails internationalization actionmailer


    【解决方案1】:

    我发现这是正常行为,我可以修复这个指定 :locale => ":it"

    【讨论】:

    • 请在哪里指定?
    • 每次调用 I18n 方法时。例如 I18n.translate("email_messages.lost_password.subject", :locale => ":it")
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-18
    • 2011-04-15
    • 1970-01-01
    • 1970-01-01
    • 2011-04-02
    • 2020-09-27
    相关资源
    最近更新 更多