i18n:特定型号的错误消息本地化
我可以为每个验证本地化错误消息,但如何为特定模型创建错误。
普通区域设置如下所示:
en:
mongoid:
errors:
messages:
taken: "It is already taken"
但我想更改 user
模型的消息:
en:
mongoid:
errors:
messages:
taken: "It is already taken"
user:
taken: "It is already taken. %{link_to 'Remember password', reset_password_path'}"
I can localize an error message for each validation, but how can I create an error for particular model.
Ordinary locale looks like this:
en:
mongoid:
errors:
messages:
taken: "It is already taken"
But I want to change message for user
model:
en:
mongoid:
errors:
messages:
taken: "It is already taken"
user:
taken: "It is already taken. %{link_to 'Remember password', reset_password_path'}"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:
参考:
ActiveRecord 代码评论
PS:
本地化字符串应使用插值变量进行动态替换。
例如:
在
user
对象的login
字段上添加错误:Try this:
Reference:
ActiveRecord code comments
PS:
The localization string should use interpolation variable for dynamic substitution.
E.g:
Add an error on the
login
field ofuser
object: