docs: fix locale option passed to query (#14472)
This commit is contained in:
@@ -176,12 +176,12 @@ The `req.locale` property contains the locale value from either the query parame
|
||||
|
||||
### Retrieve Localized Data with Query
|
||||
|
||||
To retrieve data models with translated fields, pass the `locale` option to [Query](/learn/fundamentals/module-links/query) when querying your data.
|
||||
To retrieve data models with translated fields, pass the `locale` property in the second parameter object of [Query](/learn/fundamentals/module-links/query) when querying your data.
|
||||
|
||||
For example, to retrieve products with translated names and descriptions:
|
||||
|
||||
export const queryHighlights = [
|
||||
["10", "locale", "Pass the request locale to retrieve localized data"],
|
||||
["12", "locale", "Pass the request locale to retrieve localized data"],
|
||||
]
|
||||
|
||||
```ts title="src/api/store/products/route.ts" highlights={queryHighlights}
|
||||
@@ -190,13 +190,15 @@ import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
||||
export const GET = async (req: MedusaRequest, res: MedusaResponse) => {
|
||||
const query = req.scope.resolve("query")
|
||||
|
||||
const { data: products } = await query.graph({
|
||||
entity: "product",
|
||||
fields: ["id", "title", "description"],
|
||||
options: {
|
||||
locale: req.locale,
|
||||
const { data: products } = await query.graph(
|
||||
{
|
||||
entity: "product",
|
||||
fields: ["id", "title", "description"],
|
||||
},
|
||||
})
|
||||
{
|
||||
locale: req.locale,
|
||||
}
|
||||
)
|
||||
|
||||
res.json({ products })
|
||||
}
|
||||
|
||||
@@ -856,19 +856,21 @@ This will retrieve all brands that are linked to at least one product.
|
||||
]}
|
||||
/>
|
||||
|
||||
To retrieve localized data for data models that have translations, pass an `options.locale` property to the first parameter of the `query.index` method:
|
||||
To retrieve localized data for data models that have translations, pass a `locale` property in the second parameter object of the `query.index` method.
|
||||
|
||||
```ts highlights={[["5", "locale", "Pass the locale to retrieve localized data."]]}
|
||||
const { data: products } = await query.index({
|
||||
entity: "product",
|
||||
fields: ["id", "title", "description"],
|
||||
options: {
|
||||
locale: "fr-FR",
|
||||
```ts highlights={[["7", "locale", "Pass the locale to retrieve localized data."]]}
|
||||
const { data: products } = await query.index(
|
||||
{
|
||||
entity: "product",
|
||||
fields: ["id", "title", "description"],
|
||||
},
|
||||
})
|
||||
{
|
||||
locale: "fr-FR",
|
||||
}
|
||||
)
|
||||
```
|
||||
|
||||
The `options.locale` property is a string representing the locale code following the [IETF BCP 47 standard](https://gist.github.com/typpo/b2b828a35e683b9bf8db91b5404f1bd1).
|
||||
The `locale` property is a string representing the locale code following the [IETF BCP 47 standard](https://gist.github.com/typpo/b2b828a35e683b9bf8db91b5404f1bd1).
|
||||
|
||||
The returned products will have their `title` and `description` properties in French (`fr-FR`), if translations are available.
|
||||
|
||||
|
||||
@@ -869,19 +869,21 @@ In the example above, you retrieve only deleted posts by enabling the `withDelet
|
||||
]}
|
||||
/>
|
||||
|
||||
To retrieve localized data for data models that have translations, pass an `options.locale` property to the first parameter of the `query.graph` method.
|
||||
To retrieve localized data for data models that have translations, pass a `locale` property in the second parameter object of the `query.graph` method.
|
||||
|
||||
<CodeTabs group="query">
|
||||
<CodeTab label="query.graph" value="query.graph">
|
||||
|
||||
```ts highlights={[["5", "locale", "Pass the locale to retrieve localized data."]]}
|
||||
const { data: products } = await query.graph({
|
||||
entity: "product",
|
||||
fields: ["id", "title", "description"],
|
||||
options: {
|
||||
locale: "fr-FR",
|
||||
```ts highlights={[["7", "locale", "Pass the locale to retrieve localized data."]]}
|
||||
const { data: products } = await query.graph(
|
||||
{
|
||||
entity: "product",
|
||||
fields: ["id", "title", "description"],
|
||||
},
|
||||
})
|
||||
{
|
||||
locale: "fr-FR",
|
||||
}
|
||||
)
|
||||
```
|
||||
|
||||
</CodeTab>
|
||||
@@ -900,7 +902,7 @@ const { data: products } = useQueryGraphStep({
|
||||
</CodeTab>
|
||||
</CodeTabs>
|
||||
|
||||
The `options.locale` property is a string representing the locale code following the [IETF BCP 47 standard](https://gist.github.com/typpo/b2b828a35e683b9bf8db91b5404f1bd1).
|
||||
The `locale` property is a string representing the locale code following the [IETF BCP 47 standard](https://gist.github.com/typpo/b2b828a35e683b9bf8db91b5404f1bd1).
|
||||
|
||||
The returned products will have their `title` and `description` properties in French (`fr-FR`), if translations are available.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user