-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add pluralization rules for non-English-like locales
- Loading branch information
1 parent
1c1e091
commit 392c65f
Showing
113 changed files
with
1,906 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--colour |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
19 changes: 19 additions & 0 deletions
19
lib/rails_i18n/common_pluralizations/one_upto_two_other.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
20 changes: 20 additions & 0 deletions
20
lib/rails_i18n/common_pluralizations/one_with_zero_other.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
require 'rails_i18n/common_pluralizations/one_with_zero_other' | ||
|
||
::RailsI18n::Pluralization::OneWithZeroOther.with_locale(:ak) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
require 'rails_i18n/common_pluralizations/one_with_zero_other' | ||
|
||
::RailsI18n::Pluralization::OneWithZeroOther.with_locale(:am) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 }}}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
require 'rails_i18n/common_pluralizations/other' | ||
|
||
::RailsI18n::Pluralization::Other.with_locale(:az) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
require 'rails_i18n/common_pluralizations/east_slavic' | ||
|
||
::RailsI18n::Pluralization::EastSlavic.with_locale(:be) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
require 'rails_i18n/common_pluralizations/one_with_zero_other' | ||
|
||
::RailsI18n::Pluralization::OneWithZeroOther.with_locale(:bh) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
require 'rails_i18n/common_pluralizations/other' | ||
|
||
::RailsI18n::Pluralization::Other.with_locale(:bm) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
require 'rails_i18n/common_pluralizations/other' | ||
|
||
::RailsI18n::Pluralization::Other.with_locale(:bo) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 }}}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
require 'rails_i18n/common_pluralizations/west_slavic' | ||
|
||
::RailsI18n::Pluralization::WestSlavic.with_locale(:cs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 }}}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
require 'rails_i18n/common_pluralizations/other' | ||
|
||
::RailsI18n::Pluralization::Other.with_locale(:dz) |
Oops, something went wrong.