i18n_lookup 0.1.0 → 0.2.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.
- data/i18n_lookup.rb +13 -4
- data/i18n_lookup_spec.rb +22 -3
- metadata +2 -2
data/i18n_lookup.rb
CHANGED
@@ -8,18 +8,27 @@ module I18nLookup
|
|
8
8
|
protected
|
9
9
|
|
10
10
|
def lookup(locale, key, scope = [], options = {})
|
11
|
+
@@i18n_fallbacks ||= []
|
12
|
+
@@last_key ||= nil
|
13
|
+
|
11
14
|
result = super(locale, key, scope, options)
|
12
15
|
keys = I18n.normalize_keys(locale, key, scope, options[:separator])
|
13
16
|
|
14
|
-
|
15
|
-
|
17
|
+
if same_key?(keys) && (@@i18n_fallbacks.include?(key) || same_caller?)
|
18
|
+
@@i18n_fallbacks << options[:default]
|
19
|
+
@@i18n_fallbacks << key
|
20
|
+
@@i18n_fallbacks.flatten!
|
21
|
+
else
|
22
|
+
@@last_key ||= keys.last
|
23
|
+
@@i18n_fallbacks = [options[:default], key].flatten
|
24
|
+
|
16
25
|
print_main_key(keys)
|
17
26
|
end
|
18
27
|
|
19
28
|
if result
|
20
29
|
print_keys(keys, 33)
|
21
30
|
print_result(result)
|
22
|
-
|
31
|
+
@@last_key = nil
|
23
32
|
else
|
24
33
|
print_keys(keys, 31)
|
25
34
|
end
|
@@ -40,7 +49,7 @@ module I18nLookup
|
|
40
49
|
end
|
41
50
|
|
42
51
|
def same_key?(keys)
|
43
|
-
|
52
|
+
@@last_key && @@last_key.eql?(keys.last)
|
44
53
|
end
|
45
54
|
|
46
55
|
def print_main_key(keys, color_code = 34)
|
data/i18n_lookup_spec.rb
CHANGED
@@ -22,7 +22,7 @@ describe I18nLookup do
|
|
22
22
|
{:en =>{:attributes => {:my_attribute => 'My Attribute'}}}
|
23
23
|
end
|
24
24
|
|
25
|
-
it 'should
|
25
|
+
it 'should print the keys as group with a result' do
|
26
26
|
expected_result = translations[:en][:attributes][:my_attribute]
|
27
27
|
main_key = [:en, :activemodel, :attributes, :active_model_test, :my_attribute]
|
28
28
|
second_key = [:en, :attributes, :my_attribute]
|
@@ -35,7 +35,7 @@ describe I18nLookup do
|
|
35
35
|
ActiveModelTest.human_attribute_name('my_attribute')
|
36
36
|
end
|
37
37
|
|
38
|
-
it 'should
|
38
|
+
it 'should print the keys as group without a result' do
|
39
39
|
main_key = [:en, :activemodel, :attributes, :active_model_test, :my_attribute_2]
|
40
40
|
second_key = [:en, :attributes, :my_attribute_2]
|
41
41
|
|
@@ -52,7 +52,7 @@ describe I18nLookup do
|
|
52
52
|
{:en => {:test => 'My Test'}}
|
53
53
|
end
|
54
54
|
|
55
|
-
it 'should
|
55
|
+
it 'should print the key with a result' do
|
56
56
|
expected_result = translations[:en][:test]
|
57
57
|
main_key = [:en, :test]
|
58
58
|
|
@@ -62,5 +62,24 @@ describe I18nLookup do
|
|
62
62
|
|
63
63
|
I18n.t :test
|
64
64
|
end
|
65
|
+
|
66
|
+
context 'with a default' do
|
67
|
+
let(:translations) do
|
68
|
+
{:en => {:test2 => {:my_attr => 'My Test'}}}
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'should print the key with a result' do
|
72
|
+
expected_result = translations[:en][:test2][:my_attr]
|
73
|
+
main_key = [:en, :test, :my_attr]
|
74
|
+
second_key = [:en, :test2, :my_attr]
|
75
|
+
|
76
|
+
subject.should_receive(:print_main_key).with(main_key)
|
77
|
+
subject.should_receive(:print_keys).with(main_key, 31)
|
78
|
+
subject.should_receive(:print_keys).with(second_key, 33)
|
79
|
+
subject.should_receive(:print_result).with(expected_result)
|
80
|
+
|
81
|
+
I18n.t :'test.my_attr', :default => :'test2.my_attr'
|
82
|
+
end
|
83
|
+
end
|
65
84
|
end
|
66
85
|
end
|
metadata
CHANGED
@@ -2,14 +2,14 @@
|
|
2
2
|
name: i18n_lookup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.2.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Thomas Metzmacher
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-04-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: i18n
|