ruby-on-rails 错误的I18n“格式”不会更改

vs91vp4v  于 2023-04-08  发布在  Ruby
关注(0)|答案(1)|浏览(137)

下面是我的en.yml配置(Rails 7)

en:
  hello: "Hello world"
  activerecord:
    models:
      user:
        one: "User"
        other: "Users"
    attributes:
      user:
        first_name: "First Name"
        last_name: "Last Name"
        email: "Email"
        role: "Role"
    errors:
      format: "%{message} for %{attribute}"
      messages:
        blank: "can't be blank"
        too_short: "is too short (minimum is %{count} characters)"

我尝试更改错误的格式。我进入控制台并执行I18n.t('errors.format')-〉"%{attribute} %{message}"其他更改,但格式没有。
格式从"%{attribute} %{message}"更改为"%{message} for %{attribute}"

d7v8vwbk

d7v8vwbk1#

您正在检查I18n.t('errors.format'),但它的作用域在activerecord之下。请将它移出activerecord作用域:

en:
  errors:
    format: "%{message} for %{attribute}"
  activerecord:
...
  • https:github.com/rails/rails/blob/v7.0.4.3/activemodel/lib/active_model/locale/en.yml#L4*

相关问题