docs: translation module (#14271)

* docs: translation module

* fix link in JS SDK

* add translations user guides [WIP]

* updates

* fix broken link

* remove mentions of default locale

* change header

* updates

* updated user guides

* handle todos

* fix build error

* fix lint errors
This commit is contained in:
Shahed Nasser
2025-12-17 13:07:43 +02:00
committed by GitHub
parent 1743ed7f04
commit c1a5390fc6
133 changed files with 21304 additions and 1661 deletions
+43 -1
View File
@@ -1,4 +1,4 @@
import { CodeTabs, CodeTab, Table } from "docs-ui"
import { CodeTabs, CodeTab, Table, Prerequisites } from "docs-ui"
export const metadata = {
title: `Medusa JS SDK`,
@@ -651,6 +651,48 @@ The JS SDK appends request-specific headers to authentication headers and header
---
## Localization with JS SDK
<Prerequisites
items={[
{
text: "Translation Module Configured",
link: "/commerce-modules/translation#configure-translation-module",
}
]}
/>
If you support [localization](../storefront-development/localization/page.mdx) in your storefront, you can use the `setLocale` method of the JS SDK.
The `setLocale` method stores the locale in the JS SDK to pass the it as a `x-medusa-locale` header in all subsequent requests. Also, if your application supports `localStorage`, the method sets the locale in the `medusa_locale` key of the `localStorage`.
For example, to set the locale to French (France):
```ts
sdk.setLocale("fr-FR")
// products content is fetched in French
const { products } = await sdk.store.product.list()
```
The `setLocale` method accepts the locale string in the [IETF BCP 47 standard](https://gist.github.com/typpo/b2b828a35e683b9bf8db91b5404f1bd1). All subsequent requests sent using the JS SDK will include the specified locale in the `x-medusa-locale` header.
In the above example, the product content, such as title and description, is fetched in French and falls back to the original content if translations aren't available.
You can also retrieve the currently set locale using the `getLocale` method:
```ts
const currentLocale = sdk.getLocale()
console.log(currentLocale) // "fr-FR"
```
<Note>
Learn more about localization and translations in the [Translation Module](../commerce-modules/translation/page.mdx) guide.
</Note>
---
## Medusa JS SDK Tips
### Use Tanstack (React) Query in Admin Customizations