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:
26
packages/admin/admin-shared/src/utils/deep-merge.ts
Normal file
26
packages/admin/admin-shared/src/utils/deep-merge.ts
Normal 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)
|
||||
}
|
||||
1
packages/admin/admin-shared/src/utils/index.ts
Normal file
1
packages/admin/admin-shared/src/utils/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from "./deep-merge"
|
||||
3
packages/admin/admin-shared/src/utils/is-object.ts
Normal file
3
packages/admin/admin-shared/src/utils/is-object.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export function isObject(obj: any): obj is object {
|
||||
return obj != null && obj?.constructor?.name === "Object"
|
||||
}
|
||||
Reference in New Issue
Block a user