i18n 1.11.0 → 1.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/i18n/backend/pluralization.rb +17 -52
- data/lib/i18n/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b92d195deaeca5e93f73cc62be2d2fb4c93d8a9787449e168b493773e5072458
|
4
|
+
data.tar.gz: f1172c9fac93f493c8a5b16cff4b27154ff917aed48cbc46a4a702363863111d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0174d10f7bac17e29cf7622d3ce69850e51755d53fd3d17d2f672bc9ca3c75823b851f6d04cbd367fea8ff5830c8c755fb9c80433bac9ec3c46590cbe9a874d0
|
7
|
+
data.tar.gz: ef22ed98cb7f223753a65b9d63d0f40e4b6821c93a41b1b41627e4c7b4e3de6b7bd411d8a6ed3d46dc6554432a776535c0461248e8d1fbfeee05dcda2ab89235
|
@@ -16,51 +16,26 @@ module I18n
|
|
16
16
|
module Pluralization
|
17
17
|
# Overwrites the Base backend translate method so that it will check the
|
18
18
|
# translation meta data space (:i18n) for a locale specific pluralization
|
19
|
-
# rule and use it to pluralize the given entry. I.e
|
19
|
+
# rule and use it to pluralize the given entry. I.e. the library expects
|
20
20
|
# pluralization rules to be stored at I18n.t(:'i18n.plural.rule')
|
21
21
|
#
|
22
22
|
# Pluralization rules are expected to respond to #call(count) and
|
23
|
-
# return a pluralization key. Valid keys depend on the
|
24
|
-
#
|
25
|
-
#
|
26
|
-
# :few, :many, :one, :other, :two, :zero
|
23
|
+
# return a pluralization key. Valid keys depend on the translation data
|
24
|
+
# hash (entry) but it is generally recommended to follow CLDR's style,
|
25
|
+
# i.e., return one of the keys :zero, :one, :few, :many, :other.
|
27
26
|
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
# 11 (like 11, 111, 10311).
|
33
|
-
# Similar notes apply to the :two, and :zero plural categories.
|
34
|
-
#
|
35
|
-
# If you want to have different strings for the categories of count == 0
|
36
|
-
# (e.g. "I don't have any cars") or count == 1 (e.g. "I have a single car")
|
37
|
-
# use the explicit `"0"` and `"1"` keys.
|
38
|
-
# https://unicode-org.github.io/cldr/ldml/tr35-numbers.html#Explicit_0_1_rules
|
27
|
+
# The :zero key is always picked directly when count equals 0 AND the
|
28
|
+
# translation data has the key :zero. This way translators are free to
|
29
|
+
# either pick a special :zero translation even for languages where the
|
30
|
+
# pluralizer does not return a :zero key.
|
39
31
|
def pluralize(locale, entry, count)
|
40
32
|
return entry unless entry.is_a?(Hash) && count
|
41
33
|
|
42
34
|
pluralizer = pluralizer(locale)
|
43
35
|
if pluralizer.respond_to?(:call)
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
value = entry[symbolic_count(count)]
|
48
|
-
return value if value
|
49
|
-
end
|
50
|
-
|
51
|
-
# Lateral Inheritance of "count" attribute (http://www.unicode.org/reports/tr35/#Lateral_Inheritance):
|
52
|
-
# > If there is no value for a path, and that path has a [@count="x"] attribute and value, then:
|
53
|
-
# > 1. If "x" is numeric, the path falls back to the path with [@count=«the plural rules category for x for that locale»], within that the same locale.
|
54
|
-
# > 2. If "x" is anything but "other", it falls back to a path [@count="other"], within that the same locale.
|
55
|
-
# > 3. If "x" is "other", it falls back to the path that is completely missing the count item, within that the same locale.
|
56
|
-
# Note: We don't yet implement #3 above, since we haven't decided how lateral inheritance attributes should be represented.
|
57
|
-
plural_rule_category = pluralizer.call(count)
|
58
|
-
|
59
|
-
value = if entry.has_key?(plural_rule_category) || entry.has_key?(:other)
|
60
|
-
entry[plural_rule_category] || entry[:other]
|
61
|
-
else
|
62
|
-
raise InvalidPluralizationData.new(entry, count, plural_rule_category)
|
63
|
-
end
|
36
|
+
key = count == 0 && entry.has_key?(:zero) ? :zero : pluralizer.call(count)
|
37
|
+
raise InvalidPluralizationData.new(entry, count, key) unless entry.has_key?(key)
|
38
|
+
entry[key]
|
64
39
|
else
|
65
40
|
super
|
66
41
|
end
|
@@ -68,23 +43,13 @@ module I18n
|
|
68
43
|
|
69
44
|
protected
|
70
45
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
def pluralizer(locale)
|
76
|
-
pluralizers[locale] ||= I18n.t(:'i18n.plural.rule', :locale => locale, :resolve => false)
|
77
|
-
end
|
78
|
-
|
79
|
-
private
|
46
|
+
def pluralizers
|
47
|
+
@pluralizers ||= {}
|
48
|
+
end
|
80
49
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
count = 0 if count == 0
|
85
|
-
count = 1 if count == 1
|
86
|
-
count.to_s.to_sym
|
87
|
-
end
|
50
|
+
def pluralizer(locale)
|
51
|
+
pluralizers[locale] ||= I18n.t(:'i18n.plural.rule', :locale => locale, :resolve => false)
|
52
|
+
end
|
88
53
|
end
|
89
54
|
end
|
90
55
|
end
|
data/lib/i18n/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: i18n
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.12.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sven Fuchs
|
@@ -13,7 +13,7 @@ authors:
|
|
13
13
|
autorequire:
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
|
-
date: 2022-07-
|
16
|
+
date: 2022-07-13 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: concurrent-ruby
|