自定义 i18n 错误消息会抛出 InvalidPluralizationData 错误?

发布于 2024-12-11 04:56:17 字数 886 浏览 0 评论 0原文

我有一个“用户”和一个“个人资料”模型。用户与个人资料具有一对一的关系,并且 “接受_嵌套_属性_用于配置文件”。

我正在使用两个复选框验证配置文件 - 也就是说,在验证之前必须接受其中一项协议。

无论如何,我想自定义不接受其中一个框的错误消息,因此我将以下内容添加到 en.yml 中,

activerecord:
  attributes:
    user: 
      profile:
        terms_and_conditions_a: 
          accepted: "You must accept the terms and conditions to continue"
        terms_and_conditions_b: 
          accepted: "You must accept the terms and conditions to continue"

您将看到配置文件嵌套在用户下 - 这是为了阻止将“配置文件”放在前面错误消息 (如此处解释)。

这给出我的错误:

I18n::InvalidPluralizationData
translation data {:terms_and_conditions_a=>{:invalid=>"You must accept the terms and conditions to continue"}} can not be used with :count => 1

我真的不明白它试图复数什么,有什么帮助吗?

I have a 'user' and a 'profile' model. The user has one to one relationship with profile and
"accepts_nested_attributes_for profile".

I'm validating profile with two checkboxes - that is to say one of the agreements must be accepted before it's validated.

Anyway, I want to customise the error message for not accepting one of the boxes so I added the following into en.yml

activerecord:
  attributes:
    user: 
      profile:
        terms_and_conditions_a: 
          accepted: "You must accept the terms and conditions to continue"
        terms_and_conditions_b: 
          accepted: "You must accept the terms and conditions to continue"

You'll see that profile is nested under user - this is to stop "Profile" being put at the front of the error message (as explained here).

This gives me the error:

I18n::InvalidPluralizationData
translation data {:terms_and_conditions_a=>{:invalid=>"You must accept the terms and conditions to continue"}} can not be used with :count => 1

I don't really see what it's trying to pluralize, any help?

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

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

发布评论

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

评论(1

遗失的美好 2024-12-18 04:56:17

也许应该是

activerecord:
  errors:
    models:
      user: 
        profile:
          attributes:
            terms_and_conditions_a: 
              accepted: "You must accept the terms and conditions to continue"

而不是

activerecord:
  attributes:
    user: 
      profile:
        terms_and_conditions_a: 
          accepted: "You must accept the terms and conditions to continue"

这就是我的应用程序中的情况,无可否认,它是 Rails 2 而不是 Rails 3。

或者,尝试不在用户下嵌套配置文件:

activerecord:
  errors:
    models:
      profile:
        attributes:
          terms_and_conditions_a: 
            accepted: "You must accept the terms and conditions to continue"

Maybe it should be

activerecord:
  errors:
    models:
      user: 
        profile:
          attributes:
            terms_and_conditions_a: 
              accepted: "You must accept the terms and conditions to continue"

rather than

activerecord:
  attributes:
    user: 
      profile:
        terms_and_conditions_a: 
          accepted: "You must accept the terms and conditions to continue"

?

That's how it is in my app, which is admittedly rails 2 rather than rails 3.

Alternately, try not nesting profile under user:

activerecord:
  errors:
    models:
      profile:
        attributes:
          terms_and_conditions_a: 
            accepted: "You must accept the terms and conditions to continue"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文