feat(core-flows,types,utils,medusa): Translate tax lines (#14359)

* Include locale field for traslations on tax line workflows

* Translate tax lines in getItemTaxLinesStep with new util

* Update tax calculation context, so that we pass locale to third party tax providers if they want to return translated tax rates

* Apply translations to tax lines on product and variant tax middlewares

* Cart management translations tests

* Update tax lines when order locale gets updated

* Add changeset

* Get tranlsated tax lines step

* Fix wording

* Mutate ref directly

* Update order tax lines translations upon order locale change

* Claims translations tests

* Update tax lines upon draft order locale update

* Exchange tests for tax lines translations

* Order edits test for tax line translation

* Add tests for shipping methods tax line translations on various order flows

* Returns shipping method translations tests

* Execute update in parallel

* Use TranslationFeatureFlag.key

* Fix feature flag import

* Add @medusajs/medusa dependency for feature flag usage

* Revert "Add @medusajs/medusa dependency for feature flag usage"

This reverts commit e8897aed0a88f83c1034ac73e817e4222250a2c9.

* Use feature flag string directly

* Fix test

* Parallelize tax line translations application
This commit is contained in:
Nicolas Gorga
2026-01-13 15:12:42 -03:00
committed by GitHub
parent 28fae96cee
commit cec8b8e428
23 changed files with 2032 additions and 164 deletions

View File

@@ -0,0 +1,49 @@
import { applyTranslations } from "./apply-translations"
import {
ItemTaxLineDTO,
MedusaContainer,
ShippingTaxLineDTO,
} from "@medusajs/types"
/**
* Applies translations to tax lines. If you are using a tax provider that doesn't have TaxRates defined in the database,
* you should apply the translations inside of your tax provider's `getTaxLines` method, using the `locale` provided in the context.
*
* @param taxLines - The tax lines to apply translations to.
* @param locale - The locale to apply translations to.
* @param container - The container to use for the translations.
* @returns The tax lines with translations applied.
*/
export const applyTranslationsToTaxLines = async (
taxLines: ItemTaxLineDTO[] | ShippingTaxLineDTO[],
locale: string | undefined,
container: MedusaContainer
) => {
const translatedTaxRates = taxLines.map(
(taxLine: ItemTaxLineDTO | ShippingTaxLineDTO) => ({
id: taxLine.rate_id,
name: taxLine.name,
})
)
await applyTranslations({
localeCode: locale,
objects: translatedTaxRates,
container,
})
const rateTranslationMap = new Map<string, string>()
for (const translatedRate of translatedTaxRates) {
if (!!translatedRate.id) {
rateTranslationMap.set(translatedRate.id, translatedRate.name)
}
}
for (const taxLine of taxLines) {
if (taxLine.rate_id) {
taxLine.name = rateTranslationMap.get(taxLine.rate_id)!
}
}
return taxLines
}

View File

@@ -1 +1,2 @@
export * from "./apply-translations"
export * from "./apply-translations-to-tax-lines"