i18nliner 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
@@ -8,7 +8,7 @@ module I18nliner
|
|
8
8
|
REQUIRED_PLURALIZATION_KEYS = [:one, :other]
|
9
9
|
|
10
10
|
def normalize_key(key, scope, inferred, i18n_scope)
|
11
|
-
scope.normalize_key(key
|
11
|
+
scope.normalize_key(key, inferred, i18n_scope)
|
12
12
|
end
|
13
13
|
|
14
14
|
def normalize_default(default, translate_options = {}, options = {})
|
@@ -77,8 +77,8 @@ module I18nliner
|
|
77
77
|
# default_hash, options
|
78
78
|
def key_provided?(key_or_default = nil, default_or_options = nil, maybe_options = nil, *others)
|
79
79
|
return false if key_or_default.is_a?(Hash)
|
80
|
-
return true if key_or_default.is_a?(Symbol)
|
81
|
-
raise ArgumentError.new("invalid key_or_default argument. expected String, Symbol or
|
80
|
+
return true if key_or_default.is_a?(Symbol) || key_or_default.nil? || key_or_default.is_a?(Array)
|
81
|
+
raise ArgumentError.new("invalid key_or_default argument. expected String, Symbol, Array, Hash or nil, got #{key_or_default.class}") unless key_or_default.is_a?(String)
|
82
82
|
return true if default_or_options.is_a?(String)
|
83
83
|
return true if maybe_options
|
84
84
|
return true if key_or_default =~ /\A\.?(\w+\.)+\w+\z/
|
@@ -34,11 +34,15 @@ module I18nliner
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def translations
|
37
|
-
return [] unless
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
37
|
+
return [] unless default
|
38
|
+
keys = Array(key)
|
39
|
+
keys.inject([]) do |result, key|
|
40
|
+
if default.is_a?(String)
|
41
|
+
result << [key, default]
|
42
|
+
else
|
43
|
+
result.concat default.map { |dk, dv| ["#{key}.#{dk}", dv] }
|
44
|
+
end
|
45
|
+
end
|
42
46
|
end
|
43
47
|
|
44
48
|
def validate_key
|
@@ -79,6 +83,8 @@ module I18nliner
|
|
79
83
|
def normalize_arguments(args)
|
80
84
|
@key, @options = infer_arguments(args)
|
81
85
|
@default = @options.delete(:default)
|
86
|
+
@default = nil if @default.is_a?(Symbol)
|
87
|
+
@default = @default.detect { |d| d.is_a?(String) } if @default.is_a?(Array)
|
82
88
|
raise InvalidSignatureError.new(@line, args) unless @default.nil? || @default.is_a?(String) || @default.is_a?(Hash)
|
83
89
|
rescue ArgumentError
|
84
90
|
raise InvalidSignatureError.new(@line, args)
|
data/lib/i18nliner/scope.rb
CHANGED
@@ -15,7 +15,13 @@ module I18nliner
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def normalize_key(key, inferred, i18n_scope)
|
18
|
-
|
18
|
+
return key if key.nil?
|
19
|
+
if key.is_a?(Array)
|
20
|
+
return key.map { |k| normalize_key(k, inferred, i18n_scope) }
|
21
|
+
end
|
22
|
+
|
23
|
+
key = key.to_s.dup
|
24
|
+
if allow_relative? && key.sub!(/\A\./, '')
|
19
25
|
scope + key
|
20
26
|
else
|
21
27
|
key
|
@@ -33,6 +33,16 @@ describe I18nliner::Extensions::Core do
|
|
33
33
|
i18n.translate("light", :count => 1)
|
34
34
|
end
|
35
35
|
|
36
|
+
it "should not stringify nil keys" do
|
37
|
+
expect(i18n).to receive(:simple_translate).with(nil, {:default => [:foo, :bar]})
|
38
|
+
i18n.translate(nil, {:default => [:foo, :bar]})
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should stringify array keys, but not the array itself" do
|
42
|
+
expect(i18n).to receive(:simple_translate).with(["bar", "baz"], {})
|
43
|
+
i18n.translate([:bar, :baz])
|
44
|
+
end
|
45
|
+
|
36
46
|
context "with wrappers" do
|
37
47
|
it "should apply a single wrapper" do
|
38
48
|
result = i18n.translate("Hello *bob*.", :wrapper => '<b>\1</b>')
|
@@ -50,6 +50,16 @@ describe I18nliner::Extractors::TranslateCall do
|
|
50
50
|
call.default.should == "foo"
|
51
51
|
end
|
52
52
|
|
53
|
+
it "should not extract symbol defaults" do
|
54
|
+
call = call(no_scope, :key, :default => :bar_key)
|
55
|
+
call.default.should be_nil
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should extract the first string default" do
|
59
|
+
call = call(no_scope, :key, :default => [:foo_key, :bar_key, "baz"])
|
60
|
+
call.default.should == "baz"
|
61
|
+
end
|
62
|
+
|
53
63
|
it "should ensure options is a hash, if provided" do
|
54
64
|
expect {
|
55
65
|
call(no_scope, :key, "value", Object.new)
|
@@ -103,6 +113,7 @@ describe I18nliner::Extractors::TranslateCall do
|
|
103
113
|
describe "normalization" do
|
104
114
|
it "should make keys absolute if scoped" do
|
105
115
|
call(scope, '.key', "value").translations[0][0].should =~ /\Afoo\.key/
|
116
|
+
call(scope, ['.key1', '.key2'], "value").translations.map(&:first).should == ['foo.key1', 'foo.key2']
|
106
117
|
end
|
107
118
|
|
108
119
|
it "should strip whitespace from defaults" do
|
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.
|
4
|
+
version: 0.0.10
|
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-
|
12
|
+
date: 2014-11-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|