From 7290f61e892076ce3ad4e5f8f872b623ac6ad1e0 Mon Sep 17 00:00:00 2001 From: Alberto Vena Date: Fri, 8 Apr 2022 15:05:23 +0200 Subject: [PATCH 01/19] Update routing-filter gem now that a compatible version is released --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 6d8428c..c963937 100644 --- a/Gemfile +++ b/Gemfile @@ -14,7 +14,7 @@ gem 'rails', '>0.a' # Provides basic authentication functionality for testing parts of your engine # gem 'solidus_auth_devise' -gem 'routing-filter', github: "svenfuchs/routing-filter", branch: "master" +gem 'routing-filter' case ENV['DB'] when 'mysql' From fe0388f5c28bb8fd4bc025fb5d97cc21a55bcddc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Busqu=C3=A9?= Date: Fri, 29 Jul 2022 06:22:12 +0200 Subject: [PATCH 02/19] Update to use forked solidus_frontend when needed --- Gemfile | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index c963937..5ad6f9a 100644 --- a/Gemfile +++ b/Gemfile @@ -4,7 +4,13 @@ source 'https://rubygems.org' git_source(:github) { |repo| "https://github.com/#{repo}.git" } branch = ENV.fetch('SOLIDUS_BRANCH', 'master') -gem 'solidus', github: 'solidusio/solidus', branch: branch +solidus_git, solidus_frontend_git = if (branch == 'master') || (branch >= 'v3.2') + %w[solidusio/solidus solidusio/solidus_frontend] + else + %w[solidusio/solidus] * 2 + end +gem 'solidus', github: solidus_git, branch: branch +gem 'solidus_frontend', github: solidus_frontend_git, branch: branch # Needed to help Bundler figure out how to resolve dependencies, # otherwise it takes forever to resolve them. From 385afac70a093609b4f19a0f790b2e1493daa1d7 Mon Sep 17 00:00:00 2001 From: stefan Date: Mon, 29 Aug 2022 01:54:55 +0200 Subject: [PATCH 03/19] allow ruby 3 --- solidus_globalize.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solidus_globalize.gemspec b/solidus_globalize.gemspec index e29e597..2b1503e 100644 --- a/solidus_globalize.gemspec +++ b/solidus_globalize.gemspec @@ -19,7 +19,7 @@ Gem::Specification.new do |s| s.metadata["source_code_uri"] = 'https://github.com/solidusio-contrib/solidus_globalize' end - s.required_ruby_version = '~> 2.4' + s.required_ruby_version = ['>= 2.4', '< 4.0'] s.files = Dir.chdir(File.expand_path(__dir__)) do `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } From 329fbb205cc5c91c725994dc91e8e08c549f3804 Mon Sep 17 00:00:00 2001 From: Stefan <> Date: Mon, 29 Aug 2022 23:49:39 +0200 Subject: [PATCH 04/19] describe usage with ruby 3.x --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 3ef0a03..a9b9d95 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,14 @@ Add the following to your `Gemfile`: gem 'solidus_globalize', github: 'solidusio-contrib/solidus_globalize' ``` +For Ruby 3.x you have to force the usage of the friendly_id-globalize master version: + +```ruby +gem 'friendly_id-globalize', github: 'norman/friendly_id-globalize', branch: "master" +gem 'solidus_globalize', github: 'solidusio-contrib/solidus_globalize' +``` + + Run `bundle install` You can use the generator to install migrations and append solidus_globalize assets to From 95fe64d985f9e57cd4cb3a24ff515adcf857cc8b Mon Sep 17 00:00:00 2001 From: Christopher Reeve Date: Thu, 29 Sep 2022 12:01:09 +0100 Subject: [PATCH 05/19] Fix product name search retention The override allows the product name search term to be retained after search results are shown. This was not working because the search param is for the product translations and did not match the field name. --- .../replace_name_field_with_translations_name.html.erb.deface | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 app/overrides/spree/admin/products/index/replace_name_field_with_translations_name.html.erb.deface diff --git a/app/overrides/spree/admin/products/index/replace_name_field_with_translations_name.html.erb.deface b/app/overrides/spree/admin/products/index/replace_name_field_with_translations_name.html.erb.deface new file mode 100644 index 0000000..04fe51e --- /dev/null +++ b/app/overrides/spree/admin/products/index/replace_name_field_with_translations_name.html.erb.deface @@ -0,0 +1,3 @@ + +<%= f.label :translations_name_cont, Spree::Product.human_attribute_name(:name) %> +<%= f.text_field :translations_name_cont, size: 15 %> From 4abd26c360e2d76996bf01c40147009e23462a56 Mon Sep 17 00:00:00 2001 From: Alberto Vena Date: Mon, 22 May 2023 17:22:14 +0200 Subject: [PATCH 06/19] Allow Solidus 4 Reinitialize the extension with the new defaults of solidus_dev_support, and update gemspec to allow Solidus 4. --- .circleci/config.yml | 58 +++++++++++--- .github/stale.yml | 18 +---- .github_changelog_generator | 2 + .gitignore | 5 ++ .rubocop.yml | 5 +- CHANGELOG.md | 1 + Gemfile | 20 +++-- .../spree/backend/solidus_globalize.js | 4 +- .../spree/backend/solidus_globalize.css | 4 + .../solidus_globalize/translatable.rb | 9 ++- bin/rails | 16 +--- bin/rails-engine | 13 ++++ bin/rails-sandbox | 16 ++++ bin/rake | 7 ++ bin/sandbox | 78 +++++++++++++++++++ bin/setup | 2 +- .../install/templates/initializer.rb | 6 ++ .../{ => testing_support}/factories.rb | 0 solidus_globalize.gemspec | 2 +- spec/spec_helper.rb | 16 +++- 20 files changed, 222 insertions(+), 60 deletions(-) create mode 100644 .github_changelog_generator create mode 100644 CHANGELOG.md create mode 100644 app/assets/stylesheets/spree/backend/solidus_globalize.css create mode 100755 bin/rails-engine create mode 100755 bin/rails-sandbox create mode 100755 bin/rake create mode 100755 bin/sandbox create mode 100644 lib/generators/solidus_globalize/install/templates/initializer.rb rename lib/solidus_globalize/{ => testing_support}/factories.rb (100%) diff --git a/.circleci/config.yml b/.circleci/config.yml index 12bb10e..c0e8865 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,6 +1,9 @@ version: 2.1 orbs: + # Required for feature specs. + browser-tools: circleci/browser-tools@1.1 + # Always take the latest version of the orb, this allows us to # run specs against Solidus supported versions only without the need # to change this configuration every time a Solidus version is released @@ -8,20 +11,49 @@ orbs: solidusio_extensions: solidusio/extensions@volatile jobs: - run-specs-with-postgres: - executor: solidusio_extensions/postgres + run-specs: + parameters: + solidus: + type: string + default: main + db: + type: string + default: "postgres" + ruby: + type: string + default: "3.2" + executor: + name: solidusio_extensions/<< parameters.db >> + ruby_version: << parameters.ruby >> steps: - - solidusio_extensions/run-tests - run-specs-with-mysql: - executor: solidusio_extensions/mysql + - checkout + - browser-tools/install-chrome + - solidusio_extensions/run-tests-solidus-<< parameters.solidus >> + + lint-code: + executor: + name: solidusio_extensions/sqlite + ruby_version: "3.0" steps: - - solidusio_extensions/run-tests + - solidusio_extensions/lint-code workflows: "Run specs on supported Solidus versions": jobs: - - run-specs-with-postgres - - run-specs-with-mysql + - run-specs: + name: &name "run-specs-solidus-<< matrix.solidus >>-ruby-<< matrix.ruby >>-db-<< matrix.db >>" + matrix: + parameters: { solidus: ["main"], ruby: ["3.2"], db: ["postgres"] } + - run-specs: + name: *name + matrix: + parameters: { solidus: ["current"], ruby: ["3.1"], db: ["mysql"] } + - run-specs: + name: *name + matrix: + parameters: { solidus: ["older"], ruby: ["3.0"], db: ["sqlite"] } + - lint-code + "Weekly run specs against master": triggers: - schedule: @@ -31,5 +63,11 @@ workflows: only: - master jobs: - - run-specs-with-postgres - - run-specs-with-mysql + - run-specs: + name: *name + matrix: + parameters: { solidus: ["main"], ruby: ["3.2"], db: ["postgres"] } + - run-specs: + name: *name + matrix: + parameters: { solidus: ["current"], ruby: ["3.1"], db: ["mysql"] } diff --git a/.github/stale.yml b/.github/stale.yml index d9f6563..0d0b1c9 100644 --- a/.github/stale.yml +++ b/.github/stale.yml @@ -1,17 +1 @@ -# Number of days of inactivity before an issue becomes stale -daysUntilStale: 60 -# Number of days of inactivity before a stale issue is closed -daysUntilClose: 7 -# Issues with these labels will never be considered stale -exemptLabels: - - pinned - - security -# Label to use when marking an issue as stale -staleLabel: wontfix -# Comment to post when marking an issue as stale. Set to `false` to disable -markComment: > - This issue has been automatically marked as stale because it has not had - recent activity. It will be closed if no further activity occurs. Thank you - for your contributions. -# Comment to post when closing a stale issue. Set to `false` to disable -closeComment: false \ No newline at end of file +_extends: .github diff --git a/.github_changelog_generator b/.github_changelog_generator new file mode 100644 index 0000000..eac0962 --- /dev/null +++ b/.github_changelog_generator @@ -0,0 +1,2 @@ +issues=false +exclude-labels=infrastructure diff --git a/.gitignore b/.gitignore index bcd4aea..1ba2096 100644 --- a/.gitignore +++ b/.gitignore @@ -8,9 +8,14 @@ .sass-cache coverage Gemfile.lock +Gemfile-local tmp nbproject pkg *.swp spec/dummy spec/examples.txt +/sandbox +.rvmrc +.ruby-version +.ruby-gemset diff --git a/.rubocop.yml b/.rubocop.yml index 81a15d5..b075a8f 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,6 +1,5 @@ require: - solidus_dev_support/rubocop -Rails/SkipsModelValidations: - Exclude: - - db/migrate/**/* +AllCops: + NewCops: disable diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..825c32f --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1 @@ +# Changelog diff --git a/Gemfile b/Gemfile index 5ad6f9a..33159b3 100644 --- a/Gemfile +++ b/Gemfile @@ -3,14 +3,17 @@ source 'https://rubygems.org' git_source(:github) { |repo| "https://github.com/#{repo}.git" } -branch = ENV.fetch('SOLIDUS_BRANCH', 'master') -solidus_git, solidus_frontend_git = if (branch == 'master') || (branch >= 'v3.2') - %w[solidusio/solidus solidusio/solidus_frontend] - else - %w[solidusio/solidus] * 2 - end -gem 'solidus', github: solidus_git, branch: branch -gem 'solidus_frontend', github: solidus_frontend_git, branch: branch +branch = ENV.fetch('SOLIDUS_BRANCH', 'main') +gem 'solidus', github: 'solidusio/solidus', branch: branch + +# The solidus_frontend gem has been pulled out since v3.2 +if branch >= 'v3.2' + gem 'solidus_frontend' +elsif branch == 'main' + gem 'solidus_frontend', github: 'solidusio/solidus_frontend' +else + gem 'solidus_frontend', github: 'solidusio/solidus', branch: branch +end # Needed to help Bundler figure out how to resolve dependencies, # otherwise it takes forever to resolve them. @@ -20,6 +23,7 @@ gem 'rails', '>0.a' # Provides basic authentication functionality for testing parts of your engine # gem 'solidus_auth_devise' +gem 'friendly_id-globalize', github: 'norman/friendly_id-globalize', branch: "master" gem 'routing-filter' case ENV['DB'] diff --git a/app/assets/javascripts/spree/backend/solidus_globalize.js b/app/assets/javascripts/spree/backend/solidus_globalize.js index d5d841c..8aa3b01 100644 --- a/app/assets/javascripts/spree/backend/solidus_globalize.js +++ b/app/assets/javascripts/spree/backend/solidus_globalize.js @@ -1,2 +1,2 @@ -//= require spree/backend -//= require_tree . +// Placeholder manifest file. +// the installer will append this file to the app vendored assets here: vendor/assets/javascripts/spree/backend/all.js' \ No newline at end of file diff --git a/app/assets/stylesheets/spree/backend/solidus_globalize.css b/app/assets/stylesheets/spree/backend/solidus_globalize.css new file mode 100644 index 0000000..e3c2366 --- /dev/null +++ b/app/assets/stylesheets/spree/backend/solidus_globalize.css @@ -0,0 +1,4 @@ +/* +Placeholder manifest file. +the installer will append this file to the app vendored assets here: 'vendor/assets/stylesheets/spree/backend/all.css' +*/ diff --git a/app/models/concerns/solidus_globalize/translatable.rb b/app/models/concerns/solidus_globalize/translatable.rb index 9a831d9..51a0684 100644 --- a/app/models/concerns/solidus_globalize/translatable.rb +++ b/app/models/concerns/solidus_globalize/translatable.rb @@ -6,8 +6,13 @@ module Translatable included do |klass| accepts_nested_attributes_for :translations - klass.whitelisted_ransackable_associations ||= [] - klass.whitelisted_ransackable_associations |= ['translations'] + if ::Spree.solidus_gem_version < Gem::Version.new('3.3') + klass.whitelisted_ransackable_associations ||= [] + klass.whitelisted_ransackable_associations |= ['translations'] + else + klass.allowed_ransackable_associations ||= [] + klass.allowed_ransackable_associations |= ['translations'] + end end class_methods do diff --git a/bin/rails b/bin/rails index c535fd2..6dbbbc3 100755 --- a/bin/rails +++ b/bin/rails @@ -1,15 +1,7 @@ #!/usr/bin/env ruby -# frozen_string_literal: true - -app_root = 'spec/dummy' - -unless File.exist? "#{app_root}/bin/rails" - system "bin/rake", app_root or begin # rubocop:disable Style/AndOr - warn "Automatic creation of the dummy app failed" - exit 1 - end +if %w[g generate].include? ARGV.first + exec "#{__dir__}/rails-engine", *ARGV +else + exec "#{__dir__}/rails-sandbox", *ARGV end - -Dir.chdir app_root -exec 'bin/rails', *ARGV diff --git a/bin/rails-engine b/bin/rails-engine new file mode 100755 index 0000000..59a707c --- /dev/null +++ b/bin/rails-engine @@ -0,0 +1,13 @@ +#!/usr/bin/env ruby +# This command will automatically be run when you run "rails" with Rails gems +# installed from the root of your application. + +ENGINE_ROOT = File.expand_path('..', __dir__) +ENGINE_PATH = File.expand_path('../lib/solidus_globalize/engine', __dir__) + +# Set up gems listed in the Gemfile. +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) +require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE']) + +require 'rails/all' +require 'rails/engine/commands' diff --git a/bin/rails-sandbox b/bin/rails-sandbox new file mode 100755 index 0000000..ad2df04 --- /dev/null +++ b/bin/rails-sandbox @@ -0,0 +1,16 @@ +#!/usr/bin/env ruby + +app_root = 'sandbox' + +unless File.exist? "#{app_root}/bin/rails" + warn 'Creating the sandbox app...' + Dir.chdir "#{__dir__}/.." do + system "#{__dir__}/sandbox" or begin + warn 'Automatic creation of the sandbox app failed' + exit 1 + end + end +end + +Dir.chdir app_root +exec 'bin/rails', *ARGV diff --git a/bin/rake b/bin/rake new file mode 100755 index 0000000..1e6eacd --- /dev/null +++ b/bin/rake @@ -0,0 +1,7 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("rake", "rake") diff --git a/bin/sandbox b/bin/sandbox new file mode 100755 index 0000000..75a3890 --- /dev/null +++ b/bin/sandbox @@ -0,0 +1,78 @@ +#!/usr/bin/env bash + +set -e +test -z "${DEBUG+empty_string}" || set -x + +test "$DB" = "sqlite" && export DB="sqlite3" + +if [ -z "$SOLIDUS_BRANCH" ] +then + echo "~~> Use 'export SOLIDUS_BRANCH=[master|v3.2|...]' to control the Solidus branch" + SOLIDUS_BRANCH="master" +fi +echo "~~> Using branch $SOLIDUS_BRANCH of solidus" + +if [ -z "$SOLIDUS_FRONTEND" ] +then + echo "~~> Use 'export SOLIDUS_FRONTEND=[solidus_frontend|solidus_starter_frontend]' to control the Solidus frontend" + SOLIDUS_FRONTEND="solidus_frontend" +fi +echo "~~> Using branch $SOLIDUS_FRONTEND as the solidus frontend" + +extension_name="solidus_globalize" + +# Stay away from the bundler env of the containing extension. +function unbundled { + ruby -rbundler -e'b = proc {system *ARGV}; Bundler.respond_to?(:with_unbundled_env) ? Bundler.with_unbundled_env(&b) : Bundler.with_clean_env(&b)' -- $@ +} + +rm -rf ./sandbox +unbundled bundle exec rails new sandbox \ + --database="${DB:-sqlite3}" \ + --skip-bundle \ + --skip-git \ + --skip-keeps \ + --skip-rc \ + --skip-spring \ + --skip-test \ + --skip-javascript + +if [ ! -d "sandbox" ]; then + echo 'sandbox rails application failed' + exit 1 +fi + +cd ./sandbox +cat <> Gemfile +gem 'solidus', github: 'solidusio/solidus', branch: '$SOLIDUS_BRANCH' +gem 'rails-i18n' +gem 'solidus_i18n' + +gem '$extension_name', path: '..' + +group :test, :development do + platforms :mri do + gem 'pry-byebug' + end +end +RUBY + +unbundled bundle install --gemfile Gemfile + +unbundled bundle exec rake db:drop db:create + +unbundled bundle exec rails generate solidus:install \ + --auto-accept \ + --user_class=Spree::User \ + --enforce_available_locales=true \ + --with-authentication=true \ + --payment-method=none \ + --frontend=${SOLIDUS_FRONTEND} \ + $@ + +unbundled bundle exec rails generate solidus:auth:install --auto-run-migrations +unbundled bundle exec rails generate ${extension_name}:install --auto-run-migrations + +echo +echo "🚀 Sandbox app successfully created for $extension_name!" +echo "🧪 This app is intended for test purposes." diff --git a/bin/setup b/bin/setup index 40d7811..67d9193 100755 --- a/bin/setup +++ b/bin/setup @@ -5,4 +5,4 @@ set -vx gem install bundler --conservative bundle update -bundle exec rake clobber +bin/rake clobber diff --git a/lib/generators/solidus_globalize/install/templates/initializer.rb b/lib/generators/solidus_globalize/install/templates/initializer.rb new file mode 100644 index 0000000..8e91ed1 --- /dev/null +++ b/lib/generators/solidus_globalize/install/templates/initializer.rb @@ -0,0 +1,6 @@ +# frozen_string_literal: true + +SolidusGlobalize.configure do |config| + # TODO: Remember to change this with the actual preferences you have implemented! + # config.sample_preference = 'sample_value' +end diff --git a/lib/solidus_globalize/factories.rb b/lib/solidus_globalize/testing_support/factories.rb similarity index 100% rename from lib/solidus_globalize/factories.rb rename to lib/solidus_globalize/testing_support/factories.rb diff --git a/solidus_globalize.gemspec b/solidus_globalize.gemspec index 2b1503e..4bcfb73 100644 --- a/solidus_globalize.gemspec +++ b/solidus_globalize.gemspec @@ -33,7 +33,7 @@ Gem::Specification.new do |s| s.add_dependency 'deface', '~> 1.5' s.add_dependency 'friendly_id-globalize' s.add_dependency 'globalize', '~> 6.0' - s.add_dependency 'solidus_core', ['>= 2.0.0', '< 4'] + s.add_dependency 'solidus_core', ['>= 2.0.0', '< 5'] s.add_dependency 'solidus_support', '~> 0.8' s.add_development_dependency 'byebug' diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index f737218..22f1dbf 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -6,19 +6,27 @@ # Run Coverage report require 'solidus_dev_support/rspec/coverage' -require File.expand_path('dummy/config/environment.rb', __dir__) +# Create the dummy app if it's still missing. +dummy_env = "#{__dir__}/dummy/config/environment.rb" +system 'bin/rake extension:test_app' unless File.exist? dummy_env +require dummy_env # Requires factories and other useful helpers defined in spree_core. require 'solidus_dev_support/rspec/feature_helper' # Requires supporting ruby files with custom matchers and macros, etc, # in spec/support/ and its subdirectories. -Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each { |f| require f } +Dir["#{__dir__}/support/**/*.rb"].sort.each { |f| require f } -# Requires factories defined in lib/solidus_globalize/factories.rb -require 'solidus_globalize/factories' +# Requires factories defined in Solidus core and this extension. +# See: lib/solidus_globalize/testing_support/factories.rb +SolidusDevSupport::TestingSupport::Factories.load_for(SolidusGlobalize::Engine) RSpec.configure do |config| config.infer_spec_type_from_file_location! config.use_transactional_fixtures = false + + if Spree.solidus_gem_version < Gem::Version.new('2.11') + config.extend Spree::TestingSupport::AuthorizationHelpers::Request, type: :system + end end From 5ccf2a4802cefa6e408df67b6d79ef9689d05259 Mon Sep 17 00:00:00 2001 From: Alberto Vena Date: Tue, 23 May 2023 12:01:29 +0200 Subject: [PATCH 07/19] Remove unused backend css file --- app/assets/stylesheets/spree/backend/solidus_globalize.css | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 app/assets/stylesheets/spree/backend/solidus_globalize.css diff --git a/app/assets/stylesheets/spree/backend/solidus_globalize.css b/app/assets/stylesheets/spree/backend/solidus_globalize.css deleted file mode 100644 index e3c2366..0000000 --- a/app/assets/stylesheets/spree/backend/solidus_globalize.css +++ /dev/null @@ -1,4 +0,0 @@ -/* -Placeholder manifest file. -the installer will append this file to the app vendored assets here: 'vendor/assets/stylesheets/spree/backend/all.css' -*/ From 3df4ace6c242da657597cf35863b54ea5a370915 Mon Sep 17 00:00:00 2001 From: Alberto Vena Date: Tue, 23 May 2023 11:59:36 +0200 Subject: [PATCH 08/19] Convert coffee files to plain JS This is a blind conversion, only needed to remove that tech from the stack. Also the content has been moved to the main JS file, which is the one being loaded by applications. --- .../spree/backend/solidus_globalize.js | 103 +++++++++++++++++- .../spree/backend/taxon_tree_menu.js.coffee | 35 ------ .../spree/backend/translations.js.coffee | 38 ------- 3 files changed, 101 insertions(+), 75 deletions(-) delete mode 100644 app/assets/javascripts/spree/backend/taxon_tree_menu.js.coffee delete mode 100644 app/assets/javascripts/spree/backend/translations.js.coffee diff --git a/app/assets/javascripts/spree/backend/solidus_globalize.js b/app/assets/javascripts/spree/backend/solidus_globalize.js index 8aa3b01..bf8a94e 100644 --- a/app/assets/javascripts/spree/backend/solidus_globalize.js +++ b/app/assets/javascripts/spree/backend/solidus_globalize.js @@ -1,2 +1,101 @@ -// Placeholder manifest file. -// the installer will append this file to the app vendored assets here: vendor/assets/javascripts/spree/backend/all.js' \ No newline at end of file +(function() { + var root; + + root = typeof exports !== "undefined" && exports !== null ? exports : this; + + root.taxon_tree_menu = function(obj, context) { + var admin_base_url, edit_url, id, translation_base_path, translation_url; + id = obj.attr("id"); + admin_base_url = Spree.path_for("admin/taxonomies/" + obj.data('taxonomy-id') + "/taxons"); + edit_url = admin_base_url.clone(); + edit_url.setPath(edit_url.path() + '/' + id + "/edit"); + translation_url = admin_base_url.clone(); + translation_base_path = admin_base_url.path().replace(/taxons/, "translations"); + translation_base_path = translation_base_path.replace(/taxonomies/, "taxons"); + translation_base_path = translation_base_path.replace(/\d+/, id); + translation_url.setPath(translation_base_path); + return { + create: { + label: " " + Spree.translations.add, + action: function(obj) { + return context.create(obj); + } + }, + rename: { + label: " " + Spree.translations.rename, + action: function(obj) { + return context.rename(obj); + } + }, + remove: { + label: " " + Spree.translations.remove, + action: function(obj) { + return context.remove(obj); + } + }, + edit: { + separator_before: true, + label: " " + Spree.translations.edit, + action: function(obj) { + return window.location = edit_url.toString(); + } + }, + translate: { + separator_before: true, + label: " " + Spree.translations.translations, + action: function(obj) { + return window.location = translation_url.toString(); + } + } + }; + }; + +}).call(this); + +(function() { + var display_locale_fields; + + display_locale_fields = function() { + var attr, display, locale, show, value; + attr = $('#attr_list a.active').data('attr'); + locale = $('#locale').val(); + show = $("select[name='show-only']").val(); + $('#attr_fields .panel').hide(); + value = $('#attr_fields .panel.' + attr + '.' + locale + ' :input').val().replace(/^\s+|\s+$/g, ""); + if (show === 'incomplete') { + display = value === ''; + } else if (show === 'complete') { + display = value !== ''; + } else { + display = true; + } + if (display) { + $('#attr_fields .panel.' + attr + '.' + locale).show(); + } + if ($('#attr_fields .panel:visible').length === 0 && show !== 'all') { + return $('#attr_fields .no-translations').show(); + } + }; + + $(function() { + $('#attr_list a').click(function() { + $('#attr_list a').removeClass('active'); + $(this).addClass('active'); + display_locale_fields(); + return false; + }); + $('#locale, #supported_locales_').select2({ + placeholder: Spree.translations['please_choose_language'] + }); + $('#locale').change(function() { + return display_locale_fields(); + }); + $("select[name='show-only']").change(function() { + return display_locale_fields(); + }); + if ($('#attr_list').is('*')) { + return display_locale_fields(); + } + }); + +}).call(this); diff --git a/app/assets/javascripts/spree/backend/taxon_tree_menu.js.coffee b/app/assets/javascripts/spree/backend/taxon_tree_menu.js.coffee deleted file mode 100644 index 3a64992..0000000 --- a/app/assets/javascripts/spree/backend/taxon_tree_menu.js.coffee +++ /dev/null @@ -1,35 +0,0 @@ -root = exports ? this - -root.taxon_tree_menu = (obj, context) -> - - id = obj.attr("id") - - admin_base_url = Spree.url(Spree.routes.admin_taxonomy_taxons_path) - - edit_url = admin_base_url.clone() - edit_url.setPath(edit_url.path() + '/' + id + "/edit"); - - translation_url = admin_base_url.clone() - - translation_base_path = admin_base_url.path().replace(/taxons/, "translations") - translation_base_path = translation_base_path.replace(/taxonomies/, "taxons") - translation_base_path = translation_base_path.replace(/\d+/, id) - translation_url.setPath(translation_base_path); - - create: - label: " " + Spree.translations.add, - action: (obj) -> context.create(obj) - rename: - label: " " + Spree.translations.rename, - action: (obj) -> context.rename(obj) - remove: - label: " " + Spree.translations.remove, - action: (obj) -> context.remove(obj) - edit: - separator_before: true, - label: " " + Spree.translations.edit, - action: (obj) -> window.location = edit_url.toString() - translate: - separator_before: true, - label: " " + Spree.translations.translations, - action: (obj) -> window.location = translation_url.toString() diff --git a/app/assets/javascripts/spree/backend/translations.js.coffee b/app/assets/javascripts/spree/backend/translations.js.coffee deleted file mode 100644 index 73dcf2a..0000000 --- a/app/assets/javascripts/spree/backend/translations.js.coffee +++ /dev/null @@ -1,38 +0,0 @@ -display_locale_fields = () -> - attr = $('#attr_list a.active').data('attr') - locale = $('#locale').val() - show = $("select[name='show-only']").val() - - $('#attr_fields .panel').hide() - - value = $('#attr_fields .panel.' + attr + '.' + locale + ' :input').val().replace /^\s+|\s+$/g, "" - if show == 'incomplete' - display = value == '' - else if show == 'complete' - display = value != '' - else - display = true - if display - $('#attr_fields .panel.' + attr + '.' + locale).show() - - if $('#attr_fields .panel:visible').length == 0 and show != 'all' - $('#attr_fields .no-translations').show() - -$ -> - $('#attr_list a').click -> - $('#attr_list a').removeClass('active') - $(this).addClass('active') - - display_locale_fields() - false - - $('#locale, #supported_locales_').select2({placeholder: Spree.translations['please_choose_language']}) - - $('#locale').change -> - display_locale_fields() - - $("select[name='show-only']").change -> - display_locale_fields() - - if $('#attr_list').is('*') - display_locale_fields() From c03ad9b8cdc0026bdcfceaa58cb46b9255a92f4b Mon Sep 17 00:00:00 2001 From: Alberto Vena Date: Tue, 23 May 2023 12:02:24 +0200 Subject: [PATCH 09/19] Fix specs to work with the latest test tools versions --- spec/features/admin/translations_spec.rb | 46 ++++++++++++------------ spec/features/translations_spec.rb | 4 +++ 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/spec/features/admin/translations_spec.rb b/spec/features/admin/translations_spec.rb index 4e605ff..c71b917 100644 --- a/spec/features/admin/translations_spec.rb +++ b/spec/features/admin/translations_spec.rb @@ -26,12 +26,12 @@ click_on "Translations" within("#attr_fields .name.en") { fill_in_name "Pearl Jam" } - select2("pt-BR", from: 'Select Locale') + select2("pt-BR", from: 'Select locale') within("#attr_fields .name.pt-BR") { fill_in_name "Geleia de perola" } click_on "Update" click_on "Translations" - select2("pt-BR", from: 'Select Locale') + select2("pt-BR", from: 'Select locale') within("#attr_fields .name.pt-BR") do expect(page).to have_field(with: 'Geleia de perola') end @@ -45,14 +45,14 @@ visit spree.admin_product_product_properties_path(product_property.product) within_row(1) { click_icon :globe } click_on "Value" - select2("pt-BR", from: 'Select Locale') + select2("pt-BR", from: 'Select locale') within("#attr_fields .value.pt-BR") { fill_in_name "vermelho" } click_on "Update" visit spree.admin_product_product_properties_path(product_property.product) within_row(1) { click_icon :globe } click_on "Value" - select2("pt-BR", from: 'Select Locale') + select2("pt-BR", from: 'Select locale') within("#attr_fields .value.pt-BR") do expect(page).to have_field(with: 'vermelho') end @@ -68,14 +68,14 @@ within("#attr_fields .name.en") { fill_in_name "shirt sizes" } within("#attr_list") { click_on "Presentation" } within("#attr_fields .presentation.en") { fill_in_name "size" } - select2("pt-BR", from: 'Select Locale') + select2("pt-BR", from: 'Select locale') within("#attr_fields .presentation.pt-BR") { fill_in_name "tamanho" } click_on "Update" visit spree.admin_option_types_path within_row(1) { click_icon :globe } within("#attr_list") { click_on "Presentation" } - select2("pt-BR", from: 'Select Locale') + select2("pt-BR", from: 'Select locale') within("#attr_fields .presentation.pt-BR") do expect(page).to have_field(with: 'tamanho') end @@ -104,14 +104,14 @@ within("#attr_fields .name.en") { fill_in_name "big" } within("#attr_list") { click_on "Presentation" } within("#attr_fields .presentation.en") { fill_in_name "big" } - select2("pt-BR", from: 'Select Locale') + select2("pt-BR", from: 'Select locale') within("#attr_fields .presentation.pt-BR") { fill_in_name "grande" } click_on "Update" visit spree.admin_option_types_path within_row(1) { click_icon :globe } within("#attr_list") { click_on "Presentation" } - select2("pt-BR", from: 'Select Locale') + select2("pt-BR", from: 'Select locale') within("#attr_fields .presentation.pt-BR") do expect(page).to have_field(with: 'grande') end @@ -124,20 +124,20 @@ it "saves translated attributes properly" do visit spree.admin_properties_path within_row(1) { click_icon :globe } - select2("pt-BR", from: 'Select Locale') + select2("pt-BR", from: 'Select locale') within("#attr_fields .name.pt-BR") { fill_in_name "Modelo" } within("#attr_list") { click_on "Presentation" } select2("en", from: 'Select Locale') within("#attr_fields .presentation.en") { fill_in_name "Model" } - select2("pt-BR", from: 'Select Locale') + select2("pt-BR", from: 'Select locale') within("#attr_fields .presentation.pt-BR") { fill_in_name "Modelo" } click_on "Update" visit spree.admin_properties_path within_row(1) { click_icon :globe } within("#attr_list") { click_on "Presentation" } - select2("pt-BR", from: 'Select Locale') + select2("pt-BR", from: 'Select locale') within("#attr_fields .presentation.pt-BR") do expect(page).to have_field(with: 'Modelo') end @@ -153,13 +153,13 @@ within_row(1) { click_icon :globe } within("#attr_fields .name.en") { fill_in_name "All free" } - select2("pt-BR", from: 'Select Locale') + select2("pt-BR", from: 'Select locale') within("#attr_fields .name.pt-BR") { fill_in_name "Salve salve" } click_on "Update" visit spree.admin_promotions_path within_row(1) { click_icon :globe } - select2("pt-BR", from: 'Select Locale') + select2("pt-BR", from: 'Select locale') within("#attr_fields .name.pt-BR") do expect(page).to have_field(with: 'Salve salve') end @@ -182,13 +182,13 @@ within_row(1) { click_icon :globe } within("#attr_fields .name.en") { fill_in_name "Guitars" } - select2("pt-BR", from: 'Select Locale') + select2("pt-BR", from: 'Select locale') within("#attr_fields .name.pt-BR") { fill_in_name "Guitarras" } click_on "Update" visit spree.admin_taxonomies_path within_row(1) { click_icon :globe } - select2("pt-BR", from: 'Select Locale') + select2("pt-BR", from: 'Select locale') within("#attr_fields .name.pt-BR") do expect(page).to have_field(with: 'Guitarras') end @@ -203,7 +203,7 @@ visit spree.admin_translations_path('taxons', taxon.id) within("#attr_fields .name.en") { fill_in_name "Acoustic" } - select2("pt-BR", from: 'Select Locale') + select2("pt-BR", from: 'Select locale') within("#attr_fields .name.pt-BR") { fill_in_name "Acusticas" } click_on "Update" @@ -218,7 +218,7 @@ expect(taxonomy.root.children.count).to be(1) visit spree.admin_translations_path('taxons', taxon.id) - select2("pt-BR", from: 'Select Locale') + select2("pt-BR", from: 'Select locale') within("#attr_fields .name.pt-BR") do expect(page).to have_field(with: 'Acusticas') end @@ -229,13 +229,13 @@ it 'saves translated attributes properly' do visit spree.edit_admin_general_settings_path click_link I18n.t(:'spree.globalize.store_translations') - select2("pt-BR", from: 'Select Locale') + select2("pt-BR", from: 'Select locale') within("#attr_fields .name.pt-BR") { fill_in_name "nome store" } click_on "Update" visit spree.admin_translations_path('stores', store) - select2("pt-BR", from: 'Select Locale') + select2("pt-BR", from: 'Select locale') within("#attr_fields .name.pt-BR") do expect(page).to have_field(with: 'nome store') @@ -251,12 +251,12 @@ visit spree.admin_translations_path('shipping_methods', shipping_method.id) within("#attr_fields .name.en") { fill_in_name "Urgent elivery" } - select2("pt-BR", from: 'Select Locale') + select2("pt-BR", from: 'Select locale') within("#attr_fields .name.pt-BR") { fill_in_name "Entrega urgente" } click_on "Update" visit spree.admin_translations_path('shipping_methods', shipping_method.id) - select2("pt-BR", from: 'Select Locale') + select2("pt-BR", from: 'Select locale') within("#attr_fields .name.pt-BR") do expect(page).to have_field(with: 'Entrega urgente') end @@ -300,13 +300,13 @@ click_on "Translations" click_on "Name" - select2("pt-BR", from: 'Select Locale') + select2("pt-BR", from: 'Select locale') within("#attr_fields .name.pt-BR") { fill_in_name "Produtos" } click_on "Slug" select2("en", from: 'Select Locale') within("#attr_fields .slug.en") { fill_in_name "en_link" } - select2("pt-BR", from: 'Select Locale') + select2("pt-BR", from: 'Select locale') within("#attr_fields .slug.pt-BR") { fill_in_name "pt-BR_link" } click_on "Update" diff --git a/spec/features/translations_spec.rb b/spec/features/translations_spec.rb index 1e3fbf5..eedefaa 100644 --- a/spec/features/translations_spec.rb +++ b/spec/features/translations_spec.rb @@ -11,6 +11,10 @@ Spree::Product::Translation.new( locale: 'pt-BR', name: 'Antimatéria' + ), + Spree::Product::Translation.new( + locale: 'en', + name: 'Antimatter' ) ]) end From ceeeedb35f700cead3dd46470f0af3e3152540e0 Mon Sep 17 00:00:00 2001 From: Alberto Vena Date: Tue, 23 May 2023 13:06:50 +0200 Subject: [PATCH 10/19] Make Rubocop almost happy --- .rubocop.yml | 2 + .rubocop_todo.yml | 95 ++++++++++--------- ...9041407_add_translations_to_main_models.rb | 12 +-- ...7_add_translations_to_product_permalink.rb | 6 +- ...091000_add_translations_to_option_value.rb | 8 +- ..._translations_to_promotion_translations.rb | 8 +- ...30603_update_spree_product_translations.rb | 6 +- ..._add_translations_to_product_properties.rb | 8 +- ...15_add_deleted_at_to_translation_tables.rb | 8 +- ...0150323210949_add_translations_to_store.rb | 8 +- ...8162345_add_locale_to_friendly_id_slugs.rb | 8 +- .../install/install_generator.rb | 3 +- spec/features/admin/translations_spec.rb | 2 +- spec/models/product_spec.rb | 16 ++-- spec/support/shared_contexts/locales.rb | 4 +- 15 files changed, 102 insertions(+), 92 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index b075a8f..ed101eb 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,3 +1,5 @@ +inherit_from: .rubocop_todo.yml + require: - solidus_dev_support/rubocop diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 63dd4a9..b47d97e 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,33 +1,44 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2019-11-14 12:59:11 +0100 using RuboCop version 0.76.0. +# on 2023-05-23 11:06:18 UTC using RuboCop version 1.51.0. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. # Offense count: 1 -Lint/AmbiguousBlockAssociation: +Capybara/VisibilityMatcher: Exclude: - - 'spec/features/admin/translations_spec.rb' + - 'spec/features/admin/products_spec.rb' # Offense count: 1 -Lint/BooleanSymbol: +# Configuration parameters: Severity, Include. +# Include: **/*.gemspec +Gemspec/RequiredRubyVersion: Exclude: - - 'db/migrate/20191108162345_add_locale_to_friendly_id_slugs.rb' + - 'solidus_globalize.gemspec' -# Offense count: 3 -# Cop supports --auto-correct. -# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. -# URISchemes: http, https -Metrics/LineLength: - Max: 196 +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AllowForAlignment, AllowBeforeTrailingComments, ForceEqualSignAlignment. +Layout/ExtraSpacing: + Exclude: + - 'app/models/concerns/solidus_globalize/translatable.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AllowForAlignment, EnforcedStyleForExponentOperator. +# SupportedStylesForExponentOperator: space, no_space +Layout/SpaceAroundOperators: + Exclude: + - 'app/models/concerns/solidus_globalize/translatable.rb' -# Offense count: 18 -# Configuration parameters: Prefixes. +# Offense count: 20 +# Configuration parameters: Prefixes, AllowedPatterns. # Prefixes: when, with, without RSpec/ContextWording: Exclude: + - 'spec/controllers/spree/admin/translations_controller_spec.rb' - 'spec/controllers/spree/products_controller_spec.rb' - 'spec/features/admin/products_spec.rb' - 'spec/features/admin/translations_spec.rb' @@ -35,12 +46,15 @@ RSpec/ContextWording: - 'spec/models/product_spec.rb' - 'spec/support/shared_contexts/translatable_context.rb' -# Offense count: 3 -RSpec/DescribeClass: +# Offense count: 4 +# Configuration parameters: Include, CustomTransform, IgnoreMethods, SpecSuffixOnly. +# Include: **/*_spec*rb*, **/spec/**/* +RSpec/FilePath: Exclude: - - 'spec/features/admin/products_spec.rb' - - 'spec/features/admin/translations_spec.rb' - - 'spec/features/translations_spec.rb' + - 'spec/models/product_property_spec.rb' + - 'spec/models/product_spec.rb' + - 'spec/models/shipping_method_spec.rb' + - 'spec/models/taxon_spec.rb' # Offense count: 9 RSpec/LetSetup: @@ -50,13 +64,18 @@ RSpec/LetSetup: - 'spec/features/translations_spec.rb' - 'spec/models/taxon_spec.rb' -# Offense count: 9 -# Configuration parameters: AggregateFailuresByDefault. +# Offense count: 1 +RSpec/MultipleDescribes: + Exclude: + - 'spec/models/translated_models_spec.rb' + +# Offense count: 10 RSpec/MultipleExpectations: - Max: 3 + Max: 4 # Offense count: 2 -# Configuration parameters: IgnoreSharedExamples. +# Configuration parameters: EnforcedStyle, IgnoreSharedExamples. +# SupportedStyles: always, named_only RSpec/NamedSubject: Exclude: - 'spec/models/product_property_spec.rb' @@ -64,28 +83,14 @@ RSpec/NamedSubject: # Offense count: 1 # Configuration parameters: Include. -# Include: app/**/*.rb, config/**/*.rb, db/**/*.rb, lib/**/*.rb -Rails/Output: +# Include: db/migrate/*.rb +Rails/NotNullColumn: Exclude: - - 'lib/generators/solidus_globalize/install/install_generator.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: always, never -Style/FrozenStringLiteralComment: - Exclude: - - 'spec/support/shared_contexts/translatable_context.rb' + - 'db/migrate/20191108162345_add_locale_to_friendly_id_slugs.rb' -# Offense count: 8 -# Configuration parameters: MinBodyLength. -Style/GuardClause: - Exclude: - - 'db/migrate/20130419041407_add_translations_to_main_models.rb' - - 'db/migrate/20130518224827_add_translations_to_product_permalink.rb' - - 'db/migrate/20131009091000_add_translations_to_option_value.rb' - - 'db/migrate/20140206202524_rename_activator_translations_to_promotion_translations.rb' - - 'db/migrate/20140219130603_update_spree_product_translations.rb' - - 'db/migrate/20141112121313_add_translations_to_product_properties.rb' - - 'db/migrate/20150224152415_add_deleted_at_to_translation_tables.rb' - - 'db/migrate/20150323210949_add_translations_to_store.rb' +# Offense count: 2 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns. +# URISchemes: http, https +Layout/LineLength: + Max: 128 diff --git a/db/migrate/20130419041407_add_translations_to_main_models.rb b/db/migrate/20130419041407_add_translations_to_main_models.rb index e5e0dfd..b2c5581 100644 --- a/db/migrate/20130419041407_add_translations_to_main_models.rb +++ b/db/migrate/20130419041407_add_translations_to_main_models.rb @@ -27,12 +27,12 @@ def up Spree::Taxonomy.create_translation_table!({ name: :string }, migrate_data: true) end - unless table_exists?(:spree_taxon_translations) - params = { name: :string, description: :text, meta_title: :string, - meta_description: :string, meta_keywords: :string, - permalink: :string } - Spree::Taxon.create_translation_table!(params, migrate_data: true) - end + return if table_exists?(:spree_taxon_translations) + + params = { name: :string, description: :text, meta_title: :string, + meta_description: :string, meta_keywords: :string, + permalink: :string } + Spree::Taxon.create_translation_table!(params, migrate_data: true) end def down diff --git a/db/migrate/20130518224827_add_translations_to_product_permalink.rb b/db/migrate/20130518224827_add_translations_to_product_permalink.rb index 6ddaaa8..46ab749 100644 --- a/db/migrate/20130518224827_add_translations_to_product_permalink.rb +++ b/db/migrate/20130518224827_add_translations_to_product_permalink.rb @@ -8,9 +8,9 @@ def up { slug: :string } end - unless column_exists?(:spree_product_translations, fields.keys.first) - Spree::Product.add_translation_fields!(fields, migrate_data: true) - end + return if column_exists?(:spree_product_translations, fields.keys.first) + + Spree::Product.add_translation_fields!(fields, migrate_data: true) end def down; end diff --git a/db/migrate/20131009091000_add_translations_to_option_value.rb b/db/migrate/20131009091000_add_translations_to_option_value.rb index 4e66ff5..09dc7ff 100644 --- a/db/migrate/20131009091000_add_translations_to_option_value.rb +++ b/db/migrate/20131009091000_add_translations_to_option_value.rb @@ -2,10 +2,10 @@ class AddTranslationsToOptionValue < SolidusSupport::Migration[4.2] def up - unless table_exists?(:spree_option_value_translations) - params = { name: :string, presentation: :string } - Spree::OptionValue.create_translation_table!(params, migrate_data: true) - end + return if table_exists?(:spree_option_value_translations) + + params = { name: :string, presentation: :string } + Spree::OptionValue.create_translation_table!(params, migrate_data: true) end def down diff --git a/db/migrate/20140206202524_rename_activator_translations_to_promotion_translations.rb b/db/migrate/20140206202524_rename_activator_translations_to_promotion_translations.rb index f9e541e..ad5abe7 100644 --- a/db/migrate/20140206202524_rename_activator_translations_to_promotion_translations.rb +++ b/db/migrate/20140206202524_rename_activator_translations_to_promotion_translations.rb @@ -2,9 +2,9 @@ class RenameActivatorTranslationsToPromotionTranslations < SolidusSupport::Migration[4.2] def change - if table_exists? 'spree_activator_translations' - rename_table :spree_activator_translations, :spree_promotion_translations - rename_column :spree_promotion_translations, :spree_activator_id, :spree_promotion_id - end + return unless table_exists? 'spree_activator_translations' + + rename_table :spree_activator_translations, :spree_promotion_translations + rename_column :spree_promotion_translations, :spree_activator_id, :spree_promotion_id end end diff --git a/db/migrate/20140219130603_update_spree_product_translations.rb b/db/migrate/20140219130603_update_spree_product_translations.rb index 5d507bd..acff0ed 100644 --- a/db/migrate/20140219130603_update_spree_product_translations.rb +++ b/db/migrate/20140219130603_update_spree_product_translations.rb @@ -2,8 +2,8 @@ class UpdateSpreeProductTranslations < SolidusSupport::Migration[4.2] def change - if column_exists?(:spree_product_translations, :permalink) - rename_column :spree_product_translations, :permalink, :slug - end + return unless column_exists?(:spree_product_translations, :permalink) + + rename_column :spree_product_translations, :permalink, :slug end end diff --git a/db/migrate/20141112121313_add_translations_to_product_properties.rb b/db/migrate/20141112121313_add_translations_to_product_properties.rb index 5f4f893..5a6cdc5 100644 --- a/db/migrate/20141112121313_add_translations_to_product_properties.rb +++ b/db/migrate/20141112121313_add_translations_to_product_properties.rb @@ -2,10 +2,10 @@ class AddTranslationsToProductProperties < SolidusSupport::Migration[4.2] def up - unless table_exists?(:spree_product_property_translations) - params = { value: :string } - Spree::ProductProperty.create_translation_table!(params, migrate_data: true) - end + return if table_exists?(:spree_product_property_translations) + + params = { value: :string } + Spree::ProductProperty.create_translation_table!(params, migrate_data: true) end def down diff --git a/db/migrate/20150224152415_add_deleted_at_to_translation_tables.rb b/db/migrate/20150224152415_add_deleted_at_to_translation_tables.rb index 5f1f36c..71b8ba2 100644 --- a/db/migrate/20150224152415_add_deleted_at_to_translation_tables.rb +++ b/db/migrate/20150224152415_add_deleted_at_to_translation_tables.rb @@ -2,9 +2,9 @@ class AddDeletedAtToTranslationTables < SolidusSupport::Migration[4.2] def change - unless column_exists?(:spree_product_translations, :deleted_at) - add_column :spree_product_translations, :deleted_at, :datetime - add_index :spree_product_translations, :deleted_at - end + return if column_exists?(:spree_product_translations, :deleted_at) + + add_column :spree_product_translations, :deleted_at, :datetime + add_index :spree_product_translations, :deleted_at end end diff --git a/db/migrate/20150323210949_add_translations_to_store.rb b/db/migrate/20150323210949_add_translations_to_store.rb index 5a8507b..7d09e93 100644 --- a/db/migrate/20150323210949_add_translations_to_store.rb +++ b/db/migrate/20150323210949_add_translations_to_store.rb @@ -2,10 +2,10 @@ class AddTranslationsToStore < SolidusSupport::Migration[4.2] def up - unless table_exists?(:spree_store_translations) - params = { name: :string, meta_description: :text, meta_keywords: :text, seo_title: :string } - Spree::Store.create_translation_table!(params, migrate_data: true) - end + return if table_exists?(:spree_store_translations) + + params = { name: :string, meta_description: :text, meta_keywords: :text, seo_title: :string } + Spree::Store.create_translation_table!(params, migrate_data: true) end def down diff --git a/db/migrate/20191108162345_add_locale_to_friendly_id_slugs.rb b/db/migrate/20191108162345_add_locale_to_friendly_id_slugs.rb index 74387bf..fbb186a 100644 --- a/db/migrate/20191108162345_add_locale_to_friendly_id_slugs.rb +++ b/db/migrate/20191108162345_add_locale_to_friendly_id_slugs.rb @@ -2,12 +2,14 @@ class AddLocaleToFriendlyIdSlugs < SolidusSupport::Migration[4.2] def change - add_column :friendly_id_slugs, :locale, :string, length: 2, null: :false, after: :scope + add_column :friendly_id_slugs, :locale, :string, length: 2, null: false, after: :scope remove_index :friendly_id_slugs, [:slug, :sluggable_type] - add_index :friendly_id_slugs, [:slug, :sluggable_type, :locale], length: { slug: 140, sluggable_type: 50, locale: 2 } + add_index :friendly_id_slugs, [:slug, :sluggable_type, :locale], + length: { slug: 140, sluggable_type: 50, locale: 2 } remove_index :friendly_id_slugs, [:slug, :sluggable_type, :scope] - add_index :friendly_id_slugs, [:slug, :sluggable_type, :scope, :locale], length: { slug: 70, sluggable_type: 50, scope: 70, locale: 2 }, unique: true, name: :index_friendly_id_slugs_uniqueness + add_index :friendly_id_slugs, [:slug, :sluggable_type, :scope, :locale], + length: { slug: 70, sluggable_type: 50, scope: 70, locale: 2 }, unique: true, name: :index_friendly_id_slugs_uniqueness add_index :friendly_id_slugs, :locale end end diff --git a/lib/generators/solidus_globalize/install/install_generator.rb b/lib/generators/solidus_globalize/install/install_generator.rb index 7819661..b17463e 100644 --- a/lib/generators/solidus_globalize/install/install_generator.rb +++ b/lib/generators/solidus_globalize/install/install_generator.rb @@ -15,7 +15,8 @@ def add_migrations end def run_migrations - run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask('Would you like to run the migrations now? [Y/n]')) + run_migrations = options[:auto_run_migrations] || ['', 'y', + 'Y'].include?(ask('Would you like to run the migrations now? [Y/n]')) if run_migrations run 'bundle exec rake db:migrate' else diff --git a/spec/features/admin/translations_spec.rb b/spec/features/admin/translations_spec.rb index c71b917..f4749a6 100644 --- a/spec/features/admin/translations_spec.rb +++ b/spec/features/admin/translations_spec.rb @@ -212,7 +212,7 @@ # ensure we're not duplicating translated records on database expect { click_on "Update" - }.not_to change { taxon.translations.count } + }.not_to(change { taxon.translations.count }) # ensure taxon is in root or it will not be visible expect(taxonomy.root.children.count).to be(1) diff --git a/spec/models/product_spec.rb b/spec/models/product_spec.rb index d9e29ee..92ad690 100644 --- a/spec/models/product_spec.rb +++ b/spec/models/product_spec.rb @@ -36,20 +36,20 @@ module Spree it "with name" do product.translations.create locale: "zh-CN", - name: "创意马克杯", - description: "

