feat(): Introduce translation module and preliminary application of them (#14189)

* feat(): Translation first steps

* feat(): locale middleware

* feat(): readonly links

* feat(): feature flag

* feat(): modules sdk

* feat(): translation module re export

* start adding workflows

* update typings

* update typings

* test(): Add integration tests

* test(): centralize filters preparation

* test(): centralize filters preparation

* remove unnecessary importy

* fix workflows

* Define StoreLocale inside Store Module

* Link definition to extend Store with supported_locales

* store_locale migration

* Add supported_locales handling in Store Module

* Tests

* Accept supported_locales in Store endpoints

* Add locales to js-sdk

* Include locale list and default locale in Store Detail section

* Initialize local namespace in js-sdk

* Add locales route

* Make code primary key of locale table to facilitate upserts

* Add locales routes

* Show locale code as is

* Add list translations api route

* Batch endpoint

* Types

* New batchTranslationsWorkflow and various updates to existent ones

* Edit default locale UI

* WIP

* Apply translation agnostically

* middleware

* Apply translation agnostically

* fix Apply translation agnostically

* apply translations to product list

* Add feature flag

* fetch translations by batches of 250 max

* fix apply

* improve and test util

* apply to product list

* dont manage translations if no locale

* normalize locale

* potential todo

* Protect translations routes with feature flag

* Extract normalize locale util to core/utils

* Normalize locale on write

* Normalize locale for read

* Use feature flag to guard translations UI across the board

* Avoid throwing incorrectly when locale_code not present in partial updates

* move applyTranslations util

* remove old tests

* fix util tests

* fix(): product end points

* cleanup

* update lock

* remove unused var

* cleanup

* fix apply locale

* missing new dep for test utils

* Change entity_type, entity_id to reference, reference_id

* Remove comment

* Avoid registering translations route if ff not enabled

* Prevent registering express handler for disabled route via defineFileConfig

* Add tests

* Add changeset

* Update test

* fix integration tests, module and internals

* Add locale id plus fixed

* Allow to pass array of reference_id

* fix unit tests

* fix link loading

* fix store route

* fix sales channel test

* fix tests

---------

Co-authored-by: Nicolas Gorga <nicogorga11@gmail.com>
Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
Adrien de Peretti
2025-12-08 19:33:08 +01:00
committed by GitHub
co-authored by Nicolas Gorga Oli Juhl
parent fea3d4ec49
commit 6dc0b8bed8
130 changed files with 5649 additions and 112 deletions
@@ -6,6 +6,10 @@ export const createStoreFixture: StoreTypes.CreateStoreDTO = {
{ currency_code: "usd" },
{ currency_code: "eur", is_default: true },
],
supported_locales: [
{ locale_code: "fr-FR" },
{ locale_code: "en-US", is_default: true },
],
default_sales_channel_id: "test-sales-channel",
default_region_id: "test-region",
metadata: {
@@ -15,7 +15,11 @@ moduleIntegrationTestRunner<IStoreModuleService>({
service: StoreModuleService,
}).linkable
expect(Object.keys(linkable)).toEqual(["store", "storeCurrency"])
expect(Object.keys(linkable)).toEqual([
"store",
"storeCurrency",
"storeLocale",
])
Object.keys(linkable).forEach((key) => {
delete linkable[key].toJSON
@@ -40,6 +44,15 @@ moduleIntegrationTestRunner<IStoreModuleService>({
field: "storeCurrency",
},
},
storeLocale: {
id: {
linkable: "store_locale_id",
entity: "StoreLocale",
primaryKey: "id",
serviceName: "store",
field: "storeLocale",
},
},
})
})
@@ -54,6 +67,10 @@ moduleIntegrationTestRunner<IStoreModuleService>({
expect.objectContaining({ currency_code: "eur" }),
expect.objectContaining({ currency_code: "usd" }),
]),
supported_locales: expect.arrayContaining([
expect.objectContaining({ locale_code: "fr-FR" }),
expect.objectContaining({ locale_code: "en-US" }),
]),
default_sales_channel_id: "test-sales-channel",
default_region_id: "test-region",
metadata: {
@@ -75,6 +92,19 @@ moduleIntegrationTestRunner<IStoreModuleService>({
"There should be a default currency set for the store"
)
})
it("should fail to get created if there is no default locale", async function () {
const err = await service
.createStores({
...createStoreFixture,
supported_locales: [{ locale_code: "en-US" }],
})
.catch((err) => err.message)
expect(err).toEqual(
"There should be a default locale set for the store"
)
})
})
describe("upserting a store", () => {
@@ -130,6 +160,19 @@ moduleIntegrationTestRunner<IStoreModuleService>({
)
})
it("should fail updating locales without a default one", async function () {
const createdStore = await service.createStores(createStoreFixture)
const updateErr = await service
.updateStores(createdStore.id, {
supported_locales: [{ locale_code: "en-US" }],
})
.catch((err) => err.message)
expect(updateErr).toEqual(
"There should be a default locale set for the store"
)
})
it("should fail updating currencies where a duplicate currency code exists", async function () {
const createdStore = await service.createStores(createStoreFixture)
const updateErr = await service
@@ -144,6 +187,20 @@ moduleIntegrationTestRunner<IStoreModuleService>({
expect(updateErr).toEqual("Duplicate currency codes: usd")
})
it("should fail updating locales where a duplicate locale code exists", async function () {
const createdStore = await service.createStores(createStoreFixture)
const updateErr = await service
.updateStores(createdStore.id, {
supported_locales: [
{ locale_code: "en-US" },
{ locale_code: "en-US" },
],
})
.catch((err) => err.message)
expect(updateErr).toEqual("Duplicate locale codes: en-US")
})
it("should fail updating currencies where there is more than 1 default currency", async function () {
const createdStore = await service.createStores(createStoreFixture)
const updateErr = await service
@@ -157,6 +214,20 @@ moduleIntegrationTestRunner<IStoreModuleService>({
expect(updateErr).toEqual("Only one default currency is allowed")
})
it("should fail updating locales where there is more than 1 default locale", async function () {
const createdStore = await service.createStores(createStoreFixture)
const updateErr = await service
.updateStores(createdStore.id, {
supported_locales: [
{ locale_code: "en-US", is_default: true },
{ locale_code: "fr-FR", is_default: true },
],
})
.catch((err) => err.message)
expect(updateErr).toEqual("Only one default locale is allowed")
})
})
describe("deleting a store", () => {