Method: ActionView::Helpers::TextHelper#pluralize
- Defined in:
- actionview/lib/action_view/helpers/text_helper.rb
#pluralize(count, singular, plural_arg = nil, plural: plural_arg, locale: I18n.locale) ⇒ Object
Attempts to pluralize the singular word unless count is 1. If plural is supplied, it will use that when count is > 1, otherwise it will use the Inflector to determine the plural form for the given locale, which defaults to I18n.locale.
The word will be pluralized using rules defined for the locale (you must define your own inflection rules for languages other than English). See ActiveSupport::Inflector.pluralize
pluralize(1, 'person')
# => "1 person"
pluralize(2, 'person')
# => "2 people"
pluralize(3, 'person', plural: 'users')
# => "3 users"
pluralize(0, 'person')
# => "0 people"
pluralize(2, 'Person', locale: :de)
# => "2 Personen"
290 291 292 293 294 295 296 297 298 |
# File 'actionview/lib/action_view/helpers/text_helper.rb', line 290 def pluralize(count, singular, plural_arg = nil, plural: plural_arg, locale: I18n.locale) word = if count == 1 || count.to_s.match?(/^1(\.0+)?$/) singular else plural || singular.pluralize(locale) end "#{count || 0} #{word}" end |