@intlayer/core 8.4.5 → 8.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/interpreter/getTranslation.cjs +31 -56
- package/dist/cjs/interpreter/getTranslation.cjs.map +1 -1
- package/dist/esm/interpreter/getTranslation.mjs +31 -56
- package/dist/esm/interpreter/getTranslation.mjs.map +1 -1
- package/dist/types/interpreter/getTranslation.d.ts.map +1 -1
- package/package.json +6 -6
|
@@ -2,51 +2,35 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2
2
|
|
|
3
3
|
//#region src/interpreter/getTranslation.ts
|
|
4
4
|
/**
|
|
5
|
-
* Check if a value is a plain object that can be safely
|
|
5
|
+
* Check if a value is a plain object that can be safely merged.
|
|
6
6
|
* Returns false for Promises, React elements, class instances, etc.
|
|
7
7
|
*/
|
|
8
8
|
const isPlainObject = (value) => {
|
|
9
9
|
if (value === null || typeof value !== "object") return false;
|
|
10
|
-
if (
|
|
10
|
+
if (typeof value.then === "function") return false;
|
|
11
11
|
if (value.$$typeof !== void 0 || value.__v_isVNode !== void 0 || value._isVNode !== void 0 || value.isJSX !== void 0) return false;
|
|
12
12
|
const proto = Object.getPrototypeOf(value);
|
|
13
13
|
return proto === Object.prototype || proto === null || Array.isArray(value);
|
|
14
14
|
};
|
|
15
15
|
/**
|
|
16
|
-
* Recursively merges two objects.
|
|
17
|
-
*
|
|
18
|
-
* Arrays are replaced, not merged.
|
|
16
|
+
* Recursively merges two objects, skipping undefined source values.
|
|
17
|
+
* First argument takes precedence. Arrays replace rather than merge.
|
|
19
18
|
*/
|
|
20
|
-
const
|
|
19
|
+
const deepMerge = (target, source) => {
|
|
21
20
|
if (target === void 0) return source;
|
|
22
21
|
if (source === void 0) return target;
|
|
23
22
|
if (Array.isArray(target)) return target;
|
|
24
23
|
if (isPlainObject(target) && isPlainObject(source)) {
|
|
25
24
|
const result = { ...target };
|
|
26
25
|
for (const key of Object.keys(source)) {
|
|
27
|
-
if (key === "__proto__" || key === "constructor") continue;
|
|
28
|
-
|
|
29
|
-
else result[key] = source[key];
|
|
26
|
+
if (key === "__proto__" || key === "constructor" || source[key] === void 0) continue;
|
|
27
|
+
result[key] = target[key] !== void 0 ? deepMerge(target[key], source[key]) : source[key];
|
|
30
28
|
}
|
|
31
29
|
return result;
|
|
32
30
|
}
|
|
33
31
|
return target;
|
|
34
32
|
};
|
|
35
33
|
/**
|
|
36
|
-
* Recursively removes undefined values from an object.
|
|
37
|
-
* Handles circular references by tracking visited objects.
|
|
38
|
-
*/
|
|
39
|
-
const removeUndefinedValues = (object, visited = /* @__PURE__ */ new WeakSet()) => {
|
|
40
|
-
if (typeof object !== "object" || object === null) return object;
|
|
41
|
-
if (visited.has(object)) return object;
|
|
42
|
-
visited.add(object);
|
|
43
|
-
if (!isPlainObject(object)) return object;
|
|
44
|
-
if (Array.isArray(object)) return object.map((item) => removeUndefinedValues(item, visited));
|
|
45
|
-
const result = {};
|
|
46
|
-
for (const [key, value] of Object.entries(object)) if (value !== void 0) result[key] = removeUndefinedValues(value, visited);
|
|
47
|
-
return result;
|
|
48
|
-
};
|
|
49
|
-
/**
|
|
50
34
|
* Picks the appropriate content from a locale map based on the provided locale.
|
|
51
35
|
*
|
|
52
36
|
* It handles:
|
|
@@ -70,42 +54,33 @@ const removeUndefinedValues = (object, visited = /* @__PURE__ */ new WeakSet())
|
|
|
70
54
|
* ```
|
|
71
55
|
*/
|
|
72
56
|
const getTranslation = (languageContent, locale, fallback) => {
|
|
73
|
-
const
|
|
74
|
-
const
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
if (genericLocale in languageContent) {
|
|
81
|
-
const genericContent = getContent(genericLocale);
|
|
82
|
-
if (typeof genericContent === "string") {
|
|
83
|
-
if (results.length === 0) return genericContent;
|
|
84
|
-
} else if (genericContent !== void 0) results.push(genericContent);
|
|
57
|
+
const get = (loc) => languageContent[loc];
|
|
58
|
+
const seen = /* @__PURE__ */ new Set();
|
|
59
|
+
const locales = [];
|
|
60
|
+
const addLocale = (loc) => {
|
|
61
|
+
if (loc && !seen.has(loc)) {
|
|
62
|
+
seen.add(loc);
|
|
63
|
+
locales.push(loc);
|
|
85
64
|
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
if (
|
|
95
|
-
|
|
96
|
-
if (
|
|
97
|
-
|
|
98
|
-
if (typeof genericFallbackContent === "string") {
|
|
99
|
-
if (results.length === 0) return genericFallbackContent;
|
|
100
|
-
} else if (genericFallbackContent !== void 0) results.push(genericFallbackContent);
|
|
101
|
-
}
|
|
65
|
+
};
|
|
66
|
+
addLocale(locale);
|
|
67
|
+
if (locale.includes("-")) addLocale(locale.split("-")[0]);
|
|
68
|
+
addLocale(fallback);
|
|
69
|
+
if (fallback?.includes("-")) addLocale(fallback.split("-")[0]);
|
|
70
|
+
const results = [];
|
|
71
|
+
for (const loc of locales) {
|
|
72
|
+
const val = get(loc);
|
|
73
|
+
if (val === void 0) continue;
|
|
74
|
+
if (typeof val === "string") {
|
|
75
|
+
if (results.length === 0) return val;
|
|
76
|
+
continue;
|
|
102
77
|
}
|
|
78
|
+
results.push(val);
|
|
103
79
|
}
|
|
104
|
-
if (results.length === 0) return;
|
|
105
|
-
|
|
106
|
-
if (
|
|
107
|
-
|
|
108
|
-
return cleanResults.reduce((acc, curr) => deepMergeObjects(acc, curr));
|
|
80
|
+
if (results.length === 0) return void 0;
|
|
81
|
+
if (results.length === 1) return results[0];
|
|
82
|
+
if (Array.isArray(results[0])) return results[0];
|
|
83
|
+
return results.reduce((acc, curr) => deepMerge(acc, curr));
|
|
109
84
|
};
|
|
110
85
|
|
|
111
86
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getTranslation.cjs","names":[],"sources":["../../../src/interpreter/getTranslation.ts"],"sourcesContent":["import type {\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\n\n/**\n * Check if a value is a plain object that can be safely
|
|
1
|
+
{"version":3,"file":"getTranslation.cjs","names":[],"sources":["../../../src/interpreter/getTranslation.ts"],"sourcesContent":["import type {\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\n\n/**\n * Check if a value is a plain object that can be safely merged.\n * Returns false for Promises, React elements, class instances, etc.\n */\nconst isPlainObject = (value: unknown): boolean => {\n if (value === null || typeof value !== 'object') return false;\n if (typeof (value as any).then === 'function') return false;\n if (\n (value as any).$$typeof !== undefined ||\n (value as any).__v_isVNode !== undefined ||\n (value as any)._isVNode !== undefined ||\n (value as any).isJSX !== undefined\n ) {\n return false;\n }\n const proto = Object.getPrototypeOf(value);\n return proto === Object.prototype || proto === null || Array.isArray(value);\n};\n\n/**\n * Recursively merges two objects, skipping undefined source values.\n * First argument takes precedence. Arrays replace rather than merge.\n */\nconst deepMerge = (target: any, source: any): any => {\n if (target === undefined) return source;\n if (source === undefined) return target;\n if (Array.isArray(target)) return target;\n if (isPlainObject(target) && isPlainObject(source)) {\n const result = { ...target };\n\n for (const key of Object.keys(source)) {\n if (\n key === '__proto__' ||\n key === 'constructor' ||\n source[key] === undefined\n )\n continue;\n result[key] =\n target[key] !== undefined\n ? deepMerge(target[key], source[key])\n : source[key];\n }\n return result;\n }\n return target;\n};\n\n/**\n * Picks the appropriate content from a locale map based on the provided locale.\n *\n * It handles:\n * 1. Exact locale match (e.g., 'en-US').\n * 2. Generic locale fallback (e.g., 'en' if 'en-US' is not found).\n * 3. Explicit fallback locale.\n * 4. Deep merging of objects to ensure partial translations are complemented by fallbacks.\n *\n * @param languageContent - A map of locales to content.\n * @param locale - The target locale to retrieve.\n * @param fallback - Optional fallback locale if the target is not found.\n * @returns The translated content.\n *\n * @example\n * ```ts\n * const content = getTranslation({\n * en: 'Hello',\n * fr: 'Bonjour',\n * }, 'fr');\n * // 'Bonjour'\n * ```\n */\nexport const getTranslation = <Content = string>(\n languageContent: StrictModeLocaleMap<Content>,\n locale: LocalesValues,\n fallback?: LocalesValues\n): Content => {\n const get = (loc: string): Content | undefined =>\n languageContent[loc as keyof typeof languageContent];\n\n // Build priority-ordered locale candidates (most specific first), deduped\n const seen = new Set<string>();\n const locales: string[] = [];\n const addLocale = (loc: string | undefined) => {\n if (loc && !seen.has(loc)) {\n seen.add(loc);\n locales.push(loc);\n }\n };\n\n addLocale(locale);\n if (locale.includes('-')) addLocale(locale.split('-')[0]);\n\n addLocale(fallback);\n if (fallback?.includes('-')) addLocale(fallback.split('-')[0]);\n\n // Collect results: strings exit early (if no higher-priority object was found),\n // objects are accumulated for deep merging.\n const results: Content[] = [];\n\n for (const loc of locales) {\n const val = get(loc);\n\n if (val === undefined) continue;\n if (typeof val === 'string') {\n if (results.length === 0) return val;\n continue; // an object at higher priority takes precedence\n }\n\n results.push(val);\n }\n\n if (results.length === 0) return undefined as Content;\n if (results.length === 1) return results[0];\n if (Array.isArray(results[0])) return results[0];\n\n // Merge objects: first result (most specific) takes precedence\n return (results as object[]).reduce((acc, curr) =>\n deepMerge(acc, curr)\n ) as Content;\n};\n"],"mappings":";;;;;;;AASA,MAAM,iBAAiB,UAA4B;AACjD,KAAI,UAAU,QAAQ,OAAO,UAAU,SAAU,QAAO;AACxD,KAAI,OAAQ,MAAc,SAAS,WAAY,QAAO;AACtD,KACG,MAAc,aAAa,UAC3B,MAAc,gBAAgB,UAC9B,MAAc,aAAa,UAC3B,MAAc,UAAU,OAEzB,QAAO;CAET,MAAM,QAAQ,OAAO,eAAe,MAAM;AAC1C,QAAO,UAAU,OAAO,aAAa,UAAU,QAAQ,MAAM,QAAQ,MAAM;;;;;;AAO7E,MAAM,aAAa,QAAa,WAAqB;AACnD,KAAI,WAAW,OAAW,QAAO;AACjC,KAAI,WAAW,OAAW,QAAO;AACjC,KAAI,MAAM,QAAQ,OAAO,CAAE,QAAO;AAClC,KAAI,cAAc,OAAO,IAAI,cAAc,OAAO,EAAE;EAClD,MAAM,SAAS,EAAE,GAAG,QAAQ;AAE5B,OAAK,MAAM,OAAO,OAAO,KAAK,OAAO,EAAE;AACrC,OACE,QAAQ,eACR,QAAQ,iBACR,OAAO,SAAS,OAEhB;AACF,UAAO,OACL,OAAO,SAAS,SACZ,UAAU,OAAO,MAAM,OAAO,KAAK,GACnC,OAAO;;AAEf,SAAO;;AAET,QAAO;;;;;;;;;;;;;;;;;;;;;;;;;AA0BT,MAAa,kBACX,iBACA,QACA,aACY;CACZ,MAAM,OAAO,QACX,gBAAgB;CAGlB,MAAM,uBAAO,IAAI,KAAa;CAC9B,MAAM,UAAoB,EAAE;CAC5B,MAAM,aAAa,QAA4B;AAC7C,MAAI,OAAO,CAAC,KAAK,IAAI,IAAI,EAAE;AACzB,QAAK,IAAI,IAAI;AACb,WAAQ,KAAK,IAAI;;;AAIrB,WAAU,OAAO;AACjB,KAAI,OAAO,SAAS,IAAI,CAAE,WAAU,OAAO,MAAM,IAAI,CAAC,GAAG;AAEzD,WAAU,SAAS;AACnB,KAAI,UAAU,SAAS,IAAI,CAAE,WAAU,SAAS,MAAM,IAAI,CAAC,GAAG;CAI9D,MAAM,UAAqB,EAAE;AAE7B,MAAK,MAAM,OAAO,SAAS;EACzB,MAAM,MAAM,IAAI,IAAI;AAEpB,MAAI,QAAQ,OAAW;AACvB,MAAI,OAAO,QAAQ,UAAU;AAC3B,OAAI,QAAQ,WAAW,EAAG,QAAO;AACjC;;AAGF,UAAQ,KAAK,IAAI;;AAGnB,KAAI,QAAQ,WAAW,EAAG,QAAO;AACjC,KAAI,QAAQ,WAAW,EAAG,QAAO,QAAQ;AACzC,KAAI,MAAM,QAAQ,QAAQ,GAAG,CAAE,QAAO,QAAQ;AAG9C,QAAQ,QAAqB,QAAQ,KAAK,SACxC,UAAU,KAAK,KAAK,CACrB"}
|
|
@@ -1,50 +1,34 @@
|
|
|
1
1
|
//#region src/interpreter/getTranslation.ts
|
|
2
2
|
/**
|
|
3
|
-
* Check if a value is a plain object that can be safely
|
|
3
|
+
* Check if a value is a plain object that can be safely merged.
|
|
4
4
|
* Returns false for Promises, React elements, class instances, etc.
|
|
5
5
|
*/
|
|
6
6
|
const isPlainObject = (value) => {
|
|
7
7
|
if (value === null || typeof value !== "object") return false;
|
|
8
|
-
if (
|
|
8
|
+
if (typeof value.then === "function") return false;
|
|
9
9
|
if (value.$$typeof !== void 0 || value.__v_isVNode !== void 0 || value._isVNode !== void 0 || value.isJSX !== void 0) return false;
|
|
10
10
|
const proto = Object.getPrototypeOf(value);
|
|
11
11
|
return proto === Object.prototype || proto === null || Array.isArray(value);
|
|
12
12
|
};
|
|
13
13
|
/**
|
|
14
|
-
* Recursively merges two objects.
|
|
15
|
-
*
|
|
16
|
-
* Arrays are replaced, not merged.
|
|
14
|
+
* Recursively merges two objects, skipping undefined source values.
|
|
15
|
+
* First argument takes precedence. Arrays replace rather than merge.
|
|
17
16
|
*/
|
|
18
|
-
const
|
|
17
|
+
const deepMerge = (target, source) => {
|
|
19
18
|
if (target === void 0) return source;
|
|
20
19
|
if (source === void 0) return target;
|
|
21
20
|
if (Array.isArray(target)) return target;
|
|
22
21
|
if (isPlainObject(target) && isPlainObject(source)) {
|
|
23
22
|
const result = { ...target };
|
|
24
23
|
for (const key of Object.keys(source)) {
|
|
25
|
-
if (key === "__proto__" || key === "constructor") continue;
|
|
26
|
-
|
|
27
|
-
else result[key] = source[key];
|
|
24
|
+
if (key === "__proto__" || key === "constructor" || source[key] === void 0) continue;
|
|
25
|
+
result[key] = target[key] !== void 0 ? deepMerge(target[key], source[key]) : source[key];
|
|
28
26
|
}
|
|
29
27
|
return result;
|
|
30
28
|
}
|
|
31
29
|
return target;
|
|
32
30
|
};
|
|
33
31
|
/**
|
|
34
|
-
* Recursively removes undefined values from an object.
|
|
35
|
-
* Handles circular references by tracking visited objects.
|
|
36
|
-
*/
|
|
37
|
-
const removeUndefinedValues = (object, visited = /* @__PURE__ */ new WeakSet()) => {
|
|
38
|
-
if (typeof object !== "object" || object === null) return object;
|
|
39
|
-
if (visited.has(object)) return object;
|
|
40
|
-
visited.add(object);
|
|
41
|
-
if (!isPlainObject(object)) return object;
|
|
42
|
-
if (Array.isArray(object)) return object.map((item) => removeUndefinedValues(item, visited));
|
|
43
|
-
const result = {};
|
|
44
|
-
for (const [key, value] of Object.entries(object)) if (value !== void 0) result[key] = removeUndefinedValues(value, visited);
|
|
45
|
-
return result;
|
|
46
|
-
};
|
|
47
|
-
/**
|
|
48
32
|
* Picks the appropriate content from a locale map based on the provided locale.
|
|
49
33
|
*
|
|
50
34
|
* It handles:
|
|
@@ -68,42 +52,33 @@ const removeUndefinedValues = (object, visited = /* @__PURE__ */ new WeakSet())
|
|
|
68
52
|
* ```
|
|
69
53
|
*/
|
|
70
54
|
const getTranslation = (languageContent, locale, fallback) => {
|
|
71
|
-
const
|
|
72
|
-
const
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
if (genericLocale in languageContent) {
|
|
79
|
-
const genericContent = getContent(genericLocale);
|
|
80
|
-
if (typeof genericContent === "string") {
|
|
81
|
-
if (results.length === 0) return genericContent;
|
|
82
|
-
} else if (genericContent !== void 0) results.push(genericContent);
|
|
55
|
+
const get = (loc) => languageContent[loc];
|
|
56
|
+
const seen = /* @__PURE__ */ new Set();
|
|
57
|
+
const locales = [];
|
|
58
|
+
const addLocale = (loc) => {
|
|
59
|
+
if (loc && !seen.has(loc)) {
|
|
60
|
+
seen.add(loc);
|
|
61
|
+
locales.push(loc);
|
|
83
62
|
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
if (
|
|
93
|
-
|
|
94
|
-
if (
|
|
95
|
-
|
|
96
|
-
if (typeof genericFallbackContent === "string") {
|
|
97
|
-
if (results.length === 0) return genericFallbackContent;
|
|
98
|
-
} else if (genericFallbackContent !== void 0) results.push(genericFallbackContent);
|
|
99
|
-
}
|
|
63
|
+
};
|
|
64
|
+
addLocale(locale);
|
|
65
|
+
if (locale.includes("-")) addLocale(locale.split("-")[0]);
|
|
66
|
+
addLocale(fallback);
|
|
67
|
+
if (fallback?.includes("-")) addLocale(fallback.split("-")[0]);
|
|
68
|
+
const results = [];
|
|
69
|
+
for (const loc of locales) {
|
|
70
|
+
const val = get(loc);
|
|
71
|
+
if (val === void 0) continue;
|
|
72
|
+
if (typeof val === "string") {
|
|
73
|
+
if (results.length === 0) return val;
|
|
74
|
+
continue;
|
|
100
75
|
}
|
|
76
|
+
results.push(val);
|
|
101
77
|
}
|
|
102
|
-
if (results.length === 0) return;
|
|
103
|
-
|
|
104
|
-
if (
|
|
105
|
-
|
|
106
|
-
return cleanResults.reduce((acc, curr) => deepMergeObjects(acc, curr));
|
|
78
|
+
if (results.length === 0) return void 0;
|
|
79
|
+
if (results.length === 1) return results[0];
|
|
80
|
+
if (Array.isArray(results[0])) return results[0];
|
|
81
|
+
return results.reduce((acc, curr) => deepMerge(acc, curr));
|
|
107
82
|
};
|
|
108
83
|
|
|
109
84
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getTranslation.mjs","names":[],"sources":["../../../src/interpreter/getTranslation.ts"],"sourcesContent":["import type {\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\n\n/**\n * Check if a value is a plain object that can be safely
|
|
1
|
+
{"version":3,"file":"getTranslation.mjs","names":[],"sources":["../../../src/interpreter/getTranslation.ts"],"sourcesContent":["import type {\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\n\n/**\n * Check if a value is a plain object that can be safely merged.\n * Returns false for Promises, React elements, class instances, etc.\n */\nconst isPlainObject = (value: unknown): boolean => {\n if (value === null || typeof value !== 'object') return false;\n if (typeof (value as any).then === 'function') return false;\n if (\n (value as any).$$typeof !== undefined ||\n (value as any).__v_isVNode !== undefined ||\n (value as any)._isVNode !== undefined ||\n (value as any).isJSX !== undefined\n ) {\n return false;\n }\n const proto = Object.getPrototypeOf(value);\n return proto === Object.prototype || proto === null || Array.isArray(value);\n};\n\n/**\n * Recursively merges two objects, skipping undefined source values.\n * First argument takes precedence. Arrays replace rather than merge.\n */\nconst deepMerge = (target: any, source: any): any => {\n if (target === undefined) return source;\n if (source === undefined) return target;\n if (Array.isArray(target)) return target;\n if (isPlainObject(target) && isPlainObject(source)) {\n const result = { ...target };\n\n for (const key of Object.keys(source)) {\n if (\n key === '__proto__' ||\n key === 'constructor' ||\n source[key] === undefined\n )\n continue;\n result[key] =\n target[key] !== undefined\n ? deepMerge(target[key], source[key])\n : source[key];\n }\n return result;\n }\n return target;\n};\n\n/**\n * Picks the appropriate content from a locale map based on the provided locale.\n *\n * It handles:\n * 1. Exact locale match (e.g., 'en-US').\n * 2. Generic locale fallback (e.g., 'en' if 'en-US' is not found).\n * 3. Explicit fallback locale.\n * 4. Deep merging of objects to ensure partial translations are complemented by fallbacks.\n *\n * @param languageContent - A map of locales to content.\n * @param locale - The target locale to retrieve.\n * @param fallback - Optional fallback locale if the target is not found.\n * @returns The translated content.\n *\n * @example\n * ```ts\n * const content = getTranslation({\n * en: 'Hello',\n * fr: 'Bonjour',\n * }, 'fr');\n * // 'Bonjour'\n * ```\n */\nexport const getTranslation = <Content = string>(\n languageContent: StrictModeLocaleMap<Content>,\n locale: LocalesValues,\n fallback?: LocalesValues\n): Content => {\n const get = (loc: string): Content | undefined =>\n languageContent[loc as keyof typeof languageContent];\n\n // Build priority-ordered locale candidates (most specific first), deduped\n const seen = new Set<string>();\n const locales: string[] = [];\n const addLocale = (loc: string | undefined) => {\n if (loc && !seen.has(loc)) {\n seen.add(loc);\n locales.push(loc);\n }\n };\n\n addLocale(locale);\n if (locale.includes('-')) addLocale(locale.split('-')[0]);\n\n addLocale(fallback);\n if (fallback?.includes('-')) addLocale(fallback.split('-')[0]);\n\n // Collect results: strings exit early (if no higher-priority object was found),\n // objects are accumulated for deep merging.\n const results: Content[] = [];\n\n for (const loc of locales) {\n const val = get(loc);\n\n if (val === undefined) continue;\n if (typeof val === 'string') {\n if (results.length === 0) return val;\n continue; // an object at higher priority takes precedence\n }\n\n results.push(val);\n }\n\n if (results.length === 0) return undefined as Content;\n if (results.length === 1) return results[0];\n if (Array.isArray(results[0])) return results[0];\n\n // Merge objects: first result (most specific) takes precedence\n return (results as object[]).reduce((acc, curr) =>\n deepMerge(acc, curr)\n ) as Content;\n};\n"],"mappings":";;;;;AASA,MAAM,iBAAiB,UAA4B;AACjD,KAAI,UAAU,QAAQ,OAAO,UAAU,SAAU,QAAO;AACxD,KAAI,OAAQ,MAAc,SAAS,WAAY,QAAO;AACtD,KACG,MAAc,aAAa,UAC3B,MAAc,gBAAgB,UAC9B,MAAc,aAAa,UAC3B,MAAc,UAAU,OAEzB,QAAO;CAET,MAAM,QAAQ,OAAO,eAAe,MAAM;AAC1C,QAAO,UAAU,OAAO,aAAa,UAAU,QAAQ,MAAM,QAAQ,MAAM;;;;;;AAO7E,MAAM,aAAa,QAAa,WAAqB;AACnD,KAAI,WAAW,OAAW,QAAO;AACjC,KAAI,WAAW,OAAW,QAAO;AACjC,KAAI,MAAM,QAAQ,OAAO,CAAE,QAAO;AAClC,KAAI,cAAc,OAAO,IAAI,cAAc,OAAO,EAAE;EAClD,MAAM,SAAS,EAAE,GAAG,QAAQ;AAE5B,OAAK,MAAM,OAAO,OAAO,KAAK,OAAO,EAAE;AACrC,OACE,QAAQ,eACR,QAAQ,iBACR,OAAO,SAAS,OAEhB;AACF,UAAO,OACL,OAAO,SAAS,SACZ,UAAU,OAAO,MAAM,OAAO,KAAK,GACnC,OAAO;;AAEf,SAAO;;AAET,QAAO;;;;;;;;;;;;;;;;;;;;;;;;;AA0BT,MAAa,kBACX,iBACA,QACA,aACY;CACZ,MAAM,OAAO,QACX,gBAAgB;CAGlB,MAAM,uBAAO,IAAI,KAAa;CAC9B,MAAM,UAAoB,EAAE;CAC5B,MAAM,aAAa,QAA4B;AAC7C,MAAI,OAAO,CAAC,KAAK,IAAI,IAAI,EAAE;AACzB,QAAK,IAAI,IAAI;AACb,WAAQ,KAAK,IAAI;;;AAIrB,WAAU,OAAO;AACjB,KAAI,OAAO,SAAS,IAAI,CAAE,WAAU,OAAO,MAAM,IAAI,CAAC,GAAG;AAEzD,WAAU,SAAS;AACnB,KAAI,UAAU,SAAS,IAAI,CAAE,WAAU,SAAS,MAAM,IAAI,CAAC,GAAG;CAI9D,MAAM,UAAqB,EAAE;AAE7B,MAAK,MAAM,OAAO,SAAS;EACzB,MAAM,MAAM,IAAI,IAAI;AAEpB,MAAI,QAAQ,OAAW;AACvB,MAAI,OAAO,QAAQ,UAAU;AAC3B,OAAI,QAAQ,WAAW,EAAG,QAAO;AACjC;;AAGF,UAAQ,KAAK,IAAI;;AAGnB,KAAI,QAAQ,WAAW,EAAG,QAAO;AACjC,KAAI,QAAQ,WAAW,EAAG,QAAO,QAAQ;AACzC,KAAI,MAAM,QAAQ,QAAQ,GAAG,CAAE,QAAO,QAAQ;AAG9C,QAAQ,QAAqB,QAAQ,KAAK,SACxC,UAAU,KAAK,KAAK,CACrB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getTranslation.d.ts","names":[],"sources":["../../../src/interpreter/getTranslation.ts"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"getTranslation.d.ts","names":[],"sources":["../../../src/interpreter/getTranslation.ts"],"mappings":";;;;;AA2EA;;;;;;;;;;;;;;;;;;;;;cAAa,cAAA,qBACX,eAAA,EAAiB,mBAAA,CAAoB,OAAA,GACrC,MAAA,EAAQ,aAAA,EACR,QAAA,GAAW,aAAA,KACV,OAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlayer/core",
|
|
3
|
-
"version": "8.4.
|
|
3
|
+
"version": "8.4.6",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Includes core Intlayer functions like translation, dictionary, and utility functions shared across multiple packages.",
|
|
6
6
|
"keywords": [
|
|
@@ -168,11 +168,11 @@
|
|
|
168
168
|
"typecheck": "tsc --noEmit --project tsconfig.types.json"
|
|
169
169
|
},
|
|
170
170
|
"dependencies": {
|
|
171
|
-
"@intlayer/api": "8.4.
|
|
172
|
-
"@intlayer/config": "8.4.
|
|
173
|
-
"@intlayer/dictionaries-entry": "8.4.
|
|
174
|
-
"@intlayer/types": "8.4.
|
|
175
|
-
"@intlayer/unmerged-dictionaries-entry": "8.4.
|
|
171
|
+
"@intlayer/api": "8.4.6",
|
|
172
|
+
"@intlayer/config": "8.4.6",
|
|
173
|
+
"@intlayer/dictionaries-entry": "8.4.6",
|
|
174
|
+
"@intlayer/types": "8.4.6",
|
|
175
|
+
"@intlayer/unmerged-dictionaries-entry": "8.4.6",
|
|
176
176
|
"defu": "6.1.4"
|
|
177
177
|
},
|
|
178
178
|
"devDependencies": {
|