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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8f090f4664c260c453c6287eda93ccabd1681c8ca2cef077794fcc8ec32dab4f
4
- data.tar.gz: 639643c1611bd9800407a84b1fc4c0dcf57e85e9cab85c9a4a82e56418a15a48
3
+ metadata.gz: 8261641c6a20a87755f261c21a4148f5b414577c2fbc127b31ffaf59e93bb88e
4
+ data.tar.gz: 8710ff18593cdab6cdd2388f3726d3da41d5a1129eade70b3cac8e8d100c804b
5
5
  SHA512:
6
- metadata.gz: 8b9747cc4ba7e203400ed38c21a2c6e5c35b45c4283bd56e4cb608b72c3904e6117d80b11a91b97753344ac0185fae0f340e3687b26eb40a95669d0039fad6ee
7
- data.tar.gz: 48aa51116fe7450ce06036dbd537e7711d66d755a4001bc148936573c08b74744428cf5877f757fe53fb6326d8b99f891639a31844396d9c24e1ff2477cebd1d
6
+ metadata.gz: 3a74081f5e0ad3d800857b64541ec97e0d48602bfc81b5d1e54a72ede4e8244599f9d1f3b07a0ed33eb6f2e5730c80f468e1097815fadde9f9c0c1edd63f1b10
7
+ data.tar.gz: 3ff46b06293eaa68353b15a64645323da870e6afa0f8a2b5f3559983966166a950e74cf2ade96cf3a3d22cb7940d01b448feecb71ad052bf43433ebbe1da2c3c
@@ -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,47 @@
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
+ using I18n::HashRefinements
5
+ def except(*keys)
6
+ dup.except!(*keys)
7
+ end
7
8
 
8
- def except(*less_keys)
9
- slice(*keys - less_keys)
10
- end unless Hash.method_defined?(:except)
9
+ def except!(*keys)
10
+ keys.each { |key| delete(key) }
11
+ self
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
+ result[symbolize_key(key)] = deep_symbolize_keys_in_object(value)
17
+ result
18
+ end
19
+ end
19
20
 
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)
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
- # 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
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
-
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module I18n
4
- VERSION = "1.2.0"
4
+ VERSION = "1.4.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.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: 2018-12-11 00:00:00.000000000 Z
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.x and Rails (< 6.0), this should be
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.