Medusa V2 Plugin to easily add translations to your models with Tolgee Integration
This plugin integrates Medusa eCommerce with Tolgee, an open-source localization platform, to provide an easy translation management solution. It's designed to simplify product data translation without the need for complex CMS or PIM systems. By leveraging Tolgee, users access powerful localization features directly within their Medusa admin panel.
Key Features of Tolgee
Tolgee is all about making the translation process as simple as possible. For more details on the extensive capabilities of Tolgee, visit their official website: Tolgee.io
| Model | Status |
|---|---|
| Products | ✅ |
| Product collections | ✅ |
| Product categories | ✅ |
| Product variants | ✅ |
| Product options | ✅ |
| Product types | ✅ |
| Product tags | ✅ |
| Shipping options | ✅ |
| Feature | Status |
|---|---|
| Admin widget to manage translations | ✅ |
| Add translation | ✅ |
| Sync all model instances with Tolgee | ✅ |
| Automatically add translations when instance is added | ✅ |
| Automatically remove translations when instance is removed | ✅ |
| Support for custom model attributes | ✅ |
Before configuring the Medusa plugin, ensure your Tolgee project is ready. You can either set up an open-source version of Tolgee on your own infrastructure or opt for the managed cloud version offered by Tolgee. Obtain your project ID from the project's dashboard URL (e.g., ).
npm install medusa-plugin-tolgee
or
yarn add medusa-plugin-tolgee
Once your Tolgee project is set up, add the plugin configuration to your Medusa store by modifying the file. Here's what you need to include:
import { TolgeeModuleConfig } from 'medusa-plugin-tolgee'const plugins = [{resolve: `medusa-plugin-tolgee`,options: {baseURL: process.env.TOLGEE_API_URL,apiKey: process.env.TOLGEE_API_KEY,projectId: "your_tolgee_project_id",keys: { // Optionalproduct: ["title", "subtitle", "description"]},tags: { // Optionalproduct: ["custom_tag"]}} satisfies TolgeeModuleConfig,},];
Configuration options:
TOLGEE_API_URL=your_tolgee_app_urlTOLGEE_API_KEY=your_tolgee_api_key
Explanation of Variables
After configuring your environment variables and setting up the plugin, it's time to synchronize your data with Tolgee to enable translations across your e-commerce platform. Here's how to complete the synchronization process and start translating your models:
Restart Medusa: First, ensure that all your changes are saved, then restart your Medusa server to apply the new configuration settings. This ensures that all components are loaded correctly, including the newly configured translation management plugin.
Access the Translations Section: Navigate to the edit page for a model within your Medusa admin panel, for example a product. Here's what you need to do:
Scroll to the Translations Section: On the edit page, scroll down until you find a new section labeled "Translations". This section is added by the plugin and provides the tools necessary for managing translations.
Initiate the Sync Process: Click on the "Sync all" button. This action triggers a workflow that communicates with Tolgee to create translations for all existing instances of the same model (for example all products, but not also categories, shipping options etc).
Wait for Completion: After clicking the sync button, the process may take some time depending on the number of entities and the complexity of the translations.
Congratulations! Your configuration is now complete, and you can start translating all of your models. 🎉
If you want to translate a word, press the ALT button and click on the word in the Value column.
Medusa link: All supported models have been augmented with a linked property. You can retrieve translations for a specific language or all languages by adding respectively or to your query's property. For example:
const translationsField = countryCode ? `,+translations.${countryCode},+options.translations.${countryCode},+options.values.translations.${countryCode}` : ""sdk.client.fetch<{ products: StoreProductWithTranslations[]; count: number }>(`/store/products`,{method: "GET",query: {limit,offset,region_id: region?.id,fields:`...,+metadata,+tags${translationsField}`, // <----...queryParams,},headers,next,cache: "force-cache",}).then(({ products, count }) => {const nextPage = count > offset + limit ? pageParam + 1 : nullreturn {response: {products: products.map((product) => ({...product,// assign the translations for the desired language directly to the product// so that the country code is not needed anymoreoptions: product.options?.map((option) => ({...option,translations: countryCode ? option.translations?.[countryCode] : undefined,values: option.values?.map(value => ({...value,translations: countryCode ? value.translations?.[countryCode] : undefined,}))})),translations: countryCode ? product.translations?.[countryCode] : undefined,})),count,},nextPage: nextPage,queryParams,}})
Note: the store API endpoint for shipping options ignores query fields. For now, you can use the custom endpoint below, which accepts the country code as a query parameter.
sdk.client.fetch<HttpTypes.StoreShippingOptionListResponse>(`/store/shipping-options/tolgee`,{method: "GET",query: { cart_id: cartId, country_code: countryCode },headers,next,cache: "force-cache",}).then(({ shipping_options }) => shipping_options).catch(() => {return null})
Tolgee hook: You can also directly use the hook provided by Tolgee. See more info
Licensed under the MIT License.