覆盖rails3中模型名称的默认复数 [英] override default pluralize for model-name in rails3
本文介绍了覆盖rails3中模型名称的默认复数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的语言环境是 :de,我喜欢这样:
my locale is :de and I like to get this:
Sheet.model_name.human.pluralize # => Belegs
给我添加一个尾随的e"而不是s"
to add me a trailing "e" instead of "s"
Sheet.model_name.human.pluralize # => Belege
仅适用于 Sheet 类.我可以在我的 config/locales/models/de.yml 中添加它吗?
just for the Sheet-class. Can I add it somehow in my config/locales/models/de.yml ?
推荐答案
首先,你需要停止使用.pluralize
.它使用 Inflector(主要用于 Rails 内部,例如猜测模型表的表名 -> 表).
First of all, you need to stop using .pluralize
. It uses the Inflector (which is mainly used for Rails internals, e.g. guessing table names for model Sheet -> sheets).
Sheet.model_name.human # => "Beleg"
"Beleg".pluralize # => "Belegs"
你应该做的是使用 :count
选项.
What you should do is to use the :count
option.
Sheet.model_name.human(:count => 2) # => "Belege"
这要求你修改你的de.yml
:
de:
...
activerecord:
...
models:
sheet:
one: Beleg
other: Belege
这篇关于覆盖rails3中模型名称的默认复数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文