Module: RailsI18n::Pluralization::OneFewOther
- Defined in:
- lib/rails_i18n/common_pluralizations/one_few_other.rb
Constant Summary collapse
- FROM_2_TO_4 =
(2..4).to_a.freeze
- FROM_12_TO_14 =
(12..14).to_a.freeze
Class Method Summary collapse
Class Method Details
.rule ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/rails_i18n/common_pluralizations/one_few_other.rb', line 7 def self.rule lambda do |n| return :other unless n.is_a?(Numeric) frac = (n.to_d % 1) if frac.nonzero? n = frac.to_s.split('.').last.to_i end mod10 = n % 10 mod100 = n % 100 if mod10 == 1 && mod100 != 11 :one elsif FROM_2_TO_4.include?(mod10) && !FROM_12_TO_14.include?(mod100) :few else :other end end end |
.with_locale(locale) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/rails_i18n/common_pluralizations/one_few_other.rb', line 30 def self.with_locale(locale) { locale => { :i18n => { :plural => { :keys => [:one, :few, :other], :rule => rule }}}} end |