i18nliner 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,8 +7,8 @@ module I18nliner
7
7
  ALLOWED_PLURALIZATION_KEYS = [:zero, :one, :few, :many, :other]
8
8
  REQUIRED_PLURALIZATION_KEYS = [:one, :other]
9
9
 
10
- def normalize_key(key, scope, inferred)
11
- scope.normalize_key(key.to_s, inferred)
10
+ def normalize_key(key, scope, inferred, i18n_scope)
11
+ scope.normalize_key(key.to_s, inferred, i18n_scope)
12
12
  end
13
13
 
14
14
  def normalize_default(default, translate_options = {}, options = {})
@@ -110,7 +110,7 @@ module I18nliner
110
110
  raise ArgumentError.new("invalid default translation. expected Hash or String, got #{default.class}") unless default.nil? || default.is_a?(String) || default.is_a?(Hash)
111
111
  raise ArgumentError.new("invalid options argument. expected Hash, got #{options.class}") unless options.is_a?(Hash)
112
112
  options[:default] = default if default
113
- options[:i18n_inferred_key] = true unless has_key
113
+ options[:i18nliner_inferred_key] = true unless has_key
114
114
  args
115
115
  end
116
116
 
@@ -7,12 +7,12 @@ module I18nliner
7
7
  module Controller
8
8
  include Inferpolation
9
9
 
10
- def i18n_scope; end
10
+ def i18nliner_scope; end
11
11
 
12
12
  def translate(*args)
13
13
  key, options = CallHelpers.infer_arguments(args)
14
14
  options = inferpolate(options) if I18nliner.infer_interpolation_values
15
- options[:i18n_scope] = i18n_scope
15
+ options[:i18nliner_scope] = i18nliner_scope
16
16
  super(key, options)
17
17
  end
18
18
  alias :t :translate
@@ -8,9 +8,9 @@ module I18nliner
8
8
  def translate(*args)
9
9
  key, options = *CallHelpers.infer_arguments(args)
10
10
 
11
- scope = options.delete(:i18n_scope) || Scope.root
12
- inferred_key = options.delete(:i18n_inferred_key)
13
- key = CallHelpers.normalize_key(key, scope, inferred_key)
11
+ scope = options.delete(:i18nliner_scope) || Scope.root
12
+ inferred_key = options.delete(:i18nliner_inferred_key)
13
+ key = CallHelpers.normalize_key(key, scope, inferred_key, options[:scope])
14
14
 
15
15
  if default = options[:default]
16
16
  options[:default] = CallHelpers.normalize_default(default, options)
@@ -7,12 +7,12 @@ module I18nliner
7
7
  module Model
8
8
  include Inferpolation
9
9
 
10
- def i18n_scope; end
10
+ def i18nliner_scope; end
11
11
 
12
12
  def translate(*args)
13
13
  key, options = CallHelpers.infer_arguments(args)
14
14
  options = inferpolate(options) if I18nliner.infer_interpolation_values
15
- options[:i18n_scope] = i18n_scope
15
+ options[:i18nliner_scope] = i18nliner_scope
16
16
  I18n.translate(key, options)
17
17
  end
18
18
  alias :t :translate
@@ -7,7 +7,7 @@ module I18nliner
7
7
  module View
8
8
  include Inferpolation
9
9
 
10
- def i18n_scope; end
10
+ def i18nliner_scope; end
11
11
 
12
12
  def translate(*args)
13
13
  # if a block gets through to here, it either means:
@@ -16,7 +16,7 @@ module I18nliner
16
16
  raise InvalidBlockUsageError.new("block translate calls need to be output (i.e. `<%=`) and the block body must be of the form `%>your string<%`") if block_given?
17
17
  key, options = CallHelpers.infer_arguments(args)
18
18
  options = inferpolate(options) if I18nliner.infer_interpolation_values
19
- options[:i18n_scope] = i18n_scope
19
+ options[:i18nliner_scope] = i18nliner_scope
20
20
  super(key, options)
21
21
  rescue ArgumentError
22
22
  raise
@@ -29,7 +29,7 @@ module I18nliner
29
29
  end
30
30
 
31
31
  def normalize
32
- @key = normalize_key(@key, @scope, @options[:i18n_inferred_key])
32
+ @key = normalize_key(@key, @scope, @options[:i18nliner_inferred_key], @options[:scope])
33
33
  @default = normalize_default(@default, @options || {}, {:remove_whitespace => @scope.remove_whitespace?})
34
34
  end
35
35
 
