DEV Community

Cover image for 🌍 Scaling Globally with Spree? Here's How to Automate Translations (Using DeepL + 1 Line of Code)
Chris Yaowen Zhang for Upside

Posted on

🌍 Scaling Globally with Spree? Here's How to Automate Translations (Using DeepL + 1 Line of Code)

Manually translating product catalogs? Not only is it tedious — it slows down your entire international expansion.

The good news? With Spree 4.6 and a new gem called spree_automation_interfaces, you can plug in translation tools like DeepL and have your products auto-translated with the click of a button.

Let me show you how we got it working in under 20 minutes.

đź›’ Problem: Spree supports translations, but the process is still manual

Spree’s backend already allows you to manage product translations across multiple locales. But historically, companies relied on exporting CSVs → emailing translators → re-importing the files — a messy, slow, error-prone loop.

Even with tools like Google Translate or DeepL, manual copy-paste just doesn't scale.

So we decided to automate the process, while still keeping room for human review.

đź”§ Solution: Spree Automation Interfaces + DeepL

As a part of supporting Spree users, we at Upside published spree_automation_interfaces that lets you connect automated translation services directly to your Spree store.

In this guide, we’ll show you how to:

  1. Set up your store for multiple languages (French & German)
  2. Plug in DeepL using a custom provider
  3. Add an “Auto-Translate” button inside your admin panel

Step 1: Enable Multiple Languages in Spree
(You can skip this if your store already supports multiple locales)

  1. In the Spree Admin Panel, go to Settings → Store in the sidebar to the left.
  2. You will see a list of "Supported Locales". For the purpose of this guide, we'll add set up additional locales: French and German.

  1. Click Update.
  2. 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.

Step 2: Add the Right Gems
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
gem 'spree_automation_interfaces', github: 'spree-contrib/spree_automation_interfaces'
gem 'deface'
gem 'deepl-rb', require: 'deepl'
Enter fullscreen mode Exit fullscreen mode

Then run:

bundle install
Enter fullscreen mode Exit fullscreen mode

And restart your development server.

Step 3: Implement the DeepL Translations Provider

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:

module Spree
  module Products
    module Translations
      interface _AutomatedTranslationsProvider
        def call: (source_attributes: Hash[String, String], source_locale: String, target_locale: String) -> Hash[Symbol | String, String]
      end
    end
  end
end
Enter fullscreen mode Exit fullscreen mode

Let's create an implementation in app/services/spree/translations/deepl_translations_provider.rb

module Spree
  module Translations
    class DeeplTranslationsProvider
      def call(source_attributes:, source_locale:, target_locale:)
        name = source_attributes['name']
        description = source_attributes['description']
        translated_name, translated_description = DeepL.translate([name, description], nil, target_locale)
        {
          'name' => translated_name,
          'description' => translated_description
        }
      end
    end
  end
end
Enter fullscreen mode Exit fullscreen mode

Step 4: Initialize DeepL Client
We also need to initialize DeepL's client. Let's create the following initializer config/initalizers/deepl.rb

DeepL.configure do |config|
  config.host = ENV.fetch('DEEPL_HOST', 'https://api-free.deepl.com')
  config.auth_key = ENV.fetch('DEEPL_API_KEY')
end
Enter fullscreen mode Exit fullscreen mode

Step 5: Plug Your Provider into Spree

Finally, configure Spree to use the provider we've just created

In config/initializers/spree_automation_interfaces.rb

Rails.application.config.after_initialize do  
  SpreeAutomationInterfaces::Dependencies.products_automated_translations_provider = 'Spree::Translations::DeeplTranslationsProvider'
end
Enter fullscreen mode Exit fullscreen mode

Step 6: Try It!
Head to any product’s Translations tab in the admin panel.

You’ll see a new button: “Translate automatically”

Once you click it, it will fetch translations using the provider we've just implemented and add them to the product.

Bonus: Go Further with Sidekiq or API Triggers

This interface also works programmatically, so you can:

  • Trigger translations from code
  • Run a background job to translate your entire catalog
  • Schedule daily translation syncs

For example, you could build a Sidekiq worker that batches and translates 10,000 SKUs overnight.

Top comments (0)