i18n 1.12.0 → 1.14.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +5 -1
- data/lib/i18n/backend/base.rb +14 -7
- data/lib/i18n/backend/chain.rb +2 -0
- data/lib/i18n/backend/fallbacks.rb +1 -1
- data/lib/i18n/backend/interpolation_compiler.rb +5 -7
- data/lib/i18n/backend/lazy_loadable.rb +1 -1
- data/lib/i18n/backend/pluralization.rb +58 -17
- data/lib/i18n/backend/simple.rb +9 -2
- data/lib/i18n/backend/transliterator.rb +24 -24
- data/lib/i18n/exceptions.rb +12 -2
- data/lib/i18n/interpolate/ruby.rb +15 -1
- data/lib/i18n/locale/fallbacks.rb +8 -0
- data/lib/i18n/tests/interpolation.rb +4 -0
- data/lib/i18n/tests/localization/date.rb +6 -1
- data/lib/i18n/tests/localization/date_time.rb +1 -1
- data/lib/i18n/tests/localization/time.rb +1 -1
- data/lib/i18n/tests/lookup.rb +1 -1
- data/lib/i18n/version.rb +1 -1
- 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: ef99abbb2ed698cd9dd77ab484720a5ecf68be96a7064f2f8b432a69758ada07
|
|
4
|
+
data.tar.gz: 0a4ade5577fe636c03d6ef9ca11f7a26b80a5c58078ee87c2f9dcf9fdd6882de
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 21b666c06e7c8ebdb78088ef2ecd8da866ebd414dff3f3a8535b3e950c12bf0f38695a22acac6da7775e8e245c7a99a0d1d9a6bc409e0ea3d552520a0be26f68
|
|
7
|
+
data.tar.gz: c5f81a0bafbf70daa4a2c4374f3906ef31cea1d8f94d5d5e9b980224d1b6bc75f95cdd3e08709f6cae410c34f4285deb375d7e5b06e19f283743221606e23434
|
data/README.md
CHANGED
|
@@ -13,10 +13,14 @@ Currently maintained by @radar.
|
|
|
13
13
|
|
|
14
14
|
You will most commonly use this library within a Rails app.
|
|
15
15
|
|
|
16
|
+
We support Rails versions from 6.0 and up.
|
|
17
|
+
|
|
16
18
|
[See the Rails Guide](https://guides.rubyonrails.org/i18n.html) for an example of its usage.
|
|
17
19
|
|
|
18
20
|
### Ruby (without Rails)
|
|
19
21
|
|
|
22
|
+
We support Ruby versions from 3.0 and up.
|
|
23
|
+
|
|
20
24
|
If you want to use this library without Rails, you can simply add `i18n` to your `Gemfile`:
|
|
21
25
|
|
|
22
26
|
```ruby
|
|
@@ -26,7 +30,7 @@ gem 'i18n'
|
|
|
26
30
|
Then configure I18n with some translations, and a default locale:
|
|
27
31
|
|
|
28
32
|
```ruby
|
|
29
|
-
I18n.load_path
|
|
33
|
+
I18n.load_path += Dir[File.expand_path("config/locales") + "/*.yml"]
|
|
30
34
|
I18n.default_locale = :en # (note that `en` is already the default!)
|
|
31
35
|
```
|
|
32
36
|
|
data/lib/i18n/backend/base.rb
CHANGED
|
@@ -54,19 +54,21 @@ module I18n
|
|
|
54
54
|
end
|
|
55
55
|
|
|
56
56
|
deep_interpolation = options[:deep_interpolation]
|
|
57
|
-
values = Utils.except(options, *RESERVED_KEYS)
|
|
58
|
-
if values
|
|
57
|
+
values = Utils.except(options, *RESERVED_KEYS) unless options.empty?
|
|
58
|
+
if values && !values.empty?
|
|
59
59
|
entry = if deep_interpolation
|
|
60
60
|
deep_interpolate(locale, entry, values)
|
|
61
61
|
else
|
|
62
62
|
interpolate(locale, entry, values)
|
|
63
63
|
end
|
|
64
|
+
elsif entry.is_a?(String) && entry =~ I18n.reserved_keys_pattern
|
|
65
|
+
raise ReservedInterpolationKey.new($1.to_sym, entry)
|
|
64
66
|
end
|
|
65
67
|
entry
|
|
66
68
|
end
|
|
67
69
|
|
|
68
70
|
def exists?(locale, key, options = EMPTY_HASH)
|
|
69
|
-
lookup(locale, key) != nil
|
|
71
|
+
lookup(locale, key, options[:scope]) != nil
|
|
70
72
|
end
|
|
71
73
|
|
|
72
74
|
# Acts the same as +strftime+, but uses a localized version of the
|
|
@@ -123,7 +125,12 @@ module I18n
|
|
|
123
125
|
# first translation that can be resolved. Otherwise it tries to resolve
|
|
124
126
|
# the translation directly.
|
|
125
127
|
def default(locale, object, subject, options = EMPTY_HASH)
|
|
126
|
-
|
|
128
|
+
if options.size == 1 && options.has_key?(:default)
|
|
129
|
+
options = {}
|
|
130
|
+
else
|
|
131
|
+
options = Utils.except(options, :default)
|
|
132
|
+
end
|
|
133
|
+
|
|
127
134
|
case subject
|
|
128
135
|
when Array
|
|
129
136
|
subject.each do |item|
|
|
@@ -166,7 +173,7 @@ module I18n
|
|
|
166
173
|
# Other backends can implement more flexible or complex pluralization rules.
|
|
167
174
|
def pluralize(locale, entry, count)
|
|
168
175
|
entry = entry.reject { |k, _v| k == :attributes } if entry.is_a?(Hash)
|
|
169
|
-
return entry unless entry.is_a?(Hash) && count
|
|
176
|
+
return entry unless entry.is_a?(Hash) && count
|
|
170
177
|
|
|
171
178
|
key = pluralization_key(entry, count)
|
|
172
179
|
raise InvalidPluralizationData.new(entry, count, key) unless entry.has_key?(key)
|
|
@@ -282,8 +289,8 @@ module I18n
|
|
|
282
289
|
when '%^b' then I18n.t!(:"date.abbr_month_names", :locale => locale, :format => format)[object.mon].upcase
|
|
283
290
|
when '%B' then I18n.t!(:"date.month_names", :locale => locale, :format => format)[object.mon]
|
|
284
291
|
when '%^B' then I18n.t!(:"date.month_names", :locale => locale, :format => format)[object.mon].upcase
|
|
285
|
-
when '%p' then I18n.t!(:"time.#{object.hour < 12 ? :am : :pm}", :locale => locale, :format => format).upcase
|
|
286
|
-
when '%P' then I18n.t!(:"time.#{object.hour < 12 ? :am : :pm}", :locale => locale, :format => format).downcase
|
|
292
|
+
when '%p' then I18n.t!(:"time.#{(object.respond_to?(:hour) ? object.hour : 0) < 12 ? :am : :pm}", :locale => locale, :format => format).upcase
|
|
293
|
+
when '%P' then I18n.t!(:"time.#{(object.respond_to?(:hour) ? object.hour : 0) < 12 ? :am : :pm}", :locale => locale, :format => format).downcase
|
|
287
294
|
end
|
|
288
295
|
end
|
|
289
296
|
rescue MissingTranslationData => e
|
data/lib/i18n/backend/chain.rb
CHANGED
|
@@ -16,6 +16,8 @@ module I18n
|
|
|
16
16
|
#
|
|
17
17
|
# The implementation assumes that all backends added to the Chain implement
|
|
18
18
|
# a lookup method with the same API as Simple backend does.
|
|
19
|
+
#
|
|
20
|
+
# Fallback translations using the :default option are only used by the last backend of a chain.
|
|
19
21
|
class Chain
|
|
20
22
|
module Implementation
|
|
21
23
|
include Base
|
|
@@ -95,7 +95,7 @@ module I18n
|
|
|
95
95
|
return super unless options.fetch(:fallback, true)
|
|
96
96
|
I18n.fallbacks[locale].each do |fallback|
|
|
97
97
|
begin
|
|
98
|
-
return true if super(fallback, key)
|
|
98
|
+
return true if super(fallback, key, options)
|
|
99
99
|
rescue I18n::InvalidLocale
|
|
100
100
|
# we do nothing when the locale is invalid, as this is a fallback anyways.
|
|
101
101
|
end
|
|
@@ -21,8 +21,7 @@ module I18n
|
|
|
21
21
|
module Compiler
|
|
22
22
|
extend self
|
|
23
23
|
|
|
24
|
-
TOKENIZER
|
|
25
|
-
INTERPOLATION_SYNTAX_PATTERN = /(%)?(%\{([^\}]+)\})/
|
|
24
|
+
TOKENIZER = /(%%?\{[^}]+\})/
|
|
26
25
|
|
|
27
26
|
def compile_if_an_interpolation(string)
|
|
28
27
|
if interpolated_str?(string)
|
|
@@ -37,7 +36,7 @@ module I18n
|
|
|
37
36
|
end
|
|
38
37
|
|
|
39
38
|
def interpolated_str?(str)
|
|
40
|
-
str.kind_of?(::String) && str =~
|
|
39
|
+
str.kind_of?(::String) && str =~ TOKENIZER
|
|
41
40
|
end
|
|
42
41
|
|
|
43
42
|
protected
|
|
@@ -48,13 +47,12 @@ module I18n
|
|
|
48
47
|
|
|
49
48
|
def compiled_interpolation_body(str)
|
|
50
49
|
tokenize(str).map do |token|
|
|
51
|
-
|
|
50
|
+
token.match(TOKENIZER) ? handle_interpolation_token(token) : escape_plain_str(token)
|
|
52
51
|
end.join
|
|
53
52
|
end
|
|
54
53
|
|
|
55
|
-
def handle_interpolation_token(
|
|
56
|
-
|
|
57
|
-
escaped ? pattern : compile_interpolation_token(key.to_sym)
|
|
54
|
+
def handle_interpolation_token(token)
|
|
55
|
+
token.start_with?('%%') ? token[1..] : compile_interpolation_token(token[2..-2])
|
|
58
56
|
end
|
|
59
57
|
|
|
60
58
|
def compile_interpolation_token(key)
|
|
@@ -98,7 +98,7 @@ module I18n
|
|
|
98
98
|
# Parse the load path and extract all locales.
|
|
99
99
|
def available_locales
|
|
100
100
|
if lazy_load?
|
|
101
|
-
I18n.load_path.map { |path| LocaleExtractor.locale_from_path(path) }
|
|
101
|
+
I18n.load_path.map { |path| LocaleExtractor.locale_from_path(path) }.uniq
|
|
102
102
|
else
|
|
103
103
|
super
|
|
104
104
|
end
|
|
@@ -16,26 +16,57 @@ 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
|
+
# Deprecation: The use of the `zero` key in this way is incorrect.
|
|
45
|
+
# Users that want a different string for the case of `count == 0` should use the explicit "0" key instead.
|
|
46
|
+
# We keep this incorrect behaviour for now for backwards compatibility until we can remove it.
|
|
47
|
+
# Ref: https://github.com/ruby-i18n/i18n/issues/629
|
|
48
|
+
return entry[:zero] if count == 0 && entry.has_key?(:zero)
|
|
49
|
+
|
|
50
|
+
# "0" and "1" are special cases
|
|
51
|
+
# https://unicode-org.github.io/cldr/ldml/tr35-numbers.html#Explicit_0_1_rules
|
|
52
|
+
if count == 0 || count == 1
|
|
53
|
+
value = entry[symbolic_count(count)]
|
|
54
|
+
return value if value
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# Lateral Inheritance of "count" attribute (http://www.unicode.org/reports/tr35/#Lateral_Inheritance):
|
|
58
|
+
# > If there is no value for a path, and that path has a [@count="x"] attribute and value, then:
|
|
59
|
+
# > 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.
|
|
60
|
+
# > 2. If "x" is anything but "other", it falls back to a path [@count="other"], within that the same locale.
|
|
61
|
+
# > 3. If "x" is "other", it falls back to the path that is completely missing the count item, within that the same locale.
|
|
62
|
+
# Note: We don't yet implement #3 above, since we haven't decided how lateral inheritance attributes should be represented.
|
|
63
|
+
plural_rule_category = pluralizer.call(count)
|
|
64
|
+
|
|
65
|
+
value = if entry.has_key?(plural_rule_category) || entry.has_key?(:other)
|
|
66
|
+
entry[plural_rule_category] || entry[:other]
|
|
67
|
+
else
|
|
68
|
+
raise InvalidPluralizationData.new(entry, count, plural_rule_category)
|
|
69
|
+
end
|
|
39
70
|
else
|
|
40
71
|
super
|
|
41
72
|
end
|
|
@@ -43,13 +74,23 @@ module I18n
|
|
|
43
74
|
|
|
44
75
|
protected
|
|
45
76
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
77
|
+
def pluralizers
|
|
78
|
+
@pluralizers ||= {}
|
|
79
|
+
end
|
|
49
80
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
81
|
+
def pluralizer(locale)
|
|
82
|
+
pluralizers[locale] ||= I18n.t(:'i18n.plural.rule', :locale => locale, :resolve => false)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
private
|
|
86
|
+
|
|
87
|
+
# Normalizes categories of 0.0 and 1.0
|
|
88
|
+
# and returns the symbolic version
|
|
89
|
+
def symbolic_count(count)
|
|
90
|
+
count = 0 if count == 0
|
|
91
|
+
count = 1 if count == 1
|
|
92
|
+
count.to_s.to_sym
|
|
93
|
+
end
|
|
53
94
|
end
|
|
54
95
|
end
|
|
55
96
|
end
|
data/lib/i18n/backend/simple.rb
CHANGED
|
@@ -21,6 +21,9 @@ module I18n
|
|
|
21
21
|
class Simple
|
|
22
22
|
module Implementation
|
|
23
23
|
include Base
|
|
24
|
+
|
|
25
|
+
# Mutex to ensure that concurrent translations loading will be thread-safe
|
|
26
|
+
MUTEX = Mutex.new
|
|
24
27
|
|
|
25
28
|
def initialized?
|
|
26
29
|
@initialized ||= false
|
|
@@ -68,7 +71,11 @@ module I18n
|
|
|
68
71
|
# call `init_translations`
|
|
69
72
|
init_translations if do_init && !initialized?
|
|
70
73
|
|
|
71
|
-
@translations ||= Concurrent::Hash.new
|
|
74
|
+
@translations ||= Concurrent::Hash.new do |h, k|
|
|
75
|
+
MUTEX.synchronize do
|
|
76
|
+
h[k] = Concurrent::Hash.new
|
|
77
|
+
end
|
|
78
|
+
end
|
|
72
79
|
end
|
|
73
80
|
|
|
74
81
|
protected
|
|
@@ -94,7 +101,7 @@ module I18n
|
|
|
94
101
|
return nil unless result.has_key?(_key)
|
|
95
102
|
end
|
|
96
103
|
result = result[_key]
|
|
97
|
-
result = resolve_entry(locale, _key, result, options.merge(:scope => nil)) if result.is_a?(Symbol)
|
|
104
|
+
result = resolve_entry(locale, _key, result, Utils.except(options.merge(:scope => nil), :count)) if result.is_a?(Symbol)
|
|
98
105
|
result
|
|
99
106
|
end
|
|
100
107
|
end
|
|
@@ -45,30 +45,30 @@ module I18n
|
|
|
45
45
|
"Ç"=>"C", "È"=>"E", "É"=>"E", "Ê"=>"E", "Ë"=>"E", "Ì"=>"I", "Í"=>"I",
|
|
46
46
|
"Î"=>"I", "Ï"=>"I", "Ð"=>"D", "Ñ"=>"N", "Ò"=>"O", "Ó"=>"O", "Ô"=>"O",
|
|
47
47
|
"Õ"=>"O", "Ö"=>"O", "×"=>"x", "Ø"=>"O", "Ù"=>"U", "Ú"=>"U", "Û"=>"U",
|
|
48
|
-
"Ü"=>"U", "Ý"=>"Y", "Þ"=>"Th", "ß"=>"ss", "
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"ņ"=>"n", "Ň"=>"N", "ň"=>"n", "ʼn"=>"'n", "Ŋ"=>"NG",
|
|
64
|
-
"Ō"=>"O", "ō"=>"o", "Ŏ"=>"O", "ŏ"=>"o", "Ő"=>"O", "ő"=>"o",
|
|
65
|
-
"œ"=>"oe", "Ŕ"=>"R", "ŕ"=>"r", "Ŗ"=>"R", "ŗ"=>"r", "Ř"=>"R",
|
|
66
|
-
"Ś"=>"S", "ś"=>"s", "Ŝ"=>"S", "ŝ"=>"s", "Ş"=>"S", "ş"=>"s",
|
|
67
|
-
"š"=>"s", "Ţ"=>"T", "ţ"=>"t", "Ť"=>"T", "ť"=>"t", "Ŧ"=>"T",
|
|
68
|
-
"Ũ"=>"U", "ũ"=>"u", "Ū"=>"U", "ū"=>"u", "Ŭ"=>"U", "ŭ"=>"u",
|
|
69
|
-
"ů"=>"u", "Ű"=>"U", "ű"=>"u", "Ų"=>"U", "ų"=>"u", "Ŵ"=>"W",
|
|
70
|
-
"Ŷ"=>"Y", "ŷ"=>"y", "Ÿ"=>"Y", "Ź"=>"Z", "ź"=>"z", "Ż"=>"Z",
|
|
71
|
-
"Ž"=>"Z", "ž"=>"z"
|
|
48
|
+
"Ü"=>"U", "Ý"=>"Y", "Þ"=>"Th", "ß"=>"ss", "ẞ"=>"SS", "à"=>"a",
|
|
49
|
+
"á"=>"a", "â"=>"a", "ã"=>"a", "ä"=>"a", "å"=>"a", "æ"=>"ae", "ç"=>"c",
|
|
50
|
+
"è"=>"e", "é"=>"e", "ê"=>"e", "ë"=>"e", "ì"=>"i", "í"=>"i", "î"=>"i",
|
|
51
|
+
"ï"=>"i", "ð"=>"d", "ñ"=>"n", "ò"=>"o", "ó"=>"o", "ô"=>"o", "õ"=>"o",
|
|
52
|
+
"ö"=>"o", "ø"=>"o", "ù"=>"u", "ú"=>"u", "û"=>"u", "ü"=>"u", "ý"=>"y",
|
|
53
|
+
"þ"=>"th", "ÿ"=>"y", "Ā"=>"A", "ā"=>"a", "Ă"=>"A", "ă"=>"a", "Ą"=>"A",
|
|
54
|
+
"ą"=>"a", "Ć"=>"C", "ć"=>"c", "Ĉ"=>"C", "ĉ"=>"c", "Ċ"=>"C", "ċ"=>"c",
|
|
55
|
+
"Č"=>"C", "č"=>"c", "Ď"=>"D", "ď"=>"d", "Đ"=>"D", "đ"=>"d", "Ē"=>"E",
|
|
56
|
+
"ē"=>"e", "Ĕ"=>"E", "ĕ"=>"e", "Ė"=>"E", "ė"=>"e", "Ę"=>"E", "ę"=>"e",
|
|
57
|
+
"Ě"=>"E", "ě"=>"e", "Ĝ"=>"G", "ĝ"=>"g", "Ğ"=>"G", "ğ"=>"g", "Ġ"=>"G",
|
|
58
|
+
"ġ"=>"g", "Ģ"=>"G", "ģ"=>"g", "Ĥ"=>"H", "ĥ"=>"h", "Ħ"=>"H", "ħ"=>"h",
|
|
59
|
+
"Ĩ"=>"I", "ĩ"=>"i", "Ī"=>"I", "ī"=>"i", "Ĭ"=>"I", "ĭ"=>"i", "Į"=>"I",
|
|
60
|
+
"į"=>"i", "İ"=>"I", "ı"=>"i", "IJ"=>"IJ", "ij"=>"ij", "Ĵ"=>"J", "ĵ"=>"j",
|
|
61
|
+
"Ķ"=>"K", "ķ"=>"k", "ĸ"=>"k", "Ĺ"=>"L", "ĺ"=>"l", "Ļ"=>"L", "ļ"=>"l",
|
|
62
|
+
"Ľ"=>"L", "ľ"=>"l", "Ŀ"=>"L", "ŀ"=>"l", "Ł"=>"L", "ł"=>"l", "Ń"=>"N",
|
|
63
|
+
"ń"=>"n", "Ņ"=>"N", "ņ"=>"n", "Ň"=>"N", "ň"=>"n", "ʼn"=>"'n", "Ŋ"=>"NG",
|
|
64
|
+
"ŋ"=>"ng", "Ō"=>"O", "ō"=>"o", "Ŏ"=>"O", "ŏ"=>"o", "Ő"=>"O", "ő"=>"o",
|
|
65
|
+
"Œ"=>"OE", "œ"=>"oe", "Ŕ"=>"R", "ŕ"=>"r", "Ŗ"=>"R", "ŗ"=>"r", "Ř"=>"R",
|
|
66
|
+
"ř"=>"r", "Ś"=>"S", "ś"=>"s", "Ŝ"=>"S", "ŝ"=>"s", "Ş"=>"S", "ş"=>"s",
|
|
67
|
+
"Š"=>"S", "š"=>"s", "Ţ"=>"T", "ţ"=>"t", "Ť"=>"T", "ť"=>"t", "Ŧ"=>"T",
|
|
68
|
+
"ŧ"=>"t", "Ũ"=>"U", "ũ"=>"u", "Ū"=>"U", "ū"=>"u", "Ŭ"=>"U", "ŭ"=>"u",
|
|
69
|
+
"Ů"=>"U", "ů"=>"u", "Ű"=>"U", "ű"=>"u", "Ų"=>"U", "ų"=>"u", "Ŵ"=>"W",
|
|
70
|
+
"ŵ"=>"w", "Ŷ"=>"Y", "ŷ"=>"y", "Ÿ"=>"Y", "Ź"=>"Z", "ź"=>"z", "Ż"=>"Z",
|
|
71
|
+
"ż"=>"z", "Ž"=>"Z", "ž"=>"z"
|
|
72
72
|
}.freeze
|
|
73
73
|
|
|
74
74
|
def initialize(rule = nil)
|
data/lib/i18n/exceptions.rb
CHANGED
|
@@ -47,7 +47,7 @@ module I18n
|
|
|
47
47
|
|
|
48
48
|
class MissingTranslation < ArgumentError
|
|
49
49
|
module Base
|
|
50
|
-
PERMITTED_KEYS = [:scope].freeze
|
|
50
|
+
PERMITTED_KEYS = [:scope, :default].freeze
|
|
51
51
|
|
|
52
52
|
attr_reader :locale, :key, :options
|
|
53
53
|
|
|
@@ -63,8 +63,18 @@ module I18n
|
|
|
63
63
|
end
|
|
64
64
|
|
|
65
65
|
def message
|
|
66
|
-
|
|
66
|
+
if (default = options[:default]).is_a?(Array) && default.any?
|
|
67
|
+
other_options = ([key, *default]).map { |k| normalized_option(k).prepend('- ') }.join("\n")
|
|
68
|
+
"Translation missing. Options considered were:\n#{other_options}"
|
|
69
|
+
else
|
|
70
|
+
"Translation missing: #{keys.join('.')}"
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def normalized_option(key)
|
|
75
|
+
I18n.normalize_keys(locale, key, options[:scope]).join('.')
|
|
67
76
|
end
|
|
77
|
+
|
|
68
78
|
alias :to_s :message
|
|
69
79
|
|
|
70
80
|
def to_exception
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
# heavily based on Masao Mutoh's gettext String interpolation extension
|
|
2
4
|
# http://github.com/mutoh/gettext/blob/f6566738b981fe0952548c421042ad1e0cdfb31e/lib/gettext/core_ext/string.rb
|
|
3
5
|
|
|
@@ -10,6 +12,11 @@ module I18n
|
|
|
10
12
|
INTERPOLATION_PATTERN = Regexp.union(DEFAULT_INTERPOLATION_PATTERNS)
|
|
11
13
|
deprecate_constant :INTERPOLATION_PATTERN
|
|
12
14
|
|
|
15
|
+
INTERPOLATION_PATTERNS_CACHE = Hash.new do |hash, patterns|
|
|
16
|
+
hash[patterns] = Regexp.union(patterns)
|
|
17
|
+
end
|
|
18
|
+
private_constant :INTERPOLATION_PATTERNS_CACHE
|
|
19
|
+
|
|
13
20
|
class << self
|
|
14
21
|
# Return String or raises MissingInterpolationArgument exception.
|
|
15
22
|
# Missing argument's logic is handled by I18n.config.missing_interpolation_argument_handler.
|
|
@@ -20,7 +27,12 @@ module I18n
|
|
|
20
27
|
end
|
|
21
28
|
|
|
22
29
|
def interpolate_hash(string, values)
|
|
23
|
-
|
|
30
|
+
pattern = INTERPOLATION_PATTERNS_CACHE[config.interpolation_patterns]
|
|
31
|
+
interpolated = false
|
|
32
|
+
|
|
33
|
+
interpolated_string = string.gsub(pattern) do |match|
|
|
34
|
+
interpolated = true
|
|
35
|
+
|
|
24
36
|
if match == '%%'
|
|
25
37
|
'%'
|
|
26
38
|
else
|
|
@@ -34,6 +46,8 @@ module I18n
|
|
|
34
46
|
$3 ? sprintf("%#{$3}", value) : value
|
|
35
47
|
end
|
|
36
48
|
end
|
|
49
|
+
|
|
50
|
+
interpolated ? interpolated_string : string
|
|
37
51
|
end
|
|
38
52
|
end
|
|
39
53
|
end
|
|
@@ -79,6 +79,14 @@ module I18n
|
|
|
79
79
|
end
|
|
80
80
|
end
|
|
81
81
|
|
|
82
|
+
def empty?
|
|
83
|
+
@map.empty? && @defaults.empty?
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def inspect
|
|
87
|
+
"#<#{self.class.name} @map=#{@map.inspect} @defaults=#{@defaults.inspect}>"
|
|
88
|
+
end
|
|
89
|
+
|
|
82
90
|
protected
|
|
83
91
|
|
|
84
92
|
def compute(tags, include_defaults = true, exclude = [])
|
|
@@ -112,6 +112,10 @@ module I18n
|
|
|
112
112
|
assert_raises(I18n::ReservedInterpolationKey) { interpolate(:foo => :bar, :default => '%{default}') }
|
|
113
113
|
assert_raises(I18n::ReservedInterpolationKey) { interpolate(:foo => :bar, :default => '%{separator}') }
|
|
114
114
|
assert_raises(I18n::ReservedInterpolationKey) { interpolate(:foo => :bar, :default => '%{scope}') }
|
|
115
|
+
assert_raises(I18n::ReservedInterpolationKey) { interpolate(:default => '%{scope}') }
|
|
116
|
+
|
|
117
|
+
I18n.backend.store_translations(:en, :interpolate => 'Hi %{scope}!')
|
|
118
|
+
assert_raises(I18n::ReservedInterpolationKey) { interpolate(:interpolate) }
|
|
115
119
|
end
|
|
116
120
|
|
|
117
121
|
test "interpolation: deep interpolation for default string" do
|
|
@@ -34,6 +34,11 @@ module I18n
|
|
|
34
34
|
assert_equal 'Sa', I18n.l(@date, :format => '%a', :locale => :de)
|
|
35
35
|
end
|
|
36
36
|
|
|
37
|
+
test "localize Date: given an meridian indicator format it returns the correct meridian indicator" do
|
|
38
|
+
assert_equal 'AM', I18n.l(@date, :format => '%p', :locale => :de)
|
|
39
|
+
assert_equal 'am', I18n.l(@date, :format => '%P', :locale => :de)
|
|
40
|
+
end
|
|
41
|
+
|
|
37
42
|
test "localize Date: given an abbreviated and uppercased day name format it returns the correct abbreviated day name in upcase" do
|
|
38
43
|
assert_equal 'sa'.upcase, I18n.l(@date, :format => '%^a', :locale => :de)
|
|
39
44
|
end
|
|
@@ -59,7 +64,7 @@ module I18n
|
|
|
59
64
|
end
|
|
60
65
|
|
|
61
66
|
test "localize Date: given missing translations it returns the correct error message" do
|
|
62
|
-
assert_equal '
|
|
67
|
+
assert_equal 'Translation missing: fr.date.abbr_month_names', I18n.l(@date, :format => '%b', :locale => :fr)
|
|
63
68
|
end
|
|
64
69
|
|
|
65
70
|
test "localize Date: given an unknown format it does not fail" do
|
|
@@ -60,7 +60,7 @@ module I18n
|
|
|
60
60
|
end
|
|
61
61
|
|
|
62
62
|
test "localize DateTime: given missing translations it returns the correct error message" do
|
|
63
|
-
assert_equal '
|
|
63
|
+
assert_equal 'Translation missing: fr.date.abbr_month_names', I18n.l(@datetime, :format => '%b', :locale => :fr)
|
|
64
64
|
end
|
|
65
65
|
|
|
66
66
|
test "localize DateTime: given a meridian indicator format it returns the correct meridian indicator" do
|
|
@@ -61,7 +61,7 @@ module I18n
|
|
|
61
61
|
end
|
|
62
62
|
|
|
63
63
|
test "localize Time: given missing translations it returns the correct error message" do
|
|
64
|
-
assert_equal '
|
|
64
|
+
assert_equal 'Translation missing: fr.date.abbr_month_names', I18n.l(@time, :format => '%b', :locale => :fr)
|
|
65
65
|
end
|
|
66
66
|
|
|
67
67
|
test "localize Time: given a meridian indicator format it returns the correct meridian indicator" do
|
data/lib/i18n/tests/lookup.rb
CHANGED
|
@@ -30,7 +30,7 @@ module I18n
|
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
test "lookup: given a missing key, no default and no raise option it returns an error message" do
|
|
33
|
-
assert_equal "
|
|
33
|
+
assert_equal "Translation missing: en.missing", I18n.t(:missing)
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
test "lookup: given a missing key, no default and the raise option it raises MissingTranslationData" do
|
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.14.4
|
|
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:
|
|
16
|
+
date: 2024-03-06 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.5.1
|
|
110
110
|
signing_key:
|
|
111
111
|
specification_version: 4
|
|
112
112
|
summary: New wave Internationalization support for Ruby
|