Skip to content

Commit e94e1a4

Browse files
authored
feat(): Add more translatable core entity (medusajs#14311)
* feat(): Add product type and collection translation support * Create sharp-poets-give.md * feat(): Add product type and collection translation support * feat(): Add product type and collection translation support * options * options * shipping options/type * return reason * fix * leave out shipping and return reason * leave out shipping and return reason * leave out shipping and return reason
1 parent ba6ed8d commit e94e1a4

File tree

18 files changed

+142
-69
lines changed

18 files changed

+142
-69
lines changed

.changeset/sharp-poets-give.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@medusajs/medusa": patch
3+
"@medusajs/translation": patch
4+
---
5+
6+
feat(): Add product type and collection translation support

packages/medusa/src/api/store/collections/[id]/route.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
MedusaResponse,
55
} from "@medusajs/framework/http"
66
import { refetchCollection } from "../helpers"
7+
import { applyTranslations } from "@medusajs/framework/utils"
78

89
export const GET = async (
910
req: AuthenticatedMedusaRequest<HttpTypes.SelectParams>,
@@ -15,5 +16,11 @@ export const GET = async (
1516
req.queryConfig.fields
1617
)
1718

19+
await applyTranslations({
20+
localeCode: req.locale,
21+
objects: [collection],
22+
container: req.scope,
23+
})
24+
1825
res.status(200).json({ collection })
1926
}

packages/medusa/src/api/store/collections/route.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
} from "@medusajs/framework/http"
66

77
import {
8+
applyTranslations,
89
ContainerRegistrationKeys,
910
remoteQueryObjectFromString,
1011
} from "@medusajs/framework/utils"
@@ -26,6 +27,12 @@ export const GET = async (
2627

2728
const { rows: collections, metadata } = await remoteQuery(query)
2829

30+
await applyTranslations({
31+
localeCode: req.locale,
32+
objects: collections,
33+
container: req.scope,
34+
})
35+
2936
res.json({
3037
collections,
3138
count: metadata.count,

packages/medusa/src/api/store/product-categories/[id]/route.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { StoreProductCategoryResponse } from "@medusajs/framework/types"
2-
import { MedusaError } from "@medusajs/framework/utils"
2+
import { applyTranslations, MedusaError } from "@medusajs/framework/utils"
33
import {
44
AuthenticatedMedusaRequest,
55
MedusaResponse,
@@ -24,5 +24,12 @@ export const GET = async (
2424
`Product category with id: ${req.params.id} was not found`
2525
)
2626
}
27+
28+
await applyTranslations({
29+
localeCode: req.locale,
30+
objects: [category],
31+
container: req.scope,
32+
})
33+
2734
res.json({ product_category: category })
2835
}

packages/medusa/src/api/store/product-categories/route.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1+
import {
2+
AuthenticatedMedusaRequest,
3+
MedusaResponse,
4+
} from "@medusajs/framework/http"
15
import {
26
StoreProductCategoryListParams,
37
StoreProductCategoryListResponse,
48
} from "@medusajs/framework/types"
5-
import { ContainerRegistrationKeys } from "@medusajs/framework/utils"
69
import {
7-
AuthenticatedMedusaRequest,
8-
MedusaResponse,
9-
} from "@medusajs/framework/http"
10+
applyTranslations,
11+
ContainerRegistrationKeys,
12+
} from "@medusajs/framework/utils"
1013

1114
export const GET = async (
1215
req: AuthenticatedMedusaRequest<StoreProductCategoryListParams>,
@@ -21,6 +24,12 @@ export const GET = async (
2124
pagination: req.queryConfig.pagination,
2225
})
2326

27+
await applyTranslations({
28+
localeCode: req.locale,
29+
objects: product_categories,
30+
container: req.scope,
31+
})
32+
2433
res.json({
2534
product_categories,
2635
count: metadata!.count,

packages/medusa/src/api/store/product-tags/[id]/route.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { StoreProductTagResponse } from "@medusajs/framework/types"
22
import {
3+
applyTranslations,
34
ContainerRegistrationKeys,
45
MedusaError,
56
} from "@medusajs/framework/utils"
@@ -30,5 +31,14 @@ export const GET = async (
3031
`Product tag with id: ${req.params.id} was not found`
3132
)
3233
}
33-
res.json({ product_tag: data[0] })
34+
35+
const productTag = data[0]
36+
37+
await applyTranslations({
38+
localeCode: req.locale,
39+
objects: [productTag],
40+
container: req.scope,
41+
})
42+
43+
res.json({ product_tag: productTag })
3444
}

packages/medusa/src/api/store/product-tags/route.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { HttpTypes } from "@medusajs/framework/types"
2-
import { ContainerRegistrationKeys } from "@medusajs/framework/utils"
2+
import {
3+
applyTranslations,
4+
ContainerRegistrationKeys,
5+
} from "@medusajs/framework/utils"
36
import {
47
AuthenticatedMedusaRequest,
58
MedusaResponse,
@@ -18,6 +21,12 @@ export const GET = async (
1821
fields: req.queryConfig.fields,
1922
})
2023

24+
await applyTranslations({
25+
localeCode: req.locale,
26+
objects: product_tags,
27+
container: req.scope,
28+
})
29+
2130
res.json({
2231
product_tags,
2332
count: metadata?.count ?? 0,

packages/medusa/src/api/store/product-types/[id]/route.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { StoreProductTypeResponse } from "@medusajs/framework/types"
22
import {
3+
applyTranslations,
34
ContainerRegistrationKeys,
45
MedusaError,
56
} from "@medusajs/framework/utils"
@@ -30,5 +31,14 @@ export const GET = async (
3031
`Product type with id: ${req.params.id} was not found`
3132
)
3233
}
33-
res.json({ product_type: data[0] })
34+
35+
const productType = data[0]
36+
37+
await applyTranslations({
38+
localeCode: req.locale,
39+
objects: [productType],
40+
container: req.scope,
41+
})
42+
43+
res.json({ product_type: productType })
3444
}

packages/medusa/src/api/store/product-types/route.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { HttpTypes } from "@medusajs/framework/types"
2-
import { ContainerRegistrationKeys } from "@medusajs/framework/utils"
2+
import {
3+
applyTranslations,
4+
ContainerRegistrationKeys,
5+
} from "@medusajs/framework/utils"
36
import {
47
AuthenticatedMedusaRequest,
58
MedusaResponse,
@@ -18,6 +21,12 @@ export const GET = async (
1821
fields: req.queryConfig.fields,
1922
})
2023

24+
await applyTranslations({
25+
localeCode: req.locale,
26+
objects: product_types,
27+
container: req.scope,
28+
})
29+
2130
res.json({
2231
product_types,
2332
count: metadata?.count ?? 0,

packages/medusa/src/api/store/product-variants/[id]/route.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
} from "@medusajs/framework/http"
55
import { HttpTypes, QueryContextType } from "@medusajs/framework/types"
66
import {
7+
applyTranslations,
78
ContainerRegistrationKeys,
89
MedusaError,
910
QueryContext,
@@ -60,6 +61,12 @@ export const GET = async (
6061
)
6162
}
6263

64+
await applyTranslations({
65+
localeCode: req.locale,
66+
objects: [variant],
67+
container: req.scope,
68+
})
69+
6370
if (withInventoryQuantity) {
6471
await wrapVariantsWithInventoryQuantityForSalesChannel(req, [variant])
6572
}

0 commit comments

Comments
 (0)