diff --git a/README.md b/README.md index b4475ec..c8d408f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ # GlobalizeSpree -Localizing model data in Spree using Globalize3. +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) @@ -8,60 +10,47 @@ 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 + bundle rake globalize_spree:install + bundle rake db:migrate ## 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 your default locale, for example inside config/initializers/spree.rb + +Spree.config do |config| + default_locale = "ro" +end + +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 +### TO DOs: + Fix taxon edit menu errors + More models 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 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/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/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 @@