One of the main goals of Spree 4.6, was allowing its users to scale globally. A common challenge in global expansion is providing localized content for multiple languages. While Spree's data model supports product catalogue translations out of the box, there's still a great amount of work required to prepare the actual translations. For a long time, a common approach was to coordinate the process with translation agencies and use mechanisms of import-export to mvoe the translations data around. This has however changed in the recent years, by the improvements in automated translation tools. We're seeing more and more companies taking a more efficient approach of automatically translating their content, and using a translator to proofread and correct the automated translations.
As a part of supporting Spree users, we've recently published a package called Spree Automation Interfaces that makes it easier to implement such automatons on top of Spree.
In this blog post, we will show how to use it to enable automated translations with DeepL.
(You can skip this step if your store setup already enabled additional multiple locales).
First, let's go to the Spree admin panel and select Settings -> Store in the sidebar to the left.
In the
You will see a list of "Supported Locales". For the purpose of this guide, we'll add set up additional locales: French and German.
After that, press "Update" at the bottom to save the configuration.
To confirm that the setup works correctly, navigate to a product in the admin panel, and go to its "Translations" tab. You should see a table for filling additional translations - this means that the setup is correct.
At this point, you can provide the translations manually. It's time to automate the process.
We need to add the following gems:
- spree_automation_interfaces - that brings the capability of automated translations into Spree
- deface - to allow spree_automation_interfaces to add new features to the admin panel
- deepl-rb - which we will use as a translations provider
After that run:
And restart your development server.
Now, we need to provide an implementation for the Automation Interfaces, that will be called by Spree when the user requests translations to be created.
The required interface is defined as follows:
Let's create an implementation in app/services/spree/translations/deepl_translations_provider.rb
We also need to initialize DeepL's client. Let's create the following initializer config/initalizers/deepl.rb
Finally, configure Spree to use the provider we've just created
In config/initializers/spree_automation_interfaces.rb
If you now go to the products translations page, you will see a "Translate automatically" button at the top.
Once you click it, it will fetch translations using the provider we've just implemented and add them to the product.
This is just a sample use case of the automation interfaces. The gem also provides a set of APIs for triggering automated translations, as well as additional interfaces for triggering automated translations from the code. This may be a good starting point if you'd like to e.g. write a custom Sidekiq worker that will translate all the products in your catalogue.