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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8f090f4664c260c453c6287eda93ccabd1681c8ca2cef077794fcc8ec32dab4f
4
- data.tar.gz: 639643c1611bd9800407a84b1fc4c0dcf57e85e9cab85c9a4a82e56418a15a48
3
+ metadata.gz: c1204b01f3c5f6a008558634c20f7101001d0c3ddf6a377f2d3abae1d263236f
4
+ data.tar.gz: bbd19a13dbcc3eafe8229f20c230b6545f713ecd34cf95ccd077cf38a8d2f763
5
5
  SHA512:
6
- metadata.gz: 8b9747cc4ba7e203400ed38c21a2c6e5c35b45c4283bd56e4cb608b72c3904e6117d80b11a91b97753344ac0185fae0f340e3687b26eb40a95669d0039fad6ee
7
- data.tar.gz: 48aa51116fe7450ce06036dbd537e7711d66d755a4001bc148936573c08b74744428cf5877f757fe53fb6326d8b99f891639a31844396d9c24e1ff2477cebd1d
6
+ metadata.gz: b225fd4067de248b3a1ef958aedcb78f4ea0a74ba7f06335ca33616a4703d013387753dd1ac9eaa15e4dab94fda57e7d610c627ea7777c79f2bf2f886130f3ac
7
+ data.tar.gz: cde28715096eba32109e7709db5fec75d8cf69ed2a6d2f8ffa32a328698043c8a96676f678ca230ccb11b338cbc5798993649ebfbfd437f5a1ab49583b741ea8
@@ -362,7 +362,18 @@ module I18n
362
362
  else
363
363
  keys = key.to_s.split(separator)
364
364
  keys.delete('')
365
- keys.map! { |k| k.to_sym }
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
@@ -7,6 +7,7 @@ require 'i18n/core_ext/hash'
7
7
  module I18n
8
8
  module Backend
9
9
  module Base
10
+ using I18n::HashRefinements
10
11
  include I18n::Backend::Transliterator
11
12
 
12
13
  # Accepts a list of paths to translation files. Loads translations from
@@ -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)
@@ -31,6 +31,8 @@ module I18n
31
31
  # Without it strings containing periods (".") will not be translated.
32
32
 
33
33
  module Gettext
34
+ using I18n::HashRefinements
35
+
34
36
  class PoData < Hash
35
37
  def set_comment(msgid_or_sym, comment)
36
38
  # ignore
@@ -67,6 +67,8 @@ module I18n
67
67
  #
68
68
  # This is useful if you are using a KeyValue backend chained to a Simple backend.
69
69
  class KeyValue
70
+ using I18n::HashRefinements
71
+
70
72
  module Implementation
71
73
  attr_accessor :store
72
74
 
@@ -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.deep_stringify_keys.deep_symbolize_keys
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
- _key = _key.to_sym
88
- return nil unless result.is_a?(Hash) && result.has_key?(_key)
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
@@ -1,37 +1,37 @@
1
- class Hash
2
- def slice(*keep_keys)
3
- h = {}
4
- keep_keys.each { |key| h[key] = fetch(key) if has_key?(key) }
5
- h
6
- end unless Hash.method_defined?(:slice)
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
- def except(*less_keys)
9
- slice(*keys - less_keys)
10
- end unless Hash.method_defined?(:except)
10
+ def except(*less_keys)
11
+ slice(*keys - less_keys)
12
+ end
11
13
 
12
- def deep_symbolize_keys
13
- inject({}) { |result, (key, value)|
14
- value = value.deep_symbolize_keys if value.is_a?(Hash)
15
- result[(key.to_sym rescue key) || key] = value
16
- result
17
- }
18
- end unless Hash.method_defined?(:deep_symbolize_keys)
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
- def deep_stringify_keys
21
- inject({}) { |result, (key, value)|
22
- value = value.deep_stringify_keys if value.is_a?(Hash)
23
- result[key.to_s] = value
24
- result
25
- }
26
- end unless Hash.method_defined?(:deep_stringify_keys)
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
- # deep_merge_hash! by Stefan Rusterholz, see http://www.ruby-forum.com/topic/142809
29
- MERGER = proc do |key, v1, v2|
30
- Hash === v1 && Hash === v2 ? v1.merge(v2, &MERGER) : v2
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
-
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module I18n
4
- VERSION = "1.2.0"
4
+ VERSION = "1.3.0"
5
5
  end
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.2.0
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-11 00:00:00.000000000 Z
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.x and Rails (< 6.0), this should be
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