i18n_backend_database 0.0.1

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.
Files changed (67) hide show
  1. data/LICENSE +29 -0
  2. data/README.textile +125 -0
  3. data/data/locales.yml +4 -0
  4. data/generators/i18n_backend_database/i18n_backend_database_generator.rb +8 -0
  5. data/generators/i18n_backend_database/templates/migrate/create_i18n_tables.rb +25 -0
  6. data/init.rb +1 -0
  7. data/lib/controllers/locales_controller.rb +86 -0
  8. data/lib/controllers/translations_controller.rb +141 -0
  9. data/lib/ext/i18n.rb +68 -0
  10. data/lib/google_language.rb +33 -0
  11. data/lib/i18n_backend_database.rb +9 -0
  12. data/lib/i18n_backend_database/database.rb +263 -0
  13. data/lib/i18n_util.rb +148 -0
  14. data/lib/models/locale.rb +67 -0
  15. data/lib/models/translation.rb +46 -0
  16. data/lib/models/translation_option.rb +26 -0
  17. data/lib/public/images/custom1_bar.gif +0 -0
  18. data/lib/public/images/custom1_box.gif +0 -0
  19. data/lib/public/images/percentImage.png +0 -0
  20. data/lib/public/images/percentImage_back.png +0 -0
  21. data/lib/public/images/percentImage_back1.png +0 -0
  22. data/lib/public/images/percentImage_back2.png +0 -0
  23. data/lib/public/images/percentImage_back3.png +0 -0
  24. data/lib/public/images/percentImage_back4.png +0 -0
  25. data/lib/public/javascripts/jsProgressBarHandler.js +509 -0
  26. data/lib/routing.rb +15 -0
  27. data/lib/views/layouts/translations.html.erb +23 -0
  28. data/lib/views/locales/edit.html.erb +20 -0
  29. data/lib/views/locales/index.html.erb +22 -0
  30. data/lib/views/locales/new.html.erb +19 -0
  31. data/lib/views/locales/show.html.erb +14 -0
  32. data/lib/views/translations/asset_translations.html.erb +32 -0
  33. data/lib/views/translations/edit.html.erb +35 -0
  34. data/lib/views/translations/index.html.erb +27 -0
  35. data/lib/views/translations/new.html.erb +19 -0
  36. data/lib/views/translations/show.html.erb +32 -0
  37. data/lib/views/translations/translations.html.erb +28 -0
  38. data/lib/views/translations/update.rjs +7 -0
  39. data/routes.rb +3 -0
  40. data/spec/assets/public/es/favicons/favicon1.gif +0 -0
  41. data/spec/assets/public/es/images/icons/icon1.gif +0 -0
  42. data/spec/assets/public/es/images/image1.gif +0 -0
  43. data/spec/assets/public/favicons/favicon1.gif +0 -0
  44. data/spec/assets/public/favicons/favicon2.gif +0 -0
  45. data/spec/assets/public/images/icons/icon1.gif +0 -0
  46. data/spec/assets/public/images/icons/icon2.gif +0 -0
  47. data/spec/assets/public/images/image1.gif +0 -0
  48. data/spec/assets/public/images/image2.gif +0 -0
  49. data/spec/assets/public/images/promo/sfc08_140x400_3.gif +0 -0
  50. data/spec/assets/views/test_view1.html.erb +1 -0
  51. data/spec/assets/views/test_view2.html.erb +30 -0
  52. data/spec/caching_spec.rb +87 -0
  53. data/spec/controllers/locales_controller_spec.rb +173 -0
  54. data/spec/controllers/locales_routing_spec.rb +59 -0
  55. data/spec/controllers/translations_controller_spec.rb +189 -0
  56. data/spec/controllers/translations_routing_spec.rb +59 -0
  57. data/spec/database_spec.rb +199 -0
  58. data/spec/i18n_ext_spec.rb +40 -0
  59. data/spec/localize_spec.rb +66 -0
  60. data/spec/localize_text_spec.rb +76 -0
  61. data/spec/models/locale_spec.rb +111 -0
  62. data/spec/models/translation_spec.rb +44 -0
  63. data/spec/spec_helper.rb +16 -0
  64. data/spec/translate_asset_spec.rb +57 -0
  65. data/spec/translate_spec.rb +546 -0
  66. data/tasks/i18n.rake +60 -0
  67. metadata +155 -0
