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 +4 -4
- data/lib/i18n/backend/fallbacks.rb +1 -1
- data/lib/i18n/backend/pluralization.rb +52 -17
- data/lib/i18n/config.rb +2 -2
- data/lib/i18n/exceptions.rb +1 -1
- data/lib/i18n/locale/tag/simple.rb +1 -1
- data/lib/i18n/tests/basics.rb +2 -2
- data/lib/i18n/version.rb +1 -1
- data/lib/i18n.rb +16 -10
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fec00bc17a2d4f9845a6bf1394deefaab31a14460c440d5012db8939d4de2d19
|
4
|
+
data.tar.gz: d5b2c057789154f3db274d6c0612dec850c2af96127c37204ac81308636ca841
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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,
|
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
|
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
|
-
#
|
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 :
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
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
|
-
|
37
|
-
|
38
|
-
|
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
|
-
|
47
|
-
|
48
|
-
|
71
|
+
def pluralizers
|
72
|
+
@pluralizers ||= {}
|
73
|
+
end
|
49
74
|
|
50
|
-
|
51
|
-
|
52
|
-
|
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
|
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
|
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"
|
data/lib/i18n/exceptions.rb
CHANGED
@@ -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
|
27
|
+
the desired locale explicitly with the `locale` argument, e.g. `I18n.#{method}(..., locale: :en)`
|
28
28
|
MESSAGE
|
29
29
|
end
|
30
30
|
end
|
data/lib/i18n/tests/basics.rb
CHANGED
@@ -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
|
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
|
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
data/lib/i18n.rb
CHANGED
@@ -214,18 +214,12 @@ module I18n
|
|
214
214
|
|
215
215
|
backend = config.backend
|
216
216
|
|
217
|
-
|
218
|
-
|
219
|
-
|
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
|
-
|
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.
|
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-
|
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.
|
109
|
+
rubygems_version: 3.3.16
|
110
110
|
signing_key:
|
111
111
|
specification_version: 4
|
112
112
|
summary: New wave Internationalization support for Ruby
|