Sha256: 1c5b941aa09a8876c224eb7d76ffe3dabec49b69f2c6b58ef1744d13fcbe9a8d

Contents?: true

Size: 1.55 KB

Versions: 266

Compression:

Stored size: 1.55 KB

Contents

require 'test_helper'

class I18nBackendPluralizationTest < Test::Unit::TestCase
  class Backend < I18n::Backend::Simple
    include I18n::Backend::Pluralization
    include I18n::Backend::Fallbacks
  end

  def setup
    I18n.backend = Backend.new
    @rule = lambda { |n| n == 1 ? :one : n == 0 || (2..10).include?(n % 100) ? :few : (11..19).include?(n % 100) ? :many : :other }
    store_translations(:xx, :i18n => { :plural => { :rule => @rule } })
    @entry = { :zero => 'zero', :one => 'one', :few => 'few', :many => 'many', :other => 'other' }
  end

  test "pluralization picks a pluralizer from :'i18n.pluralize'" do
    assert_equal @rule, I18n.backend.send(:pluralizer, :xx)
  end

  test "pluralization picks :one for 1" do
    assert_equal 'one', I18n.t(:count => 1, :default => @entry, :locale => :xx)
  end

  test "pluralization picks :few for 2" do
    assert_equal 'few', I18n.t(:count => 2, :default => @entry, :locale => :xx)
  end

  test "pluralization picks :many for 11" do
    assert_equal 'many', I18n.t(:count => 11, :default => @entry, :locale => :xx)
  end

  test "pluralization picks zero for 0 if the key is contained in the data" do
    assert_equal 'zero', I18n.t(:count => 0, :default => @entry, :locale => :xx)
  end

  test "pluralization picks few for 0 if the key is not contained in the data" do
    @entry.delete(:zero)
    assert_equal 'few', I18n.t(:count => 0, :default => @entry, :locale => :xx)
  end

  test "Fallbacks can pick up rules from fallback locales, too" do
    assert_equal @rule, I18n.backend.send(:pluralizer, :'xx-XX')
  end
end

Version data entries

266 entries across 236 versions & 47 rubygems

Version Path
logstash-output-scalyr-0.1.9 vendor/bundle/jruby/2.5.0/gems/i18n-0.6.9/test/backend/pluralization_test.rb
logstash-output-scalyr-0.1.8 vendor/bundle/jruby/2.5.0/gems/i18n-0.6.9/test/backend/pluralization_test.rb
logstash-output-scalyr-0.1.7 vendor/bundle/jruby/2.5.0/gems/i18n-0.6.9/test/backend/pluralization_test.rb
logstash-output-scalyr-0.1.6 vendor/bundle/jruby/2.5.0/gems/i18n-0.6.9/test/backend/pluralization_test.rb
logstash-output-newrelic-1.2.0 vendor/bundle/jruby/2.5.0/gems/i18n-0.6.9/test/backend/pluralization_test.rb
logstash-filter-csharp-0.2.1 vendor/bundle/jruby/2.5.0/gems/i18n-0.6.9/test/backend/pluralization_test.rb
logstash-filter-csharp-0.2.1 vendor/bundle/jruby/2.3.0/gems/i18n-0.6.9/test/backend/pluralization_test.rb
logstash-filter-csharp-0.2.0 vendor/bundle/jruby/2.5.0/gems/i18n-0.6.9/test/backend/pluralization_test.rb
logstash-filter-csharp-0.2.0 vendor/bundle/jruby/2.3.0/gems/i18n-0.6.9/test/backend/pluralization_test.rb
logstash-output-scalyr-0.1.5 vendor/bundle/jruby/2.5.0/gems/i18n-0.6.9/test/backend/pluralization_test.rb
logstash-output-scalyr-0.1.4 vendor/bundle/jruby/2.5.0/gems/i18n-0.6.9/test/backend/pluralization_test.rb
logstash-output-scalyr-0.1.3 vendor/bundle/jruby/2.5.0/gems/i18n-0.6.9/test/backend/pluralization_test.rb
logstash-output-scalyr-0.1.2 vendor/bundle/jruby/2.5.0/gems/i18n-0.6.9/test/backend/pluralization_test.rb
logstash-filter-device_detection-1.0.7-java vendor/bundle/jruby/1.9/gems/i18n-0.6.9/test/backend/pluralization_test.rb
mrcooper-logstash-output-azuresearch-0.2.2 vendor/jruby/2.5.0/gems/i18n-0.6.9/test/backend/pluralization_test.rb
logstash-output-icinga-1.1.0 vendor/jruby/1.9/gems/i18n-0.6.9/test/backend/pluralization_test.rb
logstash-output-icinga-1.1.0 vendor/jruby/2.3.0/gems/i18n-0.6.9/test/backend/pluralization_test.rb
logstash-filter-cache-redis-0.3.1 vendor/bundle/jruby/1.9/gems/i18n-0.6.9/test/backend/pluralization_test.rb
logstash-filter-cache-redis-0.3.0 vendor/bundle/jruby/1.9/gems/i18n-0.6.9/test/backend/pluralization_test.rb
logstash-filter-cache-redis-0.2.0 vendor/bundle/jruby/1.9/gems/i18n-0.6.9/test/backend/pluralization_test.rb