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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fec00bc17a2d4f9845a6bf1394deefaab31a14460c440d5012db8939d4de2d19
4
- data.tar.gz: d5b2c057789154f3db274d6c0612dec850c2af96127c37204ac81308636ca841
3
+ metadata.gz: b92d195deaeca5e93f73cc62be2d2fb4c93d8a9787449e168b493773e5072458
4
+ data.tar.gz: f1172c9fac93f493c8a5b16cff4b27154ff917aed48cbc46a4a702363863111d
5
5
  SHA512:
6
- metadata.gz: 468a6a2336896a0f5185350c16a49929e27b2201efe92bc5d067a7a03787bfa814bbe2de838be78205d870961e023633d8dbd494f488b1a6d77773082ed442de
7
- data.tar.gz: d6fb232b7a711de31cbc3ce93a624a858684c3f8258eb558774b36da2aa2a0ba9baa6bf6c65901cbdfc06f44b6810c383e6c0dd47eb1569c4ddb07394332f81d
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., the library expects
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 pluralization
24
- # rules for the locale, as defined in the CLDR.
25
- # As of v41, 6 locale-specific plural categories are defined:
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
- # n.b., The :one plural category does not imply the number 1.
29
- # Instead, :one is a category for any number that behaves like 1 in
30
- # that locale. For example, in some locales, :one is used for numbers
31
- # that end in "1" (like 1, 21, 151) but that don't end in
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
- # "0" and "1" are special cases
45
- # https://unicode-org.github.io/cldr/ldml/tr35-numbers.html#Explicit_0_1_rules
46
- if count == 0 || count == 1
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
- def pluralizers
72
- @pluralizers ||= {}
73
- end
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
- # Normalizes categories of 0.0 and 1.0
82
- # and returns the symbolic version
83
- def symbolic_count(count)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module I18n
4
- VERSION = "1.11.0"
4
+ VERSION = "1.12.0"
5
5
  end
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.11.0
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-10 00:00:00.000000000 Z
16
+ date: 2022-07-13 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: concurrent-ruby