i18n:特定型号的错误消息本地化 [英] i18n: error message localization for particular model
本文介绍了i18n:特定型号的错误消息本地化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以为每次验证定位错误消息,但是如何为特定模型创建错误.
I can localize an error message for each validation, but how can I create an error for particular model.
普通语言环境如下:
en:
mongoid:
errors:
messages:
taken: "It is already taken"
但是我想更改user
模型的消息:
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'}"
推荐答案
尝试一下:
en:
mongoid:
errors:
messages:
taken: "It is already taken"
models:
user:
attributes:
login:
taken: "It is already taken. %{link}"
参考:
PS: 本地化字符串应使用插值变量进行动态替换.
PS: The localization string should use interpolation variable for dynamic substitution.
例如:
在user
对象的login
字段上添加错误:
E.g:
Add an error on the login
field of user
object:
user.errors.add(:login, :taken, :link => "foo")
这篇关于i18n:特定型号的错误消息本地化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文