@@ -0,0 +1,173 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe LocalesController do
4
+
5
+ def mock_locale(stubs={})
6
+ @mock_locale ||= mock_model(Locale, stubs)
7
+ end
8
+
9
+ describe "responding to GET index" do
10
+
11
+ it "should expose all locales as @locales" do
12
+ Locale.should_receive(:find).with(:all).and_return([mock_locale])
13
+ get :index
14
+ assigns[:locales].should == [mock_locale]
15
+ end
16
+
17
+ describe "with mime type of xml" do
18
+
19
+ it "should render all locales as xml" do
20
+ request.env["HTTP_ACCEPT"] = "application/xml"
21
+ Locale.should_receive(:find).with(:all).and_return(locales = mock("Array of Locales"))
22
+ locales.should_receive(:to_xml).and_return("generated XML")
23
+ get :index
24
+ response.body.should == "generated XML"
25
+ end
26
+
27
+ end
28
+
29
+ end
30
+
31
+ describe "responding to GET show" do
32
+
33
+ it "should expose the requested locale as @locale" do
34
+ Locale.should_receive(:find_by_code).with("en").and_return(mock_locale)
35
+ get :show, :id => "en"
36
+ assigns[:locale].should equal(mock_locale)
37
+ end
38
+
39
+ describe "with mime type of xml" do
40
+
41
+ it "should render the requested locale as xml" do
42
+ request.env["HTTP_ACCEPT"] = "application/xml"
43
+ Locale.should_receive(:find_by_code).with("en").and_return(mock_locale)
44
+ mock_locale.should_receive(:to_xml).and_return("generated XML")
45
+ get :show, :id => "en"
46
+ response.body.should == "generated XML"
47
+ end
48
+
49
+ end
50
+
51
+ end
52
+
53
+ describe "responding to GET new" do
54
+
55
+ it "should expose a new locale as @locale" do
56
+ Locale.should_receive(:new).and_return(mock_locale)
57
+ get :new
58
+ assigns[:locale].should equal(mock_locale)
59
+ end
60
+
61
+ end
62
+
63
+ describe "responding to GET edit" do
64
+
65
+ it "should expose the requested locale as @locale" do
66
+ Locale.should_receive(:find_by_code).with("en").and_return(mock_locale)
67
+ get :edit, :id => "en"
68
+ assigns[:locale].should equal(mock_locale)
69
+ end
70
+
71
+ end
72
+
73
+ describe "responding to POST create" do
74
+
75
+ describe "with valid params" do
76
+
77
+ it "should expose a newly created locale as @locale" do
78
+ Locale.should_receive(:new).with({'these' => 'params'}).and_return(mock_locale(:save => true))
79
+ post :create, :locale => {:these => 'params'}
80
+ assigns(:locale).should equal(mock_locale)
81
+ end
82
+
83
+ it "should redirect to the created locale" do
84
+ Locale.stub!(:new).and_return(mock_locale(:save => true))
85
+ post :create, :locale => {}
86
+ response.should redirect_to(locale_url(mock_locale))
87
+ end
88
+
89
+ end
90
+
91
+ describe "with invalid params" do
92
+
93
+ it "should expose a newly created but unsaved locale as @locale" do
94
+ Locale.stub!(:new).with({'these' => 'params'}).and_return(mock_locale(:save => false))
95
+ post :create, :locale => {:these => 'params'}
96
+ assigns(:locale).should equal(mock_locale)
97
+ end
98
+
99
+ it "should re-render the 'new' template" do
100
+ Locale.stub!(:new).and_return(mock_locale(:save => false))
101
+ post :create, :locale => {}
102
+ response.should render_template('new')
103
+ end
104
+
105
+ end
106
+
107
+ end
108
+
109
+ describe "responding to PUT udpate" do
110
+
111
+ describe "with valid params" do
112
+
113
+ it "should update the requested locale" do
114
+ Locale.should_receive(:find_by_code).with("en").and_return(mock_locale)
115
+ mock_locale.should_receive(:update_attributes).with({'these' => 'params'})
116
+ put :update, :id => "en", :locale => {:these => 'params'}
117
+ end
118
+
119
+ it "should expose the requested locale as @locale" do
120
+ Locale.stub!(:find_by_code).and_return(mock_locale(:update_attributes => true))
121
+ put :update, :id => "en"
122
+ assigns(:locale).should equal(mock_locale)
123
+ end
124
+
125
+ it "should redirect to the locale" do
126
+ Locale.stub!(:find).and_return(mock_locale(:update_attributes => true))
127
+ put :update, :id => "1"
128
+ response.should redirect_to(locale_url(mock_locale))
129
+ end
130
+
131
+ end
132
+
133
+ describe "with invalid params" do
134
+
135
+ it "should update the requested locale" do
136
+ Locale.should_receive(:find_by_code).with("en").and_return(mock_locale)
137
+ mock_locale.should_receive(:update_attributes).with({'these' => 'params'})
138
+ put :update, :id => "en", :locale => {:these => 'params'}
139
+ end
140
+
141
+ it "should expose the locale as @locale" do
142
+ Locale.stub!(:find_by_code).and_return(mock_locale(:update_attributes => false))
143
+ put :update, :id => "en"
144
+ assigns(:locale).should equal(mock_locale)
145
+ end
146
+
147
+ it "should re-render the 'edit' template" do
148
+ Locale.stub!(:find_by_code).and_return(mock_locale(:update_attributes => false))
149
+ put :update, :id => "en"
150
+ response.should render_template('edit')
151
+ end
152
+
153
+ end
154
+
155
+ end
156
+
157
+ describe "responding to DELETE destroy" do
158
+
159
+ it "should destroy the requested locale" do
160
+ Locale.should_receive(:find_by_code).with("en").and_return(mock_locale)
161
+ mock_locale.should_receive(:destroy)
162
+ delete :destroy, :id => "en"
163
+ end
164
+
165
+ it "should redirect to the locales list" do
166
+ Locale.stub!(:find_by_code).and_return(mock_locale(:destroy => true))
167
+ delete :destroy, :id => "en"
168
+ response.should redirect_to(locales_url)
169
+ end
170
+
171
+ end
172
+
173
+ end
@@ -0,0 +1,59 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe LocalesController do
4
+ describe "route generation" do
5
+ it "should map #index" do
6
+ route_for(:controller => "locales", :action => "index").should == "/locales"
7
+ end
8
+
9
+ it "should map #new" do
10
+ route_for(:controller => "locales", :action => "new").should == "/locales/new"
11
+ end
12
+
13
+ it "should map #show" do
14
+ route_for(:controller => "locales", :action => "show", :id => "1").should == "/locales/1"
15
+ end
16
+
17
+ it "should map #edit" do
18
+ route_for(:controller => "locales", :action => "edit", :id => "1").should == "/locales/1/edit"
19
+ end
20
+
21
+ it "should map #update" do
22
+ route_for(:controller => "locales", :action => "update", :id => "1").should == {:path => "/locales/1", :method => :put}
23
+ end
24
+
25
+ it "should map #destroy" do
26
+ route_for(:controller => "locales", :action => "destroy", :id => "1").should == {:path => "/locales/1", :method => :delete}
27
+ end
28
+ end
29
+
30
+ describe "route recognition" do
31
+ it "should generate params for #index" do
32
+ params_from(:get, "/locales").should == {:controller => "locales", :action => "index"}
33
+ end
34
+
35
+ it "should generate params for #new" do
36
+ params_from(:get, "/locales/new").should == {:controller => "locales", :action => "new"}
37
+ end
38
+
39
+ it "should generate params for #create" do
40
+ params_from(:post, "/locales").should == {:controller => "locales", :action => "create"}
41
+ end
42
+
43
+ it "should generate params for #show" do
44
+ params_from(:get, "/locales/1").should == {:controller => "locales", :action => "show", :id => "1"}
45
+ end
46
+
47
+ it "should generate params for #edit" do
48
+ params_from(:get, "/locales/1/edit").should == {:controller => "locales", :action => "edit", :id => "1"}
49
+ end
50
+
51
+ it "should generate params for #update" do
52
+ params_from(:put, "/locales/1").should == {:controller => "locales", :action => "update", :id => "1"}
53
+ end
54
+
55
+ it "should generate params for #destroy" do
56
+ params_from(:delete, "/locales/1").should == {:controller => "locales", :action => "destroy", :id => "1"}
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,189 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe TranslationsController do
4
+
5
+ def mock_locale(stubs={})
6
+ stubs = {
7
+ :translations => mock("Array of Translations"),
8
+ :to_param => 'en'
9
+ }.merge(stubs)
10
+
11
+ @mock_locale ||= mock_model(Locale, stubs)
12
+ end
13
+
14
+ def mock_translation(stubs={})
15
+ stubs = {
16
+ :value => nil
17
+ }.merge(stubs)
18
+ @mock_translation ||= mock_model(Translation, stubs)
19
+ end
20
+
21
+ before(:each) do
22
+ Locale.should_receive(:find_by_code).with('en').and_return(mock_locale)
23
+ end
24
+
25
+ describe "responding to GET index" do
26
+
27
+ it "should expose all translations as @translations" do
28
+ mock_locale.translations.should_receive(:find).with(:all, {:order=>"raw_key, pluralization_index"}).and_return([mock_translation])
29
+ get :index, :locale_id => "en"
30
+ assigns[:translations].should == [mock_translation]
31
+ end
32
+
33
+ describe "with mime type of xml" do
34
+
35
+ it "should render all translations as xml" do
36
+ request.env["HTTP_ACCEPT"] = "application/xml"
37
+ mock_locale.translations.should_receive(:find).with(:all, {:order=>"raw_key, pluralization_index"}).and_return(translations = mock("Array of Translations"))
38
+ translations.should_receive(:to_xml).and_return("generated XML")
39
+ get :index, :locale_id => "en"
40
+ response.body.should == "generated XML"
41
+ end
42
+
43
+ end
44
+
45
+ end
46
+
47
+ describe "responding to GET show" do
48
+
49
+ it "should expose the requested translation as @translation" do
50
+ mock_locale.translations.should_receive(:find).with("37").and_return(mock_translation)
51
+ get :show, :locale_id => "en", :id => "37"
52
+ assigns[:translation].should equal(mock_translation)
53
+ end
54
+
55
+ describe "with mime type of xml" do
56
+
57
+ it "should render the requested translation as xml" do
58
+ request.env["HTTP_ACCEPT"] = "application/xml"
59
+ mock_locale.translations.should_receive(:find).with("37").and_return(mock_translation)
60
+ mock_translation.should_receive(:to_xml).and_return("generated XML")
61
+ get :show, :locale_id => "en", :id => "37"
62
+ response.body.should == "generated XML"
63
+ end
64
+
65
+ end
66
+
67
+ end
68
+
69
+ describe "responding to GET new" do
70
+
71
+ it "should expose a new translation as @translation" do
72
+ Translation.should_receive(:new).and_return(mock_translation)
73
+ get :new, :locale_id => "en"
74
+ assigns[:translation].should equal(mock_translation)
75
+ end
76
+
77
+ end
78
+
79
+ describe "responding to GET edit" do
80
+
81
+ it "should expose the requested translation as @translation" do
82
+ mock_locale.translations.should_receive(:find).with("37").and_return(mock_translation)
83
+ get :edit, :locale_id => "en", :id => "37"
84
+ assigns[:translation].should equal(mock_translation)
85
+ end
86
+
87
+ end
88
+
89
+ describe "responding to POST create" do
90
+
91
+ describe "with valid params" do
92
+
93
+ it "should expose a newly created translation as @translation" do
94
+ mock_locale.translations.should_receive(:build).with({'these' => 'params'}).and_return(mock_translation(:save => true))
95
+ post :create, :locale_id => "en", :translation => {:these => 'params'}
96
+ assigns(:translation).should equal(mock_translation)
97
+ end
98
+
99
+ it "should redirect to the created translation" do
100
+ mock_locale.translations.stub!(:build).and_return(mock_translation(:save => true))
101
+ post :create, :locale_id => "en", :translation => {}
102
+ response.should redirect_to(locale_translation_url(mock_locale, mock_translation))
103
+ end
104
+
105
+ end
106
+
107
+ describe "with invalid params" do
108
+
109
+ it "should expose a newly created but unsaved translation as @translation" do
110
+ mock_locale.translations.stub!(:build).with({'these' => 'params'}).and_return(mock_translation(:save => false))
111
+ post :create, :locale_id => "en", :translation => {:these => 'params'}
112
+ assigns(:translation).should equal(mock_translation)
113
+ end
114
+
115
+ it "should re-render the 'new' template" do
116
+ mock_locale.translations.stub!(:build).and_return(mock_translation(:save => false))
117
+ post :create, :locale_id => "en", :translation => {}
118
+ response.should render_template('new')
119
+ end
120
+
121
+ end
122
+
123
+ end
124
+
125
+ describe "responding to PUT udpate" do
126
+
127
+ describe "with valid params" do
128
+
129
+ it "should update the requested translation" do
130
+ mock_locale.translations.should_receive(:find).with("37").and_return(mock_translation)
131
+ mock_translation.should_receive(:update_attributes).with({'these' => 'params'})
132
+ put :update, :locale_id => "en", :id => "37", :translation => {:these => 'params'}
133
+ end
134
+
135
+ it "should expose the requested translation as @translation" do
136
+ mock_locale.translations.stub!(:find).and_return(mock_translation(:update_attributes => true))
137
+ put :update, :locale_id => "en", :id => "1"
138
+ assigns(:translation).should equal(mock_translation)
139
+ end
140
+
141
+ it "should redirect to the translation" do
142
+ mock_locale.translations.stub!(:find).and_return(mock_translation(:update_attributes => true))
143
+ put :update, :locale_id => "en", :id => "1"
144
+ response.should redirect_to(locale_translation_url(mock_locale, mock_translation))
145
+ end
146
+
147
+ end
148
+
149
+ describe "with invalid params" do
150
+
151
+ it "should update the requested translation" do
152
+ mock_locale.translations.should_receive(:find).with("37").and_return(mock_translation)
153
+ mock_translation.should_receive(:update_attributes).with({'these' => 'params'})
154
+ put :update, :locale_id => "en", :id => "37", :translation => {:these => 'params'}
155
+ end
156
+
157
+ it "should expose the translation as @translation" do
158
+ mock_locale.translations.stub!(:find).and_return(mock_translation(:update_attributes => false))
159
+ put :update, :locale_id => "en", :id => "1"
160
+ assigns(:translation).should equal(mock_translation)
161
+ end
162
+
163
+ it "should re-render the 'edit' template" do
164
+ mock_locale.translations.stub!(:find).and_return(mock_translation(:update_attributes => false))
165
+ put :update, :locale_id => "en", :id => "1"
166
+ response.should render_template('edit')
167
+ end
168
+
169
+ end
170
+
171
+ end
172
+
173
+ describe "responding to DELETE destroy" do
174
+
175
+ it "should destroy the requested translation" do
176
+ mock_locale.translations.should_receive(:find).with("37").and_return(mock_translation)
177
+ mock_translation.should_receive(:destroy)
178
+ delete :destroy, :locale_id => "en", :id => "37"
179
+ end
180
+
181
+ it "should redirect to the translations list" do
182
+ mock_locale.translations.stub!(:find).and_return(mock_translation(:destroy => true))
183
+ delete :destroy, :locale_id => "en", :id => "1"
184
+ response.should redirect_to(locale_translations_url(mock_locale))
185
+ end
186
+
187
+ end
188
+
189
+ end
@@ -0,0 +1,59 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe TranslationsController do
4
+ describe "route generation" do
5
+ it "should map #index" do
6
+ route_for(:controller => "translations", :action => "index", :locale_id => "en").should == "/locales/en/translations"
7
+ end
8
+
9
+ it "should map #new" do
10
+ route_for(:controller => "translations", :action => "new", :locale_id => "en").should == "/locales/en/translations/new"
11
+ end
12
+
13
+ it "should map #show" do
14
+ route_for(:controller => "translations", :action => "show", :id => "1", :locale_id => "en").should == "/locales/en/translations/1"
15
+ end
16
+
17
+ it "should map #edit" do
18
+ route_for(:controller => "translations", :action => "edit", :id => "1", :locale_id => "en").should == "/locales/en/translations/1/edit"
19
+ end
20
+
21
+ it "should map #update" do
22
+ route_for(:controller => "translations", :action => "update", :id => "1", :locale_id => "en").should == {:path => "/locales/en/translations/1", :method => :put}
23
+ end
24
+
25
+ it "should map #destroy" do
26
+ route_for(:controller => "translations", :action => "destroy", :id => "1", :locale_id => "en").should == {:path => "/locales/en/translations/1", :method => :delete}
27
+ end
28
+ end
29
+
30
+ describe "route recognition" do
31
+ it "should generate params for #index" do
32
+ params_from(:get, "/locales/en/translations").should == {:controller => "translations", :action => "index", :locale_id => "en"}
33
+ end
34
+
35
+ it "should generate params for #new" do
36
+ params_from(:get, "/locales/en/translations/new").should == {:controller => "translations", :action => "new", :locale_id => "en"}
37
+ end
38
+
39
+ it "should generate params for #create" do
40
+ params_from(:post, "/locales/en/translations").should == {:controller => "translations", :action => "create", :locale_id => "en"}
41
+ end
42
+
43
+ it "should generate params for #show" do
44
+ params_from(:get, "/locales/en/translations/1").should == {:controller => "translations", :action => "show", :id => "1", :locale_id => "en"}
45
+ end
46
+
47
+ it "should generate params for #edit" do
48
+ params_from(:get, "/locales/en/translations/1/edit").should == {:controller => "translations", :action => "edit", :id => "1", :locale_id => "en"}
49
+ end
50
+
51
+ it "should generate params for #update" do
52
+ params_from(:put, "/locales/en/translations/1").should == {:controller => "translations", :action => "update", :id => "1", :locale_id => "en"}
53
+ end
54
+
55
+ it "should generate params for #destroy" do
56
+ params_from(:delete, "/locales/en/translations/1").should == {:controller => "translations", :action => "destroy", :id => "1", :locale_id => "en"}
57
+ end
58
+ end
59
+ end