We recommend upgrading straight to 4.8, as we improved how we handle translations in 4.8. This also means easier database migration, especially if you have a big product catalog.

If you’re on an older version than 4.5 please follow previous upgrade guides and perform those upgrades incrementally, e.g.

  1. upgrade 4.2 to 4.3
  2. upgrade 4.3 to 4.4
  3. upgrade 4.4 to 4.5

Update gems

Run the following command to update your gems to 4.6:

bundle update

(Optional) Remove spree_globalize

If your application used the spree_globalize extension, you can remove it from your Gemfile, as translations are now supported out-of-the-box with the Mobility gem.

We’ve configured Mobility to use a strategy that uses a separate table to store translations, just like how spree_globalize did. This means, you won’t need to make any changes to the database structure or migrate data.

During the upgrade process, you may need to review your custom queries that rely on translations, as there are minor differences in how Mobility handles them. Spree 4.6 includes a few built-in concerns to make it easier to work with translatable models.

Run the following command to remove spree_globalize from your Gemfile:

bundle remove spree_globalize

Install missing migrations

bin/rake railties:install:migrations

Run migrations

bin/rails db:migrate

If you didn’t use spree_globalize before, this will install migrations that move some columns from spree_products, spree_taxons, to dedicated translation tables such as spree_products_translations, spree_taxons_translations etc.

If you’re using raw SQL queries (either in the application code, or running in external tools), you may need to review the new structure and update your queries accordingly.

Run install generators

This will copy some files from spree_backend to your application.

bin/rails g spree:backend:install

If you’re using spree_frontend you need to run the frontend install generator as well:

bin/rails g spree:frontend:install

Additional fixes and hints

Update migrations for translation tables with additional columns

If you want to translate more fields in translated resources, you have to alter copied migrations or add new ones. We’re using the Spree::TranslationMigrations to help with migrating data.

Add or update the behavior of the translated model

Each translated resource has a corresponding Translation model, see here for reference. If you want to add some more behavior to the translation, you need to do it within the Translation.class_eval block.

If you overwrote Spree models in your application, you have to define this block yourself. Apart from that, please include these modules:

  • Spree::TranslatableResource - required for all translated models
  • Spree::TranslatableResourceSlug - required for translated models with slugs/permalinks

Read more how Spree handles resource translations.

Generating slugs with friendly_id

Generating slugs/permalinks in Spree::Product and Spree::Taxon models is now based on the translated name. If you use the history plugin, read on how to use it with the mobility gem.

Resource translations and encryption

Currently, it’s not possible to translate encrypted data. If you’re already encrypting data that Spree translates, you need to remove that functionality.

Full text search with pg_search scopes

If you use the pg_search for the full text search in translated resources, you need to move your scopes to the translated model, eg. from the Spree::Product to the Spree::Product::Translation.

If you still want to have the original scope, you need to rewrite it, from:

pg_search_scope :search_by_name, against: :name

to:

self::Translation.class_eval do
  include PgSearch::Model
  pg_search_scope :search_by_name, against: :name
end

scope :search_by_name, lambda { |query|
  product_ids = Spree::Product::Translation.search_by_name(query).pluck(:spree_product_id)
  where(id: product_ids)
}

Read the release notes

For information about changes contained within this release, please read the Spree 4.6.0 Release Notes.