Module: OrdbokLib::PluralizationRules

Defined in:
modules/pluralization_rules.rb

Overview

Rules how to pluralize phrases in various language groups.

Get pluralization category for given count as defined by the Unicode Language Plural Rules. www.unicode.org/cldr/charts/29/supplemental/language_plural_rules.html

Rule names are based on rails-l18n. github.com/svenfuchs/rails-i18n/tree/master/lib/rails_i18n/common_pluralizations

Class Method Summary collapse

Class Method Details

.east_slavic(count) ⇒ Symbol

Determine pluralization category according to ‘east_slavic` rule (e.g. used in Russian).

Parameters:

  • count (Numeric)

Returns:

  • (Symbol)


41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'modules/pluralization_rules.rb', line 41

def self.east_slavic(count)
  mod10  = count % 10
  mod100 = count % 100

  if count.is_a?(Float)
    :other
  elsif mod10 == 1 && mod100 != 11
    :one
  elsif mod10.between?(2, 4) && !mod100.between?(12, 14)
    :few
  else
    :many
  end
end

.one_other(count) ⇒ Symbol

Determine pluralization category according to ‘one_other` rule (e.g. used in English, Swedish, Italian, German, Spanish).

Parameters:

  • count (Numeric)

Returns:

  • (Symbol)


21
22
23
# File 'modules/pluralization_rules.rb', line 21

def self.one_other(count)
  count == 1 ? :one : :other
end

.one_upto_two_other(count) ⇒ Symbol

Determine pluralization category according to ‘one_upto_two_other` rule (e.g. used in French and (non-European) Portuguese).

Parameters:

  • count (Numeric)

Returns:

  • (Symbol)


31
32
33
# File 'modules/pluralization_rules.rb', line 31

def self.one_upto_two_other(count)
  count >= 0 && count < 2 ? :one : :other
end

.polish(count) ⇒ Symbol

Determine pluralization category according to ‘polish` rule.

Parameters:

  • count (Numeric)

Returns:

  • (Symbol)


61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'modules/pluralization_rules.rb', line 61

def self.polish(count)
  mod10  = count % 10
  mod100 = count % 100

  if count.is_a?(Float)
    :other
  elsif count == 1
    :one
  elsif mod10.between?(2, 4) && !mod100.between?(12, 14)
    :few
  else
    :many
  end
end

.welsh(count) ⇒ Symbol

Determine pluralization category according to ‘welsh` rule.

Parameters:

  • count (Numeric)

Returns:

  • (Symbol)


81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'modules/pluralization_rules.rb', line 81

def self.welsh(count)
  case count
  when 1
    :one
  when 2
    :two
  when 3
    :few
  when 6
    :many
  else
    :other
  end
end