i18nliner 0.0.5 → 0.0.6
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/lib/i18nliner/base.rb
CHANGED
@@ -4,8 +4,17 @@ module I18nliner
|
|
4
4
|
def inferpolate(options)
|
5
5
|
default = options[:default]
|
6
6
|
return options unless default
|
7
|
+
if default.is_a?(Hash)
|
8
|
+
default.each { |key, value| inferpolate_value!(value, options) }
|
9
|
+
else
|
10
|
+
inferpolate_value!(default, options)
|
11
|
+
end
|
7
12
|
|
8
|
-
|
13
|
+
options
|
14
|
+
end
|
15
|
+
|
16
|
+
def inferpolate_value!(value, options)
|
17
|
+
value.gsub!(/%\{((@)?\w+(.\w+)*)\}/).each do
|
9
18
|
match = $~
|
10
19
|
key = $1
|
11
20
|
ivar = $2
|
@@ -21,7 +30,6 @@ module I18nliner
|
|
21
30
|
options[new_key.to_sym] = value
|
22
31
|
"%{#{new_key}}"
|
23
32
|
end
|
24
|
-
options
|
25
33
|
end
|
26
34
|
end
|
27
35
|
end
|
data/lib/i18nliner.rb
CHANGED
@@ -38,4 +38,12 @@ describe I18nliner::Extensions::Inferpolation do
|
|
38
38
|
options = {:default => "hello %{@lol} %{@bar.baz.lol}"}
|
39
39
|
foo.inferpolate(options).should == options
|
40
40
|
end
|
41
|
+
|
42
|
+
it "should work with pluralization hashes" do
|
43
|
+
options = {:default => {:one => "%{bar2} has 1 item", :other => "%{bar2} has %{count} items"}}
|
44
|
+
foo.inferpolate(options).should == {
|
45
|
+
:default => {:one => "%{bar2} has 1 item", :other => "%{bar2} has %{count} items"},
|
46
|
+
:bar2 => foo.bar2
|
47
|
+
}
|
48
|
+
end
|
41
49
|
end
|