localization 1.2.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/localization.rb +8 -5
- data/lib/localization/version.rb +1 -1
- data/spec/lib/localization_spec.rb +49 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b54429be21e9c5cf5bb33fd0331997af284d9cd
|
4
|
+
data.tar.gz: c206fda50299a375a6467e2bcfe6822c7c3ad812
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 53b8ec32e2d25501a6f5def2c931b4e9a442e17c4a586cfaebc921ccd4d84bdd54754ae635db2ec4b9c71ba76ce92bd70baba24c6583ff964e429851659dd407
|
7
|
+
data.tar.gz: b8b7ad1bd6284ed65947598b404622901448bc04e2bed39912a3cd87a63847d6c5dc82a78fa27a7473de7a4c388b48cf320c0b7769a1be5a5966fb03a1268a2b
|
data/lib/localization.rb
CHANGED
@@ -12,16 +12,19 @@ class Localization
|
|
12
12
|
@@sources
|
13
13
|
end
|
14
14
|
|
15
|
-
def initialize(tree = nil, assignments = nil)
|
15
|
+
def initialize(tree = nil, assignments = nil, parent = nil)
|
16
16
|
@assignments = assignments || {}
|
17
|
+
@parent = parent
|
17
18
|
@tree = tree || default_tree
|
18
19
|
end
|
19
20
|
|
20
21
|
def method_missing(name, *arguments, &block)
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
case
|
23
|
+
when @tree.respond_to?(:key?) && @tree.key?(name.to_s)
|
24
|
+
Localization.new(@tree[name.to_s], arguments.first, self)
|
25
|
+
when !@parent.nil?
|
26
|
+
@parent.send(name, arguments.first)
|
27
|
+
else "Localized text missing for #{name}"
|
25
28
|
end
|
26
29
|
end
|
27
30
|
|
data/lib/localization/version.rb
CHANGED
@@ -17,6 +17,55 @@ describe Localization do
|
|
17
17
|
# end
|
18
18
|
# end
|
19
19
|
|
20
|
+
# def method_missing(name, *arguments, &block)
|
21
|
+
# case
|
22
|
+
# when @tree.respond_to?(:key?) && @tree.key?(name.to_s)
|
23
|
+
# Localization.new(@tree[name.to_s], @tree, arguments.first)
|
24
|
+
# when @parent.respond_to?(:key?) && @parent.key?(name.to_s)
|
25
|
+
# Localization.new(@parent[name.to_s], @parent, arguments.first)
|
26
|
+
# else "Localized text missing for #{name}"
|
27
|
+
# end
|
28
|
+
# end
|
29
|
+
|
30
|
+
describe "#method_missing" do
|
31
|
+
let(:english) do
|
32
|
+
{
|
33
|
+
"en" => {
|
34
|
+
"name" => "Funworld",
|
35
|
+
"pages" => {
|
36
|
+
"splash" => {
|
37
|
+
"title" => "Welcome to {{world}}!"
|
38
|
+
},
|
39
|
+
"header" => "I love lucy."
|
40
|
+
},
|
41
|
+
"accounts" => {
|
42
|
+
"edit" => {
|
43
|
+
"form_header" => "Edit Your Account"
|
44
|
+
}
|
45
|
+
}
|
46
|
+
}
|
47
|
+
}
|
48
|
+
end
|
49
|
+
let(:localization) { described_class.new(english) }
|
50
|
+
let(:content) { localization.en.pages.splash }
|
51
|
+
|
52
|
+
it "returns rendered content" do
|
53
|
+
expect(content.title(world: "Foo").to_s).to eq("Welcome to Foo!")
|
54
|
+
end
|
55
|
+
|
56
|
+
it "returns content one level up if it can find it" do
|
57
|
+
expect(content.header.to_s).to eq("I love lucy.")
|
58
|
+
end
|
59
|
+
|
60
|
+
it "returns content any level up if it can find it" do
|
61
|
+
expect(content.header.to_s).to eq("Funworld")
|
62
|
+
end
|
63
|
+
|
64
|
+
it "returns unfindable message if it can never find it" do
|
65
|
+
expect(content.woop.to_s).to eq("Localized text missing for woop")
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
20
69
|
# def roots
|
21
70
|
# Localization.sources.map do |root|
|
22
71
|
# { key_from(root) => subtree_from(root) }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: localization
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kurtis Rainbolt-Greene
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-11-
|
11
|
+
date: 2013-11-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mustache
|