您的位置:首页 > 其它

使用i18n解决验证提示中文

2012-04-24 19:01 323 查看
1. i18n使用中文

config.i18n.default_locale = :'zh-CN'

2. 建立config/locales/zh-CN.yml

加入如下 :

"zh-CN":
activerecord:
models:
user: "用户"
attributes:
user:
name: "名字"
login: "用户名"
email: "Email"
errors:
models:
user: 用户
messages:
inclusion: "不包含于列表中"
exclusion: "是保留关键字"
invalid: "是无效的"
confirmation: "与确认值不匹配"
accepted: "必须是可被接受的"
empty: "不能留空"
blank: "不能为空字符"
too_long: "过长(最长为 %{count} 个字符)"
too_short: "过短(最短为 %{count} 个字符)"
wrong_length: "长度非法(必须为 %{count} 个字符)"
taken: "已经被使用"
not_a_number: "不是数字"
not_an_integer: "必须是整数"
greater_than: "必须大于 %{count}"
greater_than_or_equal_to: "必须大于或等于 %{count}"
equal_to: "必须等于 %{count}"
less_than: "必须小于 %{count}"
less_than_or_equal_to: "必须小于或等于 %{count}"
odd: "必须为单数"
even: "必须为双数"
record_invalid: "校验失败: %{errors}"
taken:
已占用
document_not_found:
没有发现类是 %{klass} ID 是 %{identifiers} 的文档
invalid_database:
数据库应该是Mongo::DB,而不是%{name}.
invalid_type:
在类%{klass}中定义了字段,实际值是%{value}的%{other}.
unsupported_version:
MongoDB %{version} 版本已过期,请升级到 %{mongo_version}.
validations:
校验失败 - %{errors}.
invalid_collection:
不允许直接访问嵌入式的集合%{klass} , 请从文档的根访问集合.
invalid_field:
字段的名字不允许为 %{name}. 你不应该定义跟Mongoid内部属性或者方法相同的名字,详细请看Use Document#instance_methods.
too_many_nested_attribute_records:
被关联的%{association} 嵌入式属性不能超过 %{limit}.
embedded_in_must_have_inverse_of:
embedded_in的关联属性必须包含inverse_of.
dependent_only_references_one_or_many:
dependent => destroy|delete 选项只有在references_one或者references_many时候有效.
association_cant_have_inverse_of:
在当前的关联中,不允许定义inverse_of去,其只有在embedded_in或者references_many是数组的情况下使用
unsaved_document:
You cannot call create or create! through a relational association
relation (%{document}) who's parent (%{base}) is not already saved.


3.要用target.errors.full_messages.each do |msg|,不要用 errors.each do |attr,msg| ,这里的attr还会是英文的

4 重启服务

参考文档:

http://zool.me/rails/2010/12/30/Chinese-rails-configuration/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