spree_product_translations 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,73 @@
1
+ # Spree Product Translations #
2
+
3
+ Makes product details, properties, prototypes, taxonomies and option types translatable by bridging the Globalize 2 plugin.
4
+
5
+ ## Installation and configuration: ##
6
+
7
+ With Spree 0.11 installed and bootstrapped, install the spree-i18n extension and the Globalize 2 plugin:
8
+
9
+ script/extension install git://github.com/railsdog/spree-i18n.git
10
+ script/plugin install git://github.com/joshmh/globalize2.git
11
+
12
+ Then go ahead and install product_translations:
13
+
14
+ script/extension install git://github.com/oliverbarnes/spree-product-translations.git
15
+
16
+ Configure product_translations to load after the i18n extension:
17
+
18
+ # config/preinitializer.rb
19
+ SPREE_EXTENSIONS_LOAD_ORDER = [:i18n, :product_translations, :all, :site]
20
+
21
+ Then run
22
+
23
+ rake db:migrate
24
+
25
+ to create the translation tables defined in the migrations here.
26
+
27
+ If you have pre-existing data, you'll need to run this rake task:
28
+
29
+ rake spree:extensions:product_translations:globalize_legacy_data
30
+
31
+ it will copy the original data over to the new translation tables. Globalize 2 doesn't default to the original model table for the default locale like v1 used to.
32
+
33
+ ## How to use it: ##
34
+
35
+ To edit the content in a specific language, simply change the locale on the language nav, and edit on the admin as usual.
36
+
37
+ ## Translated fields: ##
38
+
39
+ Product
40
+ name
41
+ description
42
+ meta_description
43
+ meta_keywords
44
+
45
+ Property
46
+ presentation
47
+
48
+ Prototype
49
+ name
50
+
51
+ Taxonomy
52
+ name
53
+
54
+ Taxon
55
+ name
56
+
57
+ OptionType
58
+ presentation
59
+
60
+ OptionValue
61
+ presentation
62
+
63
+ ## Running tests ##
64
+
65
+ You might need to comment out the rspec gem requirement under config/environments/test.rb - for some reason, even with both the rspec gem and plugin installed, I would keep getting an annoying missing gem error.
66
+
67
+ Spree is officially making a choice for Test::Unit anyway, so this shouldn't create a problem.
68
+
69
+ (not that I don't like Rspec, I actually prefer it in other projects.)
70
+
71
+ ## Feature requests and patches welcome ##
72
+
73
+ If you see anything you need missing, or if you have a useful patch, feel free to submit them on the Issues section of the github project.
@@ -0,0 +1,47 @@
1
+ require 'spree_core'
2
+ require 'globalize3'
3
+
4
+ module SpreeProductTranslations
5
+ class Engine < Rails::Engine
6
+ config.autoload_paths += %W(#{config.root}/lib)
7
+
8
+ def self.activate
9
+ Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
10
+ Rails.env.production? ? require(c) : load(c)
11
+ end
12
+
13
+ ::Product.class_eval do
14
+ translates :name, :description, :meta_description, :meta_keywords
15
+ end
16
+
17
+ ::Property.class_eval do
18
+ translates :presentation
19
+ end
20
+
21
+ ::Prototype.class_eval do
22
+ translates :name
23
+ end
24
+
25
+ ::Taxonomy.class_eval do
26
+ translates :name
27
+ end
28
+
29
+ ::Taxon.class_eval do
30
+ translates :name
31
+ end
32
+
33
+ ::OptionType.class_eval do
34
+ translates :presentation
35
+ end
36
+
37
+ ::OptionValue.class_eval do
38
+ translates :presentation
39
+ end
40
+
41
+ # Enable I18n fallbacks
42
+ require 'i18n/backend/fallbacks'
43
+ end
44
+
45
+ config.to_prepare &method(:activate).to_proc
46
+ end
47
+ end
@@ -0,0 +1,24 @@
1
+ namespace :spree_product_translations do
2
+ desc "Copies all migrations and assets (NOTE: This will be obsolete with Rails 3.1)"
3
+ task :install do
4
+ Rake::Task['spree_product_translations:install:migrations'].invoke
5
+ Rake::Task['spree_product_translations:install:assets'].invoke
6
+ end
7
+
8
+ namespace :install do
9
+ desc "Copies all migrations (NOTE: This will be obsolete with Rails 3.1)"
10
+ task :migrations do
11
+ source = File.join(File.dirname(__FILE__), '..', '..', 'db')
12
+ destination = File.join(Rails.root, 'db')
13
+ Spree::FileUtilz.mirror_files(source, destination)
14
+ end
15
+
16
+ desc "Copies all assets (NOTE: This will be obsolete with Rails 3.1)"
17
+ task :assets do
18
+ source = File.join(File.dirname(__FILE__), '..', '..', 'public')
19
+ destination = File.join(Rails.root, 'public')
20
+ puts "INFO: Mirroring assets from #{source} to #{destination}"
21
+ Spree::FileUtilz.mirror_files(source, destination)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,79 @@
1
+ namespace :spree do
2
+ namespace :extensions do
3
+ namespace :product_translations do
4
+ desc "Copies pre-existing data to globalize's translation tables"
5
+ task :globalize_legacy_data => :environment do
6
+ I18n.locale = I18n.default_locale
7
+
8
+ @sql = ActiveRecord::Base.connection
9
+
10
+ # wrapper to deal with differences in result sets from mysql, sqlite and postgres
11
+ def fetch_first_row(query)
12
+ result = @sql.execute(query)
13
+ row = if defined?(PGresult) && result.is_a?(PGresult) #postgres
14
+ result.getvalue(0,0)
15
+ elsif result.is_a?(Array) #sqlite
16
+ result[0][0]
17
+ elsif defined?(Mysql2::Result) && result.is_a?(Mysql2::Result) #mysql2
18
+ result.first.first
19
+ else #mysql
20
+ result.fetch_row.first
21
+ end
22
+ end
23
+
24
+ puts "updating product names, description, meta_keywords and meta_description..."
25
+ Product.all.each do |p|
26
+
27
+ p.name = fetch_first_row("select products.name from products where products.id=#{p.id}")
28
+ p.description = fetch_first_row("select products.description from products where products.id=#{p.id}")
29
+ p.meta_keywords = fetch_first_row("select products.meta_keywords from products where products.id=#{p.id}")
30
+ p.meta_description = fetch_first_row("select products.meta_description from products where products.id=#{p.id}")
31
+ p.save!
32
+ end
33
+ puts "done."
34
+
35
+ puts "updating taxonomy names..."
36
+ Taxonomy.all.each do |t|
37
+ t.name = fetch_first_row("select taxonomies.name from taxonomies where taxonomies.id=#{t.id}")
38
+ t.save!
39
+ end
40
+ puts "done."
41
+
42
+ puts "updating taxon names and permalinks..."
43
+ Taxon.all.each do |t|
44
+ t.name = fetch_first_row("select taxons.name from taxons where taxons.id=#{t.id}")
45
+ t.save!
46
+ end
47
+ puts "done."
48
+
49
+ puts "updating property presentations..."
50
+ Property.all.each do |p|
51
+ p.presentation = fetch_first_row("select properties.presentation from properties where properties.id=#{p.id}")
52
+ p.save!
53
+ end
54
+ puts "done."
55
+
56
+ puts "updating prototype names..."
57
+ Prototype.all.each do |p|
58
+ p.name = fetch_first_row("select prototypes.name from prototypes where prototypes.id=#{p.id}")
59
+ p.save!
60
+ end
61
+ puts "done."
62
+
63
+ puts "updating option type presentations..."
64
+
65
+ OptionType.all.each do |p|
66
+ p.presentation = fetch_first_row("select option_types.presentation from option_types where option_types.id=#{p.id}")
67
+ p.save!
68
+ end
69
+ puts "done."
70
+
71
+ OptionValue.all.each do |p|
72
+ p.presentation = fetch_first_row("select option_values.presentation from option_values where option_values.id=#{p.id}")
73
+ p.save!
74
+ end
75
+ puts "done."
76
+ end
77
+ end
78
+ end
79
+ end
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spree_product_translations
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Jeroen Jacobs
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-03-02 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: globalize3
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 31098185
30
+ segments:
31
+ - 0
32
+ - 1
33
+ - 0
34
+ - beta
35
+ version: 0.1.0.beta
36
+ type: :runtime
37
+ version_requirements: *id001
38
+ - !ruby/object:Gem::Dependency
39
+ name: spree_core
40
+ prerelease: false
41
+ requirement: &id002 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ hash: 185
47
+ segments:
48
+ - 0
49
+ - 40
50
+ - 3
51
+ version: 0.40.3
52
+ type: :runtime
53
+ version_requirements: *id002
54
+ description:
55
+ email: jacobsjeroen@gmail.com
56
+ executables: []
57
+
58
+ extensions: []
59
+
60
+ extra_rdoc_files: []
61
+
62
+ files:
63
+ - README.md
64
+ - lib/spree_product_translations.rb
65
+ - lib/tasks/install.rake
66
+ - lib/tasks/spree_product_translations.rake
67
+ has_rdoc: false
68
+ homepage: https://github.com/jeroenj/spree-product_translations
69
+ licenses: []
70
+
71
+ post_install_message:
72
+ rdoc_options: []
73
+
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ hash: 57
82
+ segments:
83
+ - 1
84
+ - 8
85
+ - 7
86
+ version: 1.8.7
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ hash: 3
93
+ segments:
94
+ - 0
95
+ version: "0"
96
+ requirements:
97
+ - none
98
+ rubyforge_project:
99
+ rubygems_version: 1.5.0
100
+ signing_key:
101
+ specification_version: 3
102
+ summary: Spree Extension that adds translations to products
103
+ test_files: []
104
+