Skip to content

Commit

Permalink
added ru plural proc
Browse files Browse the repository at this point in the history
  • Loading branch information
ddnexus committed Oct 2, 2018
1 parent 5680628 commit c461885
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions lib/locales/plurals.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,33 @@
# frozen_string_literal: true

# utility variables
zero_one = ['zero', 'one']
zero_one = ['zero', 'one']
from2to4 = (2..4)
from5to9 = (5..9)
from11to14 = (11..14)
from12to14 = (12..14)

# Plurals
# A plural proc returns a plural type string based on the passed count
# Each plural proc may apply to one or more languages below
plurals = {
zero_one_other: -> (count) {zero_one[count] || 'other'}
zero_one_other: -> (count) {zero_one[count] || 'other'},
one_few_many_other: -> (count) do
mod10, mod100 = count % 10, count % 100
if mod10 == 1 && mod100 != 11 ; 'one'
elsif from2to4.cover?(mod10) && !from12to14.cover?(mod100) ; 'few'
elsif mod10 == 0 || from5to9.cover?(mod10) || from11to14.cover?(mod100) ; 'many'
else 'other'
end
end
}

# Languages (language/plural pairs)
# Contain all the entries for all the languages defined in the pagy.yml dictionary
# The default plural for missing languages is the :zero_one_other plural (used for English)
Hash.new(plurals[:zero_one_other]).tap do |languages|
languages['en'] = plurals[:zero_one_other]

# PR for other languages and plurals are very welcome. Thanks!

languages['ru'] = plurals[:one_few_many_other]
end

# PR for other languages and plurals are very welcome. Thanks!

0 comments on commit c461885

Please sign in to comment.