Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add pluralization rules for non-English-like locales

  • Loading branch information...
commit 392c65fb1f086d1b5708e4be0301d500deb884cc 1 parent 1c1e091
@nashbridges nashbridges authored
Showing with 1,906 additions and 95 deletions.
  1. +1 −0  .rspec
  2. +8 −0 Rakefile
  3. +35 −0 lib/rails_i18n/common_pluralizations/east_slavic.rb
  4. +30 −0 lib/rails_i18n/common_pluralizations/one_two_other.rb
  5. +19 −0 lib/rails_i18n/common_pluralizations/one_upto_two_other.rb
  6. +20 −0 lib/rails_i18n/common_pluralizations/one_with_zero_other.rb
  7. +17 −0 lib/rails_i18n/common_pluralizations/other.rb
  8. +27 −0 lib/rails_i18n/common_pluralizations/romanian.rb
  9. +27 −0 lib/rails_i18n/common_pluralizations/west_slavic.rb
  10. +20 −5 lib/rails_i18n/railtie.rb
  11. +4 −1 rails-i18n.gemspec
  12. +3 −0  rails/pluralization/ak.rb
  13. +3 −0  rails/pluralization/am.rb
  14. +31 −0 rails/pluralization/ar.rb
  15. +3 −0  rails/pluralization/az.rb
  16. +3 −0  rails/pluralization/be.rb
  17. +3 −0  rails/pluralization/bh.rb
  18. +3 −0  rails/pluralization/bm.rb
  19. +3 −0  rails/pluralization/bo.rb
  20. +30 −0 rails/pluralization/br.rb
  21. +2 −6 rails/pluralization/bs.rb
  22. +3 −0  rails/pluralization/cs.rb
  23. +24 −0 rails/pluralization/cy.rb
  24. +3 −0  rails/pluralization/dz.rb
  25. +3 −0  rails/pluralization/fa.rb
  26. +3 −0  rails/pluralization/ff.rb
  27. +3 −0  rails/pluralization/fil.rb
  28. +3 −1 rails/pluralization/fr.rb
  29. +27 −0 rails/pluralization/ga.rb
  30. +25 −0 rails/pluralization/gd.rb
  31. +3 −0  rails/pluralization/guw.rb
  32. +21 −0 rails/pluralization/gv.rb
  33. +3 −0  rails/pluralization/hi.rb
  34. +3 −0  rails/pluralization/hr.rb
  35. +3 −0  rails/pluralization/hu.rb
  36. +3 −0  rails/pluralization/id.rb
  37. +3 −0  rails/pluralization/ig.rb
  38. +3 −0  rails/pluralization/ii.rb
  39. +3 −0  rails/pluralization/iu.rb
  40. +3 −0  rails/pluralization/ja.rb
  41. +3 −0  rails/pluralization/jv.rb
  42. +3 −0  rails/pluralization/ka.rb
  43. +3 −0  rails/pluralization/kab.rb
  44. +3 −0  rails/pluralization/kde.rb
  45. +3 −0  rails/pluralization/kea.rb
  46. +3 −0  rails/pluralization/km.rb
  47. +3 −0  rails/pluralization/kn.rb
  48. +3 −0  rails/pluralization/ko.rb
  49. +23 −0 rails/pluralization/ksh.rb
  50. +3 −0  rails/pluralization/kw.rb
  51. +23 −0 rails/pluralization/lag.rb
  52. +3 −0  rails/pluralization/ln.rb
  53. +3 −0  rails/pluralization/lo.rb
  54. +26 −0 rails/pluralization/lt.rb
  55. +23 −0 rails/pluralization/lv.rb
  56. +3 −0  rails/pluralization/mg.rb
  57. +21 −0 rails/pluralization/mk.rb
  58. +3 −0  rails/pluralization/mo.rb
  59. +3 −0  rails/pluralization/ms.rb
  60. +27 −0 rails/pluralization/mt.rb
  61. +3 −0  rails/pluralization/my.rb
  62. +3 −0  rails/pluralization/naq.rb
  63. +3 −0  rails/pluralization/nso.rb
  64. +28 −0 rails/pluralization/pl.rb
  65. +3 −0  rails/pluralization/ro.rb
  66. +3 −0  rails/pluralization/root.rb
  67. +2 −36 rails/pluralization/ru.rb
  68. +3 −0  rails/pluralization/sah.rb
  69. +3 −0  rails/pluralization/se.rb
  70. +3 −0  rails/pluralization/ses.rb
  71. +3 −0  rails/pluralization/sg.rb
  72. +3 −0  rails/pluralization/sh.rb
  73. +3 −0  rails/pluralization/shi.rb
  74. +3 −0  rails/pluralization/sk.rb
  75. +27 −0 rails/pluralization/sl.rb
  76. +3 −0  rails/pluralization/sma.rb
  77. +3 −0  rails/pluralization/smi.rb
  78. +3 −0  rails/pluralization/smj.rb
  79. +3 −0  rails/pluralization/smn.rb
  80. +3 −0  rails/pluralization/sms.rb
  81. +3 −0  rails/pluralization/sr.rb
  82. +3 −0  rails/pluralization/th.rb
  83. +3 −0  rails/pluralization/ti.rb
  84. +3 −0  rails/pluralization/tl.rb
  85. +3 −0  rails/pluralization/to.rb
  86. +3 −0  rails/pluralization/tr.rb
  87. +21 −0 rails/pluralization/tzm.rb
  88. +3 −0  rails/pluralization/uk.rb
  89. +3 −0  rails/pluralization/vi.rb
  90. +3 −0  rails/pluralization/wa.rb
  91. +3 −0  rails/pluralization/wo.rb
  92. +3 −0  rails/pluralization/yo.rb
  93. +3 −0  rails/pluralization/zh.rb
  94. +0 −10 spec/fake_app.rb
  95. +4 −0 spec/fixtures/nl.yml
  96. +6 −0 spec/fixtures/ru.yml
  97. +36 −0 spec/integration/pluralization_spec.rb
  98. +22 −0 spec/integration/translation_spec.rb
  99. +0 −19 spec/rails-i18n/translation_spec.rb
  100. +5 −11 spec/spec_helper.rb
  101. +28 −0 spec/support/fake_app.rb
  102. +29 −0 spec/support/pluralization_file.rb
  103. +30 −0 spec/unit/pluralization/shared/east_slavic.rb
  104. +20 −0 spec/unit/pluralization/shared/one_two_other.rb
  105. +18 −0 spec/unit/pluralization/shared/one_upto_two_other.rb
  106. +20 −0 spec/unit/pluralization/shared/one_with_zero_other.rb
  107. +17 −0 spec/unit/pluralization/shared/ordinary.rb
  108. +11 −0 spec/unit/pluralization/shared/other.rb
  109. +24 −0 spec/unit/pluralization/shared/romanian.rb
  110. +24 −0 spec/unit/pluralization/shared/west_slavic.rb
  111. +812 −0 spec/unit/pluralization_spec.rb
  112. +10 −0 spec/unit/translation_spec.rb
  113. +6 −6 spec/{rails-i18n → unit}/will_paginate_spec.rb
