pagy 4.0.0 → 4.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/config/pagy.rb +30 -24
- data/lib/javascripts/pagy.js +104 -93
- data/lib/locales/bs.yml +24 -0
- data/lib/locales/hr.yml +24 -0
- data/lib/locales/sr.yml +23 -0
- data/lib/locales/utils/i18n.rb +0 -1
- data/lib/locales/utils/loader.rb +7 -5
- data/lib/locales/utils/p11n.rb +27 -20
- data/lib/pagy.rb +50 -26
- data/lib/pagy/backend.rb +5 -3
- data/lib/pagy/countless.rb +12 -9
- data/lib/pagy/deprecation.rb +27 -0
- data/lib/pagy/exceptions.rb +7 -5
- data/lib/pagy/extras/arel.rb +4 -3
- data/lib/pagy/extras/array.rb +4 -3
- data/lib/pagy/extras/bootstrap.rb +62 -30
- data/lib/pagy/extras/bulma.rb +61 -38
- data/lib/pagy/extras/countless.rb +7 -5
- data/lib/pagy/extras/elasticsearch_rails.rb +8 -6
- data/lib/pagy/extras/foundation.rb +62 -32
- data/lib/pagy/extras/headers.rb +13 -9
- data/lib/pagy/extras/i18n.rb +7 -4
- data/lib/pagy/extras/items.rb +21 -26
- data/lib/pagy/extras/materialize.rb +59 -35
- data/lib/pagy/extras/metadata.rb +27 -21
- data/lib/pagy/extras/navs.rb +45 -20
- data/lib/pagy/extras/overflow.rb +12 -13
- data/lib/pagy/extras/searchkick.rb +9 -7
- data/lib/pagy/extras/semantic.rb +56 -30
- data/lib/pagy/extras/shared.rb +12 -11
- data/lib/pagy/extras/standalone.rb +71 -0
- data/lib/pagy/extras/support.rb +20 -11
- data/lib/pagy/extras/trim.rb +14 -9
- data/lib/pagy/extras/uikit.rb +65 -35
- data/lib/pagy/frontend.rb +62 -30
- metadata +8 -5
- data/lib/locales/README.md +0 -35
- data/pagy.gemspec +0 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea6862ff93b09769c9810860307a4a63a88de1ecf8d6a4f8176f6cb90e22565f
|
4
|
+
data.tar.gz: 5564e6b0f2e006b098dc9fe07ea8409ce4748bd6a32acb0f19bdb56e6f8b791d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b299c1727379ba77ace97691cce28df77e81a25bfaac7d0fff7668f1f5b8178b60963ec8f5fd27fb824ef5f0f067ee3070b846f7d975269cec83ddec5db6763b
|
7
|
+
data.tar.gz: daeb51d6b08394c64833938a5b594d46a189ae27357885361b6d0fb6dc1fa91c78def2b47cb09ec649fdebe39326577f989ac2569f32190ae8a756a7ccb591bf
|
data/lib/config/pagy.rb
CHANGED
@@ -1,11 +1,34 @@
|
|
1
|
-
# encoding: utf-8
|
2
1
|
# frozen_string_literal: true
|
3
2
|
|
4
|
-
# Pagy initializer file (4.
|
3
|
+
# Pagy initializer file (4.5.0)
|
5
4
|
# Customize only what you really need and notice that Pagy works also without any of the following lines.
|
6
5
|
# Should you just cherry pick part of this file, please maintain the require-order of the extras
|
7
6
|
|
8
7
|
|
8
|
+
# Pagy Variables
|
9
|
+
# See https://ddnexus.github.io/pagy/api/pagy#variables
|
10
|
+
# All the Pagy::VARS are set for all the Pagy instances but can be overridden
|
11
|
+
# per instance by just passing them to Pagy.new or the #pagy controller method
|
12
|
+
|
13
|
+
|
14
|
+
# Instance variables
|
15
|
+
# See https://ddnexus.github.io/pagy/api/pagy#instance-variables
|
16
|
+
# Pagy::VARS[:page] = 1 # default
|
17
|
+
# Pagy::VARS[:items] = 20 # default
|
18
|
+
# Pagy::VARS[:outset] = 0 # default
|
19
|
+
|
20
|
+
|
21
|
+
# Other Variables
|
22
|
+
# See https://ddnexus.github.io/pagy/api/pagy#other-variables
|
23
|
+
# Pagy::VARS[:size] = [1,4,4,1] # default
|
24
|
+
# Pagy::VARS[:page_param] = :page # default
|
25
|
+
# Pagy::VARS[:params] = {} # default
|
26
|
+
# Pagy::VARS[:fragment] = '#fragment' # example
|
27
|
+
# Pagy::VARS[:link_extra] = 'data-remote="true"' # example
|
28
|
+
# Pagy::VARS[:i18n_key] = 'pagy.item_name' # default
|
29
|
+
# Pagy::VARS[:cycle] = true # example
|
30
|
+
|
31
|
+
|
9
32
|
# Extras
|
10
33
|
# See https://ddnexus.github.io/pagy/extras
|
11
34
|
|
@@ -19,7 +42,6 @@
|
|
19
42
|
# Countless extra: Paginate without any count, saving one query per rendering
|
20
43
|
# See https://ddnexus.github.io/pagy/extras/countless
|
21
44
|
# require 'pagy/extras/countless'
|
22
|
-
# Pagy::VARS[:cycle] = false # default
|
23
45
|
|
24
46
|
# Elasticsearch Rails extra: Paginate `ElasticsearchRails::Results` objects
|
25
47
|
# See https://ddnexus.github.io/pagy/extras/elasticsearch_rails
|
@@ -88,6 +110,8 @@
|
|
88
110
|
# require 'pagy/extras/items'
|
89
111
|
# Pagy::VARS[:items_param] = :items # default
|
90
112
|
# Pagy::VARS[:max_items] = 100 # default
|
113
|
+
# set to false if you want to make :enable_items_extra an opt-in variable
|
114
|
+
# Pagy::VARS[:enable_items_extra] = false # default true
|
91
115
|
|
92
116
|
# Overflow extra: Allow for easy handling of overflowing pages
|
93
117
|
# See https://ddnexus.github.io/pagy/extras/overflow
|
@@ -105,27 +129,9 @@
|
|
105
129
|
# Trim extra: Remove the page=1 param from links
|
106
130
|
# See https://ddnexus.github.io/pagy/extras/trim
|
107
131
|
# require 'pagy/extras/trim'
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
# Pagy Variables
|
112
|
-
# See https://ddnexus.github.io/pagy/api/pagy#variables
|
113
|
-
# All the Pagy::VARS are set for all the Pagy instances but can be overridden
|
114
|
-
# per instance by just passing them to Pagy.new or the #pagy controller method
|
115
|
-
|
116
|
-
|
117
|
-
# Instance variables
|
118
|
-
# See https://ddnexus.github.io/pagy/api/pagy#instance-variables
|
119
|
-
# Pagy::VARS[:items] = 20 # default
|
120
|
-
|
121
|
-
|
122
|
-
# Other Variables
|
123
|
-
# See https://ddnexus.github.io/pagy/api/pagy#other-variables
|
124
|
-
# Pagy::VARS[:size] = [1,4,4,1] # default
|
125
|
-
# Pagy::VARS[:page_param] = :page # default
|
126
|
-
# Pagy::VARS[:params] = {} # default
|
127
|
-
# Pagy::VARS[:anchor] = '#anchor' # example
|
128
|
-
# Pagy::VARS[:link_extra] = 'data-remote="true"' # example
|
132
|
+
# after requiring it will trim by default
|
133
|
+
# set to false if you want to make :enable_trim_extra an opt-in variable
|
134
|
+
# Pagy::VARS[:enable_trim_extra] = false # default true
|
129
135
|
|
130
136
|
|
131
137
|
# Rails
|
data/lib/javascripts/pagy.js
CHANGED
@@ -2,105 +2,116 @@
|
|
2
2
|
|
3
3
|
function Pagy(){}
|
4
4
|
|
5
|
-
Pagy.version = '4.
|
5
|
+
Pagy.version = '4.5.0'
|
6
6
|
|
7
|
-
Pagy.
|
8
|
-
var target = arg instanceof Event || arg === undefined ? document : arg,
|
9
|
-
jsonTags = target.getElementsByClassName('pagy-json');
|
10
|
-
if (target === document) { // reset resize-listeners on page load (#163)
|
11
|
-
for (var id in Pagy.navResizeListeners) { window.removeEventListener('resize', Pagy.navResizeListeners[id], true) }
|
12
|
-
Pagy.navResizeListeners = {};
|
13
|
-
}
|
14
|
-
for (var i = 0, len = jsonTags.length; i < len; i++) {
|
15
|
-
var args = JSON.parse(jsonTags[i].innerHTML);
|
16
|
-
Pagy[args.shift()].apply(null, args);
|
17
|
-
}
|
18
|
-
};
|
7
|
+
Pagy.delay = 100
|
19
8
|
|
20
|
-
Pagy.
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
9
|
+
Pagy.init =
|
10
|
+
function(arg) {
|
11
|
+
var target = arg instanceof Event || arg === undefined ? document : arg,
|
12
|
+
jsonTags = target.getElementsByClassName('pagy-json')
|
13
|
+
for (var i = 0, len = jsonTags.length; i < len; i++) {
|
14
|
+
var args = JSON.parse(jsonTags[i].innerHTML),
|
15
|
+
fname = args.shift()
|
16
|
+
args.unshift(jsonTags[i].previousSibling)
|
17
|
+
Pagy[fname].apply(null, args)
|
18
|
+
}
|
19
|
+
}
|
27
20
|
|
28
|
-
|
29
|
-
|
21
|
+
Pagy.nav =
|
22
|
+
function(pagyEl, tags, sequels, trimParam) {
|
23
|
+
var lastWidth,
|
24
|
+
pageREg = new RegExp(/__pagy_page__/g),
|
25
|
+
widths = []
|
26
|
+
for (var width in sequels) {
|
27
|
+
if (sequels.hasOwnProperty(width)) { widths.push(parseInt(width, 10)) }
|
28
|
+
}
|
29
|
+
widths.sort(function(a, b) { return b - a })
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
31
|
+
pagyEl.render =
|
32
|
+
function() {
|
33
|
+
var width, i, len
|
34
|
+
for (i = 0, len = widths.length; i < len; i++) {
|
35
|
+
if (this.parentElement.clientWidth > widths[i]) { width = widths[i]; break }
|
36
|
+
}
|
37
|
+
if (width !== lastWidth) {
|
38
|
+
var html = tags.before,
|
39
|
+
series = sequels[width]
|
40
|
+
for (i = 0, len = series.length; i < len; i++) {
|
41
|
+
var item = series[i]
|
42
|
+
if (typeof(trimParam) === 'string' && item === 1) { html += Pagy.trim(tags.link.replace(pageREg, item), trimParam) }
|
43
|
+
else if (typeof(item) === 'number') { html += tags.link.replace(pageREg, item) }
|
44
|
+
else if (item === 'gap') { html += tags.gap }
|
45
|
+
else if (typeof(item) === 'string') { html += tags.active.replace(pageREg, item) }
|
46
|
+
}
|
47
|
+
html += tags.after
|
48
|
+
this.innerHTML = ''
|
49
|
+
this.insertAdjacentHTML('afterbegin', html)
|
50
|
+
lastWidth = width
|
51
|
+
}
|
52
|
+
}.bind(pagyEl)
|
53
|
+
pagyEl.render()
|
54
|
+
}
|
53
55
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
56
|
+
Pagy.combo_nav =
|
57
|
+
function(pagyEl, page, link, trimParam) {
|
58
|
+
var input = pagyEl.getElementsByTagName('input')[0],
|
59
|
+
toPage =
|
60
|
+
function() {
|
61
|
+
if (page !== input.value) {
|
62
|
+
var html = link.replace(/__pagy_page__/, input.value)
|
63
|
+
if (typeof (trimParam) === 'string' && input.value === '1') { html = Pagy.trim(html, trimParam) }
|
64
|
+
pagyEl.insertAdjacentHTML('afterbegin', html)
|
65
|
+
pagyEl.getElementsByTagName('a')[0].click()
|
66
|
+
}
|
67
|
+
}
|
68
|
+
Pagy.addInputEventListeners(input, toPage)
|
69
|
+
}
|
62
70
|
|
63
|
-
Pagy.
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
71
|
+
Pagy.items_selector =
|
72
|
+
function(pagyEl, from, link, param) {
|
73
|
+
var input = pagyEl.getElementsByTagName('input')[0],
|
74
|
+
current = input.value,
|
75
|
+
toPage =
|
76
|
+
function() {
|
77
|
+
var items = input.value
|
78
|
+
if (current !== items) {
|
79
|
+
var page = Math.max(Math.ceil(from / items), 1),
|
80
|
+
html = link.replace(/__pagy_page__/, page).replace(/__pagy_items__/, items)
|
81
|
+
if (typeof (param) === 'string' && page === 1) { html = Pagy.trim(html, param) }
|
82
|
+
pagyEl.insertAdjacentHTML('afterbegin', html)
|
83
|
+
pagyEl.getElementsByTagName('a')[0].click()
|
84
|
+
}
|
85
|
+
}
|
86
|
+
Pagy.addInputEventListeners(input, toPage)
|
87
|
+
}
|
76
88
|
|
77
|
-
Pagy.
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
if (typeof(param) === 'string' && page === 1){ html = Pagy.trim(html, param) }
|
87
|
-
pagyEl.insertAdjacentHTML('afterbegin', html);
|
88
|
-
pagyEl.getElementsByTagName('a')[0].click();
|
89
|
-
}
|
90
|
-
};
|
91
|
-
Pagy.addInputEventListeners(input, go);
|
92
|
-
};
|
89
|
+
Pagy.addInputEventListeners =
|
90
|
+
function(input, toPage) {
|
91
|
+
// select the content on click: easier for typing a number
|
92
|
+
input.addEventListener('click', function() { this.select() })
|
93
|
+
// toPage when the input looses focus
|
94
|
+
input.addEventListener('focusout', toPage)
|
95
|
+
// … and when pressing enter inside the input
|
96
|
+
input.addEventListener('keyup', function(e) { if (e.which === 13) {toPage()} }.bind(this))
|
97
|
+
}
|
93
98
|
|
94
|
-
Pagy.
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
// … and when pressing enter inside the input
|
100
|
-
input.addEventListener('keyup', function(e){ if (e.which === 13) handler() }.bind(this));
|
101
|
-
};
|
99
|
+
Pagy.trim =
|
100
|
+
function(html, param) {
|
101
|
+
var re = new RegExp('[?&]' + param + '=1\\b(?!&)|\\b' + param + '=1&')
|
102
|
+
return html.replace(re, '')
|
103
|
+
}
|
102
104
|
|
103
|
-
Pagy.
|
104
|
-
|
105
|
-
|
106
|
-
|
105
|
+
Pagy.renderNavs =
|
106
|
+
function() {
|
107
|
+
var navs = document.getElementsByClassName('pagy-njs') // 'pagy-njs' is common to all *nav_js helpers
|
108
|
+
for (var i = 0, len = navs.length; i < len; i++) { navs[i].render() }
|
109
|
+
}
|
110
|
+
|
111
|
+
Pagy.waitForMe =
|
112
|
+
function() {
|
113
|
+
if (typeof(Pagy.tid) === 'number') { clearTimeout(Pagy.tid) }
|
114
|
+
Pagy.tid = setTimeout(Pagy.renderNavs, Pagy.delay)
|
115
|
+
}
|
116
|
+
|
117
|
+
window.addEventListener('resize', Pagy.waitForMe, true)
|
data/lib/locales/bs.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
|
+
bs:
|
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: "Stranica %{page_input} od %{pages}"
|
23
|
+
|
24
|
+
items_selector_js: "Prikaži %{items_input} %{item_name} po stranici"
|
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: "Stranica %{page_input} od %{pages}"
|
23
|
+
|
24
|
+
items_selector_js: "Prikaži %{items_input} %{item_name} po stranici"
|
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: "Страниca %{page_input} од %{pages}"
|
22
|
+
|
23
|
+
items_selector_js: "Прикажи %{items_input} %{item_name} по страниcи"
|
data/lib/locales/utils/i18n.rb
CHANGED
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
|
|
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,46 +17,51 @@ 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
|
22
21
|
|
23
22
|
east_slavic: lambda do |n|
|
24
23
|
n ||= 0
|
25
24
|
mod10 = n % 10
|
26
25
|
mod100 = n % 100
|
27
26
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
27
|
+
case
|
28
|
+
when mod10 == 1 && mod100 != 11 then 'one'
|
29
|
+
when from2to4.include?(mod10) && !from12to14.include?(mod100) then 'few'
|
30
|
+
when mod10 == 0 || from5to9.include?(mod10) || from11to14.include?(mod100) then 'many' # rubocop:disable Style/NumericPredicate
|
31
|
+
else 'other'
|
32
32
|
end
|
33
33
|
end,
|
34
34
|
|
35
35
|
west_slavic: lambda do |n|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
36
|
+
case n
|
37
|
+
when 1 then 'one'
|
38
|
+
when 2, 3, 4 then 'few'
|
39
|
+
else 'other'
|
40
|
+
end
|
40
41
|
end,
|
41
42
|
|
42
43
|
one_two_other: lambda do |n|
|
43
|
-
|
44
|
-
|
45
|
-
|
44
|
+
case n
|
45
|
+
when 1 then 'one'
|
46
|
+
when 2 then 'two'
|
47
|
+
else 'other'
|
46
48
|
end
|
47
49
|
end,
|
48
50
|
|
49
|
-
one_upto_two_other:
|
51
|
+
one_upto_two_other: -> (n){ n && n >= 0 && n < 2 ? 'one' : 'other' },
|
50
52
|
|
51
|
-
other:
|
53
|
+
other: -> (*){ 'other' },
|
52
54
|
|
53
55
|
polish: lambda do |n|
|
54
56
|
n ||= 0
|
55
|
-
mod10
|
57
|
+
mod10 = n % 10
|
56
58
|
mod100 = n % 100
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
59
|
+
|
60
|
+
case
|
61
|
+
when n == 1 then 'one'
|
62
|
+
when from2to4.include?(mod10) && !from12to14.include?(mod100) then 'few'
|
63
|
+
when (from0to1 + from5to9).include?(mod10) || from12to14.include?(mod100) then 'many'
|
64
|
+
else 'other'
|
61
65
|
end
|
62
66
|
end
|
63
67
|
}
|
@@ -67,14 +71,17 @@ p11n = {
|
|
67
71
|
# The default pluralization for locales not explicitly listed here
|
68
72
|
# is the :one_other pluralization proc (used for English)
|
69
73
|
plurals = Hash.new(p11n[:one_other]).tap do |hash|
|
74
|
+
hash['bs'] = p11n[:east_slavic]
|
70
75
|
hash['cs'] = p11n[:west_slavic]
|
71
76
|
hash['id'] = p11n[:other]
|
72
77
|
hash['fr'] = p11n[:one_upto_two_other]
|
78
|
+
hash['hr'] = p11n[:east_slavic]
|
73
79
|
hash['ja'] = p11n[:other]
|
74
80
|
hash['km'] = p11n[:other]
|
75
81
|
hash['ko'] = p11n[:other]
|
76
82
|
hash['pl'] = p11n[:polish]
|
77
83
|
hash['ru'] = p11n[:east_slavic]
|
84
|
+
hash['sr'] = p11n[:east_slavic]
|
78
85
|
hash['sv'] = p11n[:one_two_other]
|
79
86
|
hash['sv-SE'] = p11n[:one_two_other]
|
80
87
|
hash['tr'] = p11n[:other]
|