如何在rails中翻译默认错误消息?

时间:2012-01-21 02:45:29

标签: ruby-on-rails

当我尝试更改translation.yml文件中的error_messages_for消息时,这对我不起作用:

activerecord:
 errors:
  template:
    header:
      one:   "Oops error"
      other: "Many errors"
    body:    "There were problems:"

我该怎么做才能翻译“1错误禁止此产品被保存:”?什么文件包含他们的文字?

1 个答案:

答案 0 :(得分:1)

如果您使用的是Rails 2.x,我相信您只需要activerecord:部分。问题可能是你的顶级水平不是一种语言。从Rails 3.x开始(现在使用单独的dynamic_form插件处理此问题),默认值为:

en:
  errors:
    template:
      header:
        one:    "1 error prohibited this %{model} from being saved"
        other:  "%{count} errors prohibited this %{model} from being saved"
      # The variable :count is also available
      body: "There were problems with the following fields:"