snusnu-dm-is-localizable 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +53 -0
- data/VERSION +1 -1
- data/dm-is-localizable.gemspec +1 -1
- data/lib/dm-is-localizable/is/localizable.rb +9 -0
- data/lib/dm-is-localizable/storage/language.rb +6 -0
- data/spec/unit/instance_level_api_spec.rb +55 -0
- data/spec/unit/language_spec.rb +33 -0
- data/spec/unit/translation_spec.rb +19 -8
- metadata +1 -1
data/CHANGELOG
CHANGED
@@ -1,3 +1,56 @@
|
|
1
|
+
[82db7fd | Mon May 18 15:42:50 UTC 2009] snusnu <gamsnjaga@gmail.com>
|
2
|
+
|
3
|
+
* Version bump to 0.0.6
|
4
|
+
|
5
|
+
[016ddd5 | Mon May 18 15:42:28 UTC 2009] snusnu <gamsnjaga@gmail.com>
|
6
|
+
|
7
|
+
* added localizable_instance.translate(attribute, language_code)
|
8
|
+
|
9
|
+
[30e7f81 | Mon May 18 15:39:08 UTC 2009] snusnu <gamsnjaga@gmail.com>
|
10
|
+
|
11
|
+
* added more specs for the remixed translation class.
|
12
|
+
|
13
|
+
Although the specs for the generated belongs_to association readers
|
14
|
+
pass, it's not possible to use :language as query condition when
|
15
|
+
calling translations.first :language => 'en-US'. Need to use
|
16
|
+
:language_id here. I've no idea why, but it could be some problem
|
17
|
+
with dm-is-remixable's enhance method, and association generation
|
18
|
+
inside this block.
|
19
|
+
|
20
|
+
TODO investigate this!
|
21
|
+
|
22
|
+
[1b3ff53 | Mon May 18 15:38:17 UTC 2009] snusnu <gamsnjaga@gmail.com>
|
23
|
+
|
24
|
+
* added Language.[](code) method
|
25
|
+
|
26
|
+
[6465349 | Mon May 18 13:28:26 UTC 2009] snusnu <gamsnjaga@gmail.com>
|
27
|
+
|
28
|
+
* removed rubygems usage from dm-is-localizable
|
29
|
+
|
30
|
+
[ce1d783 | Mon May 18 13:27:58 UTC 2009] snusnu <gamsnjaga@gmail.com>
|
31
|
+
|
32
|
+
* updated gemspec to reflect latest version
|
33
|
+
|
34
|
+
[0749a4b | Sat May 16 19:22:33 UTC 2009] snusnu <gamsnjaga@gmail.com>
|
35
|
+
|
36
|
+
* Version bump to 0.0.5
|
37
|
+
|
38
|
+
[ab0090a | Sat May 16 19:22:19 UTC 2009] snusnu <gamsnjaga@gmail.com>
|
39
|
+
|
40
|
+
* strip whitespace
|
41
|
+
|
42
|
+
[f5de7dd | Sat May 16 19:21:42 UTC 2009] snusnu <gamsnjaga@gmail.com>
|
43
|
+
|
44
|
+
* added whitespace task to gemspec
|
45
|
+
|
46
|
+
[e759d98 | Sat May 16 19:20:27 UTC 2009] snusnu <gamsnjaga@gmail.com>
|
47
|
+
|
48
|
+
* added rake task to strip whitespace (taken from brynary/webrat)
|
49
|
+
|
50
|
+
[2ad8adc | Sat May 16 19:17:42 UTC 2009] snusnu <gamsnjaga@gmail.com>
|
51
|
+
|
52
|
+
* added CHANGELOG and task to generate(update) it
|
53
|
+
|
1
54
|
[e66cccc | Sat May 16 19:02:07 UTC 2009] snusnu <gamsnjaga@gmail.com>
|
2
55
|
|
3
56
|
* Version bump to 0.0.4
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.6
|
data/dm-is-localizable.gemspec
CHANGED
@@ -81,6 +81,15 @@ module DataMapper
|
|
81
81
|
self.class.nr_of_available_languages == translations.size
|
82
82
|
end
|
83
83
|
|
84
|
+
def translate(attribute, language_code)
|
85
|
+
if language = Language[language_code]
|
86
|
+
t = translations.first(:language_id => language.id)
|
87
|
+
t.respond_to?(attribute) ? t.send(attribute) : nil
|
88
|
+
else
|
89
|
+
nil
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
84
93
|
end
|
85
94
|
|
86
95
|
end
|
@@ -153,4 +153,59 @@ describe "instance level API:" do
|
|
153
153
|
|
154
154
|
end
|
155
155
|
|
156
|
+
describe "translate(attribute, language_code)" do
|
157
|
+
|
158
|
+
before :each do
|
159
|
+
@l1 = Language.create :code => 'en-US', :name => 'English'
|
160
|
+
@l2 = Language.create :code => 'de-AT', :name => 'Deutsch'
|
161
|
+
@i1 = Item.create
|
162
|
+
@t1 = ItemTranslation.create :item => @i1, :language => @l1, :name => 'Book', :desc => 'Literature'
|
163
|
+
@t2 = ItemTranslation.create :item => @i1, :language => @l2, :name => 'Buch', :desc => 'Literatur'
|
164
|
+
end
|
165
|
+
|
166
|
+
describe "with an existing attribute" do
|
167
|
+
|
168
|
+
describe "and an existing language_code" do
|
169
|
+
|
170
|
+
it "should return the translated string" do
|
171
|
+
@i1.translate(:name, :en_US).should == 'Book'
|
172
|
+
@i1.translate(:desc, :en_US).should == 'Literature'
|
173
|
+
@i1.translate(:name, :de_AT).should == 'Buch'
|
174
|
+
@i1.translate(:desc, :de_AT).should == 'Literatur'
|
175
|
+
end
|
176
|
+
|
177
|
+
end
|
178
|
+
|
179
|
+
describe "and a non existent language_code" do
|
180
|
+
|
181
|
+
it "should return the translated string" do
|
182
|
+
@i1.translate(:name, :it).should be_nil
|
183
|
+
end
|
184
|
+
|
185
|
+
end
|
186
|
+
|
187
|
+
end
|
188
|
+
|
189
|
+
describe "with a non existent attribute" do
|
190
|
+
|
191
|
+
describe "and an existing language_code" do
|
192
|
+
|
193
|
+
it "should return the translated string" do
|
194
|
+
@i1.translate(:foo, :en_US).should be_nil
|
195
|
+
end
|
196
|
+
|
197
|
+
end
|
198
|
+
|
199
|
+
describe "and a non existent language_code" do
|
200
|
+
|
201
|
+
it "should return the translated string" do
|
202
|
+
@i1.translate(:foo, :it).should be_nil
|
203
|
+
end
|
204
|
+
|
205
|
+
end
|
206
|
+
|
207
|
+
end
|
208
|
+
|
209
|
+
end
|
210
|
+
|
156
211
|
end
|
data/spec/unit/language_spec.rb
CHANGED
@@ -61,4 +61,37 @@ describe "Language" do
|
|
61
61
|
|
62
62
|
end
|
63
63
|
|
64
|
+
describe "the [](value) class method" do
|
65
|
+
|
66
|
+
before :each do
|
67
|
+
Language.create :code => 'en-US', :name => 'English'
|
68
|
+
Language.create :code => 'de-AT', :name => 'Deutsch'
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "with nil as paramter" do
|
72
|
+
|
73
|
+
it "should return nil" do
|
74
|
+
Language[nil].should be_nil
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
describe "with an invalid (not present) language symbol as parameter" do
|
80
|
+
|
81
|
+
it "should return nil" do
|
82
|
+
Language[:it].should be_nil
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "with a valid (present) language symbol as parameter" do
|
88
|
+
|
89
|
+
it "should return the correct language instance" do
|
90
|
+
Language[:en_US].should == Language.first(:code => 'en-US')
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
64
97
|
end
|
@@ -2,15 +2,26 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
2
2
|
|
3
3
|
describe "the remixed translation resource" do
|
4
4
|
|
5
|
+
before :each do
|
6
|
+
@l = Language.create :code => 'en-US', :name => 'English'
|
7
|
+
@i = Item.create
|
8
|
+
@t1 = ItemTranslation.create(:item => @i, :language => @l)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should belong to a localizable resource" do
|
12
|
+
@t1.item.should == @i
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should belong to a language" do
|
16
|
+
@t1.language.should == @l
|
17
|
+
end
|
18
|
+
|
5
19
|
it "should store unique languages for every resource to translate" do
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
t2
|
11
|
-
t2.should be_new_record
|
12
|
-
t2.errors.should_not be_empty
|
13
|
-
t2.errors.size.should == 1
|
20
|
+
@t2 = ItemTranslation.create(:item => @i, :language => @l)
|
21
|
+
@t1.should_not be_new_record
|
22
|
+
@t2.should be_new_record
|
23
|
+
@t2.errors.should_not be_empty
|
24
|
+
@t2.errors.size.should == 1
|
14
25
|
end
|
15
26
|
|
16
27
|
end
|