Spree Commerce

Try It Now

Model Translations in Spree internationalization

Posted on May 27, 2013 by Washington L Braga Jr

Coming with the Spree 2.0 release is a brand new version of the Spree internationalization project (spree_i18n). The extension now makes use of the awesome globalize3 gem to allow users to translate records on the main models of a Spree shop.

Currently the following models are supported: Product, Promotion, Property, OptionType, Taxonomy and Taxon. You should see a flag icon on each admin section that supports the feature. Adding a translation to a product name or description is as easy as fill in the fields and submit the form.

The extension also makes good use of globalize3 fallbacks feature. It allows the system to always display content no matter what language the user is viewing the store. If a user is navigating a store in spanish and a product description is not available on that language the app will display the default english translation or whatever content exists for that product description. By the default it searches for translations on the current locale, then on the default and goes on to other locales if available. The idea is never show users a blank page even if there’s no translated record content for the locale they set on the store.

Store managers can control which languages are available to front end users and which should be displayed on the back end translations form inputs through the supported_locales and available_locales configurations respectively. The extension currently includes spree translations for 39 languages. All are listed as options on the Available Locale select box in General Settings section.

The current locale on the store is set through a :locale key on the Rails session object. When using the built in Spree core UI you should see a select box next to the cart link. It sure should be easy enough to customize that to your needs on your Spree store layout.

Check out the README file on the repo for installation instructions and more configuration details. We’re looking forward to getting your feedback!

blog comments powered by Disqus