feat(): Add more translatable core entity (#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
This commit is contained in:
Adrien de Peretti
2025-12-15 17:13:32 +01:00
committed by GitHub
parent ba6ed8d9dd
commit e94e1a4676
18 changed files with 143 additions and 70 deletions
@@ -1,50 +1,9 @@
import { LoaderOptions } from "@medusajs/framework/types"
import {
PRODUCT_TRANSLATABLE_FIELDS,
PRODUCT_VARIANT_TRANSLATABLE_FIELDS,
} from "../utils/translatable-fields"
import { asValue } from "awilix"
import { TRANSLATABLE_FIELDS_CONFIG_KEY } from "@utils/constants"
import { asValue } from "awilix"
import { translatableFieldsConfig } from "../utils/translatable-fields"
export default async ({
container,
options,
}: LoaderOptions<{
expandedTranslatableFields: { [key: string]: string[] }
}>): Promise<void> => {
const { expandedTranslatableFields } = options ?? {}
const { product, productVariant, ...others } =
expandedTranslatableFields ?? {}
const translatableFieldsConfig: Record<string, string[]> = {
product: PRODUCT_TRANSLATABLE_FIELDS,
product_variant: PRODUCT_VARIANT_TRANSLATABLE_FIELDS,
}
if (product) {
const translatableFields = new Set([
...PRODUCT_TRANSLATABLE_FIELDS,
...product,
])
translatableFieldsConfig.product = Array.from(translatableFields)
}
if (productVariant) {
const translatableFields = new Set([
...PRODUCT_VARIANT_TRANSLATABLE_FIELDS,
...productVariant,
])
translatableFieldsConfig.product_variant = Array.from(translatableFields)
}
if (others) {
Object.entries(others).forEach(([key, value]) => {
const translatableFields = new Set([...value])
translatableFieldsConfig[key] = Array.from(translatableFields)
})
}
export default async ({ container }: LoaderOptions): Promise<void> => {
container.register(
TRANSLATABLE_FIELDS_CONFIG_KEY,
asValue(translatableFieldsConfig)
@@ -5,5 +5,35 @@ export const PRODUCT_TRANSLATABLE_FIELDS = [
"subtitle",
"status",
]
export const PRODUCT_VARIANT_TRANSLATABLE_FIELDS = ["title", "material"]
export const PRODUCT_TYPE_TRANSLATABLE_FIELDS = ["value"]
export const PRODUCT_COLLECTION_TRANSLATABLE_FIELDS = ["title"]
export const PRODUCT_CATEGORY_TRANSLATABLE_FIELDS = ["name", "description"]
export const PRODUCT_TAG_TRANSLATABLE_FIELDS = ["value"]
export const PRODUCT_OPTION_TRANSLATABLE_FIELDS = ["title"]
export const PRODUCT_OPTION_VALUE_TRANSLATABLE_FIELDS = ["value"]
// export const SHIPPING_OPTION_TRANSLATABLE_FIELDS = ["name"]
// export const SHIPPING_OPTION_TYPE_TRANSLATABLE_FIELDS = ["label", "description"]
// export const RETURN_REASON_TRANSLATABLE_FIELDS = [
// "value",
// "label",
// "description",
// ]
export const translatableFieldsConfig = {
product: PRODUCT_TRANSLATABLE_FIELDS,
product_variant: PRODUCT_VARIANT_TRANSLATABLE_FIELDS,
product_type: PRODUCT_TYPE_TRANSLATABLE_FIELDS,
product_collection: PRODUCT_COLLECTION_TRANSLATABLE_FIELDS,
product_category: PRODUCT_CATEGORY_TRANSLATABLE_FIELDS,
product_tag: PRODUCT_TAG_TRANSLATABLE_FIELDS,
product_option: PRODUCT_OPTION_TRANSLATABLE_FIELDS,
product_option_value: PRODUCT_OPTION_VALUE_TRANSLATABLE_FIELDS,
// shipping_option: SHIPPING_OPTION_TRANSLATABLE_FIELDS,
// shipping_option_type: SHIPPING_OPTION_TYPE_TRANSLATABLE_FIELDS,
// return_reason: RETURN_REASON_TRANSLATABLE_FIELDS,
}