在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内部,例如,猜测模型Sheet-> sheets的表名).
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
进行如下修改:
This requires that you have modified your de.yml
as such:
de:
...
activerecord:
...
models:
sheet:
one: Beleg
other: Belege
这篇关于在rails3中覆盖模型名称的默认复数形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文