Method: Air18n::ClassMethods#pluralize
- Defined in:
- lib/air18n/class_methods.rb
#pluralize(count, singular, plural = nil) ⇒ Object
Like ActionView::Helpers::TextHelper#pluralize, except requires that ‘count’ be a real number, not a string.
ActionView::Helpers::TextHelper#pluralize is inherently English-centric. So this method is too, and assumes that the default locale’s plural forms are like “%smart_count count-is-one-form;%smart_count everything-else-form”.
Pass in nil for the count if you want to get the default text (for example, if you will be interpolating the count into the text in the front-end.) For example:
I18n.pluralize(nil, 'Review')
=> '%{smart_count} Review||||%{smart_count} Reviews'
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/air18n/class_methods.rb', line 91 def pluralize(count, singular, plural=nil) raise TypeError if count.is_a?(String) default_text = "%{smart_count} #{singular}#{SmartCount::DELIMITER}" + "%{smart_count} #{plural || singular.pluralize}" if count == nil translate(pluralize_key(singular), :default => default_text, :suppress_ct => true) else translate(pluralize_key(singular), :default => default_text, :smart_count => count, :suppress_ct => true) end end |