覆盖 Rails3 中模型名称的默认复数形式
我的语言环境是 :de,我喜欢这样:
Sheet.model_name.human.pluralize # => Belegs
添加尾随“e”而不是“s”
Sheet.model_name.human.pluralize # => Belege
为 Sheet 类 。 我可以以某种方式将其添加到我的 config/locales/models/de.yml 中吗?
my locale is :de and I like to get this:
Sheet.model_name.human.pluralize # => Belegs
to add me a trailing "e" instead of "s"
Sheet.model_name.human.pluralize # => Belege
just for the Sheet-class.
Can I add it somehow in my config/locales/models/de.yml ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
首先,您需要停止使用
.pluralize
。它使用Inflector(主要用于Rails 内部,例如猜测模型Sheet -> Sheets 的表名称)。您应该做的是使用
:count
选项。这要求您修改
de.yml
如下: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).What you should do is to use the
:count
option.This requires that you have modified your
de.yml
as such:您可以通过以下方式覆盖复数形式:
在 config/initializers/inflections.rb 中
执行以下操作:
You can override pluralizations this way:
In
config/initializers/inflections.rb
do:
如果您不喜欢明确的计数(例如 2),您可以使用
:many
例如或不使用哈希火箭(对于 Ruby >= 1.9):
If you don't like explicit count number (like 2) you could use
:many
e.g.or without hash rocket (for Ruby >= 1.9):