Ruby on Rails - Pluralization in ruby on rails- ruby on rails tutorial - rails guides - rails tutorial - ruby rails
We can let I18n handle pluralization for us, just use count argument.
Set up our locale file like this:
# config/locales/en.yml
en:
online_users:
one: "1 user is online"
other: "%{count} users are online"
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ruby on rails tutorial - rails guides - ruby rails - rubyonrails - learn ruby on rails - team
Theb use the key we just created by passing the count argument to I18n.t
I18n.t("online_users", count: 1)
#=> "1 user is online"
I18n.t("online_users", count: 4)
#=> "4 users are online"