/
east_slavic.rb
41 lines (36 loc) · 1.03 KB
/
east_slavic.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# Originally was implemented by Yaroslav Markin in "russian" gem
# (http://github.com/yaroslav/russian)
#
# Used for Belarusian, Bosnian, Croatian, Russian, Serbian, Serbo-Croatian, Ukrainian.
module RailsI18n
module Pluralization
module EastSlavic
FROM_2_TO_4 = (2..4).to_set
FROM_5_TO_9 = (5..9).to_set
FROM_11_TO_14 = (11..14).to_set
FROM_12_TO_14 = (12..14).to_set
def self.rule
lambda do |n|
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
elsif mod10 == 0 || FROM_5_TO_9.include?(mod10) || FROM_11_TO_14.include?(mod100)
:many
else
:other
end
end
end
def self.with_locale(locale)
{ locale => {
:i18n => {
:plural => {
:keys => [:one, :few, :many, :other],
:rule => rule }}}}
end
end
end
end