i18n 1.2.0 → 1.3.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 +31 -31
- 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: c1204b01f3c5f6a008558634c20f7101001d0c3ddf6a377f2d3abae1d263236f
|
4
|
+
data.tar.gz: bbd19a13dbcc3eafe8229f20c230b6545f713ecd34cf95ccd077cf38a8d2f763
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b225fd4067de248b3a1ef958aedcb78f4ea0a74ba7f06335ca33616a4703d013387753dd1ac9eaa15e4dab94fda57e7d610c627ea7777c79f2bf2f886130f3ac
|
7
|
+
data.tar.gz: cde28715096eba32109e7709db5fec75d8cf69ed2a6d2f8ffa32a328698043c8a96676f678ca230ccb11b338cbc5798993649ebfbfd437f5a1ab49583b741ea8
|
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,37 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
module I18n
|
2
|
+
module HashRefinements
|
3
|
+
refine Hash do
|
4
|
+
def slice(*keep_keys)
|
5
|
+
h = {}
|
6
|
+
keep_keys.each { |key| h[key] = fetch(key) if has_key?(key) }
|
7
|
+
h
|
8
|
+
end
|
7
9
|
|
8
|
-
|
9
|
-
|
10
|
-
|
10
|
+
def except(*less_keys)
|
11
|
+
slice(*keys - less_keys)
|
12
|
+
end
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
def deep_symbolize_keys
|
15
|
+
each_with_object({}) do |(key, value), result|
|
16
|
+
value = value.deep_symbolize_keys if value.is_a?(Hash)
|
17
|
+
result[symbolize_key(key)] = value
|
18
|
+
result
|
19
|
+
end
|
20
|
+
end
|
19
21
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
22
|
+
# deep_merge_hash! by Stefan Rusterholz, see http://www.ruby-forum.com/topic/142809
|
23
|
+
def deep_merge!(data)
|
24
|
+
merger = lambda do |_key, v1, v2|
|
25
|
+
Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2
|
26
|
+
end
|
27
|
+
merge!(data, &merger)
|
28
|
+
end
|
27
29
|
|
28
|
-
|
29
|
-
|
30
|
-
|
30
|
+
private
|
31
|
+
|
32
|
+
def symbolize_key(key)
|
33
|
+
key.respond_to?(:to_sym) ? key.to_sym : key
|
34
|
+
end
|
35
|
+
end
|
31
36
|
end
|
32
|
-
|
33
|
-
def deep_merge!(data)
|
34
|
-
merge!(data, &MERGER)
|
35
|
-
end unless Hash.method_defined?(:deep_merge!)
|
36
37
|
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.3.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: 2018-12-
|
16
|
+
date: 2018-12-20 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: concurrent-ruby
|
@@ -97,7 +97,7 @@ post_install_message: |2+
|
|
97
97
|
But that may break your application.
|
98
98
|
|
99
99
|
Please check your Rails app for 'config.i18n.fallbacks = true'.
|
100
|
-
If you're using I18n 1.1.
|
100
|
+
If you're using I18n (>= 1.1.0) and Rails (< 5.2.2), this should be
|
101
101
|
'config.i18n.fallbacks = [I18n.default_locale]'.
|
102
102
|
If not, fallbacks will be broken in your app by I18n 1.1.x.
|
103
103
|
|