radiant-globalize2-extension 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +136 -0
- data/app/views/admin/shared/_change_locale.html.haml +22 -0
- data/app/views/admin/shared/_change_locale_admin.html.haml +7 -0
- data/app/views/admin/shared/_globalize_td.html.haml +4 -0
- data/app/views/admin/shared/_globalize_th.html.haml +2 -0
- data/config/routes.rb +4 -0
- data/cucumber.yml +1 -0
- data/db/migrate/20090728084238_create_translation_tables.rb +23 -0
- data/db/migrate/20090728114627_populate_translations.rb +21 -0
- data/db/migrate/20090729085422_remove_translated_attributes.rb +16 -0
- data/features/globalize_layouts.feature +19 -0
- data/features/globalize_pages.feature +58 -0
- data/features/globalize_snippets.feature +19 -0
- data/features/step_definitions/admin_steps.rb +58 -0
- data/features/step_definitions/webrat_steps.rb +119 -0
- data/features/support/env.rb +30 -0
- data/features/support/paths.rb +26 -0
- data/globalize2_extension.rb +93 -0
- data/lib/globalize2/compatibility/archive/archive_page_extensions.rb +21 -0
- data/lib/globalize2/compatibility/copy_move/copy_move_model_extensions.rb +22 -0
- data/lib/globalize2/compatibility/paginate/globalize_tags.rb +19 -0
- data/lib/globalize2/compatibility/paginate/page_extensions.rb +9 -0
- data/lib/globalize2/compatibility/vhost/page_extensions.rb +9 -0
- data/lib/globalize2/form_builder_extensions.rb +21 -0
- data/lib/globalize2/globalize_tags.rb +203 -0
- data/lib/globalize2/globalized_fields_controller_extension.rb +22 -0
- data/lib/globalize2/page_extensions.rb +88 -0
- data/lib/globalize2/page_part_extensions.rb +21 -0
- data/lib/globalize2/pages_controller_extensions.rb +9 -0
- data/lib/globalize2/site_controller_extensions.rb +24 -0
- data/lib/tasks/globalize2_extension_tasks.rake +28 -0
- data/public/images/admin/ad.gif +0 -0
- data/public/images/admin/ae.gif +0 -0
- data/public/images/admin/af.gif +0 -0
- data/public/images/admin/ag.gif +0 -0
- data/public/images/admin/ai.gif +0 -0
- data/public/images/admin/al.gif +0 -0
- data/public/images/admin/am.gif +0 -0
- data/public/images/admin/an.gif +0 -0
- data/public/images/admin/ao.gif +0 -0
- data/public/images/admin/ar.gif +0 -0
- data/public/images/admin/as.gif +0 -0
- data/public/images/admin/at.gif +0 -0
- data/public/images/admin/au.gif +0 -0
- data/public/images/admin/aw.gif +0 -0
- data/public/images/admin/ax.gif +0 -0
- data/public/images/admin/az.gif +0 -0
- data/public/images/admin/ba.gif +0 -0
- data/public/images/admin/bb.gif +0 -0
- data/public/images/admin/bd.gif +0 -0
- data/public/images/admin/be.gif +0 -0
- data/public/images/admin/bf.gif +0 -0
- data/public/images/admin/bg.gif +0 -0
- data/public/images/admin/bh.gif +0 -0
- data/public/images/admin/bi.gif +0 -0
- data/public/images/admin/bj.gif +0 -0
- data/public/images/admin/bm.gif +0 -0
- data/public/images/admin/bn.gif +0 -0
- data/public/images/admin/bo.gif +0 -0
- data/public/images/admin/br.gif +0 -0
- data/public/images/admin/bs.gif +0 -0
- data/public/images/admin/bt.gif +0 -0
- data/public/images/admin/bv.gif +0 -0
- data/public/images/admin/bw.gif +0 -0
- data/public/images/admin/by.gif +0 -0
- data/public/images/admin/bz.gif +0 -0
- data/public/images/admin/ca.gif +0 -0
- data/public/images/admin/catalonia.gif +0 -0
- data/public/images/admin/cc.gif +0 -0
- data/public/images/admin/cd.gif +0 -0
- data/public/images/admin/cf.gif +0 -0
- data/public/images/admin/cg.gif +0 -0
- data/public/images/admin/ch.gif +0 -0
- data/public/images/admin/ci.gif +0 -0
- data/public/images/admin/ck.gif +0 -0
- data/public/images/admin/cl.gif +0 -0
- data/public/images/admin/cm.gif +0 -0
- data/public/images/admin/cn.gif +0 -0
- data/public/images/admin/co.gif +0 -0
- data/public/images/admin/cr.gif +0 -0
- data/public/images/admin/cs.gif +0 -0
- data/public/images/admin/cu.gif +0 -0
- data/public/images/admin/cv.gif +0 -0
- data/public/images/admin/cx.gif +0 -0
- data/public/images/admin/cy.gif +0 -0
- data/public/images/admin/cz.gif +0 -0
- data/public/images/admin/de.gif +0 -0
- data/public/images/admin/dj.gif +0 -0
- data/public/images/admin/dk.gif +0 -0
- data/public/images/admin/dm.gif +0 -0
- data/public/images/admin/do.gif +0 -0
- data/public/images/admin/dz.gif +0 -0
- data/public/images/admin/ec.gif +0 -0
- data/public/images/admin/ee.gif +0 -0
- data/public/images/admin/eg.gif +0 -0
- data/public/images/admin/eh.gif +0 -0
- data/public/images/admin/en.gif +0 -0
- data/public/images/admin/england.gif +0 -0
- data/public/images/admin/er.gif +0 -0
- data/public/images/admin/es.gif +0 -0
- data/public/images/admin/et.gif +0 -0
- data/public/images/admin/europeanunion.gif +0 -0
- data/public/images/admin/fam.gif +0 -0
- data/public/images/admin/fi.gif +0 -0
- data/public/images/admin/fj.gif +0 -0
- data/public/images/admin/fk.gif +0 -0
- data/public/images/admin/fm.gif +0 -0
- data/public/images/admin/fo.gif +0 -0
- data/public/images/admin/fr.gif +0 -0
- data/public/images/admin/ga.gif +0 -0
- data/public/images/admin/gb.gif +0 -0
- data/public/images/admin/gd.gif +0 -0
- data/public/images/admin/ge.gif +0 -0
- data/public/images/admin/gf.gif +0 -0
- data/public/images/admin/gh.gif +0 -0
- data/public/images/admin/gi.gif +0 -0
- data/public/images/admin/gl.gif +0 -0
- data/public/images/admin/gm.gif +0 -0
- data/public/images/admin/gn.gif +0 -0
- data/public/images/admin/gp.gif +0 -0
- data/public/images/admin/gq.gif +0 -0
- data/public/images/admin/gr.gif +0 -0
- data/public/images/admin/gs.gif +0 -0
- data/public/images/admin/gt.gif +0 -0
- data/public/images/admin/gu.gif +0 -0
- data/public/images/admin/gw.gif +0 -0
- data/public/images/admin/gy.gif +0 -0
- data/public/images/admin/hk.gif +0 -0
- data/public/images/admin/hm.gif +0 -0
- data/public/images/admin/hn.gif +0 -0
- data/public/images/admin/hr.gif +0 -0
- data/public/images/admin/ht.gif +0 -0
- data/public/images/admin/hu.gif +0 -0
- data/public/images/admin/id.gif +0 -0
- data/public/images/admin/ie.gif +0 -0
- data/public/images/admin/il.gif +0 -0
- data/public/images/admin/in.gif +0 -0
- data/public/images/admin/io.gif +0 -0
- data/public/images/admin/iq.gif +0 -0
- data/public/images/admin/ir.gif +0 -0
- data/public/images/admin/is.gif +0 -0
- data/public/images/admin/it.gif +0 -0
- data/public/images/admin/jm.gif +0 -0
- data/public/images/admin/jo.gif +0 -0
- data/public/images/admin/jp.gif +0 -0
- data/public/images/admin/ke.gif +0 -0
- data/public/images/admin/kg.gif +0 -0
- data/public/images/admin/kh.gif +0 -0
- data/public/images/admin/ki.gif +0 -0
- data/public/images/admin/km.gif +0 -0
- data/public/images/admin/kn.gif +0 -0
- data/public/images/admin/kp.gif +0 -0
- data/public/images/admin/kr.gif +0 -0
- data/public/images/admin/kw.gif +0 -0
- data/public/images/admin/ky.gif +0 -0
- data/public/images/admin/kz.gif +0 -0
- data/public/images/admin/la.gif +0 -0
- data/public/images/admin/lb.gif +0 -0
- data/public/images/admin/lc.gif +0 -0
- data/public/images/admin/li.gif +0 -0
- data/public/images/admin/lk.gif +0 -0
- data/public/images/admin/lr.gif +0 -0
- data/public/images/admin/ls.gif +0 -0
- data/public/images/admin/lt.gif +0 -0
- data/public/images/admin/lu.gif +0 -0
- data/public/images/admin/lv.gif +0 -0
- data/public/images/admin/ly.gif +0 -0
- data/public/images/admin/ma.gif +0 -0
- data/public/images/admin/mc.gif +0 -0
- data/public/images/admin/md.gif +0 -0
- data/public/images/admin/me.gif +0 -0
- data/public/images/admin/mg.gif +0 -0
- data/public/images/admin/mh.gif +0 -0
- data/public/images/admin/mk.gif +0 -0
- data/public/images/admin/ml.gif +0 -0
- data/public/images/admin/mm.gif +0 -0
- data/public/images/admin/mn.gif +0 -0
- data/public/images/admin/mo.gif +0 -0
- data/public/images/admin/mp.gif +0 -0
- data/public/images/admin/mq.gif +0 -0
- data/public/images/admin/mr.gif +0 -0
- data/public/images/admin/ms.gif +0 -0
- data/public/images/admin/mt.gif +0 -0
- data/public/images/admin/mu.gif +0 -0
- data/public/images/admin/mv.gif +0 -0
- data/public/images/admin/mw.gif +0 -0
- data/public/images/admin/mx.gif +0 -0
- data/public/images/admin/my.gif +0 -0
- data/public/images/admin/mz.gif +0 -0
- data/public/images/admin/na.gif +0 -0
- data/public/images/admin/nc.gif +0 -0
- data/public/images/admin/ne.gif +0 -0
- data/public/images/admin/nf.gif +0 -0
- data/public/images/admin/ng.gif +0 -0
- data/public/images/admin/ni.gif +0 -0
- data/public/images/admin/nl.gif +0 -0
- data/public/images/admin/no.gif +0 -0
- data/public/images/admin/np.gif +0 -0
- data/public/images/admin/nr.gif +0 -0
- data/public/images/admin/nu.gif +0 -0
- data/public/images/admin/nz.gif +0 -0
- data/public/images/admin/om.gif +0 -0
- data/public/images/admin/pa.gif +0 -0
- data/public/images/admin/pe.gif +0 -0
- data/public/images/admin/pf.gif +0 -0
- data/public/images/admin/pg.gif +0 -0
- data/public/images/admin/ph.gif +0 -0
- data/public/images/admin/pk.gif +0 -0
- data/public/images/admin/pl.gif +0 -0
- data/public/images/admin/pm.gif +0 -0
- data/public/images/admin/pn.gif +0 -0
- data/public/images/admin/pr.gif +0 -0
- data/public/images/admin/ps.gif +0 -0
- data/public/images/admin/pt.gif +0 -0
- data/public/images/admin/pw.gif +0 -0
- data/public/images/admin/py.gif +0 -0
- data/public/images/admin/qa.gif +0 -0
- data/public/images/admin/re.gif +0 -0
- data/public/images/admin/ro.gif +0 -0
- data/public/images/admin/rs.gif +0 -0
- data/public/images/admin/ru.gif +0 -0
- data/public/images/admin/rw.gif +0 -0
- data/public/images/admin/sa.gif +0 -0
- data/public/images/admin/sb.gif +0 -0
- data/public/images/admin/sc.gif +0 -0
- data/public/images/admin/scotland.gif +0 -0
- data/public/images/admin/sd.gif +0 -0
- data/public/images/admin/se.gif +0 -0
- data/public/images/admin/sg.gif +0 -0
- data/public/images/admin/sh.gif +0 -0
- data/public/images/admin/si.gif +0 -0
- data/public/images/admin/sj.gif +0 -0
- data/public/images/admin/sk.gif +0 -0
- data/public/images/admin/sl.gif +0 -0
- data/public/images/admin/sm.gif +0 -0
- data/public/images/admin/sn.gif +0 -0
- data/public/images/admin/so.gif +0 -0
- data/public/images/admin/sr.gif +0 -0
- data/public/images/admin/st.gif +0 -0
- data/public/images/admin/sv.gif +0 -0
- data/public/images/admin/sy.gif +0 -0
- data/public/images/admin/sz.gif +0 -0
- data/public/images/admin/tc.gif +0 -0
- data/public/images/admin/td.gif +0 -0
- data/public/images/admin/tf.gif +0 -0
- data/public/images/admin/tg.gif +0 -0
- data/public/images/admin/th.gif +0 -0
- data/public/images/admin/tj.gif +0 -0
- data/public/images/admin/tk.gif +0 -0
- data/public/images/admin/tl.gif +0 -0
- data/public/images/admin/tm.gif +0 -0
- data/public/images/admin/tn.gif +0 -0
- data/public/images/admin/to.gif +0 -0
- data/public/images/admin/tr.gif +0 -0
- data/public/images/admin/tt.gif +0 -0
- data/public/images/admin/tv.gif +0 -0
- data/public/images/admin/tw.gif +0 -0
- data/public/images/admin/tz.gif +0 -0
- data/public/images/admin/ua.gif +0 -0
- data/public/images/admin/ug.gif +0 -0
- data/public/images/admin/um.gif +0 -0
- data/public/images/admin/us.gif +0 -0
- data/public/images/admin/uy.gif +0 -0
- data/public/images/admin/uz.gif +0 -0
- data/public/images/admin/va.gif +0 -0
- data/public/images/admin/vc.gif +0 -0
- data/public/images/admin/ve.gif +0 -0
- data/public/images/admin/vg.gif +0 -0
- data/public/images/admin/vi.gif +0 -0
- data/public/images/admin/vn.gif +0 -0
- data/public/images/admin/vu.gif +0 -0
- data/public/images/admin/wales.gif +0 -0
- data/public/images/admin/wf.gif +0 -0
- data/public/images/admin/ws.gif +0 -0
- data/public/images/admin/ye.gif +0 -0
- data/public/images/admin/yt.gif +0 -0
- data/public/images/admin/za.gif +0 -0
- data/public/images/admin/zm.gif +0 -0
- data/public/images/admin/zw.gif +0 -0
- data/public/stylesheets/sass/admin/globalize2.sass +59 -0
- data/readme.md +159 -0
- data/spec/controllers/admin/pages_controller_spec.rb +22 -0
- data/spec/controllers/site_controller_spec.rb +40 -0
- data/spec/factories.rb +39 -0
- data/spec/models/globalize_tags_spec.rb +155 -0
- data/spec/models/page_spec.rb +91 -0
- data/spec/spec.opts +6 -0
- data/spec/spec_helper.rb +34 -0
- data/vendor/plugins/globalize2/.gitignore +5 -0
- data/vendor/plugins/globalize2/LICENSE +21 -0
- data/vendor/plugins/globalize2/README.textile +86 -0
- data/vendor/plugins/globalize2/Rakefile +39 -0
- data/vendor/plugins/globalize2/VERSION +1 -0
- data/vendor/plugins/globalize2/generators/db_backend.rb +0 -0
- data/vendor/plugins/globalize2/generators/templates/db_backend_migration.rb +25 -0
- data/vendor/plugins/globalize2/globalize2.gemspec +81 -0
- data/vendor/plugins/globalize2/init.rb +1 -0
- data/vendor/plugins/globalize2/lib/globalize.rb +15 -0
- data/vendor/plugins/globalize2/lib/globalize/active_record.rb +215 -0
- data/vendor/plugins/globalize2/lib/globalize/active_record/adapter.rb +80 -0
- data/vendor/plugins/globalize2/lib/globalize/active_record/attributes.rb +25 -0
- data/vendor/plugins/globalize2/lib/globalize/active_record/migration.rb +44 -0
- data/vendor/plugins/globalize2/lib/i18n/missing_translations_log_handler.rb +41 -0
- data/vendor/plugins/globalize2/lib/i18n/missing_translations_raise_handler.rb +25 -0
- data/vendor/plugins/globalize2/test/active_record/fallbacks_test.rb +102 -0
- data/vendor/plugins/globalize2/test/active_record/migration_test.rb +118 -0
- data/vendor/plugins/globalize2/test/active_record/sti_translated_test.rb +61 -0
- data/vendor/plugins/globalize2/test/active_record/translates_test.rb +96 -0
- data/vendor/plugins/globalize2/test/active_record/translation_class_test.rb +30 -0
- data/vendor/plugins/globalize2/test/active_record/validation_tests.rb +75 -0
- data/vendor/plugins/globalize2/test/active_record_test.rb +467 -0
- data/vendor/plugins/globalize2/test/all.rb +2 -0
- data/vendor/plugins/globalize2/test/data/models.rb +62 -0
- data/vendor/plugins/globalize2/test/data/no_globalize_schema.rb +11 -0
- data/vendor/plugins/globalize2/test/data/schema.rb +55 -0
- data/vendor/plugins/globalize2/test/i18n/missing_translations_test.rb +36 -0
- data/vendor/plugins/globalize2/test/test_helper.rb +76 -0
- metadata +409 -0
@@ -0,0 +1,22 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
|
3
|
+
describe Admin::PagesController do
|
4
|
+
dataset :users
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
login_as :admin
|
8
|
+
|
9
|
+
I18n.default_locale = :"en"
|
10
|
+
@home_page = Factory.create(:page, :title => "Home Page", :slug => "/")
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should reset the locale to default" do
|
14
|
+
switch_locale("ro") do
|
15
|
+
get :new, :page_id => @home_page.id
|
16
|
+
response.should be_success
|
17
|
+
session[:locale].should == 'en'
|
18
|
+
I18n.locale.should == :en
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe SiteController do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
I18n.locale = :"en"
|
7
|
+
home_page = Factory.create(:page, :title => "Home Page", :slug => "/", :status_id => 100)
|
8
|
+
Factory.create(:page_part, :page => home_page, :content => "Home Page")
|
9
|
+
|
10
|
+
level_one_child = Factory.create(:child_page, :title => "Level One Child", :parent => home_page)
|
11
|
+
Factory.create(:page_part, :page => level_one_child, :content => "Level one child content")
|
12
|
+
|
13
|
+
level_two_child = Factory.create(:child_page, :title => "Level Two Child", :parent => level_one_child)
|
14
|
+
Factory.create(:page_part, :page => level_two_child, :content => "Level two child content")
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should find and render home page for the current locale" do
|
18
|
+
get :show_page, :url => '/'
|
19
|
+
response.should be_success
|
20
|
+
response.body.should == 'Home Page'
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should find a page one level deep" do
|
24
|
+
get :show_page, :url => 'level-one-child/'
|
25
|
+
response.should be_success
|
26
|
+
response.body.should == 'Level one child content'
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should find a page two levels deep" do
|
30
|
+
get :show_page, :url => 'level-one-child/level-two-child/'
|
31
|
+
response.should be_success
|
32
|
+
response.body.should == 'Level two child content'
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should show page not found" do
|
36
|
+
get :show_page, :url => 'a/non-existant/page'
|
37
|
+
response.response_code.should == 404
|
38
|
+
response.should render_template('site/not_found')
|
39
|
+
end
|
40
|
+
end
|
data/spec/factories.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
Factory.define(:page) do |f|
|
2
|
+
f.sequence(:title) { |i| "Cool Page #{i}" }
|
3
|
+
f.slug { |a| a.title.downcase.gsub(/[^-a-z0-9~\s\.:;+=_]/, '').gsub(/[\s\.:;=+]+/, '-') }
|
4
|
+
f.breadcrumb { |a| a.title }
|
5
|
+
end
|
6
|
+
|
7
|
+
Factory.define(:romanian_page_translation, :class => Page::Translation, :parent => :page) do |f|
|
8
|
+
f.locale "ro"
|
9
|
+
f.association :page, :factory => :page
|
10
|
+
f.title "Pagina Cool"
|
11
|
+
end
|
12
|
+
|
13
|
+
Factory.define(:page_part) do |f|
|
14
|
+
f.name "body"
|
15
|
+
f.association :page, :factory => :page
|
16
|
+
f.content "english content"
|
17
|
+
end
|
18
|
+
|
19
|
+
Factory.define(:romanian_page_part_translation, :class => PagePart::Translation) do |f|
|
20
|
+
f.locale :ro
|
21
|
+
f.association :page_part, :factory => :page_part
|
22
|
+
f.content "continut romanesc"
|
23
|
+
end
|
24
|
+
|
25
|
+
Factory.define(:layout) do |f|
|
26
|
+
f.sequence(:name) { |i| "Cool layout #{i}" }
|
27
|
+
f.content "english content"
|
28
|
+
end
|
29
|
+
|
30
|
+
Factory.define(:snippet) do |f|
|
31
|
+
f.sequence(:name) { |i| "Cool snippet #{i}" }
|
32
|
+
f.content "english content"
|
33
|
+
end
|
34
|
+
|
35
|
+
Factory.define(:child_page, :class => "page", :parent => :page) do |f|
|
36
|
+
f.sequence(:title) {|i| "Child page #{i}"}
|
37
|
+
f.association :parent, :factory => :page
|
38
|
+
f.status_id 100
|
39
|
+
end
|
@@ -0,0 +1,155 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe "Globalize 2 Tags" do
|
4
|
+
|
5
|
+
before do
|
6
|
+
I18n.locale = "en"
|
7
|
+
@page = Factory.create(:page)
|
8
|
+
Factory.create(:romanian_page_translation, :page => @page)
|
9
|
+
@page_part = Factory.create(:page_part, :page => @page)
|
10
|
+
Factory.create(:romanian_page_part_translation, :page_part => @page_part)
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "<r:locale />" do
|
14
|
+
it "returns the current locale" do
|
15
|
+
@page.should render("<r:locale />").as("en")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "<r:locales />" do
|
20
|
+
it "raises an error if <r:normal /> tag is not included" do
|
21
|
+
@page.
|
22
|
+
should render("<r:locales codes='en|ro'><r:locale /></r:locales>").
|
23
|
+
with_error("'locales' tag must include a 'normal' tag")
|
24
|
+
end
|
25
|
+
|
26
|
+
it "renders the list of codes supplied" do
|
27
|
+
@page.
|
28
|
+
should render("<r:locales codes='en|ro'><r:normal><r:locale /></r:normal><r:active><r:locale /></r:active></r:locales>").
|
29
|
+
as("en ro")
|
30
|
+
end
|
31
|
+
|
32
|
+
it "prefers the between attribute when rendering the locales" do
|
33
|
+
@page.
|
34
|
+
should render("<r:locales codes='en|ro' between='|'><r:normal><r:locale /></r:normal><r:active><r:locale /></r:active></r:locales>").
|
35
|
+
as("en|ro")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "<r:with_locale />" do
|
40
|
+
it "raises error if 'code' tag attribute is not set" do
|
41
|
+
@page.
|
42
|
+
should render("<r:with_locale />").
|
43
|
+
with_error("'code' must be set")
|
44
|
+
end
|
45
|
+
|
46
|
+
it "switches the locale" do
|
47
|
+
@page.
|
48
|
+
should render("<r:with_locale code='ro'><r:link /></r:with_locale>").
|
49
|
+
as("<a href=\"/ro/pagina-cool/\">Pagina Cool</a>")
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "<r:if_translation_title />" do
|
54
|
+
it "expands if the page's title is translated" do
|
55
|
+
@page.
|
56
|
+
should render("<r:if_translation_title><r:title /></r:if_translation_title>").
|
57
|
+
matching(/Cool Page \d*/)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "<r:unless_translation_title />" do
|
62
|
+
it "expands if the page's title is not translated" do
|
63
|
+
not_translated_page = Factory.create(:page, :title => "Not Translated Page")
|
64
|
+
switch_locale("ro") do
|
65
|
+
not_translated_page.
|
66
|
+
should render("<r:unless_translation_title><r:title /></r:unless_translation_title>").
|
67
|
+
as("Not Translated Page")
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "<r:if_translation_content />" do
|
73
|
+
it "expands if the page's 'body' part is translated" do
|
74
|
+
@page.
|
75
|
+
should render("<r:if_translation_content part='body'><r:content /></r:if_translation_content>").
|
76
|
+
as("english content")
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe "<r:unless_translation_content" do
|
81
|
+
it "expands if the page's 'body' part is not translated" do
|
82
|
+
not_translated_page = Factory.create(:page, :title => "Not Translated Page")
|
83
|
+
not_translated_page_part = Factory.create(:page_part, :page => not_translated_page, :content => "not-translated")
|
84
|
+
switch_locale("ro") do
|
85
|
+
not_translated_page.
|
86
|
+
should render("<r:unless_translation_content part='body'><r:content /></r:unless_translation_content>").
|
87
|
+
as("not-translated")
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe "<r:link_with_globalize />" do
|
93
|
+
it "renders the link with the current locale if 'locale' tag attribute is not set" do
|
94
|
+
@page.should render("<r:link />").matching(/<a href=\"\/en\/cool-page-\d*\/\">Cool Page \d*\<\/a>/)
|
95
|
+
end
|
96
|
+
|
97
|
+
it "renders the link with the given locale if the 'locale' tag attribute is set" do
|
98
|
+
@page.should render("<r:link locale='ro' />").as("<a href=\"/ro/pagina-cool/\">Pagina Cool</a>")
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe "<r:children:each />" do
|
103
|
+
before(:each) do
|
104
|
+
@parent = Factory.create(:page)
|
105
|
+
child_one = Factory.create(:child_page, :parent => @parent)
|
106
|
+
Factory.create(:child_page, :parent => @parent)
|
107
|
+
|
108
|
+
Factory.create(:romanian_page_translation, :page => child_one, :title => "Pagina 1")
|
109
|
+
end
|
110
|
+
|
111
|
+
it "filters the children by locale if 'locale' attribute is not set to false" do
|
112
|
+
switch_locale(:ro) do
|
113
|
+
@parent.
|
114
|
+
should render("<r:children:each><r:title /> </r:children:each>").
|
115
|
+
as("Pagina 1 ")
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
it "does not filter by locale if 'locale' attribute is set to false" do
|
120
|
+
switch_locale(:ro) do
|
121
|
+
@parent.
|
122
|
+
should render("<r:children:each locale='false'><r:title /> </r:children:each>").
|
123
|
+
matching(/Pagina 1 Child page \d*/)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
if defined?(PaginateExtension)
|
129
|
+
describe "<r:paginate_with_globalize />" do
|
130
|
+
before(:each) do
|
131
|
+
@parent = Factory.create(:page)
|
132
|
+
child_one = Factory.create(:child_page, :parent => @parent)
|
133
|
+
Factory.create(:romanian_page_translation, :page => child_one, :title => "Pagina 1")
|
134
|
+
(1..4).map{ |i| Factory.create(:child_page, :parent => @parent) }
|
135
|
+
end
|
136
|
+
|
137
|
+
it "filters the paginated children by locale if 'locale' tag attribute is not set to false" do
|
138
|
+
@parent.save!
|
139
|
+
switch_locale(:ro) do
|
140
|
+
@parent.
|
141
|
+
should render("<r:paginate per_page='2'><r:each><r:title /></r:each></r:paginate>").
|
142
|
+
as("Pagina 1")
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
it "does not filter paginated children by locale if 'locale' tag attribute is set to false" do
|
147
|
+
switch_locale(:ro) do
|
148
|
+
@parent.
|
149
|
+
should render("<r:paginate per_page='2' locale='false'><r:each><r:title /> </r:each></r:paginate>").
|
150
|
+
matching(%r{Pagina 1 Child page \d*})
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe Page do
|
4
|
+
|
5
|
+
def valid_attributes
|
6
|
+
{
|
7
|
+
:title => "Kewl Page",
|
8
|
+
:slug => "kewl-page",
|
9
|
+
:breadcrumb => "Kewl Page"
|
10
|
+
}
|
11
|
+
end
|
12
|
+
|
13
|
+
def create_page(options = {})
|
14
|
+
page = Page.new
|
15
|
+
page.attributes = valid_attributes.merge(options)
|
16
|
+
page.save
|
17
|
+
page
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "validate unique_slug" do
|
21
|
+
before(:each) do
|
22
|
+
@parent = Factory.create(:page)
|
23
|
+
@child = Factory.create(:page, :parent => @parent, :title => "Child Page", :slug=>"child-page")
|
24
|
+
@another = Factory.create(:page, :parent => @parent)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "is valid" do
|
28
|
+
page = create_page
|
29
|
+
page.should be_valid
|
30
|
+
end
|
31
|
+
|
32
|
+
it "requires slug" do
|
33
|
+
lambda do
|
34
|
+
page = create_page(:slug => nil)
|
35
|
+
page.errors.on(:slug).should_not be_nil
|
36
|
+
end.should_not change(Page, :count)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "does not require slug to be unique outside the scope of parent" do
|
40
|
+
lambda do
|
41
|
+
page = create_page(:parent => @another, :slug => "child-page")
|
42
|
+
page.valid?
|
43
|
+
page.errors.on(:slug).should be_nil
|
44
|
+
end.should change(Page, :count).by(1)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "does not require slug to be unique outside the scope of locale" do
|
48
|
+
@child.save!
|
49
|
+
switch_locale(:ro) do
|
50
|
+
lambda do
|
51
|
+
page = create_page(:parent => @parent, :slug => "child-page")
|
52
|
+
page.errors.on(:slug).should be_nil
|
53
|
+
end.should change(Page, :count)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
it "requires slug to be unique within the scope of parent and locale" do
|
58
|
+
@parent.save!
|
59
|
+
lambda do
|
60
|
+
switch_locale(:en) do
|
61
|
+
page = create_page(:parent => @parent, :title=>"Child Page", :slug => "child-page")
|
62
|
+
page.errors.on(:slug).should == "must be unique"
|
63
|
+
end
|
64
|
+
end.should_not change(Page, :count)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "reset translation" do
|
69
|
+
before(:each) do
|
70
|
+
@page = Factory.create(:page)
|
71
|
+
Factory.create(:romanian_page_translation, :page => @page)
|
72
|
+
@page_part = Factory.create(:page_part, :page => @page)
|
73
|
+
Factory.create(:romanian_page_part_translation, :page_part => @page_part)
|
74
|
+
@page.reset_translations = true
|
75
|
+
end
|
76
|
+
|
77
|
+
it "deletes the translation for a locale if reset_translations is set to true" do
|
78
|
+
switch_locale("ro") do
|
79
|
+
@page.save
|
80
|
+
@page.translated_locales.should_not include("ro")
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
it "deletes the page part translation for a locale if reset_translations is set to true" do
|
85
|
+
switch_locale("ro") do
|
86
|
+
@page.save
|
87
|
+
@page.parts.first.translated_locales.should_not include("ro")
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
unless defined? RADIANT_ROOT
|
2
|
+
ENV["RAILS_ENV"] = "test"
|
3
|
+
case
|
4
|
+
when ENV["RADIANT_ENV_FILE"]
|
5
|
+
require ENV["RADIANT_ENV_FILE"]
|
6
|
+
when File.dirname(__FILE__) =~ %r{vendor/radiant/vendor/extensions}
|
7
|
+
require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../../../")}/config/environment"
|
8
|
+
else
|
9
|
+
require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../")}/config/environment"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
require "#{RADIANT_ROOT}/spec/spec_helper"
|
13
|
+
|
14
|
+
Dataset::Resolver.default << (File.dirname(__FILE__) + "/datasets")
|
15
|
+
|
16
|
+
if File.directory?(File.dirname(__FILE__) + "/matchers")
|
17
|
+
Dir[File.dirname(__FILE__) + "/matchers/*.rb"].each {|file| require file }
|
18
|
+
end
|
19
|
+
I18n.locale = :en
|
20
|
+
|
21
|
+
Spec::Runner.configure do |config|
|
22
|
+
def switch_locale(locale)
|
23
|
+
current_locale = I18n.locale
|
24
|
+
I18n.locale = locale
|
25
|
+
result = yield
|
26
|
+
I18n.locale = current_locale
|
27
|
+
result
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
gem 'thoughtbot-factory_girl', '>= 1.2.1'
|
32
|
+
require 'factory_girl'
|
33
|
+
|
34
|
+
require File.dirname(__FILE__) + "/factories.rb"
|
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2008, 2009 Joshua Harvey
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
@@ -0,0 +1,86 @@
|
|
1
|
+
h1. Globalize2
|
2
|
+
|
3
|
+
Globalize2 is the successor of Globalize for Rails.
|
4
|
+
|
5
|
+
It is compatible with and builds on the new "I18n api in Ruby on Rails":http://guides.rubyonrails.org/i18n.html. and adds model translations to ActiveRecord.
|
6
|
+
|
7
|
+
Globalize2 is much more lightweight and compatible than its predecessor was. Model translations in Globalize2 use default ActiveRecord features and do not limit any ActiveRecord functionality any more.
|
8
|
+
|
9
|
+
h2. Requirements
|
10
|
+
|
11
|
+
ActiveRecord
|
12
|
+
I18n
|
13
|
+
|
14
|
+
(or Rails > 2.2)
|
15
|
+
|
16
|
+
h2. Installation
|
17
|
+
|
18
|
+
To install Globalize2 with its default setup just use:
|
19
|
+
|
20
|
+
<pre><code>
|
21
|
+
script/plugin install git://github.com/joshmh/globalize2.git
|
22
|
+
</code></pre>
|
23
|
+
|
24
|
+
h2. Model translations
|
25
|
+
|
26
|
+
Model translations allow you to translate your models' attribute values. E.g.
|
27
|
+
|
28
|
+
<pre><code>
|
29
|
+
class Post < ActiveRecord::Base
|
30
|
+
translates :title, :text
|
31
|
+
end
|
32
|
+
</code></pre>
|
33
|
+
|
34
|
+
Allows you to values for the attributes :title and :text per locale:
|
35
|
+
|
36
|
+
<pre><code>
|
37
|
+
I18n.locale = :en
|
38
|
+
post.title # => Globalize2 rocks!
|
39
|
+
|
40
|
+
I18n.locale = :he
|
41
|
+
post.title # => גלובאלייז2 שולט!
|
42
|
+
</code></pre>
|
43
|
+
|
44
|
+
In order to make this work, you'll need to add the appropriate translation tables. Globalize2 comes with a handy helper method to help you do this. It's called @create_translation_table!@. Here's an example:
|
45
|
+
|
46
|
+
<pre><code>
|
47
|
+
class CreatePosts < ActiveRecord::Migration
|
48
|
+
def self.up
|
49
|
+
create_table :posts do |t|
|
50
|
+
t.timestamps
|
51
|
+
end
|
52
|
+
Post.create_translation_table! :title => :string, :text => :text
|
53
|
+
end
|
54
|
+
def self.down
|
55
|
+
drop_table :posts
|
56
|
+
Post.drop_translation_table!
|
57
|
+
end
|
58
|
+
end
|
59
|
+
</code></pre>
|
60
|
+
|
61
|
+
Note that the ActiveRecord model @Post@ must already exist and have a @translates@ directive listing the translated fields.
|
62
|
+
|
63
|
+
h2. Migration from Globalize
|
64
|
+
|
65
|
+
See this script by Tomasz Stachewicz: http://gist.github.com/120867
|
66
|
+
|
67
|
+
h2. Changes since Globalize2 v0.1.0
|
68
|
+
|
69
|
+
* The association globalize_translations has been renamed to translations.
|
70
|
+
|
71
|
+
h2. Alternative Solutions
|
72
|
+
|
73
|
+
* "Veger's fork":http://github.com/veger/globalize2 - uses default AR schema for the default locale, delegates to the translations table for other locales only
|
74
|
+
* "TranslatableColumns":http://github.com/iain/translatable_columns - have multiple languages of the same attribute in a model (Iain Hecker)
|
75
|
+
* "localized_record":http://github.com/glennpow/localized_record - allows records to have localized attributes without any modifications to the database (Glenn Powell)
|
76
|
+
* "model_translations":http://github.com/janne/model_translations - Minimal implementation of Globalize2 style model translations (Jan Andersson)
|
77
|
+
|
78
|
+
h2. Related solutions
|
79
|
+
|
80
|
+
* "globalize2_versioning":http://github.com/joshmh/globalize2_versioning - acts_as_versioned style versioning for Globalize2 (Joshua Harvey)
|
81
|
+
* "i18n_multi_locales_validations":http://github.com/ZenCocoon/i18n_multi_locales_validations - multi-locales attributes validations to validates attributes from Globalize2 translations models (Sébastien Grosjean)
|
82
|
+
* "Globalize2 Demo App":http://github.com/svenfuchs/globalize2-demo - demo application for Globalize2 (Sven Fuchs)</li>
|
83
|
+
* "migrate_from_globalize1":http://gist.github.com/120867 - migrate model translations from Globalize1 to Globalize2 (Tomasz Stachewicz)</li>
|
84
|
+
* "easy_globalize2_accessors":http://github.com/astropanic/easy_globalize2_accessors - easily access (read and write) globalize2-translated fields (astropanic, Tomasz Stachewicz)</li>
|
85
|
+
* "globalize2-easy-translate":http://github.com/bsamman/globalize2-easy-translate - adds methods to easily access or set translated attributes to your model (bsamman)</li>
|
86
|
+
* "batch_translations":http://github.com/alvarezrilla/batch_translations - allow saving multiple Globalize2 translations in the same request (Jose Alvarez Rilla)</li>
|