mrbrdo / spree_mobility

BSD 3-Clause "New" or "Revised" License
2 stars 1 forks source link

Spree Mobility

This is a Spree model translation gem based on spree_globalize for Spree Commerce version 4.3+. It uses mobility instead of globalize, since globalize is not actively developed anymore. It is a drop-in replacement for spree_globalize and will use your existing translations.

Currently, this gem is tested with Spree 4.3.1. Since version 1.3, it should also work with Spree 4.4.

Upgrading

Re-run bin/rails g spree_mobility:install to add new migrations.

Installation

Add the following to your Gemfile:

gem 'spree_i18n', '~> 5.0' # remove any existing spree_i18n in Gemfile
gem 'friendly_id-mobility', git: 'https://github.com/mrbrdo/friendly_id-mobility', branch: 'master'
gem 'mobility', git: 'https://github.com/mrbrdo/mobility', branch: 'mrbrdo'
gem 'spree_mobility'

Make sure this gem is above any payment method gems and plugins in your Gemfile.

Run bundle install

You can use the generator to install migrations and append spree_mobility assets to your app spree manifest file.

bin/rails g spree_mobility:install

It is also recommended to configure Mobility fallback locales, especially if your admin locale is not the same as your Store's default_locale. For example if you have en and de locale:

# config/initializers/mobility.rb
Mobility.configure do
  plugins do
    fallbacks({ :en => [:de], :de => [:en] })
  end
end

Spree 4.3.x

There is a bug with Spree.ready in Spree 4.3.x, as it hooks into Turbolinks, but Turbolinks is not used in the backend. Due to this some translation links in the admin won't work out of the box. To fix this, add to the bottom of vendor/assets/javascripts/spree/backend/all.js:

# vendor/assets/javascripts/spree/backend/all.js
$(window).on('load', function() { $(document).trigger('page:load'); });

Improvements over spree_globalize

This gem offers several improvements over spree_globalize:

Admin:

For more localization features, see my better_spree_localization gem.

Model Translations

This feature uses the Mobility gem to localize model data. So far the following models are translatable:

Product, Promotion, OptionType, Taxonomy, Taxon, Property, Store, ShippingMethod and PaymentMethod.

Start your server and you should see a TRANSLATIONS link or a flag icon on each admin section that supports this feature.

Every record needs to have a translation. If by any chance you remove spree_mobility from your Gemfile, add some records and then add spree_mobility gem back you might get errors like undefined method for nilClass because Mobility will try fetch translations that do not exist.


Contributing

See corresponding guidelines


Copyright (c) 2010-2022 MrBrdo. released under the New BSD License