Permalink
Browse files

Faster East Slavic pluralization

  • Loading branch information...
rwz committed Jan 3, 2014
1 parent 0b59c99 commit 52820982564235ec326342c75fffd043c94a92f7
Showing with 9 additions and 3 deletions.
  1. +9 −3 lib/rails_i18n/common_pluralizations/east_slavic.rb
@@ -6,16 +6,22 @@
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 [2, 3, 4].include?(mod10) && ![12, 13, 14].include?(mod100)
+ elsif FROM_2_TO_4.include?(mod10) && !FROM_12_TO_14.include?(mod100)
:few
- elsif mod10 == 0 || (5..9).to_a.include?(mod10) || (11..14).to_a.include?(mod100)
+ elsif mod10 == 0 || FROM_5_TO_9.include?(mod10) || FROM_11_TO_14.include?(mod100)
:many
else
:other
@@ -25,7 +31,7 @@ def self.rule
def self.with_locale(locale)
{ locale => {
- :'i18n' => {
+ :i18n => {
:plural => {
:keys => [:one, :few, :many, :other],
:rule => rule }}}}

0 comments on commit 5282098

Please sign in to comment.