--- generate_toc: true --- import { CodeTabs, CodeTab, ChildDocs, Prerequisites, Table } from "docs-ui" export const metadata = { title: `Translation Module`, } # {metadata.title} 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. Refer to the [Medusa Admin User Guide](!user-guide!/settings/translations) to learn how to manage translations in the dashboard. Medusa has translation features available out-of-the-box through the Translation Module. A [module](!docs!/learn/fundamentals/modules) 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. Refer to the [Module Isolation](!docs!/learn/fundamentals/modules/isolation) guide to learn more about why modules are isolated. ## Translation Features - [Translation and Locale Management](./concepts/page.mdx): Manage locales and add translations for different resources in your store. - [Multi-Language Support](./storefront/page.mdx): Manage and serve resources like products in multiple languages to cater to a diverse customer base. - [Translation for Custom Models](./custom-data-models/page.mdx): 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: ```ts title="medusa-config.ts" module.exports = defineConfig({ // ... modules: [ // other modules... { resolve: "@medusajs/medusa/translation", }, ], featureFlags: { translation: true, }, }) ``` Then, run the following command to make the necessary database changes for the Translation Module: ```bash npx medusa db:migrate ``` 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](!docs!/learn/fundamentals/workflows), 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: export const highlights = [ ["12", "Modules.TRANSLATION", "Resolve the module in a step."] ] ```ts title="src/workflows/create-translation.ts" highlights={highlights} import { createWorkflow, WorkflowResponse, createStep, StepResponse, } from "@medusajs/framework/workflows-sdk" import { Modules } from "@medusajs/framework/utils" const createTranslationStep = createStep( "create-translation", async ({}, { container }) => { const translationModuleService = container.resolve(Modules.TRANSLATION) const translation = await translationModuleService.createTranslations({ reference_id: "product_123", reference: "product", locale_code: "fr-FR", translations: { title: "Produit Exemple", description: "Ceci est une description en français.", }, }) return new StepResponse({ translation }, translation.id) }, async (translationId, { container }) => { const translationModuleService = container.resolve(Modules.TRANSLATION) await translationModuleService.deleteTranslations([translationId]) } ) export const createTranslationWorkflow = createWorkflow( "create-translation", () => { const { translation } = createTranslationStep() return new WorkflowResponse({ translation, }) } ) ``` You can then execute the workflow in your custom API routes, scheduled jobs, or subscribers: ```ts title="src/api/workflow/route.ts" highlights={[["11"], ["12"]]} collapsibleLines="1-6" expandButtonLabel="Show Imports" import type { MedusaRequest, MedusaResponse, } from "@medusajs/framework/http" import { createTranslationWorkflow } from "../../workflows/create-translation" export async function GET( req: MedusaRequest, res: MedusaResponse ) { const { result } = await createTranslationWorkflow(req.scope) .run() res.send(result) } ``` ```ts title="src/subscribers/user-created.ts" highlights={[["11"], ["12"]]} collapsibleLines="1-6" expandButtonLabel="Show Imports" import { type SubscriberConfig, type SubscriberArgs, } from "@medusajs/framework" import { createTranslationWorkflow } from "../workflows/create-translation" export default async function handleUserCreated({ event: { data }, container, }: SubscriberArgs<{ id: string }>) { const { result } = await createTranslationWorkflow(container) .run() console.log(result) } export const config: SubscriberConfig = { event: "user.created", } ``` ```ts title="src/jobs/run-daily.ts" highlights={[["7"], ["8"]]} import { MedusaContainer } from "@medusajs/framework/types" import { createTranslationWorkflow } from "../workflows/create-translation" export default async function myCustomJob( container: MedusaContainer ) { const { result } = await createTranslationWorkflow(container) .run() console.log(result) } export const config = { name: "run-once-a-day", schedule: `0 0 * * *`, } ``` Refer to the [Workflows](!docs!/learn/fundamentals/workflows) documentation to learn more. --- ## Supported Module Translations The Translation Module currently supports translations for the following data models: Data Model Translatable Fields `CustomerGroup` ([Customer Module](../customer/page.mdx)) ([+v2.12.4](https://github.com/medusajs/medusa/releases/tag/v2.12.4)) `name` `Product` ([Product Module](../product/page.mdx)) - `title` - `description` - `material` - `subtitle` `ProductCategory` ([Product Module](../product/page.mdx)) - `name` - `description` `ProductCollection` ([Product Module](../product/page.mdx)) `title` `ProductOption` ([Product Module](../product/page.mdx)) `title` `ProductOptionValue` ([Product Module](../product/page.mdx)) `value` `ProductTag` ([Product Module](../product/page.mdx)) `value` `ProductType` ([Product Module](../product/page.mdx)) `value` `ProductVariant` ([Product Module](../product/page.mdx)) - `title` - `material` `Region` ([Region Module](../region/page.mdx)) ([+v2.12.4](https://github.com/medusajs/medusa/releases/tag/v2.12.4)) `name` `ShippingOption` ([Fulfillment Module](../fulfillment/page.mdx)) ([+v2.12.4](https://github.com/medusajs/medusa/releases/tag/v2.12.4)) `name` `ShippingOptionType` ([Fulfillment Module](../fulfillment/page.mdx)) ([+v2.12.4](https://github.com/medusajs/medusa/releases/tag/v2.12.4)) - `label` - `description` `TaxRate` ([Tax Module](../tax/page.mdx)) ([+v2.12.4](https://github.com/medusajs/medusa/releases/tag/v2.12.4)) `name`
Future versions of the Translation Module will include support for all Commerce Modules. ---