pagy 3.8.0 → 4.10.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.txt +1 -1
- data/lib/config/pagy.rb +36 -25
- data/lib/javascripts/pagy.js +104 -93
- data/lib/locales/ar.yml +26 -0
- data/lib/locales/bg.yml +2 -2
- data/lib/locales/bs.yml +24 -0
- data/lib/locales/ca.yml +2 -2
- data/lib/locales/cs.yml +22 -0
- data/lib/locales/da.yml +2 -2
- data/lib/locales/de.yml +2 -2
- data/lib/locales/en.yml +2 -2
- data/lib/locales/es.yml +2 -2
- data/lib/locales/fr.yml +2 -2
- data/lib/locales/hr.yml +24 -0
- data/lib/locales/id.yml +2 -2
- data/lib/locales/it.yml +2 -2
- data/lib/locales/ja.yml +2 -2
- data/lib/locales/km.yml +2 -2
- data/lib/locales/ko.yml +2 -2
- data/lib/locales/nb.yml +2 -2
- data/lib/locales/nl.yml +2 -2
- data/lib/locales/pl.yml +2 -2
- data/lib/locales/pt-BR.yml +2 -2
- data/lib/locales/pt.yml +22 -0
- data/lib/locales/ru.yml +2 -2
- data/lib/locales/sr.yml +23 -0
- data/lib/locales/sv-SE.yml +2 -2
- data/lib/locales/sv.yml +2 -2
- data/lib/locales/sw.yml +22 -0
- data/lib/locales/tr.yml +2 -2
- data/lib/locales/uk.yml +24 -0
- data/lib/locales/utils/i18n.rb +3 -11
- data/lib/locales/utils/loader.rb +7 -10
- data/lib/locales/utils/p11n.rb +49 -17
- data/lib/locales/zh-CN.yml +2 -2
- data/lib/locales/zh-HK.yml +2 -2
- data/lib/locales/zh-TW.yml +3 -3
- data/lib/pagy.rb +50 -26
- data/lib/pagy/backend.rb +5 -3
- data/lib/pagy/console.rb +21 -0
- data/lib/pagy/countless.rb +13 -10
- data/lib/pagy/deprecation.rb +27 -0
- data/lib/pagy/exceptions.rb +7 -2
- data/lib/pagy/extras/arel.rb +4 -3
- data/lib/pagy/extras/array.rb +4 -3
- data/lib/pagy/extras/bootstrap.rb +61 -30
- data/lib/pagy/extras/bulma.rb +60 -38
- data/lib/pagy/extras/countless.rb +7 -8
- data/lib/pagy/extras/elasticsearch_rails.rb +28 -17
- data/lib/pagy/extras/foundation.rb +61 -32
- data/lib/pagy/extras/headers.rb +13 -9
- data/lib/pagy/extras/i18n.rb +11 -5
- data/lib/pagy/extras/items.rb +21 -34
- data/lib/pagy/extras/materialize.rb +58 -35
- data/lib/pagy/extras/meilisearch.rb +55 -0
- data/lib/pagy/extras/metadata.rb +27 -21
- data/lib/pagy/extras/navs.rb +44 -20
- data/lib/pagy/extras/overflow.rb +52 -48
- data/lib/pagy/extras/searchkick.rb +27 -16
- data/lib/pagy/extras/semantic.rb +55 -30
- data/lib/pagy/extras/shared.rb +14 -15
- data/lib/pagy/extras/standalone.rb +62 -0
- data/lib/pagy/extras/support.rb +26 -9
- data/lib/pagy/extras/trim.rb +12 -11
- data/lib/pagy/extras/uikit.rb +54 -35
- data/lib/pagy/frontend.rb +64 -32
- metadata +16 -7
- data/lib/locales/README.md +0 -35
- data/lib/pagy/extras/pagy_search.rb +0 -18
- data/pagy.gemspec +0 -16
data/lib/locales/en.yml
CHANGED
@@ -17,6 +17,6 @@ en:
|
|
17
17
|
single_page: "Displaying <b>%{count}</b> %{item_name}"
|
18
18
|
multiple_pages: "Displaying %{item_name} <b>%{from}-%{to}</b> of <b>%{count}</b> in total"
|
19
19
|
|
20
|
-
combo_nav_js: "Page %{page_input} of %{pages}"
|
20
|
+
combo_nav_js: "<label>Page %{page_input} of %{pages}</label>"
|
21
21
|
|
22
|
-
items_selector_js: "Show %{items_input} %{item_name} per page"
|
22
|
+
items_selector_js: "<label>Show %{items_input} %{item_name} per page</label>"
|
data/lib/locales/es.yml
CHANGED
@@ -17,6 +17,6 @@ es:
|
|
17
17
|
single_page: "Mostrando %{count} %{item_name}"
|
18
18
|
multiple_pages: "Mostrando %{item_name} %{from}-%{to} de %{count} en total"
|
19
19
|
|
20
|
-
combo_nav_js: "Página %{page_input} de %{pages}"
|
20
|
+
combo_nav_js: "<label>Página %{page_input} de %{pages}</label>"
|
21
21
|
|
22
|
-
items_selector_js: "Mostrar %{items_input} %{item_name} por página"
|
22
|
+
items_selector_js: "<label>Mostrar %{items_input} %{item_name} por página</label>"
|
data/lib/locales/fr.yml
CHANGED
@@ -17,6 +17,6 @@ fr:
|
|
17
17
|
single_page: "Affichage de <b>%{count}</b> %{item_name}"
|
18
18
|
multiple_pages: "Affichage des %{item_name} <b>%{from} à %{to}</b> sur <b>%{count}</b> au total"
|
19
19
|
|
20
|
-
combo_nav_js: "Page %{page_input} sur %{pages}"
|
20
|
+
combo_nav_js: "<label>Page %{page_input} sur %{pages}</label>"
|
21
21
|
|
22
|
-
items_selector_js: "Afficher %{items_input} %{item_name} par page"
|
22
|
+
items_selector_js: "<label>Afficher %{items_input} %{item_name} par page</label>"
|
data/lib/locales/hr.yml
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# :east_slavic pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/locales/utils/p11n.rb)
|
2
|
+
|
3
|
+
hr:
|
4
|
+
pagy:
|
5
|
+
|
6
|
+
item_name:
|
7
|
+
one: "stavka"
|
8
|
+
few: "stavke"
|
9
|
+
many: "stavki"
|
10
|
+
other: "stavki"
|
11
|
+
|
12
|
+
nav:
|
13
|
+
prev: "‹ Prethodna"
|
14
|
+
next: "Sljedeća ›"
|
15
|
+
gap: "…"
|
16
|
+
|
17
|
+
info:
|
18
|
+
no_items: "Nije pronađena %{item_name}"
|
19
|
+
single_page: "Prikazuje se <b>%{count}</b> %{item_name}"
|
20
|
+
multiple_pages: "Prikaz %{item_name} <b>%{from}-%{to}</b> od <b>%{count}</b> ukupno"
|
21
|
+
|
22
|
+
combo_nav_js: "<label>Stranica %{page_input} od %{pages}</label>"
|
23
|
+
|
24
|
+
items_selector_js: "<label>Prikaži %{items_input} %{item_name} po stranici</label>"
|
data/lib/locales/id.yml
CHANGED
@@ -15,6 +15,6 @@ id:
|
|
15
15
|
single_page: "Menampilkan <b>%{count}</b> %{item_name}"
|
16
16
|
multiple_pages: "Menampilkan %{item_name} <b>%{from}-%{to}</b> dari total <b>%{count}</b>"
|
17
17
|
|
18
|
-
combo_nav_js: "Halaman %{page_input} dari %{pages}"
|
18
|
+
combo_nav_js: "<label>Halaman %{page_input} dari %{pages}</label>"
|
19
19
|
|
20
|
-
items_selector_js: "Tampilkan %{items_input} %{item_name} per halaman"
|
20
|
+
items_selector_js: "<label>Tampilkan %{items_input} %{item_name} per halaman</label>"
|
data/lib/locales/it.yml
CHANGED
@@ -17,6 +17,6 @@ it:
|
|
17
17
|
single_page: "Visualizzazione di <b>%{count}</b> %{item_name}"
|
18
18
|
multiple_pages: "Visualizzazione %{item_name} <b>%{from}-%{to}</b> di <b>%{count}</b> in totale"
|
19
19
|
|
20
|
-
combo_nav_js: "Pagina %{page_input} di %{pages}"
|
20
|
+
combo_nav_js: "<label>Pagina %{page_input} di %{pages}</label>"
|
21
21
|
|
22
|
-
items_selector_js: "Mostra %{items_input} %{item_name} per pagina"
|
22
|
+
items_selector_js: "<label>Mostra %{items_input} %{item_name} per pagina</label>"
|
data/lib/locales/ja.yml
CHANGED
@@ -15,6 +15,6 @@ ja:
|
|
15
15
|
single_page: "<b>%{count}</b> 件の%{item_name}"
|
16
16
|
multiple_pages: "<b>%{count}</b> 件中 <b>%{from}-%{to}</b> 件目の%{item_name}を表示中"
|
17
17
|
|
18
|
-
combo_nav_js: "
|
18
|
+
combo_nav_js: "<label>%{page_input} / %{pages} ページ</label>"
|
19
19
|
|
20
|
-
items_selector_js: "
|
20
|
+
items_selector_js: "<label>%{items_input} 件ずつ表示</label>"
|
data/lib/locales/km.yml
CHANGED
@@ -14,6 +14,6 @@ km:
|
|
14
14
|
single_page: "បង្ហាញ <b>%{count}</b> %{item_name}"
|
15
15
|
multiple_pages: "បង្ហាញ %{item_name} <b>%{from}-%{to}</b> នៃ <b>%{count}</b> ជាចំនួនសរុប"
|
16
16
|
|
17
|
-
combo_nav_js: "
|
17
|
+
combo_nav_js: "<label>ទំព័រ %{page_input} នៃ %{pages}</label>"
|
18
18
|
|
19
|
-
items_selector_js: "
|
19
|
+
items_selector_js: "<label>បង្ហាញ %{items_input} %{item_name} ក្នុង ១ ទំព័រ</label>"
|
data/lib/locales/ko.yml
CHANGED
@@ -15,6 +15,6 @@ ko:
|
|
15
15
|
single_page: "<b>%{count}</b>개의 %{item_name} 표시됨"
|
16
16
|
multiple_pages: "총 <b>%{count}</b>개의 %{item_name} 중 <b>%{from}-%{to}</b>"
|
17
17
|
|
18
|
-
combo_nav_js: "
|
18
|
+
combo_nav_js: "<label>총 %{pages} 중 %{page_input} 페이지</label>"
|
19
19
|
|
20
|
-
items_selector_js: "
|
20
|
+
items_selector_js: "<label>페이지 당 %{items_input}개 표시%</label>"
|
data/lib/locales/nb.yml
CHANGED
@@ -17,6 +17,6 @@ nb:
|
|
17
17
|
single_page: "Viser <b>%{count}</b> %{item_name}"
|
18
18
|
multiple_pages: "Viser %{item_name} <b>%{from}-%{to}</b> av totalt <b>%{count}</b>"
|
19
19
|
|
20
|
-
combo_nav_js: "Side %{page_input} av %{pages}"
|
20
|
+
combo_nav_js: "<label>Side %{page_input} av %{pages}</label>"
|
21
21
|
|
22
|
-
items_selector_js: "Vis %{items_input} %{item_name} per side"
|
22
|
+
items_selector_js: "<label>Vis %{items_input} %{item_name} per side</label>"
|
data/lib/locales/nl.yml
CHANGED
@@ -17,6 +17,6 @@ nl:
|
|
17
17
|
single_page: "Toont <b>%{count}</b> %{item_name}"
|
18
18
|
multiple_pages: "Toont <b>%{from}-%{to}</b> %{item_name} van <b>%{count}</b> in totaal"
|
19
19
|
|
20
|
-
combo_nav_js: "Pagina %{page_input} van %{pages}"
|
20
|
+
combo_nav_js: "<label>Pagina %{page_input} van %{pages}</label>"
|
21
21
|
|
22
|
-
items_selector_js: "Toont %{items_input} %{item_name} per pagina"
|
22
|
+
items_selector_js: "<label>Toont %{items_input} %{item_name} per pagina</label>"
|
data/lib/locales/pl.yml
CHANGED
@@ -19,6 +19,6 @@ pl:
|
|
19
19
|
single_page: "Wyświetlono <b>%{count}</b> %{item_name}"
|
20
20
|
multiple_pages: "Wyświetlono %{item_name} <b>%{from}-%{to}</b> z wszystkich <b>%{count}</b>"
|
21
21
|
|
22
|
-
combo_nav_js: "Strona %{page_input} z %{pages}"
|
22
|
+
combo_nav_js: "<label>Strona %{page_input} z %{pages}</label>"
|
23
23
|
|
24
|
-
items_selector_js: "Pokaż %{items_input} %{item_name} na stronie"
|
24
|
+
items_selector_js: "<label>Pokaż %{items_input} %{item_name} na stronie</label>"
|
data/lib/locales/pt-BR.yml
CHANGED
@@ -17,6 +17,6 @@ pt-BR:
|
|
17
17
|
single_page: "Mostrando %{count} %{item_name}"
|
18
18
|
multiple_pages: "Mostrando %{item_name} %{from}-%{to} do total de %{count}"
|
19
19
|
|
20
|
-
combo_nav_js: "Página %{page_input} de %{pages}"
|
20
|
+
combo_nav_js: "<label>Página %{page_input} de %{pages}</label>"
|
21
21
|
|
22
|
-
items_selector_js: "Mostrar %{items_input} %{item_name} por página"
|
22
|
+
items_selector_js: "<label>Mostrar %{items_input} %{item_name} por página</label>"
|
data/lib/locales/pt.yml
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# :one_other pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/locales/utils/p11n.rb)
|
2
|
+
|
3
|
+
pt:
|
4
|
+
pagy:
|
5
|
+
|
6
|
+
item_name:
|
7
|
+
one: "item"
|
8
|
+
other: "itens"
|
9
|
+
|
10
|
+
nav:
|
11
|
+
prev: "‹ Anterior"
|
12
|
+
next: "Próximo ›"
|
13
|
+
gap: "…"
|
14
|
+
|
15
|
+
info:
|
16
|
+
no_items: "Sem resultados"
|
17
|
+
single_page: "Mostrando %{count} %{item_name}"
|
18
|
+
multiple_pages: "Mostrando %{item_name} %{from}-%{to} de um total de %{count}"
|
19
|
+
|
20
|
+
combo_nav_js: "<label>Página %{page_input} de %{pages}</label>"
|
21
|
+
|
22
|
+
items_selector_js: "<label>Mostrar %{items_input} %{item_name} por página</label>"
|
data/lib/locales/ru.yml
CHANGED
@@ -19,6 +19,6 @@ ru:
|
|
19
19
|
single_page: "<b>%{count}</b> %{item_name}"
|
20
20
|
multiple_pages: "Всего <b>%{count}</b> %{item_name}, показаны с <b>%{from}</b> по <b>%{to}</b>"
|
21
21
|
|
22
|
-
combo_nav_js: "
|
22
|
+
combo_nav_js: "<label>Страница %{page_input} из %{pages}</label>"
|
23
23
|
|
24
|
-
items_selector_js: "
|
24
|
+
items_selector_js: "<label>Показать %{items_input} %{item_name} на странице</label>"
|
data/lib/locales/sr.yml
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# :east_slavic pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/locales/utils/p11n.rb)
|
2
|
+
|
3
|
+
sr:
|
4
|
+
pagy:
|
5
|
+
item_name:
|
6
|
+
one: "ставка"
|
7
|
+
few: "ставкe"
|
8
|
+
many: "ставки"
|
9
|
+
other: "ставки"
|
10
|
+
|
11
|
+
nav:
|
12
|
+
prev: "‹ Претходна"
|
13
|
+
next: "Следећa ›"
|
14
|
+
gap: "…"
|
15
|
+
|
16
|
+
info:
|
17
|
+
no_items: "Нema пронађених %{item_name}"
|
18
|
+
single_page: "Приказује се <b>%{count}</b> %{item_name}"
|
19
|
+
multiple_pages: "Приказ %{item_name} <b>%{from}-%{to}</b> од <b>%{count}</b> укупно"
|
20
|
+
|
21
|
+
combo_nav_js: "<label>Страниca %{page_input} од %{pages}</label>"
|
22
|
+
|
23
|
+
items_selector_js: "<label>Прикажи %{items_input} %{item_name} по страниcи</label>"
|
data/lib/locales/sv-SE.yml
CHANGED
@@ -18,6 +18,6 @@ sv-SE:
|
|
18
18
|
single_page: "Visar <b>%{count}</b> %{item_name}"
|
19
19
|
multiple_pages: "Visar %{item_name} <b>%{from}-%{to}</b> av <b>%{count}</b> totalt"
|
20
20
|
|
21
|
-
combo_nav_js: "Sida %{page_input} av %{pages}"
|
21
|
+
combo_nav_js: "<label>Sida %{page_input} av %{pages}</label>"
|
22
22
|
|
23
|
-
items_selector_js: "Visa %{items_input} %{item_name} per sida"
|
23
|
+
items_selector_js: "<label>Visa %{items_input} %{item_name} per sida</label>"
|
data/lib/locales/sv.yml
CHANGED
@@ -18,6 +18,6 @@ sv:
|
|
18
18
|
single_page: "Visar <b>%{count}</b> %{item_name}"
|
19
19
|
multiple_pages: "Visar %{item_name} <b>%{from}-%{to}</b> av <b>%{count}</b> totalt"
|
20
20
|
|
21
|
-
combo_nav_js: "Sida %{page_input} av %{pages}"
|
21
|
+
combo_nav_js: "<label>Sida %{page_input} av %{pages}</label>"
|
22
22
|
|
23
|
-
items_selector_js: "Visa %{items_input} %{item_name} per sida"
|
23
|
+
items_selector_js: "<label>Visa %{items_input} %{item_name} per sida</label>"
|
data/lib/locales/sw.yml
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# :one_other pluralization
|
2
|
+
|
3
|
+
sw:
|
4
|
+
pagy:
|
5
|
+
|
6
|
+
item_name:
|
7
|
+
one: "kifaa"
|
8
|
+
other: "vifaa"
|
9
|
+
|
10
|
+
nav:
|
11
|
+
prev: "‹ Awali"
|
12
|
+
next: "Ifuatayo ›"
|
13
|
+
gap: "…"
|
14
|
+
|
15
|
+
info:
|
16
|
+
no_items: "Hamna %{item_name} vilivyopatikana"
|
17
|
+
single_page: "Inaonyesha %{item_name} <b>%{count}</b>"
|
18
|
+
multiple_pages: "Inaonyesha %{item_name} <b>%{from}-%{to}</b> ya <b>%{count}</b> kwa jumla"
|
19
|
+
|
20
|
+
combo_nav_js: "<label>Kurasa %{page_input} ya %{pages}</label>"
|
21
|
+
|
22
|
+
items_selector_js: "<label>Onyesha %{items_input} %{item_name} kwa kila ukurasa</label>"
|
data/lib/locales/tr.yml
CHANGED
@@ -15,6 +15,6 @@ tr:
|
|
15
15
|
single_page: "Toplam <b>%{count}</b> %{item_name} gösteriliyor"
|
16
16
|
multiple_pages: "<b>%{count}</b> %{item_name} içerisinden <b>%{from}-%{to}</b> kadarı gösteriliyor"
|
17
17
|
|
18
|
-
combo_nav_js: "Sayfa %{page_input} / %{pages}"
|
18
|
+
combo_nav_js: "<label>Sayfa %{page_input} / %{pages}</label>"
|
19
19
|
|
20
|
-
items_selector_js: "Sayfada %{items_input} %{item_name} göster"
|
20
|
+
items_selector_js: "<label>Sayfada %{items_input} %{item_name} göster</label>"
|
data/lib/locales/uk.yml
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# :east_slavic pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/locales/utils/p11n.rb)
|
2
|
+
|
3
|
+
uk:
|
4
|
+
pagy:
|
5
|
+
|
6
|
+
item_name:
|
7
|
+
one: "запис"
|
8
|
+
few: "записів"
|
9
|
+
many: "записів"
|
10
|
+
other: "записів"
|
11
|
+
|
12
|
+
nav:
|
13
|
+
prev: "‹ Назад"
|
14
|
+
next: "Далі ›"
|
15
|
+
gap: "…"
|
16
|
+
|
17
|
+
info:
|
18
|
+
no_items: "Більше %{item_name} немає"
|
19
|
+
single_page: "<b>%{count}</b> %{item_name}"
|
20
|
+
multiple_pages: "Загалом <b>%{count}</b> %{item_name}, показані з <b>%{from}</b> по <b>%{to}</b>"
|
21
|
+
|
22
|
+
combo_nav_js: "<label>Сторінка %{page_input} з %{pages}</label>"
|
23
|
+
|
24
|
+
items_selector_js: "<label>Показати %{items_input} %{item_name} на сторінці</label>"
|
data/lib/locales/utils/i18n.rb
CHANGED
@@ -1,25 +1,17 @@
|
|
1
1
|
# See https://ddnexus.github.io/pagy/api/frontend#i18n
|
2
|
-
# encoding: utf-8
|
3
2
|
# frozen_string_literal: true
|
4
3
|
|
5
4
|
# this file returns the I18n hash used as default alternative to the i18n gem
|
6
5
|
|
7
|
-
Pagy::DEPRECATED_LOCALES = {'pt-br' =>'pt-BR', 'se' => 'sv-SE'}
|
8
|
-
|
9
6
|
Hash.new{|h,_| h.first[1]}.tap do |i18n_hash| # first loaded locale used as default
|
10
7
|
i18n_hash.define_singleton_method(:load) do |*load_args|
|
11
8
|
# eval: we don't need to keep the loader proc in memory
|
12
9
|
eval(Pagy.root.join('locales', 'utils', 'loader.rb').read).call(i18n_hash, *load_args) #rubocop:disable Security/Eval
|
13
10
|
end
|
14
|
-
i18n_hash.define_singleton_method(:t) do |locale,
|
15
|
-
if Pagy::DEPRECATED_LOCALES.key?(locale)
|
16
|
-
new_locale = Pagy::DEPRECATED_LOCALES[locale]
|
17
|
-
$stderr.puts("WARNING: the Pagy locale '#{locale}' is deprecated; use '#{new_locale}' instead")
|
18
|
-
locale = new_locale
|
19
|
-
end
|
11
|
+
i18n_hash.define_singleton_method(:t) do |locale, key, **opts|
|
20
12
|
data, pluralize = self[locale]
|
21
|
-
translate = data[
|
22
|
-
translate.call(
|
13
|
+
translate = data[key] || opts[:count] && data[key+=".#{pluralize.call(opts[:count])}"] or return %([translation missing: "#{key}"])
|
14
|
+
translate.call(opts)
|
23
15
|
end
|
24
16
|
i18n_hash.load(locale: 'en')
|
25
17
|
end
|
data/lib/locales/utils/loader.rb
CHANGED
@@ -1,18 +1,20 @@
|
|
1
|
-
# encoding: utf-8
|
2
1
|
# frozen_string_literal: true
|
3
2
|
|
4
3
|
# the whole file will be eval'ed/executed and gc-collected after returning/executing the loader proc
|
5
4
|
|
6
5
|
# eval: no need for the whole file in memory
|
7
|
-
plurals,
|
6
|
+
plurals, = eval Pagy.root.join('locales', 'utils', 'p11n.rb').read # rubocop:disable Security/Eval
|
8
7
|
|
9
8
|
# flatten the dictionary file nested keys
|
10
9
|
# convert each value to a simple ruby interpolation proc
|
11
10
|
flatten = lambda do |hash, key=''|
|
12
11
|
hash.each.reduce({}) do |h, (k, v)|
|
13
|
-
v.is_a?(Hash)
|
14
|
-
|
15
|
-
|
12
|
+
if v.is_a?(Hash)
|
13
|
+
h.merge! flatten.call(v, "#{key}#{k}.")
|
14
|
+
else
|
15
|
+
code = %({"#{key}#{k}" => lambda{|vars|"#{v.gsub(/%{[^}]+?}/){|m| "\#{vars[:#{m[2..-2]}]||'#{m}'}" }}"}})
|
16
|
+
h.merge! eval(code) # rubocop:disable Security/Eval
|
17
|
+
end
|
16
18
|
end
|
17
19
|
end
|
18
20
|
|
@@ -20,11 +22,6 @@ flatten = lambda do |hash, key=''|
|
|
20
22
|
lambda do |i18n, *args|
|
21
23
|
i18n.clear
|
22
24
|
args.each do |arg|
|
23
|
-
if Pagy::DEPRECATED_LOCALES.key?(arg[:locale])
|
24
|
-
new_locale = Pagy::DEPRECATED_LOCALES[arg[:locale]]
|
25
|
-
$stderr.puts("WARNING: the Pagy locale '#{arg[:locale]}' is deprecated; use '#{new_locale}' instead")
|
26
|
-
arg[:locale] = new_locale
|
27
|
-
end
|
28
25
|
arg[:filepath] ||= Pagy.root.join('locales', "#{arg[:locale]}.yml")
|
29
26
|
arg[:pluralize] ||= plurals[arg[:locale]]
|
30
27
|
hash = YAML.load(File.read(arg[:filepath], encoding: 'UTF-8')) #rubocop:disable Security/YAMLLoad
|
data/lib/locales/utils/p11n.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
# See https://ddnexus.github.io/pagy/api/frontend#i18n
|
2
|
-
# encoding: utf-8
|
3
2
|
# frozen_string_literal: true
|
4
3
|
|
5
4
|
# This file adds support for multiple built-in plualization types.
|
@@ -18,41 +17,68 @@ from12to14 = [12,13,14].freeze
|
|
18
17
|
# Each proc may apply to one or more locales below.
|
19
18
|
# Pluralization logic adapted from https://github.com/svenfuchs/rails-i18n
|
20
19
|
p11n = {
|
21
|
-
one_other:
|
20
|
+
one_other: -> (n){ n == 1 ? 'one' : 'other' }, # default
|
21
|
+
|
22
|
+
arabic: lambda do |n|
|
23
|
+
n ||= 0
|
24
|
+
mod100 = n % 100
|
25
|
+
|
26
|
+
case
|
27
|
+
when n == 0 then 'zero' # rubocop:disable Style/NumericPredicate
|
28
|
+
when n == 1 then 'one'
|
29
|
+
when n == 2 then 'two'
|
30
|
+
when (3..10).to_a.include?(mod100) then 'few'
|
31
|
+
when (11..99).to_a.include?(mod100) then 'many'
|
32
|
+
else 'other'
|
33
|
+
end
|
34
|
+
end,
|
22
35
|
|
23
36
|
east_slavic: lambda do |n|
|
24
37
|
n ||= 0
|
25
38
|
mod10 = n % 10
|
26
39
|
mod100 = n % 100
|
27
40
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
41
|
+
case
|
42
|
+
when mod10 == 1 && mod100 != 11 then 'one'
|
43
|
+
when from2to4.include?(mod10) && !from12to14.include?(mod100) then 'few'
|
44
|
+
when mod10 == 0 || from5to9.include?(mod10) || from11to14.include?(mod100) then 'many' # rubocop:disable Style/NumericPredicate
|
45
|
+
else 'other'
|
32
46
|
end
|
33
47
|
end,
|
34
48
|
|
35
49
|
one_two_other: lambda do |n|
|
36
|
-
|
37
|
-
|
38
|
-
|
50
|
+
case n
|
51
|
+
when 1 then 'one'
|
52
|
+
when 2 then 'two'
|
53
|
+
else 'other'
|
39
54
|
end
|
40
55
|
end,
|
41
56
|
|
42
|
-
one_upto_two_other:
|
57
|
+
one_upto_two_other: -> (n){ n && n >= 0 && n < 2 ? 'one' : 'other' },
|
43
58
|
|
44
|
-
other:
|
59
|
+
other: -> (*){ 'other' },
|
45
60
|
|
46
61
|
polish: lambda do |n|
|
47
62
|
n ||= 0
|
48
|
-
mod10
|
63
|
+
mod10 = n % 10
|
49
64
|
mod100 = n % 100
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
65
|
+
|
66
|
+
case
|
67
|
+
when n == 1 then 'one'
|
68
|
+
when from2to4.include?(mod10) && !from12to14.include?(mod100) then 'few'
|
69
|
+
when (from0to1 + from5to9).include?(mod10) || from12to14.include?(mod100) then 'many'
|
70
|
+
else 'other'
|
71
|
+
end
|
72
|
+
end,
|
73
|
+
|
74
|
+
west_slavic: lambda do |n|
|
75
|
+
case n
|
76
|
+
when 1 then 'one'
|
77
|
+
when 2, 3, 4 then 'few'
|
78
|
+
else 'other'
|
54
79
|
end
|
55
80
|
end
|
81
|
+
|
56
82
|
}
|
57
83
|
|
58
84
|
# Hash of locale/pluralization pairs
|
@@ -60,19 +86,25 @@ p11n = {
|
|
60
86
|
# The default pluralization for locales not explicitly listed here
|
61
87
|
# is the :one_other pluralization proc (used for English)
|
62
88
|
plurals = Hash.new(p11n[:one_other]).tap do |hash|
|
89
|
+
hash['ar'] = p11n[:arabic]
|
90
|
+
hash['bs'] = p11n[:east_slavic]
|
91
|
+
hash['cs'] = p11n[:west_slavic]
|
63
92
|
hash['id'] = p11n[:other]
|
64
93
|
hash['fr'] = p11n[:one_upto_two_other]
|
94
|
+
hash['hr'] = p11n[:east_slavic]
|
65
95
|
hash['ja'] = p11n[:other]
|
96
|
+
hash['km'] = p11n[:other]
|
66
97
|
hash['ko'] = p11n[:other]
|
67
98
|
hash['pl'] = p11n[:polish]
|
68
99
|
hash['ru'] = p11n[:east_slavic]
|
100
|
+
hash['sr'] = p11n[:east_slavic]
|
69
101
|
hash['sv'] = p11n[:one_two_other]
|
70
102
|
hash['sv-SE'] = p11n[:one_two_other]
|
71
103
|
hash['tr'] = p11n[:other]
|
104
|
+
hash['uk'] = p11n[:east_slavic]
|
72
105
|
hash['zh-CN'] = p11n[:other]
|
73
106
|
hash['zh-HK'] = p11n[:other]
|
74
107
|
hash['zh-TW'] = p11n[:other]
|
75
|
-
hash['km'] = p11n[:other]
|
76
108
|
end
|
77
109
|
|
78
110
|
[ plurals, p11n ]
|