I18n 错误"format"不会更改



这是我的en。yml config (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}"

您正在检查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

相关内容

最新更新