Translation Module
In this section of the documentation, you will find resources to learn more about the Translation Module and how to use it in your application.
Medusa has translation features available out-of-the-box through the Translation Module. A module is a standalone package that provides features for a single domain. Each of Medusa's commerce features is provided in Commerce Modules, such as the Translation Module.
Translation Features#
- Translation and Locale Management: Manage locales and add translations for different resources in your store.
- Multi-Language Support: Manage and serve resources like products in multiple languages to cater to a diverse customer base.
- Translation for Custom Models: Extend translation capabilities to custom data models in your Medusa application.
Configure Translation Module#
The Translation Module is currently behind a feature flag. To use it in your Medusa application, add it to the modules array and enable the translation feature flag.
In your medusa-config.ts file, add the Translation Module to the modules array and enable the translation feature flag:
Then, run the following command to make the necessary database changes for the Translation Module:
You can then use the Translation Module in your Medusa application.
How to Use the Translation Module#
In your Medusa application, you build flows around Commerce Modules. A flow is built as a Workflow, which is a special function composed of a series of steps that guarantees data consistency and a reliable rollback mechanism.
You can build custom workflows and steps. You can also re-use Medusa's workflows and steps, which are provided by the @medusajs/medusa/core-flows package.
For example:
1import { 2 createWorkflow, 3 WorkflowResponse,4 createStep,5 StepResponse,6} from "@medusajs/framework/workflows-sdk"7import { Modules } from "@medusajs/framework/utils"8 9const createTranslationStep = createStep(10 "create-translation",11 async ({}, { container }) => {12 const translationModuleService = container.resolve(Modules.TRANSLATION)13 14 const translation = await translationModuleService.createTranslations({15 reference_id: "product_123",16 reference: "product",17 locale_code: "fr-FR",18 translations: {19 title: "Produit Exemple",20 description: "Ceci est une description en français.",21 },22 })23 24 return new StepResponse({ translation }, translation.id)25 },26 async (translationId, { container }) => {27 const translationModuleService = container.resolve(Modules.TRANSLATION)28 29 await translationModuleService.deleteTranslations([translationId])30 }31)32 33export const createTranslationWorkflow = createWorkflow(34 "create-translation",35 () => {36 const { translation } = createTranslationStep()37 38 return new WorkflowResponse({39 translation,40 })41 }42)
You can then execute the workflow in your custom API routes, scheduled jobs, or subscribers:
Refer to the Workflows documentation to learn more.
Supported Module Translations#
The Translation Module currently supports translations for the following data models:
Data Model | Translatable Fields |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Future versions of the Translation Module will include support for all Commerce Modules.