i18n 1.2.0 → 1.4.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.rb +12 -1
- data/lib/i18n/backend/base.rb +1 -0
- data/lib/i18n/backend/chain.rb +4 -2
- data/lib/i18n/backend/gettext.rb +2 -0
- data/lib/i18n/backend/key_value.rb +2 -0
- data/lib/i18n/backend/simple.rb +10 -3
- data/lib/i18n/core_ext/hash.rb +41 -31
- data/lib/i18n/version.rb +1 -1
- metadata +3 -4
- data/lib/i18n/core_ext/string/interpolate.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8261641c6a20a87755f261c21a4148f5b414577c2fbc127b31ffaf59e93bb88e
|
4
|
+
data.tar.gz: 8710ff18593cdab6cdd2388f3726d3da41d5a1129eade70b3cac8e8d100c804b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a74081f5e0ad3d800857b64541ec97e0d48602bfc81b5d1e54a72ede4e8244599f9d1f3b07a0ed33eb6f2e5730c80f468e1097815fadde9f9c0c1edd63f1b10
|
7
|
+
data.tar.gz: 3ff46b06293eaa68353b15a64645323da870e6afa0f8a2b5f3559983966166a950e74cf2ade96cf3a3d22cb7940d01b448feecb71ad052bf43433ebbe1da2c3c
|
data/lib/i18n.rb
CHANGED
@@ -362,7 +362,18 @@ module I18n
|
|
362
362
|
else
|
363
363
|
keys = key.to_s.split(separator)
|
364
364
|
keys.delete('')
|
365
|
-
keys.map!
|
365
|
+
keys.map! do |k|
|
366
|
+
case k
|
367
|
+
when /\A[-+]?\d+\z/ # integer
|
368
|
+
k.to_i
|
369
|
+
when 'true'
|
370
|
+
true
|
371
|
+
when 'false'
|
372
|
+
false
|
373
|
+
else
|
374
|
+
k.to_sym
|
375
|
+
end
|
376
|
+
end
|
366
377
|
keys
|
367
378
|
end
|
368
379
|
end
|
data/lib/i18n/backend/base.rb
CHANGED
data/lib/i18n/backend/chain.rb
CHANGED
@@ -17,6 +17,8 @@ module I18n
|
|
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
19
|
class Chain
|
20
|
+
using I18n::HashRefinements
|
21
|
+
|
20
22
|
module Implementation
|
21
23
|
include Base
|
22
24
|
|
@@ -34,7 +36,7 @@ module I18n
|
|
34
36
|
end
|
35
37
|
true
|
36
38
|
end
|
37
|
-
|
39
|
+
|
38
40
|
def reload!
|
39
41
|
backends.each { |backend| backend.reload! }
|
40
42
|
end
|
@@ -94,7 +96,7 @@ module I18n
|
|
94
96
|
init_translations unless initialized?
|
95
97
|
translations
|
96
98
|
end
|
97
|
-
end
|
99
|
+
end
|
98
100
|
|
99
101
|
def namespace_lookup?(result, options)
|
100
102
|
result.is_a?(Hash) && !options.has_key?(:count)
|
data/lib/i18n/backend/gettext.rb
CHANGED
data/lib/i18n/backend/simple.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'i18n/backend/base'
|
4
|
+
|
3
5
|
module I18n
|
4
6
|
module Backend
|
5
7
|
# A simple backend that reads translations from YAML files and stores them in
|
@@ -17,6 +19,8 @@ module I18n
|
|
17
19
|
#
|
18
20
|
# I18n::Backend::Simple.include(I18n::Backend::Pluralization)
|
19
21
|
class Simple
|
22
|
+
using I18n::HashRefinements
|
23
|
+
|
20
24
|
(class << self; self; end).class_eval { public :include }
|
21
25
|
|
22
26
|
module Implementation
|
@@ -39,7 +43,7 @@ module I18n
|
|
39
43
|
end
|
40
44
|
locale = locale.to_sym
|
41
45
|
translations[locale] ||= {}
|
42
|
-
data = data.
|
46
|
+
data = data.deep_symbolize_keys
|
43
47
|
translations[locale].deep_merge!(data)
|
44
48
|
end
|
45
49
|
|
@@ -84,8 +88,11 @@ module I18n
|
|
84
88
|
keys = I18n.normalize_keys(locale, key, scope, options[:separator])
|
85
89
|
|
86
90
|
keys.inject(translations) do |result, _key|
|
87
|
-
|
88
|
-
|
91
|
+
return nil unless result.is_a?(Hash)
|
92
|
+
unless result.has_key?(_key)
|
93
|
+
_key = _key.to_s.to_sym
|
94
|
+
return nil unless result.has_key?(_key)
|
95
|
+
end
|
89
96
|
result = result[_key]
|
90
97
|
result = resolve(locale, _key, result, options.merge(:scope => nil)) if result.is_a?(Symbol)
|
91
98
|
result
|
data/lib/i18n/core_ext/hash.rb
CHANGED
@@ -1,37 +1,47 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
module I18n
|
2
|
+
module HashRefinements
|
3
|
+
refine Hash do
|
4
|
+
using I18n::HashRefinements
|
5
|
+
def except(*keys)
|
6
|
+
dup.except!(*keys)
|
7
|
+
end
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
9
|
+
def except!(*keys)
|
10
|
+
keys.each { |key| delete(key) }
|
11
|
+
self
|
12
|
+
end
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end unless Hash.method_defined?(:deep_symbolize_keys)
|
14
|
+
def deep_symbolize_keys
|
15
|
+
each_with_object({}) do |(key, value), result|
|
16
|
+
result[symbolize_key(key)] = deep_symbolize_keys_in_object(value)
|
17
|
+
result
|
18
|
+
end
|
19
|
+
end
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
21
|
+
# deep_merge_hash! by Stefan Rusterholz, see http://www.ruby-forum.com/topic/142809
|
22
|
+
def deep_merge!(data)
|
23
|
+
merger = lambda do |_key, v1, v2|
|
24
|
+
Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2
|
25
|
+
end
|
26
|
+
merge!(data, &merger)
|
27
|
+
end
|
27
28
|
|
28
|
-
|
29
|
-
|
30
|
-
|
29
|
+
def symbolize_key(key)
|
30
|
+
key.respond_to?(:to_sym) ? key.to_sym : key
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def deep_symbolize_keys_in_object(value)
|
36
|
+
case value
|
37
|
+
when Hash
|
38
|
+
value.deep_symbolize_keys
|
39
|
+
when Array
|
40
|
+
value.map { |e| deep_symbolize_keys_in_object(e) }
|
41
|
+
else
|
42
|
+
value
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
31
46
|
end
|
32
|
-
|
33
|
-
def deep_merge!(data)
|
34
|
-
merge!(data, &MERGER)
|
35
|
-
end unless Hash.method_defined?(:deep_merge!)
|
36
47
|
end
|
37
|
-
|
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.4.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:
|
16
|
+
date: 2019-01-01 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: concurrent-ruby
|
@@ -56,7 +56,6 @@ files:
|
|
56
56
|
- lib/i18n/backend/transliterator.rb
|
57
57
|
- lib/i18n/config.rb
|
58
58
|
- lib/i18n/core_ext/hash.rb
|
59
|
-
- lib/i18n/core_ext/string/interpolate.rb
|
60
59
|
- lib/i18n/exceptions.rb
|
61
60
|
- lib/i18n/gettext.rb
|
62
61
|
- lib/i18n/gettext/helpers.rb
|
@@ -97,7 +96,7 @@ post_install_message: |2+
|
|
97
96
|
But that may break your application.
|
98
97
|
|
99
98
|
Please check your Rails app for 'config.i18n.fallbacks = true'.
|
100
|
-
If you're using I18n 1.1.
|
99
|
+
If you're using I18n (>= 1.1.0) and Rails (< 5.2.2), this should be
|
101
100
|
'config.i18n.fallbacks = [I18n.default_locale]'.
|
102
101
|
If not, fallbacks will be broken in your app by I18n 1.1.x.
|
103
102
|
|
@@ -1,9 +0,0 @@
|
|
1
|
-
# This file used to backport the Ruby 1.9 String interpolation syntax to Ruby 1.8.
|
2
|
-
#
|
3
|
-
# Since I18n has dropped support to Ruby 1.8, this file is not required anymore,
|
4
|
-
# however, Rails 3.2 still requires it directly:
|
5
|
-
#
|
6
|
-
# https://github.com/rails/rails/blob/3-2-stable/activesupport/lib/active_support/core_ext/string/interpolation.rb#L2
|
7
|
-
#
|
8
|
-
# So we can't just drop the file entirely, which would then break Rails users
|
9
|
-
# under Ruby 1.9. This file can be removed once Rails 3.2 support is dropped.
|