1 ---
2 products:
3 - store
4 - product
5 - cart
6 ---
7
8 import { Prerequisites, CodeTabs } from "docs-ui"
9
10 export const metadata = {
11 title: `Serve Translations in the Storefront`,
12 }
13
14 # {metadata.title}
15
16 In this guide, you’ll learn how to use locales and serve translated content in your storefront application in your Medusa application.
17
18 <Prerequisites
19 items={[
20 {
21 text: "Translation Module Configured",
22 link: "/commerce-modules/translation#configure-translation-module",
23 },
24 ]}
25 />
26
27 ## Fetch Store Locales
28
29 You can retrieve the list of locales available in your store using the [List Locales Store API route](!api!/store/locales/list-locales). You can display this list to customers, allowing them to select their preferred language.
30
31 For example, to fetch the list of locales, send a `GET` request to the following endpoint:
32
33 ```bash
34 curl "http://localhost:9000/store/locales" \
35 -H 'x-publishable-api-key: {your_publishable_api_key}'
36 ```
37
38 Learn more in the [Localization](../../../storefront-development/localization/page.mdx) storefront guide.
39
40 <Note title="Tip">
41
42 You must pass a publishable API key in the request header to store API routes. Learn more in the [Store API reference](!api!/store/publishable-api-key).
43
44 </Note>
45
46 ---
47
48 ## Retrieve Translations for Resources
49
50 You can retrieve translations using the [Store API routes](!api!/store) for [supported](../page.mdx#supported-module-translations) and [custom](../custom-data-models/page.mdx) data models. Future releases will expand translation support to additional resources.
51
52 Medusa determines the locale for the request in the following order of priority:
53
54 - The `locale` query parameter in the API request.
55 - The `x-medusa-locale` header in the API request.
56
57 If translations aren't available for the selected locale, or no locale is selected, the original content stored in the resource's data model is returned.
58
59 For example, to retrieve products with translations in French (France):
60
61 ```bash
62 curl "http://localhost:9000/store/products?locale=fr-FR" \
63 -H 'x-publishable-api-key: {your_publishable_api_key}'
64 ```
65
66 This returns the list of products with their French (France) translations if available:
67
68 ```json
69 {
70 "products": [
71 {
72 "id": "prod_123",
73 "title": "Produit Exemple",
74 "description": "Ceci est une description en français.",
75 // other product fields...
76 },
77 // other products...
78 ]
79 }
80 ```
81
82 Learn more in the [List Products](../../../storefront-development/products/list/page.mdx#retrieve-translations-for-products) storefront guide.
83
84 ---
85
86 ## Set a Cart's Locale
87
88 A cart can have a locale, which determines the language of the item contents. You can set the locale when creating the cart and update it if the user changes their language preference.
89
90 For example, when creating a cart, set the `locale` property in the request body:
91
92 ```bash
93 curl -X POST "http://localhost:9000/store/carts" \
94 -H 'x-publishable-api-key: {your_publishable_api_key}' \
95 -H "Content-Type: application/json" \
96 -d '{
97 // other cart properties...
98 "locale": "fr-FR"
99 }'
100 ```
101
102 This creates a cart with the French (France) locale. When you add items to the cart, their titles and descriptions are displayed in French if translations are available.
103
104 If you don't specify a locale when creating the cart, the original product content is used for the items in the cart.
105
106 Learn more in the [Create Cart](../../../storefront-development/cart/create/page.mdx) and [Update Cart](../../../storefront-development/cart/update/page.mdx) storefront guides.
107
108 ---
109
110 ## Locale of Placed Order
111
112 When a cart is completed and an order is placed, the locale of the cart is copied to the order. The content of items in the order is displayed in the locale that was set in the cart.
113
114 This ensures that customers see order details in their preferred language.