i18n 1.10.0 → 1.11.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: bcce939890b82f2f78ef93aa98b2be5995f172f6c37b95c53800c155f2036eec
4
- data.tar.gz: ae4d72446e698fc7c0666f0e9dad6f11fa669d768fe9272d0c89e14aba8d2274
3
+ metadata.gz: fec00bc17a2d4f9845a6bf1394deefaab31a14460c440d5012db8939d4de2d19
4
+ data.tar.gz: d5b2c057789154f3db274d6c0612dec850c2af96127c37204ac81308636ca841
5
5
  SHA512:
6
- metadata.gz: bf36e9389526d5a48bbfc4043bc2c4587ddbfbfab41a2ccaafa801570c3a838530a001c6c3df1669d5e0beb14b63b394253cef6d6fdd12aa936ae8c07ecdbf72
7
- data.tar.gz: 82b972e13f2342ca864e4ead724008aa75ad24bbf6d4f14603330e2999501cfb5c05ee6a9e5cd2cffbf48f07f6da868fccc33b4771f7b4b085989c4def36a7b9
6
+ metadata.gz: 468a6a2336896a0f5185350c16a49929e27b2201efe92bc5d067a7a03787bfa814bbe2de838be78205d870961e023633d8dbd494f488b1a6d77773082ed442de
7
+ data.tar.gz: d6fb232b7a711de31cbc3ce93a624a858684c3f8258eb558774b36da2aa2a0ba9baa6bf6c65901cbdfc06f44b6810c383e6c0dd47eb1569c4ddb07394332f81d
@@ -107,7 +107,7 @@ module I18n
107
107
  private
108
108
 
109
109
  # Overwrite on_fallback to add specified logic when the fallback succeeds.
110
- def on_fallback(_original_locale, _fallback_locale, _key, _optoins)
110
+ def on_fallback(_original_locale, _fallback_locale, _key, _options)
111
111
  nil
112
112
  end
113
113
  end
@@ -16,26 +16,51 @@ 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 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.
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
26
27
  #
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.
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
31
39
  def pluralize(locale, entry, count)
32
40
  return entry unless entry.is_a?(Hash) && count
33
41
 
34
42
  pluralizer = pluralizer(locale)
35
43
  if pluralizer.respond_to?(:call)
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]
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
39
64
  else
40
65
  super
41
66
  end
@@ -43,13 +68,23 @@ module I18n
43
68
 
44
69
  protected
45
70
 
46
- def pluralizers
47
- @pluralizers ||= {}
48
- end
71
+ def pluralizers
72
+ @pluralizers ||= {}
73
+ end
49
74
 
50
- def pluralizer(locale)
51
- pluralizers[locale] ||= I18n.t(:'i18n.plural.rule', :locale => locale, :resolve => false)
52
- end
75
+ def pluralizer(locale)
76
+ pluralizers[locale] ||= I18n.t(:'i18n.plural.rule', :locale => locale, :resolve => false)
77
+ end
78
+
79
+ private
80
+
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
53
88
  end
54
89
  end
55
90
  end
data/lib/i18n/config.rb CHANGED
@@ -38,7 +38,7 @@ module I18n
38
38
  end
39
39
 
40
40
  # Returns an array of locales for which translations are available.
41
- # Unless you explicitely set these through I18n.available_locales=
41
+ # Unless you explicitly set these through I18n.available_locales=
42
42
  # the call will be delegated to the backend.
43
43
  def available_locales
44
44
  @@available_locales ||= nil
@@ -106,7 +106,7 @@ module I18n
106
106
  # if you don't care about arity.
107
107
  #
108
108
  # == Example:
109
- # You can supress raising an exception and return string instead:
109
+ # You can suppress raising an exception and return string instead:
110
110
  #
111
111
  # I18n.config.missing_interpolation_argument_handler = Proc.new do |key|
112
112
  # "#{key} is missing"