一流工程师设计制造手工艺品

", - meta_description: '顶尖工艺设计', - meta_keywords: '工艺品' + name: "创意马克杯", + description: "

一流工程师设计制造手工艺品

", + meta_description: '顶尖工艺设计', + meta_keywords: '工艺品' expect(described_class.like_any([:name], ['创意'])).to include(product) end it "with name or description" do product.translations.create locale: "zh-CN", - name: "创意马克杯", - description: "

一流工程师设计制造手工艺品

", - meta_description: '顶尖工艺设计', - meta_keywords: '工艺品' + name: "创意马克杯", + description: "

一流工程师设计制造手工艺品

", + meta_description: '顶尖工艺设计', + meta_keywords: '工艺品' expect(described_class.like_any([:name, :description], ['手工艺品'])).to include(product) end diff --git a/spec/support/shared_contexts/locales.rb b/spec/support/shared_contexts/locales.rb index 200819d..218edf8 100644 --- a/spec/support/shared_contexts/locales.rb +++ b/spec/support/shared_contexts/locales.rb @@ -3,8 +3,8 @@ shared_context 'with pt-BR locale file in place' do before do I18n.backend.store_translations(:'pt-BR', spree: { - i18n: { this_file_language: "Português brasileiro" }, - }) + i18n: { this_file_language: "Português brasileiro" }, + }) end after do From 56af622b4df184a4620ab7c5c42165cebbc38ea7 Mon Sep 17 00:00:00 2001 From: Harmony Bouvier Date: Tue, 21 Jan 2025 13:56:42 -0800 Subject: [PATCH 11/19] Remove circleCI config that uses ruby 3.0 This is no longer available for any supported solidus version --- .circleci/config.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index c0e8865..e6ec045 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -33,7 +33,7 @@ jobs: lint-code: executor: name: solidusio_extensions/sqlite - ruby_version: "3.0" + ruby_version: "3.2" steps: - solidusio_extensions/lint-code @@ -48,10 +48,6 @@ workflows: name: *name matrix: parameters: { solidus: ["current"], ruby: ["3.1"], db: ["mysql"] } - - run-specs: - name: *name - matrix: - parameters: { solidus: ["older"], ruby: ["3.0"], db: ["sqlite"] } - lint-code "Weekly run specs against master": From cdacfa360534eefe10dcde2a60fee5d68c756af3 Mon Sep 17 00:00:00 2001 From: Harmony Bouvier Date: Tue, 21 Jan 2025 13:57:18 -0800 Subject: [PATCH 12/19] Define ransackable_ methods on ::Translation models After ransack v4, we need to declare these methods on the Translation model if they are ransackable associations. https://github.com/activeadmin/activeadmin/discussions/8033#discussioncomment-6564120 --- .../concerns/solidus_globalize/translatable.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/models/concerns/solidus_globalize/translatable.rb b/app/models/concerns/solidus_globalize/translatable.rb index 51a0684..0aaadc1 100644 --- a/app/models/concerns/solidus_globalize/translatable.rb +++ b/app/models/concerns/solidus_globalize/translatable.rb @@ -13,6 +13,18 @@ module Translatable klass.allowed_ransackable_associations ||= [] klass.allowed_ransackable_associations |= ['translations'] end + + klass.const_set("TranslationRansackable", Module.new).module_eval do + def ransackable_attributes(*_args) + authorizable_ransackable_attributes + end + + def ransackable_associations(*_args) + authorizable_ransackable_associations + end + + "#{klass}::Translation".constantize.singleton_class.prepend(self) + end end class_methods do From f3e1c43e80db14c6748180d2ead9672e8c0e6146 Mon Sep 17 00:00:00 2001 From: Harmony Bouvier Date: Tue, 21 Jan 2025 13:59:26 -0800 Subject: [PATCH 13/19] Change tests to use query param locale instead of route Routing translations is not directly supported by solidus globalize and the upstream dependency doesn not support rails 7. In order to test against newer versions of solidus, these tests are changed to use the query param instead. --- spec/features/admin/translations_spec.rb | 2 +- spec/features/translations_spec.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/features/admin/translations_spec.rb b/spec/features/admin/translations_spec.rb index f4749a6..53eaca5 100644 --- a/spec/features/admin/translations_spec.rb +++ b/spec/features/admin/translations_spec.rb @@ -314,7 +314,7 @@ visit spree.product_path 'en_link' expect(page).to have_text_like 'Product' - visit '/pt-BR/products/pt-BR_link' + visit '/products/pt-BR_link?locale=pt-BR' expect(page).to have_text_like 'Produtos' end end diff --git a/spec/features/translations_spec.rb b/spec/features/translations_spec.rb index eedefaa..57492cf 100644 --- a/spec/features/translations_spec.rb +++ b/spec/features/translations_spec.rb @@ -30,12 +30,12 @@ end it 'displays translated product page' do - visit '/pt-BR/products/antimatter' + visit '/products/antimatter?locale=pt-BR' expect(page.title).to have_content('Antimatéria') end it 'displays translated products list' do - visit '/pt-BR/products' + visit '/products?locale=pt-BR' expect(page).to have_content('Antimatéria') end end From caf31d363798d90258180f2a19b2fadcf27c6e4a Mon Sep 17 00:00:00 2001 From: Harmony Bouvier Date: Tue, 21 Jan 2025 14:00:43 -0800 Subject: [PATCH 14/19] Remove routing-filter This gem was only utilized in the test sandbox, but users are expected to configure locale routing themselves. Since this gem does not support rails 7. https://github.com/svenfuchs/routing-filter/pull/87 --- Gemfile | 1 - solidus_globalize.gemspec | 1 - spec/support/routing_filter.rb | 15 --------------- 3 files changed, 17 deletions(-) delete mode 100644 spec/support/routing_filter.rb diff --git a/Gemfile b/Gemfile index 33159b3..5f7f279 100644 --- a/Gemfile +++ b/Gemfile @@ -24,7 +24,6 @@ gem 'rails', '>0.a' # gem 'solidus_auth_devise' gem 'friendly_id-globalize', github: 'norman/friendly_id-globalize', branch: "master" -gem 'routing-filter' case ENV['DB'] when 'mysql' diff --git a/solidus_globalize.gemspec b/solidus_globalize.gemspec index 4bcfb73..e743dce 100644 --- a/solidus_globalize.gemspec +++ b/solidus_globalize.gemspec @@ -38,6 +38,5 @@ Gem::Specification.new do |s| s.add_development_dependency 'byebug' s.add_development_dependency 'pry-rails', '>= 0.3.0' - s.add_development_dependency 'routing-filter', '~> 0.6' s.add_development_dependency 'solidus_dev_support' end diff --git a/spec/support/routing_filter.rb b/spec/support/routing_filter.rb deleted file mode 100644 index 0c7be77..0000000 --- a/spec/support/routing_filter.rb +++ /dev/null @@ -1,15 +0,0 @@ -# frozen_string_literal: true - -require 'routing-filter' - -# In this support file we simulate how we want routes to be in a real -# host application that uses solidus_i18n and solidus_globalize. -RSpec.configure do |config| - config.before(:all) do - Rails.application.routes.draw do - filter :locale - - mount Spree::Core::Engine, at: '/' - end - end -end From 6db9f8e2baa09a84a802b881daeb2b32aea72cde Mon Sep 17 00:00:00 2001 From: Harmony Bouvier Date: Mon, 27 Jan 2025 15:08:41 -0800 Subject: [PATCH 15/19] Override serialize to support Rails 7.1 with Globalize 6 Globalize 6 provides an override for serialize that only suits the deprecated signature. This override is applied only if Rails is >= 7.1 and Globalize is < 7 Since globalize 6 does not support Rails 7.2, no handling of Globalize 6 with Rails 7.2 is needed. The override here is from Globalize v7.0.0 and will be modified in the next commit. --- lib/solidus_globalize.rb | 2 ++ .../serialization_rails_7_1_globalize_6.rb | 31 +++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 lib/solidus_globalize/serialization_rails_7_1_globalize_6.rb diff --git a/lib/solidus_globalize.rb b/lib/solidus_globalize.rb index d0e4d9e..3f756bd 100644 --- a/lib/solidus_globalize.rb +++ b/lib/solidus_globalize.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require 'solidus_globalize/serialization_rails_7_1_globalize_6' + require 'solidus_core' require 'solidus_support' diff --git a/lib/solidus_globalize/serialization_rails_7_1_globalize_6.rb b/lib/solidus_globalize/serialization_rails_7_1_globalize_6.rb new file mode 100644 index 0000000..fd8d02b --- /dev/null +++ b/lib/solidus_globalize/serialization_rails_7_1_globalize_6.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +require 'globalize' + +module SerializationRails71Globalize6 + def serialize(attr_name, class_name_or_coder = nil, **options) + self.globalize_serialized_attributes = globalize_serialized_attributes.dup + + if class_name_or_coder.nil? + globalize_serialized_attributes[attr_name] = options + + super(attr_name, **options) + elsif class_name_or_coder.is_a?(Hash) + globalize_serialized_attributes[attr_name] = class_name_or_coder + + # https://github.com/rails/rails/blob/7-2-stable/activerecord/lib/active_record/attribute_methods/serialization.rb#L183 + super(attr_name, **class_name_or_coder) + else + globalize_serialized_attributes[attr_name] = [class_name_or_coder, options] + + # this is only needed for ACTIVE_RECORD_71. class_name_or_coder will be removed with Rails 7.2 + # https://github.com/rails/rails/blob/7-1-stable/activerecord/lib/active_record/attribute_methods/serialization.rb#L183 + super(attr_name, class_name_or_coder, **options) + end + end + + if Rails.gem_version >= Gem::Version.new('7.1') && + Gem.loaded_specs["globalize"]&.version&.public_send(:<, "7") + Globalize::AttributeMethods::Serialization.prepend(self) + end +end From c8caf176426a45831c2d8948a7b7689ed852fb8d Mon Sep 17 00:00:00 2001 From: Harmony Bouvier Date: Mon, 27 Jan 2025 15:16:01 -0800 Subject: [PATCH 16/19] Always pass a class_name_or_coder param to super The Globalize 6 override that exists in the ancestor chain requires this value to be passed from :type. --- lib/solidus_globalize/serialization_rails_7_1_globalize_6.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/solidus_globalize/serialization_rails_7_1_globalize_6.rb b/lib/solidus_globalize/serialization_rails_7_1_globalize_6.rb index fd8d02b..e8a96b3 100644 --- a/lib/solidus_globalize/serialization_rails_7_1_globalize_6.rb +++ b/lib/solidus_globalize/serialization_rails_7_1_globalize_6.rb @@ -9,12 +9,12 @@ def serialize(attr_name, class_name_or_coder = nil, **options) if class_name_or_coder.nil? globalize_serialized_attributes[attr_name] = options - super(attr_name, **options) + super(attr_name, options[:type] || Object, **options) elsif class_name_or_coder.is_a?(Hash) globalize_serialized_attributes[attr_name] = class_name_or_coder # https://github.com/rails/rails/blob/7-2-stable/activerecord/lib/active_record/attribute_methods/serialization.rb#L183 - super(attr_name, **class_name_or_coder) + super(attr_name, class_name_or_coder[:type] || Object, **class_name_or_coder) else globalize_serialized_attributes[attr_name] = [class_name_or_coder, options] From 845c4b34d49a0e4d1cd5c01888070f070918b524 Mon Sep 17 00:00:00 2001 From: Graham Bouvier Date: Thu, 16 Sep 2021 16:27:30 -0700 Subject: [PATCH 17/19] Utilize configuration object for translatable fields Previously, translatable fields were hard-coded in the various decorators. With this change, they can be overridden with configuration in the client application using similar configuration patterns to other solidus extensions. --- .../spree/option_type_decorator.rb | 3 +- .../spree/option_value_decorator.rb | 3 +- .../spree/product_decorator.rb | 9 ++--- .../spree/product_property_decorator.rb | 3 +- .../spree/promotion_decorator.rb | 3 +- .../spree/property_decorator.rb | 3 +- .../spree/shipping_method_decorator.rb | 3 +- .../spree/store_decorator.rb | 7 ++-- .../spree/taxon_decorator.rb | 9 ++--- .../spree/taxonomy_decorator.rb | 3 +- lib/solidus_globalize/configuration.rb | 33 +++++++++++++++++++ 11 files changed, 53 insertions(+), 26 deletions(-) diff --git a/app/decorators/models/solidus_globalize/spree/option_type_decorator.rb b/app/decorators/models/solidus_globalize/spree/option_type_decorator.rb index dcf82d3..6028278 100644 --- a/app/decorators/models/solidus_globalize/spree/option_type_decorator.rb +++ b/app/decorators/models/solidus_globalize/spree/option_type_decorator.rb @@ -4,8 +4,9 @@ module SolidusGlobalize module Spree module OptionTypeDecorator def self.prepended(base) + translatable_fields = ::SolidusGlobalize::Config.translatable_fields[base.to_s] base.class_eval do - translates :name, :presentation, fallbacks_for_empty_translations: true + translates(*translatable_fields, fallbacks_for_empty_translations: true) include SolidusGlobalize::Translatable end end diff --git a/app/decorators/models/solidus_globalize/spree/option_value_decorator.rb b/app/decorators/models/solidus_globalize/spree/option_value_decorator.rb index 1d481c4..96d3471 100644 --- a/app/decorators/models/solidus_globalize/spree/option_value_decorator.rb +++ b/app/decorators/models/solidus_globalize/spree/option_value_decorator.rb @@ -4,8 +4,9 @@ module SolidusGlobalize module Spree module OptionValueDecorator def self.prepended(base) + translatable_fields = ::SolidusGlobalize::Config.translatable_fields[base.to_s] base.class_eval do - translates :name, :presentation, fallbacks_for_empty_translations: true + translates(*translatable_fields, fallbacks_for_empty_translations: true) include SolidusGlobalize::Translatable end end diff --git a/app/decorators/models/solidus_globalize/spree/product_decorator.rb b/app/decorators/models/solidus_globalize/spree/product_decorator.rb index 6a6cdc6..a060945 100644 --- a/app/decorators/models/solidus_globalize/spree/product_decorator.rb +++ b/app/decorators/models/solidus_globalize/spree/product_decorator.rb @@ -4,14 +4,9 @@ module SolidusGlobalize module Spree module ProductDecorator def self.prepended(base) + translatable_fields = ::SolidusGlobalize::Config.translatable_fields[base.to_s] base.class_eval do - translates :name, - :description, - :meta_description, - :meta_keywords, - :meta_title, - :slug, - fallbacks_for_empty_translations: true + translates(*translatable_fields, fallbacks_for_empty_translations: true) friendly_id :slug_candidates, use: [:history, :globalize] diff --git a/app/decorators/models/solidus_globalize/spree/product_property_decorator.rb b/app/decorators/models/solidus_globalize/spree/product_property_decorator.rb index 23ac283..806cc10 100644 --- a/app/decorators/models/solidus_globalize/spree/product_property_decorator.rb +++ b/app/decorators/models/solidus_globalize/spree/product_property_decorator.rb @@ -4,8 +4,9 @@ module SolidusGlobalize module Spree module ProductPropertyDecorator def self.prepended(base) + translatable_fields = ::SolidusGlobalize::Config.translatable_fields[base.to_s] base.class_eval do - translates :value, fallbacks_for_empty_translations: true + translates(*translatable_fields, fallbacks_for_empty_translations: true) include SolidusGlobalize::Translatable end end diff --git a/app/decorators/models/solidus_globalize/spree/promotion_decorator.rb b/app/decorators/models/solidus_globalize/spree/promotion_decorator.rb index 635f75e..f87ec7c 100644 --- a/app/decorators/models/solidus_globalize/spree/promotion_decorator.rb +++ b/app/decorators/models/solidus_globalize/spree/promotion_decorator.rb @@ -4,8 +4,9 @@ module SolidusGlobalize module Spree module PromotionDecorator def self.prepended(base) + translatable_fields = ::SolidusGlobalize::Config.translatable_fields[base.to_s] base.class_eval do - translates :name, :description, fallbacks_for_empty_translations: true + translates(*translatable_fields, fallbacks_for_empty_translations: true) include SolidusGlobalize::Translatable end end diff --git a/app/decorators/models/solidus_globalize/spree/property_decorator.rb b/app/decorators/models/solidus_globalize/spree/property_decorator.rb index 42dea7c..b51ac50 100644 --- a/app/decorators/models/solidus_globalize/spree/property_decorator.rb +++ b/app/decorators/models/solidus_globalize/spree/property_decorator.rb @@ -4,8 +4,9 @@ module SolidusGlobalize module Spree module PropertyDecorator def self.prepended(base) + translatable_fields = ::SolidusGlobalize::Config.translatable_fields[base.to_s] base.class_eval do - translates :name, :presentation, fallbacks_for_empty_translations: true + translates(*translatable_fields, fallbacks_for_empty_translations: true) include SolidusGlobalize::Translatable end end diff --git a/app/decorators/models/solidus_globalize/spree/shipping_method_decorator.rb b/app/decorators/models/solidus_globalize/spree/shipping_method_decorator.rb index b572415..d87d3bf 100644 --- a/app/decorators/models/solidus_globalize/spree/shipping_method_decorator.rb +++ b/app/decorators/models/solidus_globalize/spree/shipping_method_decorator.rb @@ -4,8 +4,9 @@ module SolidusGlobalize module Spree module ShippingMethodDecorator def self.prepended(base) + translatable_fields = ::SolidusGlobalize::Config.translatable_fields[base.to_s] base.class_eval do - translates :name, fallbacks_for_empty_translations: true + translates(*translatable_fields, fallbacks_for_empty_translations: true) include SolidusGlobalize::Translatable end end diff --git a/app/decorators/models/solidus_globalize/spree/store_decorator.rb b/app/decorators/models/solidus_globalize/spree/store_decorator.rb index fd7e8e2..b661bc5 100644 --- a/app/decorators/models/solidus_globalize/spree/store_decorator.rb +++ b/app/decorators/models/solidus_globalize/spree/store_decorator.rb @@ -4,12 +4,9 @@ module SolidusGlobalize module Spree module StoreDecorator def self.prepended(base) + translatable_fields = ::SolidusGlobalize::Config.translatable_fields[base.to_s] base.class_eval do - translates :name, - :meta_description, - :meta_keywords, - :seo_title, - fallbacks_for_empty_translations: true + translates(*translatable_fields, fallbacks_for_empty_translations: true) include SolidusGlobalize::Translatable end end diff --git a/app/decorators/models/solidus_globalize/spree/taxon_decorator.rb b/app/decorators/models/solidus_globalize/spree/taxon_decorator.rb index 5bda292..c9a256a 100644 --- a/app/decorators/models/solidus_globalize/spree/taxon_decorator.rb +++ b/app/decorators/models/solidus_globalize/spree/taxon_decorator.rb @@ -4,14 +4,9 @@ module SolidusGlobalize module Spree module TaxonDecorator def self.prepended(base) + translatable_fields = ::SolidusGlobalize::Config.translatable_fields[base.to_s] base.class_eval do - translates :name, - :description, - :meta_title, - :meta_description, - :meta_keywords, - :permalink, - fallbacks_for_empty_translations: true + translates(*translatable_fields, fallbacks_for_empty_translations: true) include SolidusGlobalize::Translatable end end diff --git a/app/decorators/models/solidus_globalize/spree/taxonomy_decorator.rb b/app/decorators/models/solidus_globalize/spree/taxonomy_decorator.rb index a11e696..c9edb12 100644 --- a/app/decorators/models/solidus_globalize/spree/taxonomy_decorator.rb +++ b/app/decorators/models/solidus_globalize/spree/taxonomy_decorator.rb @@ -4,8 +4,9 @@ module SolidusGlobalize module Spree module TaxonomyDecorator def self.prepended(base) + translatable_fields = ::SolidusGlobalize::Config.translatable_fields[base.to_s] base.class_eval do - translates :name, fallbacks_for_empty_translations: true + translates(*translatable_fields, fallbacks_for_empty_translations: true) include SolidusGlobalize::Translatable end end diff --git a/lib/solidus_globalize/configuration.rb b/lib/solidus_globalize/configuration.rb index a0cbe6a..bdd8b58 100644 --- a/lib/solidus_globalize/configuration.rb +++ b/lib/solidus_globalize/configuration.rb @@ -10,5 +10,38 @@ class Configuration < Spree::Preferences::Configuration # e.g. If available_locales are [:en, :es] admin can translate model records # to spanish as well. Once it's done :es can be added to supported_locales preference :supported_locales, :array, default: [:en] + + preference(:translatable_fields, :hash, + default: { + 'Spree::OptionType' => [:name, :presentation], + 'Spree::OptionValue' => [:name, :presentation], + 'Spree::Product' => [ + :name, + :description, + :meta_description, + :meta_keywords, + :meta_title, + :slug + ], + 'Spree::ProductProperty' => [:value], + 'Spree::Promotion' => [:name, :description], + 'Spree::Property' => [:name, :presentation], + 'Spree::ShippingMethod' => [:name], + 'Spree::Store' => [ + :name, + :meta_description, + :meta_keywords, + :seo_title + ], + 'Spree::Taxon' => [ + :name, + :description, + :meta_title, + :meta_description, + :meta_keywords, + :permalink + ], + 'Spree::Taxonomy' => [:name], + }) end end From 780056d937e7b6a4364b7c9c4623deb297871e93 Mon Sep 17 00:00:00 2001 From: Graham Bouvier Date: Thu, 16 Sep 2021 16:37:14 -0700 Subject: [PATCH 18/19] Add note to README explaining configuring translatable fields --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index a9b9d95..54e32ae 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,16 @@ into an initializer: SolidusGlobalize::Config.supported_locales = [:en, :'pt-BR'] ``` +Additionally, the translatable fields on individual models can be adjusted with configuration: + +```ruby +SolidusGlobalize::Config[:translatable_fields].merge!( + { + 'Spree::OptionValue' => [:presentation] + } +) +``` + **PS 1.** The languages you add to this configuration need to be supported by your store. This means that you need to have a transations file for them into `/config/locales/` (eg. `/config/locales/pt-BR.yml`). From 632711469b6c12fa41ce92fe00a811ce793457b3 Mon Sep 17 00:00:00 2001 From: Graham Bouvier Date: Tue, 28 Sep 2021 11:35:58 -0700 Subject: [PATCH 19/19] Don't use globalize friendly_id for slug unless slug is translatable --- .../models/solidus_globalize/spree/product_decorator.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/decorators/models/solidus_globalize/spree/product_decorator.rb b/app/decorators/models/solidus_globalize/spree/product_decorator.rb index a060945..ecdf9cc 100644 --- a/app/decorators/models/solidus_globalize/spree/product_decorator.rb +++ b/app/decorators/models/solidus_globalize/spree/product_decorator.rb @@ -8,7 +8,9 @@ def self.prepended(base) base.class_eval do translates(*translatable_fields, fallbacks_for_empty_translations: true) - friendly_id :slug_candidates, use: [:history, :globalize] + if translatable_fields.include?(:slug) + friendly_id :slug_candidates, use: [:history, :globalize] + end include SolidusGlobalize::Translatable