【问题标题】:Rails 2.3.5 model name translation problem in error messagesRails 2.3.5 错误信息中的模型名称翻译问题
【发布时间】:2011-02-25 23:25:45
【问题描述】:

我在尝试在 Rails 2.3.5 应用程序中翻译模型的名称和属性时遇到了一些问题。

我有以下型号:

class BillingPlan < ActiveRecord::Base

  validates_presence_of :billing_option_id

  belongs_to :order
  belongs_to :user
  belongs_to :billing_option
end

当验证失败时,我的模型属性被正确翻译,但模型名本身不是。我在 de.yml 中使用以下翻译框架

de:
  activerecord:
    models:
      shipping_plan: "Versandart"
      billing_plan: "Rechnungsart"
    attributes:
      shipping_plan:
        shipping_option_id: "Versandoption"
      billing_plan:
        billing_option_id: "Rechnungsoption"

我的翻译文件的依据是:http://github.com/svenfuchs/rails-i18n/blob/master/rails/locale/de.yml

有人可以帮忙吗?

提前谢谢 J.

【问题讨论】:

  • 你怎么称呼错误? by error_message_for ?
  • 这里变得更加混乱。我的大多数表单都使用 formtastic,但也必须使用标准表单。如果我像这样使用formtastic: ... 一切都翻译得很好。如果是标准表格: ... 还是有模型名没有翻译的问题。

标签: ruby-on-rails model internationalization translation


【解决方案1】:

尝试检查您的翻译活动记录模型,查看 i18n 文档,Rails 指南上的 5.1.3 部分 (http://guides.rubyonrails.org/i18n.html)

rails 默认使用这个,你应该为你的 de i18n 创建一个:

en:
  activerecord:
    errors:
      template:
        header:
          one:   "1 error prohibited this {{model}} from being saved"
          other: "{{count}} errors prohibited this {{model}} from being saved"
        body:    "There were problems with the following fields:"

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-25
  • 2020-10-09
  • 1970-01-01
  • 2016-11-13
  • 2012-11-15
相关资源
最近更新 更多