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
parent fea3d4ec49
commit 6dc0b8bed8
130 changed files with 5649 additions and 112 deletions

View File

@@ -45,6 +45,7 @@ import { User } from "./user"
import { Views } from "./views"
import { WorkflowExecution } from "./workflow-execution"
import { ShippingOptionType } from "./shipping-option-type"
import { Locale } from "./locale"
export class Admin {
/**
@@ -179,6 +180,10 @@ export class Admin {
* @tags currency
*/
public currency: Currency
/**
* @tags locale
*/
public locale: Locale
/**
* @tags payment
*/
@@ -265,6 +270,7 @@ export class Admin {
this.store = new Store(client)
this.productTag = new ProductTag(client)
this.user = new User(client)
this.locale = new Locale(client)
this.currency = new Currency(client)
this.payment = new Payment(client)
this.productVariant = new ProductVariant(client)

View File

@@ -0,0 +1,119 @@
import { HttpTypes } from "@medusajs/types"
import { Client } from "../client"
import { ClientHeaders } from "../types"
export class Locale {
/**
* @ignore
*/
private client: Client
/**
* @ignore
*/
constructor(client: Client) {
this.client = client
}
/**
* This method retrieves a paginated list of locales. It sends a request to the
* [List Locales](https://docs.medusajs.com/api/admin#locales_getlocales)
* API route.
*
* @param query - Filters and pagination configurations.
* @param headers - Headers to pass in the request.
* @returns The paginated list of locales.
*
* @example
* To retrieve the list of locales:
*
* ```ts
* sdk.admin.locales.list()
* .then(({ locales, count, limit, offset }) => {
* console.log(locales)
* })
* ```
*
* To configure the pagination, pass the `limit` and `offset` query parameters.
*
* For example, to retrieve only 10 items and skip 10 items:
*
* ```ts
* sdk.admin.locales.list({
* limit: 10,
* offset: 10
* })
* .then(({ locales, count, limit, offset }) => {
* console.log(locales)
* })
* ```
*
* Using the `fields` query parameter, you can specify the fields and relations to retrieve
* in each locale:
*
* ```ts
* sdk.admin.locales.list({
* fields: "code,name"
* })
* .then(({ locales, count, limit, offset }) => {
* console.log(locales)
* })
* ```
*
* Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/api/store#select-fields-and-relations).
*/
async list(query?: HttpTypes.AdminLocaleListParams, headers?: ClientHeaders) {
return this.client.fetch<HttpTypes.AdminLocaleListResponse>(
`/admin/locales`,
{
headers,
query,
}
)
}
/**
* This method retrieves a locale by its code. It sends a request to the
* [Get Locale](https://docs.medusajs.com/api/admin#locales_getlocalescode) API route.
*
* @param code - The locale's code.
* @param query - Configure the fields to retrieve in the locale.
* @param headers - Headers to pass in the request
* @returns The locale's details.
*
* @example
* To retrieve a locale by its code:
*
* ```ts
* sdk.admin.locale.retrieve("en-US")
* .then(({ locale }) => {
* console.log(locale)
* })
* ```
*
* To specify the fields and relations to retrieve:
*
* ```ts
* sdk.admin.locale.retrieve("en-US", {
* fields: "code,name"
* })
* .then(({ locale }) => {
* console.log(locale)
* })
* ```
*
* Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/api/store#select-fields-and-relations).
*/
async retrieve(
code: string,
query?: HttpTypes.AdminLocaleParams,
headers?: ClientHeaders
) {
return this.client.fetch<HttpTypes.AdminLocaleResponse>(
`/admin/locales/${code}`,
{
headers,
query,
}
)
}
}