@@ -237,7 +237,7 @@ module I18nliner
237
237
  end
238
238
 
239
239
  def options_to_ruby(options)
240
- options["i18n_inferred_key"] = "true"
240
+ options["i18nliner_inferred_key"] = "true"
241
241
  options.map do |key, value|
242
242
  ":" << key << " => (" << value << ")"
243
243
  end.join(", ")
@@ -14,7 +14,7 @@ module I18nliner
14
14
  @context = options.fetch(:context, nil)
15
15
  end
16
16
 
17
- def normalize_key(key, inferred)
17
+ def normalize_key(key, inferred, i18n_scope)
18
18
  if allow_relative? && (key = key.dup) && key.sub!(/\A\./, '')
19
19
  scope + key
20
20
  else
data/lib/i18nliner.rb CHANGED
@@ -3,6 +3,6 @@ require 'i18nliner/base'
3
3
 
4
4
  require 'i18nliner/extensions/core'
5
5
  I18n.send :extend, I18nliner::Extensions::Core
6
- I18n::RESERVED_KEYS << :i18n_scope << :i18n_inferred_key
6
+ I18n::RESERVED_KEYS << :i18nliner_scope << :i18nliner_inferred_key
7
7
 
8
8
  require 'i18nliner/railtie' if defined?(Rails)
@@ -7,7 +7,7 @@ describe I18nliner::Extensions::Controller do
7
7
  Module.new do
