Rails 2.3.5 错误消息中的模型名称翻译问题

发布于 2024-09-03 18:46:44 字数 825 浏览 3 评论 0 原文

我在尝试在 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。

I encountered some problem while trying to translate my model's names and attributes in a Rails 2.3.5 app.

I have the following model:

class BillingPlan < ActiveRecord::Base

  validates_presence_of :billing_option_id

  belongs_to :order
  belongs_to :user
  belongs_to :billing_option
end

When validation fails, my models attributes are translated correctly, but the modelname itself is not. I use the following translation skeleton in de.yml

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

Basis for my translation file is: http://github.com/svenfuchs/rails-i18n/blob/master/rails/locale/de.yml

Can anyone help?

Thx in advance
J.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

抚笙 2024-09-10 18:46:44

尝试检查活动记录模型的翻译,请查看 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:"

try to check your translations for active record models, look at the i18n documentation, 5.1.3 section on the Rails Guides (http://guides.rubyonrails.org/i18n.html)

by default rails uses this, you should create one for your 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:"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文