How to pluralize “There is/are N object/objects”?

前端 未结 4 578
别跟我提以往
别跟我提以往 2020-12-31 02:04

Pluralizing a single word is simple:

pluralize(@total_users, \"user\")

But what if I want to print \"There is/are N user/u

4条回答
  •  离开以前
    2020-12-31 02:25

    This is probably best covered by the Rails i18n pluralization features. Adapted from http://guides.rubyonrails.org/i18n.html#pluralization

    I18n.backend.store_translations :en, :user_msg => {
      :one => 'There is 1 user',
      :other => 'There are %{count} users'
    }
    I18n.translate :user_msg, :count => 2
    # => 'There are 2 users'
    

提交回复
热议问题