8
8
  extend(Module.new do
9
9
  def translate(key, options)
10
- options.delete(:i18n_inferred_key)
10
+ options.delete(:i18nliner_inferred_key)
11
11
  I18n.translate(key, options)
12
12
  end
13
13
 
@@ -25,12 +25,12 @@ describe I18nliner::Extensions::Controller do
25
25
  i18n.stub(:foo).and_return("FOO")
26
26
  I18nliner::CallHelpers.stub(:infer_key).and_return(:key)
27
27
 
28
- expect(I18n).to receive(:translate).with(:key, :default => "hello %{foo}", :foo => "FOO", :i18n_scope => i18n.i18n_scope)
28
+ expect(I18n).to receive(:translate).with(:key, :default => "hello %{foo}", :foo => "FOO", :i18nliner_scope => i18n.i18nliner_scope)
29
29
  i18n.translate("hello %{foo}")
30
30
  end
31
31
 
32
32
  it "should pass along its scope to I18n.t" do
33
- expect(I18n).to receive(:translate).with(:key, :default => "foo", :i18n_scope => i18n.i18n_scope)
33
+ expect(I18n).to receive(:translate).with(:key, :default => "foo", :i18nliner_scope => i18n.i18nliner_scope)
34
34
  i18n.translate(:key, "foo")
35
35
  end
36
36
  end
@@ -15,12 +15,12 @@ describe I18nliner::Extensions::Model do
15
15
  i18n.stub(:foo).and_return("FOO")
16
16
  I18nliner::CallHelpers.stub(:infer_key).and_return(:key)
17
17
 
18
- expect(I18n).to receive(:translate).with(:key, :default => "hello %{foo}", :foo => "FOO", :i18n_scope => i18n.i18n_scope, :i18n_inferred_key => true)
18
+ expect(I18n).to receive(:translate).with(:key, :default => "hello %{foo}", :foo => "FOO", :i18nliner_scope => i18n.i18nliner_scope, :i18nliner_inferred_key => true)
19
19
  i18n.translate("hello %{foo}")
20
20
  end
21
21
 
22
22
  it "should pass along its scope to I18n.t" do
23
- expect(I18n).to receive(:translate).with(:key, :default => "foo", :i18n_scope => i18n.i18n_scope)
23
+ expect(I18n).to receive(:translate).with(:key, :default => "foo", :i18nliner_scope => i18n.i18nliner_scope)
24
24
  i18n.translate(:key, "foo")
25
25
  end
26
26
  end
@@ -7,7 +7,7 @@ describe I18nliner::Extensions::View do
7
7
  Module.new do
8
8
  extend(Module.new do
9
9
  def translate(key, options)
10
- options.delete(:i18n_inferred_key)
10
+ options.delete(:i18nliner_inferred_key)
11
11
  I18n.translate(key, options)
12
12
  end
13
13
  end)
@@ -21,7 +21,7 @@ describe I18nliner::Extensions::View do
21
21
  i18n.stub(:foo).and_return("FOO")
22
22
  I18nliner::CallHelpers.stub(:infer_key).and_return(:key)
23
23
 
24
- expect(I18n).to receive(:translate).with(:key, :default => "hello %{foo}", :foo => "FOO", :i18n_scope => i18n.i18n_scope)
24
+ expect(I18n).to receive(:translate).with(:key, :default => "hello %{foo}", :foo => "FOO", :i18nliner_scope => i18n.i18nliner_scope)
25
25
  i18n.translate("hello %{foo}")
26
26
  end
27
27
 
@@ -40,7 +40,7 @@ describe I18nliner::Extensions::View do
40
40
  end
41
41
 
42
42
  it "should pass along its scope to I18n.t" do
43
- expect(I18n).to receive(:translate).with(:key, :default => "foo", :i18n_scope => i18n.i18n_scope)
43
+ expect(I18n).to receive(:translate).with(:key, :default => "foo", :i18nliner_scope => i18n.i18nliner_scope)
44
44
  i18n.translate(:key, "foo")
45
45
  end
46
46
  end
@@ -17,12 +17,12 @@ describe I18nliner::PreProcessors::ErbPreProcessor do
17
17
 
18
18
  it "should transform t block expressions" do
19
19
  process("<%= t do %>hello world!<% end %>").should ==
20
- '<%= t :key, "hello world!", :i18n_inferred_key => (true) %>'
20
+ '<%= t :key, "hello world!", :i18nliner_inferred_key => (true) %>'
21
21
  end
22
22
 
23
23
  it "should remove extraneous whitespace from the default" do
24
24
  process("<%= t do %> ohai! lulz\t <% end %>").should ==
25
- '<%= t :key, "ohai! lulz", :i18n_inferred_key => (true) %>'
25
+ '<%= t :key, "ohai! lulz", :i18nliner_inferred_key => (true) %>'
26
26
  end
27
27
 
28
28
  # so that line numbers are close-ish when you get an error in a
@@ -39,7 +39,7 @@ describe I18nliner::PreProcessors::ErbPreProcessor do
39
39
  <% end %>
40
40
  SOURCE
41
41
  should == <<-EXPECTED.strip_heredoc
42
- <%= t :key, "ohai! %{test} lulz", :test => (test), :i18n_inferred_key => (true)
42
+ <%= t :key, "ohai! %{test} lulz", :test => (test), :i18nliner_inferred_key => (true)
43
43
 
44
44
 
45
45
 
@@ -57,7 +57,7 @@ describe I18nliner::PreProcessors::ErbPreProcessor do
57
57
  SOURCE
58
58
  should == <<-EXPECTED
59
59
  <%= form_for do %>
60
- <%= t :key, "Your Name", :i18n_inferred_key => (true) %>
60
+ <%= t :key, "Your Name", :i18nliner_inferred_key => (true) %>
61
61
  <input>
62
62
  <% end %>
63
63
  EXPECTED
@@ -87,7 +87,7 @@ describe I18nliner::PreProcessors::ErbPreProcessor do
87
87
  <% end %>
88
88
  SOURCE
89
89
  should == <<-EXPECTED
90
- <%= t :key, "*bold*, or even **combos** get wrapper'd", :i18n_inferred_key => (true), :wrappers => ["<b>\\\\1</b>", "<a href=\\\"#\\\"><i><img>\\\\1</i></a>"] %>
90
+ <%= t :key, "*bold*, or even **combos** get wrapper'd", :i18nliner_inferred_key => (true), :wrappers => ["<b>\\\\1</b>", "<a href=\\\"#\\\"><i><img>\\\\1</i></a>"] %>
91
91
  EXPECTED
92
92
  end
93
93
 
@@ -104,7 +104,7 @@ describe I18nliner::PreProcessors::ErbPreProcessor do
104
104
  <% end %>
105
105
  SOURCE
106
106
  should == <<-EXPECTED
107
- <%= t :key, "You should *create a profile*. idk why **this link** has concatention", :i18n_inferred_key => (true), :wrappers => [link_to("\\\\1", "/profile"), link_to("\\\\1", "/zomg")] %>
107
+ <%= t :key, "You should *create a profile*. idk why **this link** has concatention", :i18nliner_inferred_key => (true), :wrappers => [link_to("\\\\1", "/profile"), link_to("\\\\1", "/zomg")] %>
108
108
  EXPECTED
109
109
  end
110
110
 
@@ -115,7 +115,7 @@ describe I18nliner::PreProcessors::ErbPreProcessor do
115
115
  <% end %>
116
116
  SOURCE
117
117
  should == <<-EXPECTED
118
- <%= t :key, "Your account rep is *%{user_name}*", :user_name => (@user.name), :i18n_inferred_key => (true), :wrappers => [link_to("\\\\1", "/user/\#{@user.id}")] %>
118
+ <%= t :key, "Your account rep is *%{user_name}*", :user_name => (@user.name), :i18nliner_inferred_key => (true), :wrappers => [link_to("\\\\1", "/user/\#{@user.id}")] %>
119
119
  EXPECTED
120
120
  end
121
121
 
@@ -129,7 +129,7 @@ describe I18nliner::PreProcessors::ErbPreProcessor do
129
129
  <% end %>
130
130
  SOURCE
131
131
  should == <<-EXPECTED
132
- <%= t :key, "the wrappers for **these** **links** are the same, as are the ones for *these* *tags*", :i18n_inferred_key => (true), :wrappers => ["<b>\\\\1</b>", link_to("\\\\1", url)] %>
132
+ <%= t :key, "the wrappers for **these** **links** are the same, as are the ones for *these* *tags*", :i18nliner_inferred_key => (true), :wrappers => ["<b>\\\\1</b>", link_to("\\\\1", url)] %>
133
133
  EXPECTED
134
134
  end
135
135
 
@@ -140,7 +140,7 @@ describe I18nliner::PreProcessors::ErbPreProcessor do
140
140
  <% end %>
141
141
  SOURCE
142
142
  should == <<-EXPECTED
143
- <%= t :key, "Hello, %{name}", :name => (name), :i18n_inferred_key => (true) %>
143
+ <%= t :key, "Hello, %{name}", :name => (name), :i18nliner_inferred_key => (true) %>
144
144
  EXPECTED
145
145
  end
146
146
 
@@ -151,7 +151,7 @@ describe I18nliner::PreProcessors::ErbPreProcessor do
151
151
  <% end %>
152
152
  SOURCE
153
153
  should == <<-EXPECTED
154
- <%= t :key, "Go to *your account*", :i18n_inferred_key => (true), :wrappers => ["<a href=\\"/asdf\\" title=\\"\#{name}\\">\\\\1</a>"] %>
154
+ <%= t :key, "Go to *your account*", :i18nliner_inferred_key => (true), :wrappers => ["<a href=\\"/asdf\\" title=\\"\#{name}\\">\\\\1</a>"] %>
155
155
  EXPECTED
156
156
  end
157
157
 
@@ -165,7 +165,7 @@ describe I18nliner::PreProcessors::ErbPreProcessor do
165
165
  <% end %>
166
166
  SOURCE
167
167
  should == <<-EXPECTED
168
- <%= t :key, "Go to *your account*", :i18n_inferred_key => (true), :wrappers => ["<a href=\\"/asdf\\" title=\\"\#{t :key, \"manage account stuffs, %{name}\", :name => (name), :i18n_inferred_key => (true)}\\">\\\\1</a>"] %>
168
+ <%= t :key, "Go to *your account*", :i18nliner_inferred_key => (true), :wrappers => ["<a href=\\"/asdf\\" title=\\"\#{t :key, \"manage account stuffs, %{name}\", :name => (name), :i18nliner_inferred_key => (true)}\\">\\\\1</a>"] %>
169
169
  EXPECTED
170
170
  end
171
171
 
@@ -176,7 +176,7 @@ describe I18nliner::PreProcessors::ErbPreProcessor do
176
176
  <% end %>
177
177
  SOURCE
178
178
  should == <<-EXPECTED
179
- <%= t :key, "Create %{input_name_count} groups", :input_name_count => ("<input name=\\"count\\">".html_safe), :i18n_inferred_key => (true) %>
179
+ <%= t :key, "Create %{input_name_count} groups", :input_name_count => ("<input name=\\"count\\">".html_safe), :i18nliner_inferred_key => (true) %>
180
180
  EXPECTED
181
181
  end
182
182
 
@@ -187,7 +187,7 @@ describe I18nliner::PreProcessors::ErbPreProcessor do
187
187
  <% end %>
188
188
  SOURCE
189
189
  should == <<-EXPECTED
190
- <%= t :key, "© %{year} ACME Corp. All Rights Reserved. Our lawyers > your lawyers", :year => (year), :i18n_inferred_key => (true) %>
190
+ <%= t :key, "© %{year} ACME Corp. All Rights Reserved. Our lawyers > your lawyers", :year => (year), :i18nliner_inferred_key => (true) %>
191
191
  EXPECTED
192
192
  end
193
193
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i18nliner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-10-20 00:00:00.000000000 Z
12
+ date: 2014-10-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport