diff --git a/lib/locales/ar.yml b/lib/locales/ar.yml
new file mode 100644
index 000000000..68a933303
--- /dev/null
+++ b/lib/locales/ar.yml
@@ -0,0 +1,26 @@
+# :arabic pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/locales/utils/p11n.rb)
+
+ar:
+ pagy:
+
+ item_name:
+ zero:
+ one: "عنصر"
+ two:
+ few:
+ many:
+ other: "عناصر"
+
+ nav:
+ prev: "‹ السابق"
+ next: "التالي ›"
+ gap: "…"
+
+ info:
+ no_items: "لا يوجد %{item_name}"
+ single_page: "عرض %{count} %{item_name}"
+ multiple_pages: "عرض %{item_name} %{from}-%{to} من اجمالي %{count}"
+
+ combo_nav_js: "الصفحة %{page_input} من %{pages}"
+
+ items_selector_js: "عرض %{items_input} %{item_name} لكل صفحة"
diff --git a/lib/locales/utils/p11n.rb b/lib/locales/utils/p11n.rb
index 4298287cc..9b189b0c2 100644
--- a/lib/locales/utils/p11n.rb
+++ b/lib/locales/utils/p11n.rb
@@ -19,6 +19,20 @@
p11n = {
one_other: -> (n){ n == 1 ? 'one' : 'other' }, # default
+ arabic: lambda do |n|
+ n ||= 0
+ mod100 = n % 100
+
+ case
+ when n == 0 then 'zero' # rubocop:disable Style/NumericPredicate
+ when n == 1 then 'one'
+ when n == 2 then 'two'
+ when (3..10).to_a.include?(mod100) then 'few'
+ when (11..99).to_a.include?(mod100) then 'many'
+ else 'other'
+ end
+ end,
+
east_slavic: lambda do |n|
n ||= 0
mod10 = n % 10
@@ -32,14 +46,6 @@
end
end,
- west_slavic: lambda do |n|
- case n
- when 1 then 'one'
- when 2, 3, 4 then 'few'
- else 'other'
- end
- end,
-
one_two_other: lambda do |n|
case n
when 1 then 'one'
@@ -63,7 +69,16 @@
when (from0to1 + from5to9).include?(mod10) || from12to14.include?(mod100) then 'many'
else 'other'
end
+ end,
+
+ west_slavic: lambda do |n|
+ case n
+ when 1 then 'one'
+ when 2, 3, 4 then 'few'
+ else 'other'
+ end
end
+
}
# Hash of locale/pluralization pairs
@@ -71,6 +86,7 @@
# The default pluralization for locales not explicitly listed here
# is the :one_other pluralization proc (used for English)
plurals = Hash.new(p11n[:one_other]).tap do |hash|
+ hash['ar'] = p11n[:arabic]
hash['bs'] = p11n[:east_slavic]
hash['cs'] = p11n[:west_slavic]
hash['id'] = p11n[:other]
diff --git a/pagy.manifest b/pagy.manifest
index 633aa8e66..9c9ddfc06 100644
--- a/pagy.manifest
+++ b/pagy.manifest
@@ -1,5 +1,6 @@
lib/config/pagy.rb
lib/javascripts/pagy.js
+lib/locales/ar.yml
lib/locales/bg.yml
lib/locales/bs.yml
lib/locales/ca.yml
diff --git a/test/locales/utils/p11n_test.rb b/test/locales/utils/p11n_test.rb
index f8a922aef..f9211df84 100644
--- a/test/locales/utils/p11n_test.rb
+++ b/test/locales/utils/p11n_test.rb
@@ -7,6 +7,57 @@
describe 'locales/utils/p11n' do
let(:p11n) { eval(Pagy.root.join('locales', 'utils', 'p11n.rb').read)[1].freeze } #rubocop:disable Security/Eval
+ describe :arabic do
+ it "detects that 0 belongs to 'zero'" do
+ _(p11n[:arabic].call(0)).must_equal 'zero'
+ end
+ it "detects that 1 belongs to 'one'" do
+ _(p11n[:arabic].call(1)).must_equal 'one'
+ end
+ it "detects that 2 belongs to 'two'" do
+ _(p11n[:arabic].call(2)).must_equal 'two'
+ end
+ [3, 4, 103, 208, 210, 807].each do |count|
+ it "detects that #{count} belongs to 'few'" do
+ _(p11n[:arabic].call(count)).must_equal 'few'
+ end
+ end
+ [11, 112, 280, 344, 523, 699, 820, 25, 27, 936].each do |count|
+ it "detects that #{count} belongs to 'many'" do
+ _(p11n[:arabic].call(count)).must_equal 'many'
+ end
+ end
+ [101, 102, 801, 1.2, 3.7, 11.5, 20.8, 1004.3].each do |count|
+ it "detects that #{count} in ru is 'other'" do
+ _(p11n[:arabic].call(count)).must_equal 'other'
+ end
+ end
+ end
+
+ describe :east_slavic do
+ [1, 21, 51, 71, 101, 1031].each do |count|
+ it "detects that #{count} belongs to 'one'" do
+ _(p11n[:east_slavic].call(count)).must_equal 'one'
+ end
+ end
+ [2, 3, 4, 22, 23, 24, 92, 93, 94].each do |count|
+ it "detects that #{count} belongs to 'few'" do
+ _(p11n[:east_slavic].call(count)).must_equal 'few'
+ end
+ end
+ [0, 5, 8, 10, 11, 18, 20, 25, 27, 30, 35, 38, 40].each do |count|
+ it "detects that #{count} belongs to 'many'" do
+ _(p11n[:east_slavic].call(count)).must_equal 'many'
+ end
+ end
+ [1.2, 3.7, 11.5, 20.8, 1004.3].each do |count|
+ it "detects that #{count} in ru is 'other'" do
+ _(p11n[:east_slavic].call(count)).must_equal 'other'
+ end
+ end
+ end
+
+ # default
describe :one_other do
it "detects that 1 belongs to 'one'" do
_(p11n[:one_other].call(1)).must_equal 'one'
@@ -53,29 +104,6 @@
end
end
- describe :east_slavic do
- [1, 21, 51, 71, 101, 1031].each do |count|
- it "detects that #{count} belongs to 'one'" do
- _(p11n[:east_slavic].call(count)).must_equal 'one'
- end
- end
- [2, 3, 4, 22, 23, 24, 92, 93, 94].each do |count|
- it "detects that #{count} belongs to 'few'" do
- _(p11n[:east_slavic].call(count)).must_equal 'few'
- end
- end
- [0, 5, 8, 10, 11, 18, 20, 25, 27, 30, 35, 38, 40].each do |count|
- it "detects that #{count} belongs to 'many'" do
- _(p11n[:east_slavic].call(count)).must_equal 'many'
- end
- end
- [1.2, 3.7, 11.5, 20.8, 1004.3].each do |count|
- it "detects that #{count} in ru is 'other'" do
- _(p11n[:east_slavic].call(count)).must_equal 'other'
- end
- end
- end
-
describe :polish do
it "detects that 1 belongs to 'one'" do
_(p11n[:polish].call(1)).must_equal 'one'