diff --git a/.rspec b/.rspec new file mode 100644 index 000000000..cf6add7ea --- /dev/null +++ b/.rspec @@ -0,0 +1 @@ +--colour \ No newline at end of file diff --git a/Rakefile b/Rakefile index ae612f062..c9d083889 100644 --- a/Rakefile +++ b/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 diff --git a/lib/rails_i18n/common_pluralizations/east_slavic.rb b/lib/rails_i18n/common_pluralizations/east_slavic.rb new file mode 100644 index 000000000..f9c6130fe --- /dev/null +++ b/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 diff --git a/lib/rails_i18n/common_pluralizations/one_two_other.rb b/lib/rails_i18n/common_pluralizations/one_two_other.rb new file mode 100644 index 000000000..d2029edb9 --- /dev/null +++ b/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 \ No newline at end of file diff --git a/lib/rails_i18n/common_pluralizations/one_upto_two_other.rb b/lib/rails_i18n/common_pluralizations/one_upto_two_other.rb new file mode 100644 index 000000000..bb1b4fffc --- /dev/null +++ b/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 \ No newline at end of file diff --git a/lib/rails_i18n/common_pluralizations/one_with_zero_other.rb b/lib/rails_i18n/common_pluralizations/one_with_zero_other.rb new file mode 100644 index 000000000..9c51999f8 --- /dev/null +++ b/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 diff --git a/lib/rails_i18n/common_pluralizations/other.rb b/lib/rails_i18n/common_pluralizations/other.rb new file mode 100644 index 000000000..3a1825bc5 --- /dev/null +++ b/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 diff --git a/lib/rails_i18n/common_pluralizations/romanian.rb b/lib/rails_i18n/common_pluralizations/romanian.rb new file mode 100644 index 000000000..bd8c2280b --- /dev/null +++ b/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 diff --git a/lib/rails_i18n/common_pluralizations/west_slavic.rb b/lib/rails_i18n/common_pluralizations/west_slavic.rb new file mode 100644 index 000000000..91de2671c --- /dev/null +++ b/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 diff --git a/lib/rails_i18n/railtie.rb b/lib/rails_i18n/railtie.rb index 8eae08677..7e1e3edf6 100644 --- a/lib/rails_i18n/railtie.rb +++ b/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 diff --git a/rails-i18n.gemspec b/rails-i18n.gemspec index 9fb70c8fc..4454c43e9 100644 --- a/rails-i18n.gemspec +++ b/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 diff --git a/rails/pluralization/ak.rb b/rails/pluralization/ak.rb new file mode 100644 index 000000000..53f039e44 --- /dev/null +++ b/rails/pluralization/ak.rb @@ -0,0 +1,3 @@ +require 'rails_i18n/common_pluralizations/one_with_zero_other' + +::RailsI18n::Pluralization::OneWithZeroOther.with_locale(:ak) \ No newline at end of file diff --git a/rails/pluralization/am.rb b/rails/pluralization/am.rb new file mode 100644 index 000000000..c954daeb3 --- /dev/null +++ b/rails/pluralization/am.rb @@ -0,0 +1,3 @@ +require 'rails_i18n/common_pluralizations/one_with_zero_other' + +::RailsI18n::Pluralization::OneWithZeroOther.with_locale(:am) \ No newline at end of file diff --git a/rails/pluralization/ar.rb b/rails/pluralization/ar.rb new file mode 100644 index 000000000..fe365947b --- /dev/null +++ b/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 }}}} \ No newline at end of file diff --git a/rails/pluralization/az.rb b/rails/pluralization/az.rb new file mode 100644 index 000000000..9cccda4ea --- /dev/null +++ b/rails/pluralization/az.rb @@ -0,0 +1,3 @@ +require 'rails_i18n/common_pluralizations/other' + +::RailsI18n::Pluralization::Other.with_locale(:az) \ No newline at end of file diff --git a/rails/pluralization/be.rb b/rails/pluralization/be.rb new file mode 100644 index 000000000..bd830e706 --- /dev/null +++ b/rails/pluralization/be.rb @@ -0,0 +1,3 @@ +require 'rails_i18n/common_pluralizations/east_slavic' + +::RailsI18n::Pluralization::EastSlavic.with_locale(:be) \ No newline at end of file diff --git a/rails/pluralization/bh.rb b/rails/pluralization/bh.rb new file mode 100644 index 000000000..b11920076 --- /dev/null +++ b/rails/pluralization/bh.rb @@ -0,0 +1,3 @@ +require 'rails_i18n/common_pluralizations/one_with_zero_other' + +::RailsI18n::Pluralization::OneWithZeroOther.with_locale(:bh) \ No newline at end of file diff --git a/rails/pluralization/bm.rb b/rails/pluralization/bm.rb new file mode 100644 index 000000000..a05709297 --- /dev/null +++ b/rails/pluralization/bm.rb @@ -0,0 +1,3 @@ +require 'rails_i18n/common_pluralizations/other' + +::RailsI18n::Pluralization::Other.with_locale(:bm) \ No newline at end of file diff --git a/rails/pluralization/bo.rb b/rails/pluralization/bo.rb new file mode 100644 index 000000000..c032f48ac --- /dev/null +++ b/rails/pluralization/bo.rb @@ -0,0 +1,3 @@ +require 'rails_i18n/common_pluralizations/other' + +::RailsI18n::Pluralization::Other.with_locale(:bo) \ No newline at end of file diff --git a/rails/pluralization/br.rb b/rails/pluralization/br.rb new file mode 100644 index 000000000..1d2ab7ad8 --- /dev/null +++ b/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 }}}} \ No newline at end of file diff --git a/rails/pluralization/bs.rb b/rails/pluralization/bs.rb index 56b1208d4..f4c78bb52 100644 --- a/rails/pluralization/bs.rb +++ b/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 } } } } } \ No newline at end of file +::RailsI18n::Pluralization::EastSlavic.with_locale(:bs) \ No newline at end of file diff --git a/rails/pluralization/cs.rb b/rails/pluralization/cs.rb new file mode 100644 index 000000000..63f01658b --- /dev/null +++ b/rails/pluralization/cs.rb @@ -0,0 +1,3 @@ +require 'rails_i18n/common_pluralizations/west_slavic' + +::RailsI18n::Pluralization::WestSlavic.with_locale(:cs) \ No newline at end of file diff --git a/rails/pluralization/cy.rb b/rails/pluralization/cy.rb new file mode 100644 index 000000000..d7f374b21 --- /dev/null +++ b/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 }}}} \ No newline at end of file diff --git a/rails/pluralization/dz.rb b/rails/pluralization/dz.rb new file mode 100644 index 000000000..075f5c3d8 --- /dev/null +++ b/rails/pluralization/dz.rb @@ -0,0 +1,3 @@ +require 'rails_i18n/common_pluralizations/other' + +::RailsI18n::Pluralization::Other.with_locale(:dz) \ No newline at end of file diff --git a/rails/pluralization/fa.rb b/rails/pluralization/fa.rb new file mode 100644 index 000000000..9b7e1bc77 --- /dev/null +++ b/rails/pluralization/fa.rb @@ -0,0 +1,3 @@ +require 'rails_i18n/common_pluralizations/other' + +::RailsI18n::Pluralization::Other.with_locale(:fa) \ No newline at end of file diff --git a/rails/pluralization/ff.rb b/rails/pluralization/ff.rb new file mode 100644 index 000000000..6cd207b43 --- /dev/null +++ b/rails/pluralization/ff.rb @@ -0,0 +1,3 @@ +require 'rails_i18n/common_pluralizations/one_upto_two_other' + +::RailsI18n::Pluralization::OneUptoTwoOther.with_locale(:ff) \ No newline at end of file diff --git a/rails/pluralization/fil.rb b/rails/pluralization/fil.rb new file mode 100644 index 000000000..9462d9bd3 --- /dev/null +++ b/rails/pluralization/fil.rb @@ -0,0 +1,3 @@ +require 'rails_i18n/common_pluralizations/one_with_zero_other' + +::RailsI18n::Pluralization::OneWithZeroOther.with_locale(:fil) \ No newline at end of file diff --git a/rails/pluralization/fr.rb b/rails/pluralization/fr.rb index e568ba246..9d0a86067 100644 --- a/rails/pluralization/fr.rb +++ b/rails/pluralization/fr.rb @@ -1 +1,3 @@ -{ :fr => { :i18n => {:plural => { :keys => [:one, :other], :rule => lambda { |n| n.between?(0, 2) && n != 2 ? :one : :other } } } } } \ No newline at end of file +require 'rails_i18n/common_pluralizations/one_upto_two_other' + +::RailsI18n::Pluralization::OneUptoTwoOther.with_locale(:fr) \ No newline at end of file diff --git a/rails/pluralization/ga.rb b/rails/pluralization/ga.rb new file mode 100644 index 000000000..0a288c7b4 --- /dev/null +++ b/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 }}}} \ No newline at end of file diff --git a/rails/pluralization/gd.rb b/rails/pluralization/gd.rb new file mode 100644 index 000000000..371b3e20c --- /dev/null +++ b/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 }}}} \ No newline at end of file diff --git a/rails/pluralization/guw.rb b/rails/pluralization/guw.rb new file mode 100644 index 000000000..700f1cf82 --- /dev/null +++ b/rails/pluralization/guw.rb @@ -0,0 +1,3 @@ +require 'rails_i18n/common_pluralizations/one_with_zero_other' + +::RailsI18n::Pluralization::OneWithZeroOther.with_locale(:guw) \ No newline at end of file diff --git a/rails/pluralization/gv.rb b/rails/pluralization/gv.rb new file mode 100644 index 000000000..dd61d01af --- /dev/null +++ b/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 }}}} \ No newline at end of file diff --git a/rails/pluralization/hi.rb b/rails/pluralization/hi.rb new file mode 100644 index 000000000..1ab6425b8 --- /dev/null +++ b/rails/pluralization/hi.rb @@ -0,0 +1,3 @@ +require 'rails_i18n/common_pluralizations/one_with_zero_other' + +::RailsI18n::Pluralization::OneWithZeroOther.with_locale(:hi) \ No newline at end of file diff --git a/rails/pluralization/hr.rb b/rails/pluralization/hr.rb new file mode 100644 index 000000000..72ca49f8b --- /dev/null +++ b/rails/pluralization/hr.rb @@ -0,0 +1,3 @@ +require 'rails_i18n/common_pluralizations/east_slavic' + +::RailsI18n::Pluralization::EastSlavic.with_locale(:hr) \ No newline at end of file diff --git a/rails/pluralization/hu.rb b/rails/pluralization/hu.rb new file mode 100644 index 000000000..128fba317 --- /dev/null +++ b/rails/pluralization/hu.rb @@ -0,0 +1,3 @@ +require 'rails_i18n/common_pluralizations/other' + +::RailsI18n::Pluralization::Other.with_locale(:hu) \ No newline at end of file diff --git a/rails/pluralization/id.rb b/rails/pluralization/id.rb new file mode 100644 index 000000000..04900e5bd --- /dev/null +++ b/rails/pluralization/id.rb @@ -0,0 +1,3 @@ +require 'rails_i18n/common_pluralizations/other' + +::RailsI18n::Pluralization::Other.with_locale(:id) \ No newline at end of file diff --git a/rails/pluralization/ig.rb b/rails/pluralization/ig.rb new file mode 100644 index 000000000..081d35973 --- /dev/null +++ b/rails/pluralization/ig.rb @@ -0,0 +1,3 @@ +require 'rails_i18n/common_pluralizations/other' + +::RailsI18n::Pluralization::Other.with_locale(:ig) \ No newline at end of file diff --git a/rails/pluralization/ii.rb b/rails/pluralization/ii.rb new file mode 100644 index 000000000..57f2015e6 --- /dev/null +++ b/rails/pluralization/ii.rb @@ -0,0 +1,3 @@ +require 'rails_i18n/common_pluralizations/other' + +::RailsI18n::Pluralization::Other.with_locale(:ii) \ No newline at end of file diff --git a/rails/pluralization/iu.rb b/rails/pluralization/iu.rb new file mode 100644 index 000000000..692c9a44d --- /dev/null +++ b/rails/pluralization/iu.rb @@ -0,0 +1,3 @@ +require 'rails_i18n/common_pluralizations/one_two_other' + +::RailsI18n::Pluralization::OneTwoOther.with_locale(:iu) \ No newline at end of file diff --git a/rails/pluralization/ja.rb b/rails/pluralization/ja.rb new file mode 100644 index 000000000..507a5e8b3 --- /dev/null +++ b/rails/pluralization/ja.rb @@ -0,0 +1,3 @@ +require 'rails_i18n/common_pluralizations/other' + +::RailsI18n::Pluralization::Other.with_locale(:ja) \ No newline at end of file diff --git a/rails/pluralization/jv.rb b/rails/pluralization/jv.rb new file mode 100644 index 000000000..d8862088d --- /dev/null +++ b/rails/pluralization/jv.rb @@ -0,0 +1,3 @@ +require 'rails_i18n/common_pluralizations/other' + +::RailsI18n::Pluralization::Other.with_locale(:jv) \ No newline at end of file diff --git a/rails/pluralization/ka.rb b/rails/pluralization/ka.rb new file mode 100644 index 000000000..f8a87b54d --- /dev/null +++ b/rails/pluralization/ka.rb @@ -0,0 +1,3 @@ +require 'rails_i18n/common_pluralizations/other' + +::RailsI18n::Pluralization::Other.with_locale(:ka) \ No newline at end of file diff --git a/rails/pluralization/kab.rb b/rails/pluralization/kab.rb new file mode 100644 index 000000000..011e9b06a --- /dev/null +++ b/rails/pluralization/kab.rb @@ -0,0 +1,3 @@ +require 'rails_i18n/common_pluralizations/one_upto_two_other' + +::RailsI18n::Pluralization::OneUptoTwoOther.with_locale(:kab) \ No newline at end of file diff --git a/rails/pluralization/kde.rb b/rails/pluralization/kde.rb new file mode 100644 index 000000000..64beb6794 --- /dev/null +++ b/rails/pluralization/kde.rb @@ -0,0 +1,3 @@ +require 'rails_i18n/common_pluralizations/other' + +::RailsI18n::Pluralization::Other.with_locale(:kde) \ No newline at end of file diff --git a/rails/pluralization/kea.rb b/rails/pluralization/kea.rb new file mode 100644 index 000000000..3b8a32c12 --- /dev/null +++ b/rails/pluralization/kea.rb @@ -0,0 +1,3 @@ +require 'rails_i18n/common_pluralizations/other' + +::RailsI18n::Pluralization::Other.with_locale(:kea) \ No newline at end of file diff --git a/rails/pluralization/km.rb b/rails/pluralization/km.rb new file mode 100644 index 000000000..824cb0bb0 --- /dev/null +++ b/rails/pluralization/km.rb @@ -0,0 +1,3 @@ +require 'rails_i18n/common_pluralizations/other' + +::RailsI18n::Pluralization::Other.with_locale(:km) \ No newline at end of file diff --git a/rails/pluralization/kn.rb b/rails/pluralization/kn.rb new file mode 100644 index 000000000..d70d56e2d --- /dev/null +++ b/rails/pluralization/kn.rb @@ -0,0 +1,3 @@ +require 'rails_i18n/common_pluralizations/other' + +::RailsI18n::Pluralization::Other.with_locale(:kn) \ No newline at end of file diff --git a/rails/pluralization/ko.rb b/rails/pluralization/ko.rb new file mode 100644 index 000000000..f4f48ca40 --- /dev/null +++ b/rails/pluralization/ko.rb @@ -0,0 +1,3 @@ +require 'rails_i18n/common_pluralizations/other' + +::RailsI18n::Pluralization::Other.with_locale(:ko) \ No newline at end of file diff --git a/rails/pluralization/ksh.rb b/rails/pluralization/ksh.rb new file mode 100644 index 000000000..7e16e8f48 --- /dev/null +++ b/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 }}}} \ No newline at end of file diff --git a/rails/pluralization/kw.rb b/rails/pluralization/kw.rb new file mode 100644 index 000000000..b5e9f381e --- /dev/null +++ b/rails/pluralization/kw.rb @@ -0,0 +1,3 @@ +require 'rails_i18n/common_pluralizations/one_two_other' + +::RailsI18n::Pluralization::OneTwoOther.with_locale(:kw) \ No newline at end of file diff --git a/rails/pluralization/lag.rb b/rails/pluralization/lag.rb new file mode 100644 index 000000000..b0b1f53c9 --- /dev/null +++ b/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 }}}} \ No newline at end of file diff --git a/rails/pluralization/ln.rb b/rails/pluralization/ln.rb new file mode 100644 index 000000000..0f89d4525 --- /dev/null +++ b/rails/pluralization/ln.rb @@ -0,0 +1,3 @@ +require 'rails_i18n/common_pluralizations/one_with_zero_other' + +::RailsI18n::Pluralization::OneWithZeroOther.with_locale(:ln) \ No newline at end of file diff --git a/rails/pluralization/lo.rb b/rails/pluralization/lo.rb new file mode 100644 index 000000000..b6e15a94f --- /dev/null +++ b/rails/pluralization/lo.rb @@ -0,0 +1,3 @@ +require 'rails_i18n/common_pluralizations/other' + +::RailsI18n::Pluralization::Other.with_locale(:lo) \ No newline at end of file diff --git a/rails/pluralization/lt.rb b/rails/pluralization/lt.rb new file mode 100644 index 000000000..15002a04c --- /dev/null +++ b/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 }}}} \ No newline at end of file diff --git a/rails/pluralization/lv.rb b/rails/pluralization/lv.rb new file mode 100644 index 000000000..c564478fc --- /dev/null +++ b/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 }}}} \ No newline at end of file diff --git a/rails/pluralization/mg.rb b/rails/pluralization/mg.rb new file mode 100644 index 000000000..17c28a487 --- /dev/null +++ b/rails/pluralization/mg.rb @@ -0,0 +1,3 @@ +require 'rails_i18n/common_pluralizations/one_with_zero_other' + +::RailsI18n::Pluralization::OneWithZeroOther.with_locale(:mg) \ No newline at end of file diff --git a/rails/pluralization/mk.rb b/rails/pluralization/mk.rb new file mode 100644 index 000000000..5100631a3 --- /dev/null +++ b/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 }}}} \ No newline at end of file diff --git a/rails/pluralization/mo.rb b/rails/pluralization/mo.rb new file mode 100644 index 000000000..c32170ee7 --- /dev/null +++ b/rails/pluralization/mo.rb @@ -0,0 +1,3 @@ +require 'rails_i18n/common_pluralizations/romanian' + +::RailsI18n::Pluralization::Romanian.with_locale(:mo) \ No newline at end of file diff --git a/rails/pluralization/ms.rb b/rails/pluralization/ms.rb new file mode 100644 index 000000000..d0a2e4139 --- /dev/null +++ b/rails/pluralization/ms.rb @@ -0,0 +1,3 @@ +require 'rails_i18n/common_pluralizations/other' + +::RailsI18n::Pluralization::Other.with_locale(:ms) \ No newline at end of file diff --git a/rails/pluralization/mt.rb b/rails/pluralization/mt.rb new file mode 100644 index 000000000..593fbdac5 --- /dev/null +++ b/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 }}}} \ No newline at end of file diff --git a/rails/pluralization/my.rb b/rails/pluralization/my.rb new file mode 100644 index 000000000..9b861b399 --- /dev/null +++ b/rails/pluralization/my.rb @@ -0,0 +1,3 @@ +require 'rails_i18n/common_pluralizations/other' + +::RailsI18n::Pluralization::Other.with_locale(:my) \ No newline at end of file diff --git a/rails/pluralization/naq.rb b/rails/pluralization/naq.rb new file mode 100644 index 000000000..5f82b8612 --- /dev/null +++ b/rails/pluralization/naq.rb @@ -0,0 +1,3 @@ +require 'rails_i18n/common_pluralizations/one_two_other' + +::RailsI18n::Pluralization::OneTwoOther.with_locale(:naq) \ No newline at end of file diff --git a/rails/pluralization/nso.rb b/rails/pluralization/nso.rb new file mode 100644 index 000000000..780a70e18 --- /dev/null +++ b/rails/pluralization/nso.rb @@ -0,0 +1,3 @@ +require 'rails_i18n/common_pluralizations/one_with_zero_other' + +::RailsI18n::Pluralization::OneWithZeroOther.with_locale(:nso) \ No newline at end of file diff --git a/rails/pluralization/pl.rb b/rails/pluralization/pl.rb new file mode 100644 index 000000000..984e49575 --- /dev/null +++ b/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 }}}} \ No newline at end of file diff --git a/rails/pluralization/ro.rb b/rails/pluralization/ro.rb new file mode 100644 index 000000000..9400df18f --- /dev/null +++ b/rails/pluralization/ro.rb @@ -0,0 +1,3 @@ +require 'rails_i18n/common_pluralizations/romanian' + +::RailsI18n::Pluralization::Romanian.with_locale(:ro) \ No newline at end of file diff --git a/rails/pluralization/root.rb b/rails/pluralization/root.rb new file mode 100644 index 000000000..87068089f --- /dev/null +++ b/rails/pluralization/root.rb @@ -0,0 +1,3 @@ +require 'rails_i18n/common_pluralizations/other' + +::RailsI18n::Pluralization::Other.with_locale(:root) \ No newline at end of file diff --git a/rails/pluralization/ru.rb b/rails/pluralization/ru.rb index c49f83d1b..2549573e5 100644 --- a/rails/pluralization/ru.rb +++ b/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 - } - } - } - } -} \ No newline at end of file +::RailsI18n::Pluralization::EastSlavic.with_locale(:ru) \ No newline at end of file diff --git a/rails/pluralization/sah.rb b/rails/pluralization/sah.rb new file mode 100644 index 000000000..9fb7e0617 --- /dev/null +++ b/rails/pluralization/sah.rb @@ -0,0 +1,3 @@ +require 'rails_i18n/common_pluralizations/other' + +::RailsI18n::Pluralization::Other.with_locale(:sah) \ No newline at end of file diff --git a/rails/pluralization/se.rb b/rails/pluralization/se.rb new file mode 100644 index 000000000..5e7f3b023 --- /dev/null +++ b/rails/pluralization/se.rb @@ -0,0 +1,3 @@ +require 'rails_i18n/common_pluralizations/one_two_other' + +::RailsI18n::Pluralization::OneTwoOther.with_locale(:se) \ No newline at end of file diff --git a/rails/pluralization/ses.rb b/rails/pluralization/ses.rb new file mode 100644 index 000000000..14cf5b882 --- /dev/null +++ b/rails/pluralization/ses.rb @@ -0,0 +1,3 @@ +require 'rails_i18n/common_pluralizations/other' + +::RailsI18n::Pluralization::Other.with_locale(:ses) \ No newline at end of file diff --git a/rails/pluralization/sg.rb b/rails/pluralization/sg.rb new file mode 100644 index 000000000..1672cceba --- /dev/null +++ b/rails/pluralization/sg.rb @@ -0,0 +1,3 @@ +require 'rails_i18n/common_pluralizations/other' + +::RailsI18n::Pluralization::Other.with_locale(:sg) \ No newline at end of file diff --git a/rails/pluralization/sh.rb b/rails/pluralization/sh.rb new file mode 100644 index 000000000..1a0fa45b6 --- /dev/null +++ b/rails/pluralization/sh.rb @@ -0,0 +1,3 @@ +require 'rails_i18n/common_pluralizations/east_slavic' + +::RailsI18n::Pluralization::EastSlavic.with_locale(:sh) \ No newline at end of file diff --git a/rails/pluralization/shi.rb b/rails/pluralization/shi.rb new file mode 100644 index 000000000..20b5fe1b6 --- /dev/null +++ b/rails/pluralization/shi.rb @@ -0,0 +1,3 @@ +require 'rails_i18n/common_pluralizations/one_with_zero_other' + +::RailsI18n::Pluralization::OneWithZeroOther.with_locale(:shi) \ No newline at end of file diff --git a/rails/pluralization/sk.rb b/rails/pluralization/sk.rb new file mode 100644 index 000000000..512a00070 --- /dev/null +++ b/rails/pluralization/sk.rb @@ -0,0 +1,3 @@ +require 'rails_i18n/common_pluralizations/west_slavic' + +::RailsI18n::Pluralization::WestSlavic.with_locale(:sk) \ No newline at end of file diff --git a/rails/pluralization/sl.rb b/rails/pluralization/sl.rb new file mode 100644 index 000000000..507bdc35c --- /dev/null +++ b/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 }}}} \ No newline at end of file diff --git a/rails/pluralization/sma.rb b/rails/pluralization/sma.rb new file mode 100644 index 000000000..b95531e27 --- /dev/null +++ b/rails/pluralization/sma.rb @@ -0,0 +1,3 @@ +require 'rails_i18n/common_pluralizations/one_two_other' + +::RailsI18n::Pluralization::OneTwoOther.with_locale(:sma) \ No newline at end of file diff --git a/rails/pluralization/smi.rb b/rails/pluralization/smi.rb new file mode 100644 index 000000000..7cb8d8b36 --- /dev/null +++ b/rails/pluralization/smi.rb @@ -0,0 +1,3 @@ +require 'rails_i18n/common_pluralizations/one_two_other' + +::RailsI18n::Pluralization::OneTwoOther.with_locale(:smi) \ No newline at end of file diff --git a/rails/pluralization/smj.rb b/rails/pluralization/smj.rb new file mode 100644 index 000000000..42bd97128 --- /dev/null +++ b/rails/pluralization/smj.rb @@ -0,0 +1,3 @@ +require 'rails_i18n/common_pluralizations/one_two_other' + +::RailsI18n::Pluralization::OneTwoOther.with_locale(:smj) \ No newline at end of file diff --git a/rails/pluralization/smn.rb b/rails/pluralization/smn.rb new file mode 100644 index 000000000..5f44e77d7 --- /dev/null +++ b/rails/pluralization/smn.rb @@ -0,0 +1,3 @@ +require 'rails_i18n/common_pluralizations/one_two_other' + +::RailsI18n::Pluralization::OneTwoOther.with_locale(:smn) \ No newline at end of file diff --git a/rails/pluralization/sms.rb b/rails/pluralization/sms.rb new file mode 100644 index 000000000..1eaceeea1 --- /dev/null +++ b/rails/pluralization/sms.rb @@ -0,0 +1,3 @@ +require 'rails_i18n/common_pluralizations/one_two_other' + +::RailsI18n::Pluralization::OneTwoOther.with_locale(:sms) \ No newline at end of file diff --git a/rails/pluralization/sr.rb b/rails/pluralization/sr.rb new file mode 100644 index 000000000..e526dc52c --- /dev/null +++ b/rails/pluralization/sr.rb @@ -0,0 +1,3 @@ +require 'rails_i18n/common_pluralizations/east_slavic' + +::RailsI18n::Pluralization::EastSlavic.with_locale(:sr) \ No newline at end of file diff --git a/rails/pluralization/th.rb b/rails/pluralization/th.rb new file mode 100644 index 000000000..c916ca96f --- /dev/null +++ b/rails/pluralization/th.rb @@ -0,0 +1,3 @@ +require 'rails_i18n/common_pluralizations/other' + +::RailsI18n::Pluralization::Other.with_locale(:th) \ No newline at end of file diff --git a/rails/pluralization/ti.rb b/rails/pluralization/ti.rb new file mode 100644 index 000000000..24d0c5e0a --- /dev/null +++ b/rails/pluralization/ti.rb @@ -0,0 +1,3 @@ +require 'rails_i18n/common_pluralizations/one_with_zero_other' + +::RailsI18n::Pluralization::OneWithZeroOther.with_locale(:ti) \ No newline at end of file diff --git a/rails/pluralization/tl.rb b/rails/pluralization/tl.rb new file mode 100644 index 000000000..a885e82b4 --- /dev/null +++ b/rails/pluralization/tl.rb @@ -0,0 +1,3 @@ +require 'rails_i18n/common_pluralizations/one_with_zero_other' + +::RailsI18n::Pluralization::OneWithZeroOther.with_locale(:tl) \ No newline at end of file diff --git a/rails/pluralization/to.rb b/rails/pluralization/to.rb new file mode 100644 index 000000000..ca96d0e4b --- /dev/null +++ b/rails/pluralization/to.rb @@ -0,0 +1,3 @@ +require 'rails_i18n/common_pluralizations/other' + +::RailsI18n::Pluralization::Other.with_locale(:to) \ No newline at end of file diff --git a/rails/pluralization/tr.rb b/rails/pluralization/tr.rb new file mode 100644 index 000000000..1c53a77dc --- /dev/null +++ b/rails/pluralization/tr.rb @@ -0,0 +1,3 @@ +require 'rails_i18n/common_pluralizations/other' + +::RailsI18n::Pluralization::Other.with_locale(:tr) \ No newline at end of file diff --git a/rails/pluralization/tzm.rb b/rails/pluralization/tzm.rb new file mode 100644 index 000000000..6b8eb2f90 --- /dev/null +++ b/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 }}}} \ No newline at end of file diff --git a/rails/pluralization/uk.rb b/rails/pluralization/uk.rb new file mode 100644 index 000000000..b0a3ab66f --- /dev/null +++ b/rails/pluralization/uk.rb @@ -0,0 +1,3 @@ +require 'rails_i18n/common_pluralizations/east_slavic' + +::RailsI18n::Pluralization::EastSlavic.with_locale(:uk) \ No newline at end of file diff --git a/rails/pluralization/vi.rb b/rails/pluralization/vi.rb new file mode 100644 index 000000000..64935285d --- /dev/null +++ b/rails/pluralization/vi.rb @@ -0,0 +1,3 @@ +require 'rails_i18n/common_pluralizations/other' + +::RailsI18n::Pluralization::Other.with_locale(:vi) \ No newline at end of file diff --git a/rails/pluralization/wa.rb b/rails/pluralization/wa.rb new file mode 100644 index 000000000..53ab58212 --- /dev/null +++ b/rails/pluralization/wa.rb @@ -0,0 +1,3 @@ +require 'rails_i18n/common_pluralizations/one_with_zero_other' + +::RailsI18n::Pluralization::OneWithZeroOther.with_locale(:wa) \ No newline at end of file diff --git a/rails/pluralization/wo.rb b/rails/pluralization/wo.rb new file mode 100644 index 000000000..dd8e85d72 --- /dev/null +++ b/rails/pluralization/wo.rb @@ -0,0 +1,3 @@ +require 'rails_i18n/common_pluralizations/other' + +::RailsI18n::Pluralization::Other.with_locale(:wo) \ No newline at end of file diff --git a/rails/pluralization/yo.rb b/rails/pluralization/yo.rb new file mode 100644 index 000000000..67f0708c8 --- /dev/null +++ b/rails/pluralization/yo.rb @@ -0,0 +1,3 @@ +require 'rails_i18n/common_pluralizations/other' + +::RailsI18n::Pluralization::Other.with_locale(:yo) \ No newline at end of file diff --git a/rails/pluralization/zh.rb b/rails/pluralization/zh.rb new file mode 100644 index 000000000..3a76ca0c5 --- /dev/null +++ b/rails/pluralization/zh.rb @@ -0,0 +1,3 @@ +require 'rails_i18n/common_pluralizations/other' + +::RailsI18n::Pluralization::Other.with_locale(:zh) \ No newline at end of file diff --git a/spec/fake_app.rb b/spec/fake_app.rb deleted file mode 100644 index f7b465b86..000000000 --- a/spec/fake_app.rb +++ /dev/null @@ -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! diff --git a/spec/fixtures/nl.yml b/spec/fixtures/nl.yml new file mode 100644 index 000000000..63e363a97 --- /dev/null +++ b/spec/fixtures/nl.yml @@ -0,0 +1,4 @@ +nl: + retiree: + one: gepensioneerde + other: gepensioneerden \ No newline at end of file diff --git a/spec/fixtures/ru.yml b/spec/fixtures/ru.yml new file mode 100644 index 000000000..92e91bec9 --- /dev/null +++ b/spec/fixtures/ru.yml @@ -0,0 +1,6 @@ +ru: + grandmother: + one: бабушка + few: бабушки + many: бабушек + other: бабушки \ No newline at end of file diff --git a/spec/integration/pluralization_spec.rb b/spec/integration/pluralization_spec.rb new file mode 100644 index 000000000..af23c959f --- /dev/null +++ b/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 \ No newline at end of file diff --git a/spec/integration/translation_spec.rb b/spec/integration/translation_spec.rb new file mode 100644 index 000000000..99ef0b110 --- /dev/null +++ b/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 \ No newline at end of file diff --git a/spec/rails-i18n/translation_spec.rb b/spec/rails-i18n/translation_spec.rb deleted file mode 100644 index 063b052e6..000000000 --- a/spec/rails-i18n/translation_spec.rb +++ /dev/null @@ -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 \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index bca11e423..82d569d80 100644 --- a/spec/spec_helper.rb +++ b/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 \ No newline at end of file diff --git a/spec/support/fake_app.rb b/spec/support/fake_app.rb new file mode 100644 index 000000000..7ad758832 --- /dev/null +++ b/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 diff --git a/spec/support/pluralization_file.rb b/spec/support/pluralization_file.rb new file mode 100644 index 000000000..fa4288a89 --- /dev/null +++ b/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 \ No newline at end of file diff --git a/spec/unit/pluralization/shared/east_slavic.rb b/spec/unit/pluralization/shared/east_slavic.rb new file mode 100644 index 000000000..0290c0715 --- /dev/null +++ b/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 \ No newline at end of file diff --git a/spec/unit/pluralization/shared/one_two_other.rb b/spec/unit/pluralization/shared/one_two_other.rb new file mode 100644 index 000000000..50262a0bb --- /dev/null +++ b/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 \ No newline at end of file diff --git a/spec/unit/pluralization/shared/one_upto_two_other.rb b/spec/unit/pluralization/shared/one_upto_two_other.rb new file mode 100644 index 000000000..1ccfa37e8 --- /dev/null +++ b/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 \ No newline at end of file diff --git a/spec/unit/pluralization/shared/one_with_zero_other.rb b/spec/unit/pluralization/shared/one_with_zero_other.rb new file mode 100644 index 000000000..9639120dd --- /dev/null +++ b/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 \ No newline at end of file diff --git a/spec/unit/pluralization/shared/ordinary.rb b/spec/unit/pluralization/shared/ordinary.rb new file mode 100644 index 000000000..b1e5ad1ce --- /dev/null +++ b/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 \ No newline at end of file diff --git a/spec/unit/pluralization/shared/other.rb b/spec/unit/pluralization/shared/other.rb new file mode 100644 index 000000000..aed3c3265 --- /dev/null +++ b/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 \ No newline at end of file diff --git a/spec/unit/pluralization/shared/romanian.rb b/spec/unit/pluralization/shared/romanian.rb new file mode 100644 index 000000000..2512b32c5 --- /dev/null +++ b/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 \ No newline at end of file diff --git a/spec/unit/pluralization/shared/west_slavic.rb b/spec/unit/pluralization/shared/west_slavic.rb new file mode 100644 index 000000000..526e02a1d --- /dev/null +++ b/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 \ No newline at end of file diff --git a/spec/unit/pluralization_spec.rb b/spec/unit/pluralization_spec.rb new file mode 100644 index 000000000..25cbedab3 --- /dev/null +++ b/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| + it "detects that #{count} in category 'other'" do + rule.call(count).should == :other + end + end + end + + describe 'Romanian', :locale => :ro do + it_behaves_like 'an ordinary rule' + it_behaves_like 'Romanian language' + end + + describe 'Root', :locale => :root do + it_behaves_like 'an ordinary rule' + it_behaves_like 'other form language' + end + + describe 'Russian', :locale => :ru do + it_behaves_like 'an ordinary rule' + it_behaves_like 'East Slavic' + end + + describe 'Sakha', :locale => :sah do + it_behaves_like 'an ordinary rule' + it_behaves_like 'other form language' + end + + describe 'Sami Language', :locale => :smi do + it_behaves_like 'an ordinary rule' + it_behaves_like 'one-two-other forms language' + end + + describe 'Sango', :locale => :sg do + it_behaves_like 'an ordinary rule' + it_behaves_like 'other form language' + end + + describe 'Scottish Gaelic', :locale => :gd do + it_behaves_like 'an ordinary rule' + + it 'has "one", "two", "few", and "other" plural keys' do + plural_keys.size.should == 4 + plural_keys.should include(:one, :few, :two, :other) + end + + [1, 11].each do |count| + it "detects that #{count} in category 'one'" do + rule.call(count).should == :one + end + end + + [2, 12].each do |count| + it "detects that #{count} in category 'two'" do + rule.call(count).should == :two + end + end + + [3, 5, 7, 9, 10, 13, 14, 16, 18, 19].each do |count| + it "detects that #{count} in category 'few'" do + rule.call(count).should == :few + end + end + + [0, 1.2, 3.7, 20, 21, 23, 25, 31, 44, 58, 71, 84, 99, 100].each do |count| + it "detects that #{count} in category 'other'" do + rule.call(count).should == :other + end + end + end + + describe 'Serbian', :locale => :sr do + it_behaves_like 'an ordinary rule' + it_behaves_like 'East Slavic' + end + + describe 'Serbo-Croatian', :locale => :sh do + it_behaves_like 'an ordinary rule' + it_behaves_like 'East Slavic' + end + + describe 'Sichuan Yi', :locale => :ii do + it_behaves_like 'an ordinary rule' + it_behaves_like 'other form language' + end + + describe 'Skolt Sami', :locale => :sms do + it_behaves_like 'an ordinary rule' + it_behaves_like 'one-two-other forms language' + end + + describe 'Slovak', :locale => :sk do + it_behaves_like 'an ordinary rule' + it_behaves_like 'West Slavic' + end + + describe 'Slovenian', :locale => :sl do + it_behaves_like 'an ordinary rule' + + it 'has "one", "two", "few", and "other" plural keys' do + plural_keys.size.should == 4 + plural_keys.should include(:one, :few, :two, :other) + end + + [1, 101, 201, 301, 601].each do |count| + it "detects that #{count} in category 'one'" do + rule.call(count).should == :one + end + end + + [2, 102, 302, 502].each do |count| + it "detects that #{count} in category 'two'" do + rule.call(count).should == :two + end + end + + [3, 4, 103, 104, 203, 204, 403, 404].each do |count| + it "detects that #{count} in category 'few'" do + rule.call(count).should == :few + end + end + + [0, 1.2, 3.7, 5, 10, 11, 12, 13, 17, 20, 21, 23, 71, 84, 99, 100].each do |count| + it "detects that #{count} in category 'other'" do + rule.call(count).should == :other + end + end + end + + describe 'Southern Sami', :locale => :sma do + it_behaves_like 'an ordinary rule' + it_behaves_like 'one-two-other forms language' + end + + describe 'Tachelhit', :locale => :shi do + it_behaves_like 'an ordinary rule' + it_behaves_like 'one(with zero)-other forms language' + end + + describe 'Tagalog', :locale => :tl do + it_behaves_like 'an ordinary rule' + it_behaves_like 'one(with zero)-other forms language' + end + + describe 'Thai', :locale => :th do + it_behaves_like 'an ordinary rule' + it_behaves_like 'other form language' + end + + describe 'Tibetan', :locale => :bo do + it_behaves_like 'an ordinary rule' + it_behaves_like 'other form language' + end + + describe 'Tigrinya', :locale => :ti do + it_behaves_like 'an ordinary rule' + it_behaves_like 'one(with zero)-other forms language' + end + + describe 'Tongan', :locale => :to do + it_behaves_like 'an ordinary rule' + it_behaves_like 'other form language' + end + + describe 'Turkish', :locale => :tr do + it_behaves_like 'an ordinary rule' + it_behaves_like 'other form language' + end + + describe 'Ukrainian', :locale => :uk do + it_behaves_like 'an ordinary rule' + it_behaves_like 'East Slavic' + end + + describe 'Vietnamese', :locale => :vi do + it_behaves_like 'an ordinary rule' + it_behaves_like 'other form language' + end + + describe 'Walloon', :locale => :wa do + it_behaves_like 'an ordinary rule' + it_behaves_like 'one(with zero)-other forms language' + end + + describe 'Welsh', :locale => :cy 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 + + it "detects that 3 in category 'few'" do + rule.call(3).should == :few + end + + it "detects that 6 in category 'many'" do + rule.call(6).should == :many + end + + [0.3, 1.2, 4, 5, 7, 10, 11, 12, 13, 17, 20, 21, 23, 71, 84, 99, 100].each do |count| + it "detects that #{count} in category 'other'" do + rule.call(count).should == :other + end + end + end + + describe 'Wolof', :locale => :wo do + it_behaves_like 'an ordinary rule' + it_behaves_like 'other form language' + end + + describe 'Yoruba', :locale => :yo do + it_behaves_like 'an ordinary rule' + it_behaves_like 'other form language' + end +end \ No newline at end of file diff --git a/spec/unit/translation_spec.rb b/spec/unit/translation_spec.rb new file mode 100644 index 000000000..f7e780e73 --- /dev/null +++ b/spec/unit/translation_spec.rb @@ -0,0 +1,10 @@ +# coding: utf-8 + +require 'spec_helper' + +Dir.glob('rails/locale/*.yml') do |locale_file| + describe "a rails-i18n #{locale_file} 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 \ No newline at end of file diff --git a/spec/rails-i18n/will_paginate_spec.rb b/spec/unit/will_paginate_spec.rb similarity index 61% rename from spec/rails-i18n/will_paginate_spec.rb rename to spec/unit/will_paginate_spec.rb index eec4e6caf..20296c1d0 100644 --- a/spec/rails-i18n/will_paginate_spec.rb +++ b/spec/unit/will_paginate_spec.rb @@ -1,11 +1,11 @@ require 'spec_helper' -describe "will_paginate" do - it "should give translations for will_paginate" do - I18n.t("will_paginate.next_label").should == "Next →" - end -end - +#describe "will_paginate" do +# it "should give translations for will_paginate" do +# I18n.t("will_paginate.next_label").should == "Next →" +# end +#end +# Dir.glob('will_paginate/*.yml') do |locale_file| describe "a will_paginate locale file" do it_behaves_like 'a valid locale file', locale_file