From 3573a49a085c7f2d4ea8b192e5a325b4605d7a72 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 23 Dec 2012 16:09:31 -0500 Subject: [PATCH 1/8] namespaced product and taxon models for spree 1.2.2 compatibility --- app/models/product_decorator.rb | 2 +- app/models/taxon_decorator.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/product_decorator.rb b/app/models/product_decorator.rb index a640be4..157dbdc 100644 --- a/app/models/product_decorator.rb +++ b/app/models/product_decorator.rb @@ -1,4 +1,4 @@ -Product.class_eval do +Spree::Product.class_eval do translates :name, :description extend Globalize::Migratable diff --git a/app/models/taxon_decorator.rb b/app/models/taxon_decorator.rb index 6ecc0ae..8426d4b 100644 --- a/app/models/taxon_decorator.rb +++ b/app/models/taxon_decorator.rb @@ -1,4 +1,4 @@ -Taxon.class_eval do +Spree::Taxon.class_eval do translates :name, :description extend Globalize::Migratable From dd841e8c4ecee910e9414a9fd686e7cac2efa9ac Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 23 Dec 2012 18:23:08 -0500 Subject: [PATCH 2/8] spree namespacing for product admin partial and migrations --- app/overrides/product_globalize_form_left.rb | 6 +++--- .../admin/shared/_product_globalize_form_left.html.erb | 10 +++++----- db/migrate/20101107175511_add_globalize_to_products.rb | 6 +++--- db/migrate/20101107185551_add_globalize_to_taxons.rb | 6 +++--- 4 files changed, 14 insertions(+), 14 deletions(-) rename app/views/{ => spree}/admin/shared/_product_globalize_form_left.html.erb (86%) diff --git a/app/overrides/product_globalize_form_left.rb b/app/overrides/product_globalize_form_left.rb index 3cb1af4..1b9025c 100644 --- a/app/overrides/product_globalize_form_left.rb +++ b/app/overrides/product_globalize_form_left.rb @@ -1,4 +1,4 @@ -Deface::Override.new(:virtual_path => "admin/products/_form", +Deface::Override.new(:virtual_path => "spree/admin/products/_form", :replace => "[data-hook='admin_product_form_left']", - :partial => "admin/shared/product_globalize_form_left", - :name => "product_globalize_form_left") \ No newline at end of file + :partial => "spree/admin/shared/product_globalize_form_left", + :name => "product_globalize_form_left") diff --git a/app/views/admin/shared/_product_globalize_form_left.html.erb b/app/views/spree/admin/shared/_product_globalize_form_left.html.erb similarity index 86% rename from app/views/admin/shared/_product_globalize_form_left.html.erb rename to app/views/spree/admin/shared/_product_globalize_form_left.html.erb index fb6ef44..18106b2 100644 --- a/app/views/admin/shared/_product_globalize_form_left.html.erb +++ b/app/views/spree/admin/shared/_product_globalize_form_left.html.erb @@ -1,5 +1,5 @@
-<% if(Product.easy_accessors.blank?) %> +<% if(Spree::Product.easy_accessors.blank?) %> <%= f.field_container :name do %> <%= f.label :name, t("name") %> *
<%= f.text_field :name, :class => 'fullwidth title' %> @@ -7,7 +7,7 @@ <% end %> <% else %> - <%- Product.easy_accessors.each do |locale| %> + <% Spree::Product.easy_accessors.each do |locale| %> <% fieldsym = "name_#{locale}".to_sym %> <%= f.field_container fieldsym do %> <%= f.label fieldsym, t(fieldsym.to_s) %>
@@ -24,7 +24,7 @@ <%= f.error_message_on :permalink %> <% end %> -<% if(Product.easy_accessors.blank?) %> +<% if(Spree::Product.easy_accessors.blank?) %> <%= f.field_container :description do %> <%= f.label :description, t("description")%>
@@ -34,7 +34,7 @@ <% else %> - <%- Product.easy_accessors.each do |locale| %> + <%- Spree::Product.easy_accessors.each do |locale| %> <% fieldsym = "description_#{locale}".to_sym %> <%= f.field_container fieldsym do %> <%= f.label fieldsym, t(fieldsym.to_s)%>
@@ -44,4 +44,4 @@ <% end %> <% end %> -
\ No newline at end of file + diff --git a/db/migrate/20101107175511_add_globalize_to_products.rb b/db/migrate/20101107175511_add_globalize_to_products.rb index bfcf049..24b9322 100644 --- a/db/migrate/20101107175511_add_globalize_to_products.rb +++ b/db/migrate/20101107175511_add_globalize_to_products.rb @@ -1,12 +1,12 @@ class AddGlobalizeToProducts < ActiveRecord::Migration def self.up - Product.create_translation_table! :name => :string, :description => :text + Spree::Product.create_translation_table! :name => :string, :description => :text # save old values into brand new translations table - Product.migrate_translated_fields + Spree::Product.migrate_translated_fields end def self.down - Product.drop_translation_table! + Spree::Product.drop_translation_table! end end diff --git a/db/migrate/20101107185551_add_globalize_to_taxons.rb b/db/migrate/20101107185551_add_globalize_to_taxons.rb index f2da23e..7bb87a6 100644 --- a/db/migrate/20101107185551_add_globalize_to_taxons.rb +++ b/db/migrate/20101107185551_add_globalize_to_taxons.rb @@ -1,12 +1,12 @@ class AddGlobalizeToTaxons < ActiveRecord::Migration def self.up - Taxon.create_translation_table! :name => :string, :description => :text + Spree::Taxon.create_translation_table! :name => :string, :description => :text # save old values into brand new translations table - Taxon.migrate_translated_fields + Spree::Taxon.migrate_translated_fields end def self.down - Taxon.drop_translation_table! + Spree::Taxon.drop_translation_table! end end From 337b37516680528cdc9ec228bc41972e252ad943 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 30 Dec 2012 12:01:40 -0500 Subject: [PATCH 3/8] taxon admin form for entering name translation --- app/overrides/taxon_globalize_form.rb | 5 +++ app/views/spree/admin/taxons/_form.html.erb | 34 +++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 app/overrides/taxon_globalize_form.rb create mode 100644 app/views/spree/admin/taxons/_form.html.erb diff --git a/app/overrides/taxon_globalize_form.rb b/app/overrides/taxon_globalize_form.rb new file mode 100644 index 0000000..190e056 --- /dev/null +++ b/app/overrides/taxon_globalize_form.rb @@ -0,0 +1,5 @@ +Deface::Override.new(:virtual_path => "spree/admin/taxons/_form", + :replace => "[data-hook='admin_taxon_form']", + :partial => "spree/admin/taxon/form", + :name => "taxon_globalize_form") + diff --git a/app/views/spree/admin/taxons/_form.html.erb b/app/views/spree/admin/taxons/_form.html.erb new file mode 100644 index 0000000..e4c219d --- /dev/null +++ b/app/views/spree/admin/taxons/_form.html.erb @@ -0,0 +1,34 @@ +
+ +<% if(Spree::Taxon.easy_accessors.blank?) %> + <%= f.field_container :name do %> + <%= f.label :name, t(:name) %> *
+ <%= error_message_on :taxon, :name, :class => 'fullwidth title' %> + <%= text_field :taxon, :name %> + <% end %> +<% else %> + <% Spree::Taxon.easy_accessors.each do |locale| %> + <% fieldsym = "name_#{locale}".to_sym %> + <%= f.field_container fieldsym do %> + <%= f.label fieldsym, t(fieldsym.to_s) %> *
+ <%= f.error_message_on fieldsym %> + <%= f.text_field fieldsym, :class => 'fullwidth title' %> + <% end %> +<% end %> + + <%= f.field_container :permalink_part do %> + <%= f.label :permalink_part, t(:permalink) %>*
+ <%= @taxon.permalink.split("/")[0...-1].join("/") + "/" %><%= text_field_tag :permalink_part, @permalink_part %> + <% end %> + + <%= f.field_container :icon do %> + <%= f.label :icon, t(:icon) %>
+ <%= f.file_field :icon %> + <% end %> + + <%= f.field_container :description do %> + <%= f.label :description, t(:description) %>
+ <%= f.text_area :description %> + <% end %> +
+ From f9e1cdcca689148890630739ba7a3a45ef6061a0 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 30 Dec 2012 12:13:59 -0500 Subject: [PATCH 4/8] closing end block --- app/views/spree/admin/taxons/_form.html.erb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/views/spree/admin/taxons/_form.html.erb b/app/views/spree/admin/taxons/_form.html.erb index e4c219d..df616ea 100644 --- a/app/views/spree/admin/taxons/_form.html.erb +++ b/app/views/spree/admin/taxons/_form.html.erb @@ -10,9 +10,10 @@ <% Spree::Taxon.easy_accessors.each do |locale| %> <% fieldsym = "name_#{locale}".to_sym %> <%= f.field_container fieldsym do %> - <%= f.label fieldsym, t(fieldsym.to_s) %> *
- <%= f.error_message_on fieldsym %> - <%= f.text_field fieldsym, :class => 'fullwidth title' %> + <%= f.label fieldsym, t(fieldsym.to_s) %> *
+ <%= f.error_message_on fieldsym %> + <%= f.text_field fieldsym, :class => 'fullwidth title' %> + <% end %> <% end %> <% end %> From 381b7f07d6c07fa9dbfafdb5c9eae33f2a6cd283 Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 2 Jan 2013 16:10:20 -0500 Subject: [PATCH 5/8] updated README --- README.md | 46 ++++++++++++++-------------------------------- 1 file changed, 14 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index b4475ec..7e791d8 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # GlobalizeSpree -Localizing model data in Spree using Globalize3. +Localizes model data in Spree using Gloablize3. This is a fork of Tomash's globalize-spree plugin, that was updated to be compatible with Rails 3.2 and Spree 1.2 [![Build Status](https://secure.travis-ci.org/tomash/globalize-spree.png)](http://travis-ci.org/tomash/globalize-spree) @@ -8,18 +8,12 @@ Localizing model data in Spree using Globalize3. ## Installation - Add to Gemfile: - gem "globalize_spree", :git => 'git://github.com/tomash/globalize-spree.git' - -Also, to be super-sure (I've ran into some trouble before that, needs investigation) add - + gem "globalize_spree", :git => 'https://github.com/victor-github/globalize-spree' gem "i18n" gem "globalize3" -to your application Gemfile as well. - Now run the rake task to copy migrations and run them: rake globalize_spree:install rake db:migrate @@ -27,41 +21,29 @@ Now run the rake task to copy migrations and run them: ## Usage -Works OOTB. - Currently globalizes: Product (name, description), Taxon (name). -### Basic usage (vanilla Globalize way) +### Basic usage + +It works like Globalize. To set your locale, add, inside an initializer for example, + +Spree::Config.set(:default_locale => 'en') + +Then you can do: -Basically works like Globalize, so - - # set the locale or do not to leave default one - I18n.locale = :en - # and you are ready to go Product.last.name # <= get name for this product for :en locale Product.last.name = "something" # <= set name for this product for :en locale ### Easy Globalize Accessors -For easy editing of translated stuff for predefined locales, it uses code from easy-globalize2-accessors. Inside self.activate of your lib/spree_site.rb put +For easy editing of translated stuff for predefined locales, it uses code from easy-globalize2-accessors. Inside config.to_prepare of your config/application.rb put Product.class_eval do - globalize_accessors :pl, :en, :de + globalize_accessors :en, :ro, :de + attr_accessible :name_en, :name_ro, name_de, :description_en, :description_ro, :description_de end -And spree-globalize will replace Product form's "name" field with, respectively, "name_pl", "name_en" and "name_de" fields ("description" following same pattern) in admin panel. Try it! - - -## ToDo - -More models. - - -## Contributing - -Feel free to use Github issues and/or contact me via Github PM. Pull requests are welcome, provided they include some explanation (and relevant open issue maybe?). - +And spree-globalize will replace Product form's "name" field with, respectively, "name_en", "name_ro" and "name_de" fields ("description" following same pattern) in admin panel. -## Usual blabber +The attr_accessible line is necessary since in Rails 3.2 attributes need to be whitelisted explicitly in order for assignment to work. -Copyright (c) 2010 Tomasz "Tomash" Stachewicz, released under the New BSD License From 12217fddacc9bb2ab14ed1a82d9641e79e0a6666 Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 2 Jan 2013 16:34:17 -0500 Subject: [PATCH 6/8] updated readme --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7e791d8..f882d28 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ # GlobalizeSpree -Localizes model data in Spree using Gloablize3. This is a fork of Tomash's globalize-spree plugin, that was updated to be compatible with Rails 3.2 and Spree 1.2 +This is a fork of Tomash's globalize-spree plugin, that was updated to be compatible with Rails 3.2 and Spree 1.2. +It provides localization using the gem globalize3. +I also added an admin form for specifying the taxon name. This can be done by right clicking on the taxon in the Categories pages and choosing Edit. (ignore the errors displayed in the dropdown, they are harmless) [![Build Status](https://secure.travis-ci.org/tomash/globalize-spree.png)](http://travis-ci.org/tomash/globalize-spree) @@ -47,3 +49,6 @@ And spree-globalize will replace Product form's "name" field with, respectively, The attr_accessible line is necessary since in Rails 3.2 attributes need to be whitelisted explicitly in order for assignment to work. +### TO DOs: + Fix taxon edit menu errors + More models From 1a8141e4465d20a6948103887f0aed5c22580adf Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 6 Jan 2013 15:08:31 -0500 Subject: [PATCH 7/8] updated README --- README.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f882d28..3a51b55 100644 --- a/README.md +++ b/README.md @@ -17,8 +17,8 @@ Add to Gemfile: gem "globalize3" Now run the rake task to copy migrations and run them: - rake globalize_spree:install - rake db:migrate + bundle rake globalize_spree:install + bundle rake db:migrate ## Usage @@ -27,9 +27,11 @@ Currently globalizes: Product (name, description), Taxon (name). ### Basic usage -It works like Globalize. To set your locale, add, inside an initializer for example, +It works like Globalize. To set your locale, add your default locale, for example inside config/initializers/spree.rb -Spree::Config.set(:default_locale => 'en') +Spree.config do |config| + default_locale = "ro" +end Then you can do: From ccf18bff12e3535f959e60f643c227d395c33428 Mon Sep 17 00:00:00 2001 From: Victor Olteanu Date: Sat, 19 Jan 2013 17:41:36 -0500 Subject: [PATCH 8/8] readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3a51b55..c8d408f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # GlobalizeSpree -This is a fork of Tomash's globalize-spree plugin, that was updated to be compatible with Rails 3.2 and Spree 1.2. +Updated to be compatible with Rails 3.2 and Spree 1.2. It provides localization using the gem globalize3. I also added an admin form for specifying the taxon name. This can be done by right clicking on the taxon in the Categories pages and choosing Edit. (ignore the errors displayed in the dropdown, they are harmless)