I have my model names declared in config/locales/models.en.yml
:
en:
activerecord:
models:
news_item:
zero: No News Items
one: News Item
other: News Items
I know I can get the correctly pluralized model name using:
NewsItem.model_name.human(count: n)
So I could do:
"#{n} {NewsItem.model_name.human(count: n)}
Which is fine for 1 and many items, but with no items will render:
0 No News Items
Obviously I can add some logic to skip rendering the numeric part if there are no items, but I'm wondering if Rails has this built in?
There is a basic translation method that does what I'm after, but it doesn't pick up on model name translations:
I18n.translate :news_item, count: 2
Gives the error:
"translation missing: en.news_item"