feat(admin-*,dashboard): add dashboard i18n extensions (#13763)

* virtual i18n module

* changeset

* fallback ns

fallback to the default "translation" ns if the key isnt found. Allows to use a single "useTranslation("customNs")" hook for both custom and medusa-provided keys

* simplify merges

* optional for backward compat

* fix HMR

* fix generated deepMerge

* test
This commit is contained in:
Leonardo Benini
2025-10-23 21:16:43 +02:00
committed by GitHub
parent 012e30801e
commit 226984cf0f
25 changed files with 314 additions and 9 deletions

View File

@@ -0,0 +1,26 @@
import { isObject } from "./is-object"
export function deepMerge(target: any, source: any) {
const recursive = (a:any, b:any) => {
if (!isObject(a)) {
return b
}
if (!isObject(b)) {
return a
}
Object.keys(b).forEach((key) => {
if (isObject((b as any)[key])) {
(a as any)[key] ??= {};
(a as any)[key] = deepMerge((a as any)[key], (b as any)[key])
} else {
(a as any)[key] = (b as any)[key]
}
})
return a
}
const copy = { ...target }
return recursive(copy, source)
}

View File

@@ -0,0 +1 @@
export * from "./deep-merge"

View File

@@ -0,0 +1,3 @@
export function isObject(obj: any): obj is object {
return obj != null && obj?.constructor?.name === "Object"
}