Sha256: 73eaf479543c5347b44eff2af1c3821a7ddf5e392a9a2a7f6358cb36d25c631d

Contents?: true

Size: 1.07 KB

Versions: 22

Compression:

Stored size: 1.07 KB

Contents

# 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_a.freeze
      FROM_5_TO_9   = (5..9).to_a.freeze
      FROM_11_TO_14 = (11..14).to_a.freeze
      FROM_12_TO_14 = (12..14).to_a.freeze

      def self.rule
        lambda do |n|
          n ||= 0
          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

Version data entries

22 entries across 22 versions & 2 rubygems

Version Path
rails-i18n-6.0.0 lib/rails_i18n/common_pluralizations/east_slavic.rb
rails-i18n-6.0.0.beta1 lib/rails_i18n/common_pluralizations/east_slavic.rb
rails-i18n-5.1.3 lib/rails_i18n/common_pluralizations/east_slavic.rb
rails-i18n-5.1.2 lib/rails_i18n/common_pluralizations/east_slavic.rb
rails-i18n-5.1.1 lib/rails_i18n/common_pluralizations/east_slavic.rb
rails-i18n-5.1.0 lib/rails_i18n/common_pluralizations/east_slavic.rb
rails-i18n-5.0.4 lib/rails_i18n/common_pluralizations/east_slavic.rb
rails-i18n-5.0.3 lib/rails_i18n/common_pluralizations/east_slavic.rb
rails-i18n-5.0.2 lib/rails_i18n/common_pluralizations/east_slavic.rb
rails-i18n-5.0.1 lib/rails_i18n/common_pluralizations/east_slavic.rb
rails-i18n-5.0.0 lib/rails_i18n/common_pluralizations/east_slavic.rb
rails-i18n-4.0.9 lib/rails_i18n/common_pluralizations/east_slavic.rb
rails-i18n-5.0.0.beta4 lib/rails_i18n/common_pluralizations/east_slavic.rb
rails-i18n-5.0.0.beta3 lib/rails_i18n/common_pluralizations/east_slavic.rb
rails-i18n-5.0.0.beta2 lib/rails_i18n/common_pluralizations/east_slavic.rb
rails-i18n-4.0.8 lib/rails_i18n/common_pluralizations/east_slavic.rb
rails-i18n-5.0.0.beta1 lib/rails_i18n/common_pluralizations/east_slavic.rb
rails-i18n-4.0.7 lib/rails_i18n/common_pluralizations/east_slavic.rb
rails-i18n-4.0.6 lib/rails_i18n/common_pluralizations/east_slavic.rb
sc_core-0.0.7 test/dummy/vendor/bundle/ruby/2.2.0/gems/rails-i18n-4.0.5/lib/rails_i18n/common_pluralizations/east_slavic.rb