View
1  .rspec
@@ -0,0 +1 @@
+--colour
View
8 Rakefile
@@ -18,6 +18,14 @@ RSpec::Core::RakeTask.new(:spec) do |spec|
spec.pattern = FileList['spec/**/*_spec.rb']
end
+RSpec::Core::RakeTask.new("spec:unit") do |spec|
+ spec.pattern = 'spec/unit/**/*_spec.rb'
+end
+
+RSpec::Core::RakeTask.new("spec:integration") do |spec|
+ spec.pattern = 'spec/integration/**/*_spec.rb'
+end
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
spec.pattern = 'spec/**/*_spec.rb'
spec.rcov = true
View
35 lib/rails_i18n/common_pluralizations/east_slavic.rb
@@ -0,0 +1,35 @@
+# 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
+ 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)
+ :few
+ elsif mod10 == 0 || (5..9).to_a.include?(mod10) || (11..14).to_a.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
View
30 lib/rails_i18n/common_pluralizations/one_two_other.rb
@@ -0,0 +1,30 @@
+# Used for Cornish, Inari Sami, Inuktitut, Lule Sami, Nama, Northern Sami,
+# Sami Language, Skolt Sami, Southern Sami.
+
+module RailsI18n
+ module Pluralization
+ module OneTwoOther
+ def self.rule
+ def self.rule
+ lambda do |n|
+ if n == 1
+ :one
+ elsif n == 2
+ :two
+ else
+ :other
+ end
+ end
+ end
+ end
+
+ def self.with_locale(locale)
+ { locale => {
+ :'i18n' => {
+ :plural => {
+ :keys => [:one, :two, :other],
+ :rule => rule }}}}
+ end
+ end
+ end
+end
View
19 lib/rails_i18n/common_pluralizations/one_upto_two_other.rb
@@ -0,0 +1,19 @@
+# Used for French, Fulah, Kabyle.
+
+module RailsI18n
+ module Pluralization
+ module OneUptoTwoOther
+ def self.rule
+ lambda { |n| (0...2).cover?(n) ? :one : :other }
+ end
+
+ def self.with_locale(locale)
+ { locale => {
+ :'i18n' => {
+ :plural => {
+ :keys => [:one, :other],
+ :rule => rule }}}}
+ end
+ end
+ end
+end
View
20 lib/rails_i18n/common_pluralizations/one_with_zero_other.rb
@@ -0,0 +1,20 @@
+# Used in Akan, Amharic, Bihari, Filipino, guw, Hindi, Lingala, Malagasy,
+# Northen Sotho, Tachelhit, Tagalog, Tigrinya, Walloon.
+
+module RailsI18n
+ module Pluralization
+ module OneWithZeroOther
+ def self.rule
+ lambda { |n| n == 0 || n == 1 ? :one : :other }
+ end
+
+ def self.with_locale(locale)
+ { locale => {
+ :'i18n' => {
+ :plural => {
+ :keys => [:one, :other],
+ :rule => rule }}}}
+ end
+ end
+ end
+end
View
17 lib/rails_i18n/common_pluralizations/other.rb
@@ -0,0 +1,17 @@
+module RailsI18n
+ module Pluralization
+ module Other
+ def self.rule
+ Proc.new { :other }
+ end
+
+ def self.with_locale(locale)
+ { locale => {
+ :'i18n' => {
+ :plural => {
+ :keys => [:other],
+ :rule => rule }}}}
+ end
+ end
+ end
+end
View
27 lib/rails_i18n/common_pluralizations/romanian.rb
@@ -0,0 +1,27 @@
+# Used for Moldavian, Romanian.
+
+module RailsI18n
+ module Pluralization
+ module Romanian
+ def self.rule
+ lambda do |n|
+ if n == 1
+ :one
+ elsif n == 0 || (1..19).to_a.include?(n % 100)
+ :few
+ else
+ :other
+ end
+ end
+ end
+
+ def self.with_locale(locale)
+ { locale => {
+ :'i18n' => {
+ :plural => {
+ :keys => [:one, :few, :other],
+ :rule => rule }}}}
+ end
+ end
+ end
+end
View
27 lib/rails_i18n/common_pluralizations/west_slavic.rb
@@ -0,0 +1,27 @@
+# Used for Czech, Slovak.
+
+module RailsI18n
+ module Pluralization
+ module WestSlavic
+ def self.rule
+ lambda do |n|
+ if n == 1
+ :one
+ elsif [2, 3, 4].include?(n)
+ :few
+ else
+ :other
+ end
+ end
+ end
+
+ def self.with_locale(locale)
+ { locale => {
+ :'i18n' => {
+ :plural => {
+ :keys => [:one, :few, :other],
+ :rule => rule }}}}
+ end
+ end
+ end
+end
View
25 lib/rails_i18n/railtie.rb
@@ -2,12 +2,27 @@
module RailsI18n
class Railtie < ::Rails::Railtie #:nodoc:
- initializer 'rails-i18n' do |app|
- I18n.load_path << Dir[File.join(File.expand_path(File.dirname(__FILE__) + '/../../rails/locale'), '*.{rb,yml}')]
- if defined? ::WillPaginate
- I18n.load_path << Dir[File.join(File.expand_path(File.dirname(__FILE__) + '/../../will_paginate'), '*.{rb,yml}')]
+ initializer 'rails-i18n' do
+ RailsI18n::Railtie.instance_eval do
+ add('rails/locale/*.yml')
+ add('rails/pluralization/*.rb')
+ if defined? ::WillPaginate
+ add('will_paginate/*.yml')
+ end
+
+ init_pluralization_module
end
- I18n.load_path.flatten!
+ end
+
+ protected
+
+ def self.add(pattern)
+ files = Dir[File.join(File.dirname(__FILE__), '../..', pattern)]
+ I18n.load_path.concat(files)
+ end
+
+ def self.init_pluralization_module
+ I18n.backend.class.send(:include, I18n::Backend::Pluralization)
end
end
end
View
5 rails-i18n.gemspec
@@ -9,7 +9,9 @@ Gem::Specification.new do |s|
s.summary = "Common locale data and translations for Rails i18n."
s.description = "A set of common locale data and translations to internationalize and/or localize your Rails applications."
- s.files = Dir.glob("lib/**/*") + Dir.glob("rails/locale/*") + Dir.glob("will_paginate/*") + %w(README.md MIT-LICENSE.txt)
+ s.files = Dir.glob("lib/**/*") + Dir.glob("rails/locale/*") +
+ Dir.glob("rails/pluralization/*") + Dir.glob("rails/transliteration/*") +
+ Dir.glob("will_paginate/*") + %w(README.md MIT-LICENSE.txt)
s.platform = Gem::Platform::RUBY
s.require_path = 'lib'
s.rubyforge_project = '[none]'
@@ -20,4 +22,5 @@ Gem::Specification.new do |s|
s.add_development_dependency "rspec-rails", ">= 2.7.0"
s.add_development_dependency "i18n-spec", ">= 0.1.1"
s.add_development_dependency "will_paginate", ">= 3.0.0"
+ s.add_development_dependency "spork", "~> 1.0rc"
end
View
3  rails/pluralization/ak.rb
@@ -0,0 +1,3 @@
+require 'rails_i18n/common_pluralizations/one_with_zero_other'
+
+::RailsI18n::Pluralization::OneWithZeroOther.with_locale(:ak)
View
3  rails/pluralization/am.rb
@@ -0,0 +1,3 @@
+require 'rails_i18n/common_pluralizations/one_with_zero_other'
+
+::RailsI18n::Pluralization::OneWithZeroOther.with_locale(:am)
View
31 rails/pluralization/ar.rb
@@ -0,0 +1,31 @@
+module RailsI18n
+ module Pluralization
+ module Arabic
+ def self.rule
+ lambda do |n|
+ mod100 = n % 100
+
+ if n == 0
+ :zero
+ elsif n == 1
+ :one
+ elsif n == 2
+ :two
+ elsif (3..10).to_a.include?(mod100)
+ :few
+ elsif (11..99).to_a.include?(mod100)
+ :many
+ else
+ :other
+ end
+ end
+ end
+ end
+ end
+end
+
+{ :ar => {
+ :'i18n' => {
+ :plural => {
+ :keys => [:zero, :one, :two, :few, :many, :other],
+ :rule => RailsI18n::Pluralization::Arabic.rule }}}}
View
3  rails/pluralization/az.rb
@@ -0,0 +1,3 @@
+require 'rails_i18n/common_pluralizations/other'
+
+::RailsI18n::Pluralization::Other.with_locale(:az)
View
3  rails/pluralization/be.rb
@@ -0,0 +1,3 @@
+require 'rails_i18n/common_pluralizations/east_slavic'
+
+::RailsI18n::Pluralization::EastSlavic.with_locale(:be)
View
3  rails/pluralization/bh.rb
@@ -0,0 +1,3 @@
+require 'rails_i18n/common_pluralizations/one_with_zero_other'
+
+::RailsI18n::Pluralization::OneWithZeroOther.with_locale(:bh)
View
3  rails/pluralization/bm.rb
@@ -0,0 +1,3 @@
+require 'rails_i18n/common_pluralizations/other'
+
+::RailsI18n::Pluralization::Other.with_locale(:bm)
View
3  rails/pluralization/bo.rb
@@ -0,0 +1,3 @@
+require 'rails_i18n/common_pluralizations/other'
+
+::RailsI18n::Pluralization::Other.with_locale(:bo)
View
30 rails/pluralization/br.rb
@@ -0,0 +1,30 @@
+module RailsI18n
+ module Pluralization
+ module Breton
+ def self.rule
+ lambda do |n|
+ mod10 = n % 10
+ mod100 = n % 100
+
+ if mod10 == 1 && ![11,71,91].include?(mod100)
+ :one
+ elsif mod10 == 2 && ![12,72,92].include?(mod100)
+ :two
+ elsif [3,4,9].include?(mod10) && !((10..19).to_a + (70..79).to_a + (90..99).to_a).include?(mod100)
+ :few
+ elsif n % 1000000 == 0 && n != 0
+ :many
+ else
+ :other
+ end
+ end
+ end
+ end
+ end
+end
+
+{ :br => {
+ :'i18n' => {
+ :plural => {
+ :keys => [:one, :two, :few, :many, :other],
+ :rule => RailsI18n::Pluralization::Breton.rule }}}}
View
8 rails/pluralization/bs.rb
@@ -1,7 +1,3 @@
-# Bosnia and Herzegovina (Bosnian) pluralization rule implementation for rails
-# Picked up from https://github.com/svenfuchs/i18n/blob/master/test/test_data/locales/plurals.rb
-#
-# In order for this to work, add folowing to application.rb
-# I18n::Backend::Simple.include(I18n::Backend::Pluralization)
+require 'rails_i18n/common_pluralizations/east_slavic'
-{ :bs => { :i18n => { :plural => { :rule => lambda { |n| n % 10 == 1 && n % 100 != 11 ? :one : [2, 3, 4].include?(n % 10) && ![12, 13, 14].include?(n % 100) ? :few : n % 10 == 0 || [5, 6, 7, 8, 9].include?(n % 10) || [11, 12, 13, 14].include?(n % 100) ? :many : :other } } } } }
+::RailsI18n::Pluralization::EastSlavic.with_locale(:bs)
View
3  rails/pluralization/cs.rb
@@ -0,0 +1,3 @@
+require 'rails_i18n/common_pluralizations/west_slavic'
+
+::RailsI18n::Pluralization::WestSlavic.with_locale(:cs)
View
24 rails/pluralization/cy.rb
@@ -0,0 +1,24 @@
+module RailsI18n
+ module Pluralization
+ module Welsh
+ def self.rule
+ lambda do |n|
+ case n
+ when 0 then :zero
+ when 1 then :one
+ when 2 then :two
+ when 3 then :few
+ when 6 then :many
+ else :other
+ end
+ end
+ end
+ end
+ end
+end
+
+{ :cy => {
+ :'i18n' => {
+ :plural => {
+ :keys => [:zero, :one, :two, :few, :many, :other],
+ :rule => RailsI18n::Pluralization::Welsh.rule }}}}
View
3  rails/pluralization/dz.rb
@@ -0,0 +1,3 @@
+require 'rails_i18n/common_pluralizations/other'
+
+::RailsI18n::Pluralization::Other.with_locale(:dz)
View
3  rails/pluralization/fa.rb
@@ -0,0 +1,3 @@
+require 'rails_i18n/common_pluralizations/other'
+
+::RailsI18n::Pluralization::Other.with_locale(:fa)
View
3  rails/pluralization/ff.rb
@@ -0,0 +1,3 @@
+require 'rails_i18n/common_pluralizations/one_upto_two_other'
+
+::RailsI18n::Pluralization::OneUptoTwoOther.with_locale(:ff)
View
3  rails/pluralization/fil.rb
@@ -0,0 +1,3 @@
+require 'rails_i18n/common_pluralizations/one_with_zero_other'
+
+::RailsI18n::Pluralization::OneWithZeroOther.with_locale(:fil)
View
4 rails/pluralization/fr.rb
@@ -1 +1,3 @@
-{ :fr => { :i18n => {:plural => { :keys => [:one, :other], :rule => lambda { |n| n.between?(0, 2) && n != 2 ? :one : :other } } } } }
+require 'rails_i18n/common_pluralizations/one_upto_two_other'
+
+::RailsI18n::Pluralization::OneUptoTwoOther.with_locale(:fr)
View
27 rails/pluralization/ga.rb
@@ -0,0 +1,27 @@
+module RailsI18n
+ module Pluralization
+ module Irish
+ def self.rule
+ lambda do |n|
+ if n == 1
+ :one
+ elsif n == 2
+ :two
+ elsif (3..6).to_a.include?(n)
+ :few
+ elsif (7..10).to_a.include?(n)
+ :many
+ else
+ :other
+ end
+ end
+ end
+ end
+ end
+end
+
+{ :ga => {
+ :'i18n' => {
+ :plural => {
+ :keys => [:one, :two, :few, :many, :other],
+ :rule => RailsI18n::Pluralization::Irish.rule }}}}
View
25 rails/pluralization/gd.rb
@@ -0,0 +1,25 @@
+module RailsI18n
+ module Pluralization
+ module ScottishGaelic
+ def self.rule
+ lambda do |n|
+ if n == 1 || n == 11
+ :one
+ elsif n == 2 || n == 12
+ :two
+ elsif ((3..10).to_a + (13..19).to_a).include?(n)
+ :few
+ else
+ :other
+ end
+ end
+ end
+ end
+ end
+end
+
+{ :gd => {
+ :'i18n' => {
+ :plural => {
+ :keys => [:one, :two, :few, :other],
+ :rule => RailsI18n::Pluralization::ScottishGaelic.rule }}}}
View
3  rails/pluralization/guw.rb
@@ -0,0 +1,3 @@
+require 'rails_i18n/common_pluralizations/one_with_zero_other'
+
+::RailsI18n::Pluralization::OneWithZeroOther.with_locale(:guw)
View
21 rails/pluralization/gv.rb
@@ -0,0 +1,21 @@
+module RailsI18n
+ module Pluralization
+ module Manx
+ def self.rule
+ lambda do |n|
+ if [1, 2].include?(n % 10) || n % 20 == 0
+ :one
+ else
+ :other
+ end
+ end
+ end
+ end
+ end
+end
+
+{ :gv => {
+ :'i18n' => {
+ :plural => {
+ :keys => [:one, :other],
+ :rule => RailsI18n::Pluralization::Manx.rule }}}}
View
3  rails/pluralization/hi.rb
@@ -0,0 +1,3 @@
+require 'rails_i18n/common_pluralizations/one_with_zero_other'
+
+::RailsI18n::Pluralization::OneWithZeroOther.with_locale(:hi)
View
3  rails/pluralization/hr.rb
@@ -0,0 +1,3 @@
+require 'rails_i18n/common_pluralizations/east_slavic'
+
+::RailsI18n::Pluralization::EastSlavic.with_locale(:hr)
View
3  rails/pluralization/hu.rb
@@ -0,0 +1,3 @@
+require 'rails_i18n/common_pluralizations/other'
+
+::RailsI18n::Pluralization::Other.with_locale(:hu)
View
3  rails/pluralization/id.rb
@@ -0,0 +1,3 @@
+require 'rails_i18n/common_pluralizations/other'
+
+::RailsI18n::Pluralization::Other.with_locale(:id)
View
3  rails/pluralization/ig.rb
@@ -0,0 +1,3 @@
+require 'rails_i18n/common_pluralizations/other'
+
+::RailsI18n::Pluralization::Other.with_locale(:ig)
View
3  rails/pluralization/ii.rb
@@ -0,0 +1,3 @@
+require 'rails_i18n/common_pluralizations/other'
+
+::RailsI18n::Pluralization::Other.with_locale(:ii)
View
3  rails/pluralization/iu.rb
@@ -0,0 +1,3 @@
+require 'rails_i18n/common_pluralizations/one_two_other'
+
+::RailsI18n::Pluralization::OneTwoOther.with_locale(:iu)
View
3  rails/pluralization/ja.rb
@@ -0,0 +1,3 @@
+require 'rails_i18n/common_pluralizations/other'
+
+::RailsI18n::Pluralization::Other.with_locale(:ja)
View
3  rails/pluralization/jv.rb
@@ -0,0 +1,3 @@
+require 'rails_i18n/common_pluralizations/other'
+
+::RailsI18n::Pluralization::Other.with_locale(:jv)
View
3  rails/pluralization/ka.rb
@@ -0,0 +1,3 @@
+require 'rails_i18n/common_pluralizations/other'
+
+::RailsI18n::Pluralization::Other.with_locale(:ka)
View
3  rails/pluralization/kab.rb
@@ -0,0 +1,3 @@
+require 'rails_i18n/common_pluralizations/one_upto_two_other'
+
+::RailsI18n::Pluralization::OneUptoTwoOther.with_locale(:kab)
View
3  rails/pluralization/kde.rb
@@ -0,0 +1,3 @@
+require 'rails_i18n/common_pluralizations/other'
+
+::RailsI18n::Pluralization::Other.with_locale(:kde)
View
3  rails/pluralization/kea.rb
@@ -0,0 +1,3 @@
+require 'rails_i18n/common_pluralizations/other'
+
+::RailsI18n::Pluralization::Other.with_locale(:kea)
View
3  rails/pluralization/km.rb
@@ -0,0 +1,3 @@
+require 'rails_i18n/common_pluralizations/other'
+
+::RailsI18n::Pluralization::Other.with_locale(:km)
View
3  rails/pluralization/kn.rb
@@ -0,0 +1,3 @@
+require 'rails_i18n/common_pluralizations/other'
+
+::RailsI18n::Pluralization::Other.with_locale(:kn)
View
3  rails/pluralization/ko.rb
@@ -0,0 +1,3 @@
+require 'rails_i18n/common_pluralizations/other'
+
+::RailsI18n::Pluralization::Other.with_locale(:ko)
View
23 rails/pluralization/ksh.rb
@@ -0,0 +1,23 @@
+module RailsI18n
+ module Pluralization
+ module Colognian
+ def self.rule
+ lambda do |n|
+ if n == 0
+ :zero
+ elsif n == 1
+ :one
+ else
+ :other
+ end
+ end
+ end
+ end
+ end
+end
+
+{ :ksh => {
+ :'i18n' => {
+ :plural => {
+ :keys => [:zero, :one, :other],
+ :rule => RailsI18n::Pluralization::Colognian.rule }}}}
View
3  rails/pluralization/kw.rb
@@ -0,0 +1,3 @@
+require 'rails_i18n/common_pluralizations/one_two_other'
+
+::RailsI18n::Pluralization::OneTwoOther.with_locale(:kw)
View
23 rails/pluralization/lag.rb
@@ -0,0 +1,23 @@
+module RailsI18n
+ module Pluralization
+ module Langi
+ def self.rule
+ lambda do |n|
+ if n == 0
+ :zero
+ elsif (0...2).cover?(n)
+ :one
+ else
+ :other
+ end
+ end
+ end
+ end
+ end
+end
+
+{ :lag => {
+ :'i18n' => {
+ :plural => {
+ :keys => [:zero, :one, :other],
+ :rule => RailsI18n::Pluralization::Langi.rule }}}}
View
3  rails/pluralization/ln.rb
@@ -0,0 +1,3 @@
+require 'rails_i18n/common_pluralizations/one_with_zero_other'
+
+::RailsI18n::Pluralization::OneWithZeroOther.with_locale(:ln)
View
3  rails/pluralization/lo.rb
@@ -0,0 +1,3 @@
+require 'rails_i18n/common_pluralizations/other'
+
+::RailsI18n::Pluralization::Other.with_locale(:lo)
View
26 rails/pluralization/lt.rb
@@ -0,0 +1,26 @@
+module RailsI18n
+ module Pluralization
+ module Lithuanian
+ def self.rule
+ lambda do |n|
+ mod10 = n % 10
+ mod100 = n % 100
+
+ if mod10 == 1 && !(11..19).to_a.include?(mod100)
+ :one
+ elsif (2..9).to_a.include?(mod10) && !(11..19).to_a.include?(mod100)
+ :few
+ else
+ :other
+ end
+ end
+ end
+ end
+ end
+end
+
+{ :lt => {
+ :'i18n' => {
+ :plural => {
+ :keys => [:one, :few, :other],
+ :rule => RailsI18n::Pluralization::Lithuanian.rule }}}}
View
23 rails/pluralization/lv.rb
@@ -0,0 +1,23 @@
+module RailsI18n
+ module Pluralization
+ module Latvian
+ def self.rule
+ lambda do |n|
+ if n == 0
+ :zero
+ elsif n % 10 == 1 && n % 100 != 11
+ :one
+ else
+ :other
+ end
+ end
+ end
+ end
+ end
+end
+
+{ :lv => {
+ :'i18n' => {
+ :plural => {
+ :keys => [:zero, :one, :other],
+ :rule => RailsI18n::Pluralization::Latvian.rule }}}}
View
3  rails/pluralization/mg.rb
@@ -0,0 +1,3 @@
+require 'rails_i18n/common_pluralizations/one_with_zero_other'
+
+::RailsI18n::Pluralization::OneWithZeroOther.with_locale(:mg)
View
21 rails/pluralization/mk.rb
@@ -0,0 +1,21 @@
+module RailsI18n
+ module Pluralization
+ module Macedonian
+ def self.rule
+ lambda do |n|
+ if n % 10 == 1 && n != 11
+ :one
+ else
+ :other
+ end
+ end
+ end
+ end
+ end
+end
+
+{ :mk => {
+ :'i18n' => {
+ :plural => {
+ :keys => [:one, :other],
+ :rule => RailsI18n::Pluralization::Macedonian.rule }}}}
View
3  rails/pluralization/mo.rb
@@ -0,0 +1,3 @@
+require 'rails_i18n/common_pluralizations/romanian'
+
+::RailsI18n::Pluralization::Romanian.with_locale(:mo)
View
3  rails/pluralization/ms.rb
@@ -0,0 +1,3 @@
+require 'rails_i18n/common_pluralizations/other'
+
+::RailsI18n::Pluralization::Other.with_locale(:ms)
View
27 rails/pluralization/mt.rb
@@ -0,0 +1,27 @@
+module RailsI18n
+ module Pluralization
+ module Maltese
+ def self.rule
+ lambda do |n|
+ mod100 = n % 100
+
+ if n == 1
+ :one
+ elsif n == 0 || (2..10).to_a.include?(mod100)
+ :few
+ elsif (11..19).to_a.include?(mod100)
+ :many
+ else
+ :other
+ end
+ end
+ end
+ end
+ end
+end
+
+{ :mt => {
+ :'i18n' => {
+ :plural => {
+ :keys => [:one, :few, :many, :other],
+ :rule => RailsI18n::Pluralization::Maltese.rule }}}}
View
3  rails/pluralization/my.rb
@@ -0,0 +1,3 @@
+require 'rails_i18n/common_pluralizations/other'
+
+::RailsI18n::Pluralization::Other.with_locale(:my)
View
3  rails/pluralization/naq.rb
@@ -0,0 +1,3 @@
+require 'rails_i18n/common_pluralizations/one_two_other'
+
+::RailsI18n::Pluralization::OneTwoOther.with_locale(:naq)
View
3  rails/pluralization/nso.rb
@@ -0,0 +1,3 @@
+require 'rails_i18n/common_pluralizations/one_with_zero_other'
+
+::RailsI18n::Pluralization::OneWithZeroOther.with_locale(:nso)
View
28 rails/pluralization/pl.rb
@@ -0,0 +1,28 @@
+module RailsI18n
+ module Pluralization
+ module Polish
+ def self.rule
+ lambda do |n|
+ mod10 = n % 10
+ mod100 = n % 100
+
+ if n == 1
+ :one
+ elsif [2, 3, 4].include?(mod10) && ![12, 13, 14].include?(mod100)
+ :few
+ elsif ([0, 1] + (5..9).to_a).include?(mod10) || [12, 13, 14].include?(mod100)
+ :many
+ else
+ :other
+ end
+ end
+ end
+ end
+ end
+end
+
+{ :pl => {
+ :'i18n' => {
+ :plural => {
+ :keys => [:one, :few, :many, :other],
+ :rule => RailsI18n::Pluralization::Polish.rule }}}}
View
3  rails/pluralization/ro.rb
@@ -0,0 +1,3 @@
+require 'rails_i18n/common_pluralizations/romanian'
+
+::RailsI18n::Pluralization::Romanian.with_locale(:ro)
View
3  rails/pluralization/root.rb
@@ -0,0 +1,3 @@
+require 'rails_i18n/common_pluralizations/other'
+
+::RailsI18n::Pluralization::Other.with_locale(:root)
View
38 rails/pluralization/ru.rb
@@ -1,37 +1,3 @@
-# -*- encoding: utf-8 -*-
+require 'rails_i18n/common_pluralizations/east_slavic'
-# Be sure to check out "russian" gem (http://github.com/yaroslav/russian) for
-# full Russian language support in Rails (month names, pluralization, etc).
-# The following is an excerpt from that gem.
-#
-# Для полноценной поддержки русского языка (варианты названий месяцев,
-# плюрализация и так далее) в Rails 2.2+ и Rails 3 нужно использовать gem "russian"
-# (http://github.com/yaroslav/russian). Следующие данные -- выдержка их него, чтобы
-# была возможность минимальной локализации приложения на русский язык.
-
-# Правило плюрализации для русского языка, взято из CLDR, http://unicode.org/cldr/
-#
-# Russian language pluralization rules, taken from CLDR project, http://unicode.org/cldr/
-#
-# one -> n mod 10 is 1 and n mod 100 is not 11;
-# few -> n mod 10 in 2..4 and n mod 100 not in 12..14;
-# many -> n mod 10 is 0 or n mod 10 in 5..9 or n mod 100 in 11..14;
-# other -> everything else
-#
-# Пример
-#
-# :one = 1, 21, 31, 41, 51, 61...
-# :few = 2-4, 22-24, 32-34...
-# :many = 0, 5-20, 25-30, 35-40...
-# :other = 1.31, 2.31, 5.31...
-{
- :ru => {
- :'i18n' => {
- :plural => {
- :rule => lambda { |n|
- n % 10 == 1 && n % 100 != 11 ? :one : [2, 3, 4].include?(n % 10) && ![12, 13, 14].include?(n % 100) ? :few : n % 10 == 0 || [5, 6, 7, 8, 9].include?(n % 10) || [11, 12, 13, 14].include?(n % 100) ? :many : :other
- }
- }
- }
- }
-}
+::RailsI18n::Pluralization::EastSlavic.with_locale(:ru)
View
3  rails/pluralization/sah.rb
@@ -0,0 +1,3 @@
+require 'rails_i18n/common_pluralizations/other'
+
+::RailsI18n::Pluralization::Other.with_locale(:sah)
View
3  rails/pluralization/se.rb
@@ -0,0 +1,3 @@
+require 'rails_i18n/common_pluralizations/one_two_other'
+
+::RailsI18n::Pluralization::OneTwoOther.with_locale(:se)
View
3  rails/pluralization/ses.rb
@@ -0,0 +1,3 @@
+require 'rails_i18n/common_pluralizations/other'
+
+::RailsI18n::Pluralization::Other.with_locale(:ses)
View
3  rails/pluralization/sg.rb
@@ -0,0 +1,3 @@
+require 'rails_i18n/common_pluralizations/other'
+
+::RailsI18n::Pluralization::Other.with_locale(:sg)
View
3  rails/pluralization/sh.rb
@@ -0,0 +1,3 @@
+require 'rails_i18n/common_pluralizations/east_slavic'
+
+::RailsI18n::Pluralization::EastSlavic.with_locale(:sh)
View
3  rails/pluralization/shi.rb
@@ -0,0 +1,3 @@
+require 'rails_i18n/common_pluralizations/one_with_zero_other'
+
+::RailsI18n::Pluralization::OneWithZeroOther.with_locale(:shi)
View
3  rails/pluralization/sk.rb
@@ -0,0 +1,3 @@
+require 'rails_i18n/common_pluralizations/west_slavic'
+
+::RailsI18n::Pluralization::WestSlavic.with_locale(:sk)
View
27 rails/pluralization/sl.rb
@@ -0,0 +1,27 @@
+module RailsI18n
+ module Pluralization
+ module Slovenian
+ def self.rule
+ lambda do |n|
+ mod100 = n % 100
+
+ if mod100 == 1
+ :one
+ elsif mod100 == 2
+ :two
+ elsif mod100 == 3 || mod100 == 4
+ :few
+ else
+ :other
+ end
+ end
+ end
+ end
+ end
+end
+
+{ :sl => {
+ :'i18n' => {
+ :plural => {
+ :keys => [:one, :two, :few, :other],
+ :rule => RailsI18n::Pluralization::Slovenian.rule }}}}
View
3  rails/pluralization/sma.rb
@@ -0,0 +1,3 @@
+require 'rails_i18n/common_pluralizations/one_two_other'
+
+::RailsI18n::Pluralization::OneTwoOther.with_locale(:sma)
View
3  rails/pluralization/smi.rb
@@ -0,0 +1,3 @@
+require 'rails_i18n/common_pluralizations/one_two_other'
+
+::RailsI18n::Pluralization::OneTwoOther.with_locale(:smi)
View
3  rails/pluralization/smj.rb
@@ -0,0 +1,3 @@
+require 'rails_i18n/common_pluralizations/one_two_other'
+
+::RailsI18n::Pluralization::OneTwoOther.with_locale(:smj)
View
3  rails/pluralization/smn.rb
@@ -0,0 +1,3 @@
+require 'rails_i18n/common_pluralizations/one_two_other'
+
+::RailsI18n::Pluralization::OneTwoOther.with_locale(:smn)
View
3  rails/pluralization/sms.rb
@@ -0,0 +1,3 @@
+require 'rails_i18n/common_pluralizations/one_two_other'
+
+::RailsI18n::Pluralization::OneTwoOther.with_locale(:sms)
View
3  rails/pluralization/sr.rb
@@ -0,0 +1,3 @@
+require 'rails_i18n/common_pluralizations/east_slavic'
+
+::RailsI18n::Pluralization::EastSlavic.with_locale(:sr)
View
3  rails/pluralization/th.rb
@@ -0,0 +1,3 @@
+require 'rails_i18n/common_pluralizations/other'
+
+::RailsI18n::Pluralization::Other.with_locale(:th)
View
3  rails/pluralization/ti.rb
@@ -0,0 +1,3 @@
+require 'rails_i18n/common_pluralizations/one_with_zero_other'
+
+::RailsI18n::Pluralization::OneWithZeroOther.with_locale(:ti)
View
3  rails/pluralization/tl.rb
@@ -0,0 +1,3 @@
+require 'rails_i18n/common_pluralizations/one_with_zero_other'
+
+::RailsI18n::Pluralization::OneWithZeroOther.with_locale(:tl)
View
3  rails/pluralization/to.rb
@@ -0,0 +1,3 @@
+require 'rails_i18n/common_pluralizations/other'
+
+::RailsI18n::Pluralization::Other.with_locale(:to)
View
3  rails/pluralization/tr.rb
@@ -0,0 +1,3 @@
+require 'rails_i18n/common_pluralizations/other'
+
+::RailsI18n::Pluralization::Other.with_locale(:tr)
View
21 rails/pluralization/tzm.rb
@@ -0,0 +1,21 @@
+module RailsI18n
+ module Pluralization
+ module CentralMoroccoTamazight
+ def self.rule
+ lambda do |n|
+ if ([0, 1] + (11..99).to_a).include?(n)
+ :one
+ else
+ :other
+ end
+ end
+ end
+ end
+ end
+end
+
+{ :tzm => {
+ :'i18n' => {
+ :plural => {
+ :keys => [:one, :other],
+ :rule => RailsI18n::Pluralization::CentralMoroccoTamazight.rule }}}}
View
3  rails/pluralization/uk.rb
@@ -0,0 +1,3 @@
+require 'rails_i18n/common_pluralizations/east_slavic'
+
+::RailsI18n::Pluralization::EastSlavic.with_locale(:uk)
View
3  rails/pluralization/vi.rb
@@ -0,0 +1,3 @@
+require 'rails_i18n/common_pluralizations/other'
+
+::RailsI18n::Pluralization::Other.with_locale(:vi)
View
3  rails/pluralization/wa.rb
@@ -0,0 +1,3 @@
+require 'rails_i18n/common_pluralizations/one_with_zero_other'
+
+::RailsI18n::Pluralization::OneWithZeroOther.with_locale(:wa)
View
3  rails/pluralization/wo.rb
@@ -0,0 +1,3 @@
+require 'rails_i18n/common_pluralizations/other'
+
+::RailsI18n::Pluralization::Other.with_locale(:wo)
View
3  rails/pluralization/yo.rb
@@ -0,0 +1,3 @@
+require 'rails_i18n/common_pluralizations/other'
+
+::RailsI18n::Pluralization::Other.with_locale(:yo)
View
3  rails/pluralization/zh.rb
@@ -0,0 +1,3 @@
+require 'rails_i18n/common_pluralizations/other'
+
+::RailsI18n::Pluralization::Other.with_locale(:zh)
View
10 spec/fake_app.rb
@@ -1,10 +0,0 @@
-#require 'active_record'
-require 'action_controller/railtie'
-require 'action_view/railtie'
-
-app = Class.new(Rails::Application)
-app.config.secret_token = "4d616dad7a1c4460246f0a8c946a17ab"
-app.config.session_store :cookie_store, :key => "_myapp_session"
-app.config.active_support.deprecation = :log
-app.config.i18n.default_locale = "en-US"
-app.initialize!
View
4 spec/fixtures/nl.yml
@@ -0,0 +1,4 @@
+nl:
+ retiree:
+ one: gepensioneerde
+ other: gepensioneerden
View
6 spec/fixtures/ru.yml
@@ -0,0 +1,6 @@
+ru:
+ grandmother:
+ one: бабушка
+ few: бабушки
+ many: бабушек
+ other: бабушки
View
36 spec/integration/pluralization_spec.rb
@@ -0,0 +1,36 @@
+# encoding: utf-8
+
+require 'spec_helper'
+
+describe "Pluralization" do
+
+ let(:app) do
+ RailsI18n::Spec::FakeApp
+ end
+
+ context "when default locale has special pluralization rule" do
+ let(:translation) do
+ app.run ->{ I18n.t(:grandmother, :count => 6) } do |config|
+ config.i18n.default_locale = :ru
+ config.i18n.load_path << 'spec/fixtures/ru.yml'
+ end
+ end
+
+ it "works" do
+ translation.should == "бабушек"
+ end
+ end
+
+ context "when default locale has 'one-other' pluralization rule" do
+ let(:translation) do
+ app.run ->{ I18n.t(:retiree, :count => 3) } do |config|
+ config.i18n.default_locale = :nl
+ config.i18n.load_path << 'spec/fixtures/nl.yml'
+ end
+ end
+
+ it "works" do
+ translation.should == "gepensioneerden"
+ end
+ end
+end
View
22 spec/integration/translation_spec.rb
@@ -0,0 +1,22 @@
+# encoding: utf-8
+
+require 'spec_helper'
+
+describe "Translation" do
+
+ let(:app) do
+ RailsI18n::Spec::FakeApp
+ end
+
+ context "when default locale is not English" do
+ let(:translation) do
+ app.run ->{ I18n.t("helpers.select.prompt") } do |config|
+ config.i18n.default_locale = :de
+ end
+ end
+
+ it "is available" do
+ translation.should == "Bitte wählen"
+ end
+ end
+end
View
19 spec/rails-i18n/translation_spec.rb
@@ -1,19 +0,0 @@
-# coding: utf-8
-
-require 'spec_helper'
-
-describe "translation" do
- it "should give translations for rails" do
- require "rails_i18n"
- require "fake_app"
- I18n.t("helpers.select.prompt").should == "Please select"
- end
-end
-
-
-Dir.glob('rails/locale/*.yml') do |locale_file|
- describe "a rails-i18n locale file" do
- it_behaves_like 'a valid locale file', locale_file
- it { locale_file.should be_a_subset_of('rails/locale/en-US.yml') }
- end
-end
View
16 spec/spec_helper.rb
@@ -1,16 +1,10 @@
-# Configure Rails envinronment
ENV["RAILS_ENV"] = "test"
-require "action_controller/railtie"
-require "rspec/rails"
-require "will_paginate"
-require "rails_i18n"
-require "fake_app"
-require "i18n-spec"
+require 'rspec'
+require 'i18n-spec'
+require 'support/fake_app'
-# Configure RSpec
RSpec.configure do |config|
- require 'rspec/expectations'
- config.include RSpec::Matchers
config.mock_with :rspec
-end
+ config.fail_fast = true
+end
View
28 spec/support/fake_app.rb
@@ -0,0 +1,28 @@
+require 'spork'
+
+module RailsI18n
+ module Spec
+ module FakeApp
+ # Initialize Rails app in a clean environment.
+ # @param tests [Proc] which have to be run after app was initialized
+ # @return [Array, Object] single result if one test was passed given,
+ # otherwise returns an array of results
+ def self.run(*tests)
+ forker = Spork::Forker.new do
+ require 'rails-i18n'
+ require 'action_controller/railtie'
+
+ app = Class.new(Rails::Application)
+ app.config.active_support.deprecation = :log
+
+ yield(app.config) if block_given?
+ app.initialize!
+
+ results = tests.map &:call
+ results.size == 1 ? results.first : results
+ end
+ forker.result
+ end
+ end
+ end
+end
View
29 spec/support/pluralization_file.rb
@@ -0,0 +1,29 @@
+module RailsI18n
+ module Spec
+ class PluralizationFile
+ def initialize(filepath)
+ @filepath = filepath
+ end
+
+ def content
+ @content ||= eval(IO.read(@filepath), TOPLEVEL_BINDING)
+ end
+
+ # @return [Object, nil] Nil if path can't be traversed with the given key
+ # sequence, unless return Object at last key (it also can be nil)
+ def traverse_path(options)
+ keys = options[:keys] || []
+ where = options[:where] || content
+
+ if (key = keys.shift) && where.is_a?(Hash)
+ value = where[key]
+ if keys.empty?
+ value
+ else
+ traverse_path(:keys => keys, :where => value) if value
+ end
+ end
+ end
+ end
+ end
+end
View
30 spec/unit/pluralization/shared/east_slavic.rb
@@ -0,0 +1,30 @@
+shared_examples 'East Slavic' do
+ it 'has "one", "few", "many" and "other" plural keys' do
+ plural_keys.size.should == 4
+ plural_keys.should include(:one, :few, :many, :other)
+ end
+
+ [1, 21, 51, 71, 101, 1031].each do |count|
+ it "detects that #{count} in category 'one'" do
+ rule.call(count).should == :one
+ end
+ end
+
+ [2, 3, 4, 22, 23, 24, 92, 93, 94].each do |count|
+ it "detects that #{count} in category 'few'" do
+ rule.call(count).should == :few
+ end
+ end
+
+ [0, 5, 8, 10, 11, 18, 20, 25, 27, 30, 35, 38, 40].each do |count|
+ it "detects that #{count} in category 'many'" do
+ rule.call(count).should == :many
+ end
+ end
+
+ [1.2, 3.7, 11.5, 20.8, 1004.3].each do |count|
+ it "detects that #{count} in category 'other'" do
+ rule.call(count).should == :other
+ end
+ end
+end
View
20 spec/unit/pluralization/shared/one_two_other.rb
@@ -0,0 +1,20 @@
+shared_examples 'one-two-other forms language' do
+ it 'has "one", "two" and "other" plural keys' do
+ plural_keys.size.should == 3
+ plural_keys.should include(:one, :two, :other)
+ end
+
+ it "detects that 1 in category 'one'" do
+ rule.call(1).should == :one
+ end
+
+ it "detects that 2 in category 'two'" do
+ rule.call(2).should == :two
+ end
+
+ [0, 0.3, 1.2, 3, 5, 10, 11, 21, 23, 31, 50, 81, 99, 100].each do |count|
+ it "detects that #{count} in category 'other'" do
+ rule.call(count).should == :other
+ end
+ end
+end
View
18 spec/unit/pluralization/shared/one_upto_two_other.rb
@@ -0,0 +1,18 @@
+shared_examples 'one(upto 2)-other forms language' do
+ it 'has "one" and "other" plural keys' do
+ plural_keys.size.should == 2
+ plural_keys.should include(:one, :other)
+ end
+
+ [0, 0.5, 1, 1.2, 1.8].each do |count|
+ it "detects that #{count} in category 'one'" do
+ rule.call(count).should == :one
+ end
+ end
+
+ [2, 2.1, 5, 11, 21, 22, 37, 40, 900.5].each do |count|
+ it "detects that #{count} in category 'other'" do
+ rule.call(count).should == :other
+ end
+ end
+end
View
20 spec/unit/pluralization/shared/one_with_zero_other.rb
@@ -0,0 +1,20 @@
+shared_examples 'one(with zero)-other forms language' do
+ it 'has "one" and "other" plural keys' do
+ plural_keys.size.should == 2
+ plural_keys.should include(:one, :other)
+ end
+
+ it "detects that 0 in category 'one'" do
+ rule.call(0).should == :one
+ end
+
+ it "detects that 1 in category 'one'" do
+ rule.call(1).should == :one
+ end
+
+ [0.4, 1.2, 2, 5, 11, 21, 22, 27, 99, 1000].each do |count|
+ it "detects that #{count} in category 'other'" do
+ rule.call(count).should == :other
+ end
+ end
+end
View
17 spec/unit/pluralization/shared/ordinary.rb
@@ -0,0 +1,17 @@
+shared_examples 'an ordinary rule' do
+ it 'returns a hash' do
+ file.content.should be_a Hash
+ end
+
+ it 'has one top level namespace' do
+ file.content.keys.size.should == 1
+ end
+
+ it 'has its locale tag as a top level namespace' do
+ file.content.keys.first.should == example.metadata[:locale]
+ end
+
+ it 'has lambda or Proc under the "i18n.plural.rule" namespace' do
+ rule.should respond_to :call
+ end
+end
View
11 spec/unit/pluralization/shared/other.rb
@@ -0,0 +1,11 @@
+shared_examples 'other form language' do
+ it 'has "other" plural keys' do
+ plural_keys.should == [:other]
+ end
+
+ [0, 1, 1.2, 2, 5, 11, 21, 22, 27, 99, 1000].each do |count|
+ it "detects that #{count} in category 'other'" do
+ rule.call(count).should == :other
+ end
+ end
+end
View
24 spec/unit/pluralization/shared/romanian.rb
@@ -0,0 +1,24 @@
+shared_examples 'Romanian language' do
+ it_behaves_like 'an ordinary rule'
+
+ it 'has "one", "few", and "other" plural keys' do
+ plural_keys.size.should == 3
+ plural_keys.should include(:one, :few, :other)
+ end
+
+ it "detects that 1 in category 'one'" do
+ rule.call(1).should == :one
+ end
+
+ [0, 2, 3, 5, 8, 9, 10, 11, 15, 19, 101, 106, 112, 117, 119, 201].each do |count|
+ it "detects that #{count} in category 'few'" do
+ rule.call(count).should == :few
+ end
+ end
+
+ [0.4, 1.7, 20, 21, 23, 34, 45, 66, 89, 100, 120, 138].each do |count|
+ it "detects that #{count} in category 'other'" do
+ rule.call(count).should == :other
+ end
+ end
+ end
View
24 spec/unit/pluralization/shared/west_slavic.rb
@@ -0,0 +1,24 @@
+shared_examples 'West Slavic' do
+ it_behaves_like 'an ordinary rule'
+
+ it 'has "one", "few" and "other" plural keys' do
+ plural_keys.size.should == 3
+ plural_keys.should include(:one, :few, :other)
+ end
+
+ it "detects that 1 in category 'one'" do
+ rule.call(1).should == :one
+ end
+
+ [2, 3, 4].each do |count|
+ it "detects that #{count} in category 'few'" do
+ rule.call(count).should == :few
+ end
+ end
+
+ [0, 0.5, 1.7, 2.1, 5, 7.8, 10, 875].each do |count|
+ it "detects that #{count} in category 'other'" do
+ rule.call(count).should == :other
+ end
+ end
+ end
View
812 spec/unit/pluralization_spec.rb
@@ -0,0 +1,812 @@
+# Implementation of http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html
+# with additional specs for I18n pluralization data format.
+#
+# Locales that behave like English are omitted, because I18n applies English plural rule
+# to all locales without own plural rule.
+
+require 'spec_helper'
+require 'support/pluralization_file'
+
+require 'unit/pluralization/shared/ordinary'
+require 'unit/pluralization/shared/other'
+require 'unit/pluralization/shared/one_with_zero_other'
+require 'unit/pluralization/shared/one_upto_two_other'
+require 'unit/pluralization/shared/one_two_other'
+require 'unit/pluralization/shared/east_slavic'
+require 'unit/pluralization/shared/west_slavic'
+require 'unit/pluralization/shared/romanian'
+
+describe 'Pluralization rule for' do
+
+ pluralizations_dir = File.join('rails', 'pluralization')
+
+ let(:file) do
+ filename = File.join(pluralizations_dir, "#{example.metadata[:locale]}.rb")
+ RailsI18n::Spec::PluralizationFile.new(filename)
+ end
+
+ let(:rule) do
+ file.traverse_path(:keys => [example.metadata[:locale], :i18n, :plural, :rule])
+ end
+
+ let(:plural_keys) do
+ file.traverse_path(:keys => [example.metadata[:locale], :i18n, :plural, :keys])
+ end
+
+ describe 'Akan', :locale => :ak do
+ it_behaves_like 'an ordinary rule'
+ it_behaves_like 'one(with zero)-other forms language'
+ end
+
+ describe 'Amharic', :locale => :am do
+ it_behaves_like 'an ordinary rule'
+ it_behaves_like 'one(with zero)-other forms language'
+ end
+
+ describe 'Arabic', :locale => :ar do
+ it_behaves_like 'an ordinary rule'
+
+ it 'has "zero", "one", "two", "few", "many" and "other" plural keys' do
+ plural_keys.size.should == 6
+ plural_keys.should include(:zero, :one, :two, :few, :many, :other)
+ end
+
+ it "detects that 0 in category 'zero'" do
+ rule.call(0).should == :zero
+ end
+
+ it "detects that 1 in category 'one'" do
+ rule.call(1).should == :one
+ end
+
+ it "detects that 2 in category 'two'" do
+ rule.call(2).should == :two
+ end
+
+ [3, 4, 5, 6, 7, 8, 9, 10, 103, 105, 110].each do |count|
+ it "detects that #{count} in category 'few'" do
+ rule.call(count).should == :few
+ end
+ end
+
+ [11, 12, 20, 51, 67, 89, 91, 99, 111, 158, 199].each do |count|
+ it "detects that #{count} in category 'many'" do
+ rule.call(count).should == :many
+ end
+ end
+
+ [0.3, 1.2, 2.2, 8.5, 11.68, 100, 101, 102, 200, 201, 202].each do |count|
+ it "detects that #{count} in category 'other'" do
+ rule.call(count).should == :other
+ end
+ end
+ end
+
+ describe 'Azerbaijani', :locale => :az do
+ it_behaves_like 'an ordinary rule'
+ it_behaves_like 'other form language'
+ end
+
+ describe 'Bambara', :locale => :bm do
+ it_behaves_like 'an ordinary rule'
+ it_behaves_like 'other form language'
+ end
+
+ describe 'Belarusian', :locale => :be do
+ it_behaves_like 'an ordinary rule'
+ it_behaves_like 'East Slavic'
+ end
+
+ describe 'Bihari', :locale => :bh do
+ it_behaves_like 'an ordinary rule'
+ it_behaves_like 'one(with zero)-other forms language'
+ end
+
+ describe 'Bosnian', :locale => :bs do
+ it_behaves_like 'an ordinary rule'
+ it_behaves_like 'East Slavic'
+ end
+
+ describe 'Breton', :locale => :br do
+ it_behaves_like 'an ordinary rule'
+
+ it 'has "one", "two", "few", "many" and "other" plural keys' do
+ plural_keys.size.should == 5
+ plural_keys.should include(:one, :two, :few, :many, :other)
+ end
+
+ [1, 21, 31, 41, 51, 61, 81, 101, 1031].each do |count|
+ it "detects that #{count} in category 'one'" do
+ rule.call(count).should == :one
+ end
+ end
+
+ [2, 22, 32, 42, 52, 62, 82, 102, 1000002].each do |count|
+ it "detects that #{count} in category 'two'" do
+ rule.call(count).should == :two
+ end
+ end
+
+ [3, 4, 9, 23, 24, 29].each do |count|
+ it "detects that #{count} in category 'few'" do
+ rule.call(count).should == :few
+ end
+ end
+
+ [1000000, 3000000].each do |count|
+ it "detects that #{count} in category 'many'" do
+ rule.call(count).should == :many
+ end
+ end
+
+ [0, 1.2, 3.94, 5, 6, 7, 8, 10, 11, 12, 15, 19, 20, 25, 26, 27, 28, 71, 72, 91, 92, 95, 99].each do |count|
+ it "detects that #{count} in category 'other'" do
+ rule.call(count).should == :other
+ end
+ end
+
+ end
+
+ describe 'Burmese', :locale => :my do
+ it_behaves_like 'an ordinary rule'
+ it_behaves_like 'other form language'
+ end
+
+ describe 'Central Morocco Tamazight', :locale => :tzm do
+ it_behaves_like 'an ordinary rule'
+
+ it 'has "one" and "other" plural keys' do
+ plural_keys.size.should == 2
+ plural_keys.should include(:one, :other)
+ end
+
+ [0, 1, 11, 12, 21, 22, 29, 37, 49, 87, 99].each do |count|
+ it "detects that #{count} in category 'one'" do
+ rule.call(count).should == :one
+ end
+ end
+
+ [0.3, 1.7, 2, 3, 4, 5, 6, 7, 8, 9, 10, 100, 111, 121, 122, 137, 249].each do |count|
+ it "detects that #{count} in category 'other'" do
+ rule.call(count).should == :other
+ end
+ end
+ end
+
+ describe 'Chinese', :locale => :zh do
+ it_behaves_like 'an ordinary rule'
+ it_behaves_like 'other form language'
+ end
+
+ describe 'Colognian', :locale => :ksh do
+ it_behaves_like 'an ordinary rule'
+
+ it 'has "zero", "one" and "other" plural keys' do
+ plural_keys.size.should == 3
+ plural_keys.should include(:zero, :one, :other)
+ end
+
+ it "detects that 0 in category 'zero'" do
+ rule.call(0).should == :zero
+ end
+
+ it "detects that 1 in category 'one'" do
+ rule.call(1).should == :one
+ end
+
+ [0.3, 1.2, 2, 4, 5, 10, 11, 21, 23, 31, 50, 99, 100].each do |count|
+ it "detects that #{count} in category 'other'" do
+ rule.call(count).should == :other
+ end
+ end
+ end
+
+ describe 'Cornish', :locale => :kw do
+ it_behaves_like 'an ordinary rule'
+ it_behaves_like 'one-two-other forms language'
+ end
+
+ describe 'Croatian', :locale => :hr do
+ it_behaves_like 'an ordinary rule'
+ it_behaves_like 'East Slavic'
+ end
+
+ describe 'Czech', :locale => :cs do
+ it_behaves_like 'an ordinary rule'
+ it_behaves_like 'West Slavic'
+ end
+
+ describe 'Dzongkha', :locale => :dz do
+ it_behaves_like 'an ordinary rule'
+ it_behaves_like 'other form language'
+ end
+
+ describe 'Filipino', :locale => :fil do
+ it_behaves_like 'an ordinary rule'
+ it_behaves_like 'one(with zero)-other forms language'
+ end
+
+ describe 'French', :locale => :fr do
+ it_behaves_like 'an ordinary rule'
+ it_behaves_like 'one(upto 2)-other forms language'
+ end
+
+ describe 'Fulah', :locale => :ff do
+ it_behaves_like 'an ordinary rule'
+ it_behaves_like 'one(upto 2)-other forms language'
+ end
+
+ describe 'Georgian', :locale => :ka do
+ it_behaves_like 'an ordinary rule'
+ it_behaves_like 'other form language'
+ end
+
+ describe 'guw', :locale => :guw do
+ it_behaves_like 'an ordinary rule'
+ it_behaves_like 'one(with zero)-other forms language'
+ end
+
+ describe 'Hindi', :locale => :hi do
+ it_behaves_like 'an ordinary rule'
+ it_behaves_like 'one(with zero)-other forms language'
+ end
+
+ describe 'Hungarian', :locale => :hu do
+ it_behaves_like 'an ordinary rule'
+ it_behaves_like 'other form language'
+ end
+
+ describe 'Igbo', :locale => :ig do
+ it_behaves_like 'an ordinary rule'
+ it_behaves_like 'other form language'
+ end
+
+ describe 'Inari Sami', :locale => :smn do
+ it_behaves_like 'an ordinary rule'
+ it_behaves_like 'one-two-other forms language'
+ end
+
+ describe 'Indonesian', :locale => :id do
+ it_behaves_like 'an ordinary rule'
+ it_behaves_like 'other form language'
+ end
+
+ describe 'Inuktitut', :locale => :iu do
+ it_behaves_like 'an ordinary rule'
+ it_behaves_like 'one-two-other forms language'
+ end
+
+ describe 'Irish', :locale => :ga do
+ it_behaves_like 'an ordinary rule'
+
+ it 'has "one", "two", "few", "many" and "other" plural keys' do
+ plural_keys.size.should == 5
+ plural_keys.should include(:one, :two, :few, :many, :other)
+ end
+
+ it "detects that 1 in category 'one'" do
+ rule.call(1).should == :one
+ end
+
+ it "detects that 2 in category 'two'" do
+ rule.call(2).should == :two
+ end
+
+ [3, 4, 5, 6].each do |count|
+ it "detects that #{count} in category 'few'" do
+ rule.call(count).should == :few
+ end
+ end
+
+ [7, 8, 9, 10].each do |count|
+ it "detects that #{count} in category 'many'" do
+ rule.call(count).should == :many
+ end
+ end
+
+ [0, 1.2, 3.94, 8.2, 11, 12, 15, 19, 20, 25, 27, 31, 52, 84, 99, 100].each do |count|
+ it "detects that #{count} in category 'other'" do
+ rule.call(count).should == :other
+ end
+ end
+ end
+
+ describe 'Japanese', :locale => :ja do
+ it_behaves_like 'an ordinary rule'
+ it_behaves_like 'other form language'
+ end
+
+ describe 'Javanese', :locale => :jv do
+ it_behaves_like 'an ordinary rule'
+ it_behaves_like 'other form language'
+ end
+
+ describe 'Kabuverdianu', :locale => :kea do
+ it_behaves_like 'an ordinary rule'
+ it_behaves_like 'other form language'
+ end
+
+ describe 'Kabyle', :locale => :kab do
+ it_behaves_like 'an ordinary rule'
+ it_behaves_like 'one(upto 2)-other forms language'
+ end
+
+ describe 'Kannada', :locale => :kn do
+ it_behaves_like 'an ordinary rule'
+ it_behaves_like 'other form language'
+ end
+
+ describe 'Khmer', :locale => :km do
+ it_behaves_like 'an ordinary rule'
+ it_behaves_like 'other form language'
+ end
+
+ describe 'Korean', :locale => :ko do
+ it_behaves_like 'an ordinary rule'
+ it_behaves_like 'other form language'
+ end
+
+ describe 'Koyraboro Senni', :locale => :ses do
+ it_behaves_like 'an ordinary rule'
+ it_behaves_like 'other form language'
+ end
+
+ describe 'Langi', :locale => :lag do
+ it_behaves_like 'an ordinary rule'
+
+ it 'has "zero", "one" and "other" plural keys' do
+ plural_keys.size.should == 3
+ plural_keys.should include(:zero, :one, :other)
+ end
+
+ it "detects that 0 in category 'zero'" do
+ rule.call(0).should == :zero
+ end
+
+ [0.5, 1, 1.2, 1.8].each do |count|
+ it "detects that #{count} in category 'one'" do
+ rule.call(count).should == :one
+ end
+ end
+
+ [2, 2.1, 5, 11, 21, 22, 37, 40, 900.5].each do |count|
+ it "detects that #{count} in category 'other'" do
+ rule.call(count).should == :other
+ end
+ end
+ end
+
+ describe 'Lao', :locale => :lo do
+ it_behaves_like 'an ordinary rule'
+ it_behaves_like 'other form language'
+ end
+
+ describe 'Latvian', :locale => :lv do
+ it_behaves_like 'an ordinary rule'
+
+ it 'has "zero", "one" and "other" plural keys' do
+ plural_keys.size.should == 3
+ plural_keys.should include(:zero, :one, :other)
+ end
+
+ it "detects that 0 in category 'zero'" do
+ rule.call(0).should == :zero
+ end
+
+ [1, 21, 31, 41, 51, 61, 101].each do |count|
+ it "detects that #{count} in category 'one'" do
+ rule.call(count).should == :one
+ end
+ end
+
+ [0.4, 1.7, 2, 5, 10, 11, 20, 22, 37, 40, 111, 123].each do |count|
+ it "detects that #{count} in category 'other'" do
+ rule.call(count).should == :other
+ end
+ end
+ end
+
+ describe 'Lingala', :locale => :ln do
+ it_behaves_like 'an ordinary rule'
+ it_behaves_like 'one(with zero)-other forms language'
+ end
+
+ describe 'Lithuanian', :locale => :lt do
+ it_behaves_like 'an ordinary rule'
+
+ it 'has "one", "few" and "other" plural keys' do
+ plural_keys.size.should == 3
+ plural_keys.should include(:one, :few, :other)
+ end
+
+ [1, 21, 31, 41, 51, 61, 101].each do |count|
+ it "detects that #{count} in category 'one'" do
+ rule.call(count).should == :one
+ end
+ end
+
+ [2, 3, 5, 8, 9, 22, 26, 29, 32, 34, 39, 109].each do |count|
+ it "detects that #{count} in category 'few'" do
+ rule.call(count).should == :few
+ end
+ end
+
+ [0, 0.4, 1.7, 10, 11, 15, 20, 30, 40, 70, 111, 122.7].each do |count|
+ it "detects that #{count} in category 'other'" do
+ rule.call(count).should == :other
+ end
+ end
+ end
+
+ describe 'Lule Sami', :locale => :smj do
+ it_behaves_like 'an ordinary rule'
+ it_behaves_like 'one-two-other forms language'
+ end
+
+ # TODO http://unicode.org/cldr/trac/ticket/3426
+ describe 'Macedonian', :locale => :mk do
+ it_behaves_like 'an ordinary rule'
+
+ it 'has "one" and "other" plural keys' do
+ plural_keys.size.should == 2
+ plural_keys.should include(:one, :other)
+ end
+
+ [1, 21, 31, 41, 51, 61, 101, 111, 131].each do |count|
+ it "detects that #{count} in category 'one'" do
+ rule.call(count).should == :one
+ end
+ end
+
+ [0, 0.4, 1.7, 2, 7, 10, 11, 15, 20, 27, 33, 46, 70, 122.7].each do |count|
+ it "detects that #{count} in category 'other'" do
+ rule.call(count).should == :other
+ end
+ end
+ end
+
+ describe 'Makonde', :locale => :kde do
+ it_behaves_like 'an ordinary rule'
+ it_behaves_like 'other form language'
+ end
+
+ describe 'Malagasy', :locale => :mg do
+ it_behaves_like 'an ordinary rule'
+ it_behaves_like 'one(with zero)-other forms language'
+ end
+
+ describe 'Malay', :locale => :ms do
+ it_behaves_like 'an ordinary rule'
+ it_behaves_like 'other form language'
+ end
+
+ # TODO http://unicode.org/cldr/trac/ticket/3426
+ describe 'Maltese', :locale => :mt do
+ it_behaves_like 'an ordinary rule'
+
+ it 'has "one", "few", "many" and "other" plural keys' do
+ plural_keys.size.should == 4
+ plural_keys.should include(:one, :few, :many, :other)
+ end
+
+ it "detects that 1 in category 'one'" do
+ rule.call(1).should == :one
+ end
+
+ [0, 2, 3, 5, 8, 9, 10, 102, 104, 106, 107, 110].each do |count|
+ it "detects that #{count} in category 'few'" do
+ rule.call(count).should == :few
+ end
+ end
+
+ [11, 13, 16, 18, 19, 111, 112, 115, 117, 119].each do |count|
+ it "detects that #{count} in category 'many'" do
+ rule.call(count).should == :many
+ end
+ end
+
+ [0.4, 1.7, 20, 21, 23, 34, 45, 66, 89, 100, 101].each do |count|
+ it "detects that #{count} in category 'other'" do
+ rule.call(count).should == :other
+ end
+ end
+ end
+
+ describe 'Manx', :locale => :gv do
+ it_behaves_like 'an ordinary rule'
+
+ it 'has "one", and "other" plural keys' do
+ plural_keys.size.should == 2
+ plural_keys.should include(:one, :other)
+ end
+
+ [0, 1, 2, 11, 12, 20, 21, 22, 51, 60].each do |count|
+ it "detects that #{count} in category 'one'" do
+ rule.call(count).should == :one
+ end
+ end
+
+ [0.4, 1.7, 3, 4, 6, 9, 10, 13, 15, 17, 19, 23, 28, 30].each do |count|
+ it "detects that #{count} in category 'other'" do
+ rule.call(count).should == :other
+ end
+ end
+ end
+
+ describe 'Moldavian', :locale => :mo do
+ it_behaves_like 'an ordinary rule'
+ it_behaves_like 'Romanian language'
+ end
+
+ describe 'Nama', :locale => :naq do
+ it_behaves_like 'an ordinary rule'
+ it_behaves_like 'one-two-other forms language'
+ end
+
+ describe 'Northern Sami', :locale => :se do
+ it_behaves_like 'an ordinary rule'
+ it_behaves_like 'one-two-other forms language'
+ end
+
+ describe 'Northen Sotho', :locale => :nso do
+ it_behaves_like 'an ordinary rule'
+ it_behaves_like 'one(with zero)-other forms language'
+ end
+
+ describe 'Persian', :locale => :fa do
+ it_behaves_like 'an ordinary rule'
+ it_behaves_like 'other form language'
+ end
+
+ describe 'Polish', :locale => :pl do
+ it_behaves_like 'an ordinary rule'
+
+ it 'has "one", "few", "many" and "other" plural keys' do
+ plural_keys.size.should == 4
+ plural_keys.should include(:one, :few, :many, :other)
+ end
+
+ it "detects that 1 in category 'one'" do
+ rule.call(1).should == :one
+ end
+
+ [2, 3, 4, 22, 23, 24, 92, 93, 94].each do |count|
+ it "detects that #{count} in category 'few'" do
+ rule.call(count).should == :few
+ end
+ end
+
+ [0, 5, 8, 10, 11, 18, 20, 21, 25, 27, 30, 31, 35, 38, 40, 41, 114].each do |count|
+ it "detects that #{count} in category 'many'" do
+ rule.call(count).should == :many
+ end
+ end
+
+ [1.2, 3.7, 11.5, 20.8, 1004.3].each do |count|