@@ -24,7 +24,7 @@ module I18n
24
24
  been set is likely to display text from the wrong locale to some users.
25
25
 
26
26
  If you have a legitimate reason to access i18n data outside of the user flow, you can do so by passing
27
- the desired locale explictly with the `locale` argument, e.g. `I18n.#{method}(..., locale: :en)`
27
+ the desired locale explicitly with the `locale` argument, e.g. `I18n.#{method}(..., locale: :en)`
28
28
  MESSAGE
29
29
  end
30
30
  end
@@ -1,5 +1,5 @@
1
1
  # Simple Locale tag implementation that computes subtags by simply splitting
2
- # the locale tag at '-' occurences.
2
+ # the locale tag at '-' occurrences.
3
3
  module I18n
4
4
  module Locale
5
5
  module Tag
@@ -26,7 +26,7 @@ module I18n
26
26
  assert_equal I18n.available_locales, I18n.backend.available_locales
27
27
  end
28
28
 
29
- test "available_locales memoizes when set explicitely" do
29
+ test "available_locales memoizes when set explicitly" do
30
30
  I18n.backend.expects(:available_locales).never
31
31
  I18n.available_locales = [:foo]
32
32
  I18n.backend.store_translations('de', :bar => 'baz')
@@ -34,7 +34,7 @@ module I18n
34
34
  assert_equal [:foo], I18n.available_locales
35
35
  end
36
36
 
37
- test "available_locales delegates to the backend when not set explicitely" do
37
+ test "available_locales delegates to the backend when not set explicitly" do
38
38
  original_available_locales_value = I18n.backend.available_locales
39
39
  I18n.backend.expects(:available_locales).returns(original_available_locales_value).twice
40
40
  assert_equal I18n.backend.available_locales, I18n.available_locales
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.10.0"
4
+ VERSION = "1.11.0"
5
5
  end
data/lib/i18n.rb CHANGED
@@ -214,18 +214,12 @@ module I18n
214
214
 
215
215
  backend = config.backend
216
216
 
217
- result = catch(:exception) do
218
- if key.is_a?(Array)
219
- key.map { |k| backend.translate(locale, k, options) }
220
- else
221
- backend.translate(locale, key, options)
217
+ if key.is_a?(Array)
218
+ key.map do |k|
219
+ translate_key(k, throw, raise, locale, backend, options)
222
220
  end
223
- end
224
-
225
- if result.is_a?(MissingTranslation)
226
- handle_exception((throw && :throw || raise && :raise), result, locale, key, options)
227
221
  else
228
- result
222
+ translate_key(key, throw, raise, locale, backend, options)
229
223
  end
230
224
  end
231
225
  alias :t :translate
@@ -364,6 +358,18 @@ module I18n
364
358
 
365
359
  private
366
360
 
361
+ def translate_key(key, throw, raise, locale, backend, options)
362
+ result = catch(:exception) do
363
+ backend.translate(locale, key, options)
364
+ end
365
+
366
+ if result.is_a?(MissingTranslation)
367
+ handle_exception((throw && :throw || raise && :raise), result, locale, key, options)
368
+ else
369
+ result
370
+ end
371
+ end
372
+
367
373
  # Any exceptions thrown in translate will be sent to the @@exception_handler
368
374
  # which can be a Symbol, a Proc or any other Object unless they're forced to
369
375
  # be raised or thrown (MissingTranslation).
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.10.0
4
+ version: 1.11.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-02-14 00:00:00.000000000 Z
16
+ date: 2022-07-10 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: concurrent-ruby
@@ -106,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
106
  - !ruby/object:Gem::Version
107
107
  version: 1.3.5
108
108
  requirements: []
109
- rubygems_version: 3.1.6
109
+ rubygems_version: 3.3.16
110
110
  signing_key:
111
111
  specification_version: 4
112
112
  summary: New wave Internationalization support for Ruby