如何翻译活动记录模型验证 [英] How to translate active record model validations
本文介绍了如何翻译活动记录模型验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我提交表单,在这一个错误,它会返回一个错误信息。我怎么能翻译与l18n这些错误信息?我已经有翻译都在我的意见的其他文本,所以我知道在Rails中如何l18n工作。现在我得到这样的:
When I submit a form with an error in it, it returns an error message. How can I translate these error messages with l18n? I already have translation for all the other texts in my views, so I know how l18n works in Rails. I now get this:
2 errors prohibited this user from being saved:
Email translation missing: nl.activerecord.errors.models.user.attributes.email.blank
Email translation missing: nl.activerecord.errors.models.user.attributes.email.blank
我要翻译标题和错误。
I want to translate both the title and the errors.
推荐答案
翻译为标题将是:
nl:
activerecord:
errors:
template:
header:
one: "1 error prohibited this %{model} from being saved"
other: "%{count} errors prohibited this %{model} from being saved"
body: "There were problems with the following fields:"
有关翻译的错误信息,Rails会使用翻译的顺序如下:
For translating the error messages, Rails will use the following order of translations:
activerecord.errors.models.user.attributes.name.blank
activerecord.errors.models.user.blank
activerecord.errors.messages.blank
errors.attributes.name.blank
errors.messages.blank
所以,你可以添加:
So you could add:
nl:
activerecord:
errors:
models:
user:
attributes:
email:
blank: "foo blank in nl bar baz"
它记录在 Rails的国际化(i18n)API指南,这可能会给你更深入的了解。
It's documented in the Rails Internationalization (I18n) API Guide, which might give you some more insight.
这篇关于如何翻译活动记录模型验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文