Ruby on Rails I18n - Internationalization Pluralization


Example

You can let I18n handle pluralization for you, just use count argument.

You need to set up your locale file like this:

# config/locales/en.yml
en:
  online_users:
    one: "1 user is online"
    other: "%{count} users are online"

And then use the key you just created by passing the count argument to I18n.t helper:

I18n.t("online_users", count: 1)
#=> "1 user is online"

I18n.t("online_users", count: 4)
#=> "4 users are online"