i18n-interpolate_nested 1.0.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9a565eda07817800537b85b071f09bfbeaa83424
4
+ data.tar.gz: e2bce42a056ebae27cf1e7a405b42cebded61ef3
5
+ SHA512:
6
+ metadata.gz: 509089098fa1063014e014a2aba24587fbf4b75331667980383524773997221e121fe064ce8dfeef87e2c1f3b549e56fce389e7c282515fa0fcef5b683a909bc
7
+ data.tar.gz: 472ab5d2e4a0e099998b21a458113f436d00880b8359d5665650d22f5f334019f7a26041f675932d4c99f3c4879a2ca153803213c8782f8ff74a565ef625392c
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2018
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,53 @@
1
+ # i18n-interpolate_nested
2
+
3
+ Enables nested values when using I18n interpolation:
4
+
5
+ ```yaml
6
+ # config/locales/en.yml
7
+ en:
8
+ greeting: "Hello, %{user.name}!"
9
+ ```
10
+
11
+ ```ruby
12
+ user = OpenStruct.new(name: "Matz")
13
+ I18n.t(:greeting, user: user) # == "Hello, Matz!"
14
+ ```
15
+
16
+ Interpolation keys are split into individual symbols (e.g. `:user`
17
+ and `:name` in the above example), and passed to the `#[]` method of
18
+ each nesting object. Thus, interpolation works with nested Hashes,
19
+ Structs, OpenStructs, Active Record objects, etc.
20
+
21
+
22
+ ## Installation
23
+
24
+ Add this line to your application's Gemfile:
25
+
26
+ ```ruby
27
+ gem "i18n-interpolate_nested"
28
+ ```
29
+
30
+ And then execute:
31
+
32
+ ```bash
33
+ $ bundle install
34
+ ```
35
+
36
+ **If you are not using Rails,** you will also need to invoke
37
+ `I18n::InterpolateNested::init` in order to hook this gem into I18n:
38
+
39
+ ```ruby
40
+ require "i18n/interpolate_nested"
41
+
42
+ I18n::InterpolateNested.init
43
+ ```
44
+
45
+
46
+ ## Contributing
47
+
48
+ Run `rake test` to run the tests.
49
+
50
+
51
+ ## License
52
+
53
+ [MIT License](https://opensource.org/licenses/MIT)
data/Rakefile ADDED
@@ -0,0 +1,23 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'yard'
8
+
9
+ YARD::Rake::YardocTask.new(:doc) do |t|
10
+ end
11
+
12
+
13
+ require 'bundler/gem_tasks'
14
+
15
+ require 'rake/testtask'
16
+
17
+ Rake::TestTask.new(:test) do |t|
18
+ t.libs << 'test'
19
+ t.pattern = 'test/**/*_test.rb'
20
+ t.verbose = false
21
+ end
22
+
23
+ task default: :test
@@ -0,0 +1,36 @@
1
+ require "i18n"
2
+ require "i18n/interpolate_nested/version"
3
+ require "i18n/interpolate_nested/railtie" if defined?(Rails)
4
+
5
+
6
+ module I18n::InterpolateNested
7
+
8
+ # Hooks into I18n and enables nested values when interpolating. This
9
+ # method is idempotent.
10
+ #
11
+ # @return [void]
12
+ def self.init
13
+ return if defined?(@@initialized)
14
+
15
+ original_handler = I18n.config.missing_interpolation_argument_handler
16
+ I18n.config.missing_interpolation_argument_handler = ->(key, values, string) do
17
+ keys = key.to_s.split(".")
18
+
19
+ if keys.length > 1
20
+ keys.reduce(values) do |vs, k|
21
+ break original_handler.call(key, values, string) if vs.nil?
22
+ vs[k.to_sym]
23
+ end
24
+ else
25
+ original_handler.call(key, values, string)
26
+ end
27
+ end
28
+
29
+ pattern = Regexp.union(I18n::INTERPOLATION_PATTERN, /%\{[\w.]+\}/)
30
+ I18n.send(:remove_const, :INTERPOLATION_PATTERN)
31
+ I18n.const_set(:INTERPOLATION_PATTERN, pattern)
32
+
33
+ @@initialized = true
34
+ end
35
+
36
+ end
@@ -0,0 +1,10 @@
1
+ module I18n
2
+ module InterpolateNested
3
+ # @!visibility private
4
+ class Railtie < ::Rails::Railtie
5
+ config.after_initialize do
6
+ I18n::InterpolateNested.init
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,5 @@
1
+ module I18n
2
+ module InterpolateNested
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: i18n-interpolate_nested
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jonathan Hefner
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-07-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: i18n
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '5.1'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '5.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: sqlite3
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: yard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.9'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.9'
69
+ description:
70
+ email:
71
+ - jonathan.hefner@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - MIT-LICENSE
77
+ - README.md
78
+ - Rakefile
79
+ - lib/i18n/interpolate_nested.rb
80
+ - lib/i18n/interpolate_nested/railtie.rb
81
+ - lib/i18n/interpolate_nested/version.rb
82
+ homepage: https://github.com/jonathanhefner/i18n-interpolate_nested
83
+ licenses:
84
+ - MIT
85
+ metadata: {}
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ requirements: []
101
+ rubyforge_project:
102
+ rubygems_version: 2.5.2.1
103
+ signing_key:
104
+ specification_version: 4
105
+ summary: I18n interpolation support for nested values
106
+ test_files: []