ref: https://github.com/medusajs/medusa/pull/14189 **Summary** This PR extends the translation module to support automatic translation syncing for cart line items based on the cart's locale. Key changes: - Added locale field to the Cart model to store the cart's locale preference - Created new workflow steps: - getTranslatedLineItemsStep - Translates line items when adding to cart or creating a cart - updateCartItemsTranslationsStep - Re-translates all cart items when the cart's locale changes - Integrated translation logic into cart workflows: - createCartWorkflow - Applies translations to initial line items - addToCartWorkflow - Applies translations when adding new items - updateCartWorkflow - Re-translates all items when locale_code is updated - refreshCartItemsWorkflow - Maintains translations during cart refresh - Added applyTranslationsToItems utility to map variant/product/type/collection translations to line item fields (title, subtitle, description, etc.)
101 lines
2.4 KiB
JavaScript
101 lines
2.4 KiB
JavaScript
const { defineConfig, Modules } = require("@medusajs/utils")
|
|
const os = require("os")
|
|
const path = require("path")
|
|
|
|
const DB_HOST = process.env.DB_HOST
|
|
const DB_USERNAME = process.env.DB_USERNAME
|
|
const DB_PASSWORD = process.env.DB_PASSWORD
|
|
const DB_NAME = process.env.DB_TEMP_NAME
|
|
const DB_URL = `postgres://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOST}/${DB_NAME}`
|
|
process.env.DATABASE_URL = DB_URL
|
|
process.env.LOG_LEVEL = "error"
|
|
|
|
const customFulfillmentProvider = {
|
|
resolve: "@medusajs/fulfillment-manual",
|
|
id: "test-provider",
|
|
}
|
|
|
|
const customFulfillmentProviderCalculated = {
|
|
resolve: require("./dist/utils/providers/fulfillment-manual-calculated")
|
|
.default,
|
|
id: "test-provider-calculated",
|
|
}
|
|
|
|
const translationModuleResolutions =
|
|
process.env.MEDUSA_FF_TRANSLATION === "true"
|
|
? {
|
|
[Modules.TRANSLATION]: {
|
|
resolve: "@medusajs/translation",
|
|
},
|
|
}
|
|
: {}
|
|
|
|
const modules = {
|
|
...translationModuleResolutions,
|
|
[Modules.FULFILLMENT]: {
|
|
/** @type {import('@medusajs/fulfillment').FulfillmentModuleOptions} */
|
|
options: {
|
|
providers: [
|
|
customFulfillmentProvider,
|
|
customFulfillmentProviderCalculated,
|
|
],
|
|
},
|
|
},
|
|
[Modules.NOTIFICATION]: {
|
|
resolve: "@medusajs/notification",
|
|
options: {
|
|
providers: [
|
|
{
|
|
resolve: "@medusajs/notification-local",
|
|
id: "local",
|
|
options: {
|
|
name: "Local Notification Provider",
|
|
channels: ["feed"],
|
|
},
|
|
},
|
|
],
|
|
},
|
|
},
|
|
[Modules.FILE]: {
|
|
resolve: "@medusajs/file",
|
|
options: {
|
|
providers: [
|
|
{
|
|
resolve: "@medusajs/file-local",
|
|
id: "local",
|
|
options: {
|
|
// This is the directory where we can reliably write in CI environments
|
|
upload_dir: path.join(os.tmpdir(), "uploads"),
|
|
private_upload_dir: path.join(os.tmpdir(), "static"),
|
|
},
|
|
},
|
|
],
|
|
},
|
|
},
|
|
[Modules.INDEX]: {
|
|
resolve: "@medusajs/index",
|
|
disable: process.env.ENABLE_INDEX_MODULE !== "true",
|
|
},
|
|
}
|
|
|
|
if (process.env.MEDUSA_FF_TRANSLATION === "true") {
|
|
modules[Modules.TRANSLATION] = {
|
|
resolve: "@medusajs/translation",
|
|
}
|
|
}
|
|
|
|
module.exports = defineConfig({
|
|
admin: {
|
|
disable: true,
|
|
},
|
|
projectConfig: {
|
|
http: {
|
|
jwtSecret: "test",
|
|
},
|
|
},
|
|
featureFlags: {
|
|
index_engine: process.env.ENABLE_INDEX_MODULE === "true",
|
|
},
|
|
modules,
|
|
})
|