@intlayer/core 7.0.6 → 7.0.8-canary.0
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/deepTransformPlugins/getFilterMissingTranslationsContent.cjs +0 -1
- package/dist/cjs/deepTransformPlugins/getFilterMissingTranslationsContent.cjs.map +1 -1
- package/dist/cjs/deepTransformPlugins/getFilterTranslationsOnlyContent.cjs +0 -1
- package/dist/cjs/deepTransformPlugins/getFilterTranslationsOnlyContent.cjs.map +1 -1
- package/dist/cjs/deepTransformPlugins/getFilteredLocalesContent.cjs +0 -1
- package/dist/cjs/deepTransformPlugins/getFilteredLocalesContent.cjs.map +1 -1
- package/dist/cjs/deepTransformPlugins/getMissingLocalesContent.cjs +0 -1
- package/dist/cjs/deepTransformPlugins/getMissingLocalesContent.cjs.map +1 -1
- package/dist/cjs/deepTransformPlugins/getSplittedContent.cjs +0 -1
- package/dist/cjs/deepTransformPlugins/getSplittedContent.cjs.map +1 -1
- package/dist/cjs/deepTransformPlugins/insertContentInDictionary.cjs +0 -1
- package/dist/cjs/deepTransformPlugins/insertContentInDictionary.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/editDictionaryByKeyPath.cjs +0 -1
- package/dist/cjs/dictionaryManipulator/editDictionaryByKeyPath.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/getContentNodeByKeyPath.cjs +0 -1
- package/dist/cjs/dictionaryManipulator/getContentNodeByKeyPath.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/getDefaultNode.cjs +0 -1
- package/dist/cjs/dictionaryManipulator/getDefaultNode.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/getEmptyNode.cjs +0 -1
- package/dist/cjs/dictionaryManipulator/getEmptyNode.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/getNodeChildren.cjs +0 -1
- package/dist/cjs/dictionaryManipulator/getNodeChildren.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/getNodeType.cjs +0 -1
- package/dist/cjs/dictionaryManipulator/getNodeType.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/mergeDictionaries.cjs +0 -1
- package/dist/cjs/dictionaryManipulator/mergeDictionaries.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/removeContentNodeByKeyPath.cjs +0 -1
- package/dist/cjs/dictionaryManipulator/removeContentNodeByKeyPath.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/renameContentNodeByKeyPath.cjs +0 -1
- package/dist/cjs/dictionaryManipulator/renameContentNodeByKeyPath.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/updateNodeChildren.cjs +0 -1
- package/dist/cjs/dictionaryManipulator/updateNodeChildren.cjs.map +1 -1
- package/dist/cjs/getStorageAttributes.cjs +0 -1
- package/dist/cjs/getStorageAttributes.cjs.map +1 -1
- package/dist/cjs/interpreter/getContent/deepTransform.cjs +0 -1
- package/dist/cjs/interpreter/getContent/deepTransform.cjs.map +1 -1
- package/dist/cjs/interpreter/getContent/plugins.cjs +0 -1
- package/dist/cjs/interpreter/getContent/plugins.cjs.map +1 -1
- package/dist/cjs/interpreter/getIntlayer.cjs +0 -1
- package/dist/cjs/interpreter/getIntlayer.cjs.map +1 -1
- package/dist/cjs/localization/getBrowserLocale.cjs +0 -1
- package/dist/cjs/localization/getBrowserLocale.cjs.map +1 -1
- package/dist/cjs/localization/getHTMLTextDir.cjs +0 -1
- package/dist/cjs/localization/getHTMLTextDir.cjs.map +1 -1
- package/dist/cjs/localization/getLocaleFromPath.cjs +0 -1
- package/dist/cjs/localization/getLocaleFromPath.cjs.map +1 -1
- package/dist/cjs/localization/getLocalizedUrl.cjs.map +1 -1
- package/dist/cjs/localization/getMultilingualUrls.cjs +0 -1
- package/dist/cjs/localization/getMultilingualUrls.cjs.map +1 -1
- package/dist/cjs/localization/localeMapper.cjs +0 -1
- package/dist/cjs/localization/localeMapper.cjs.map +1 -1
- package/dist/cjs/transpiler/condition/condition.cjs +0 -1
- package/dist/cjs/transpiler/condition/condition.cjs.map +1 -1
- package/dist/cjs/transpiler/enumeration/enumeration.cjs +0 -1
- package/dist/cjs/transpiler/enumeration/enumeration.cjs.map +1 -1
- package/dist/cjs/transpiler/file/file.cjs +0 -4
- package/dist/cjs/transpiler/file/file.cjs.map +1 -1
- package/dist/cjs/transpiler/file/fileBrowser.cjs +0 -2
- package/dist/cjs/transpiler/file/fileBrowser.cjs.map +1 -1
- package/dist/cjs/transpiler/gender/gender.cjs +0 -1
- package/dist/cjs/transpiler/gender/gender.cjs.map +1 -1
- package/dist/cjs/transpiler/insertion/insertion.cjs +0 -1
- package/dist/cjs/transpiler/insertion/insertion.cjs.map +1 -1
- package/dist/cjs/transpiler/markdown/markdown.cjs +0 -1
- package/dist/cjs/transpiler/markdown/markdown.cjs.map +1 -1
- package/dist/cjs/transpiler/nesting/nesting.cjs +0 -1
- package/dist/cjs/transpiler/nesting/nesting.cjs.map +1 -1
- package/dist/cjs/transpiler/translation/translation.cjs +0 -1
- package/dist/cjs/transpiler/translation/translation.cjs.map +1 -1
- package/dist/cjs/utils/intl.cjs +0 -1
- package/dist/cjs/utils/intl.cjs.map +1 -1
- package/dist/esm/localization/getLocalizedUrl.mjs.map +1 -1
- package/dist/types/deepTransformPlugins/getFilterMissingTranslationsContent.d.ts +1 -0
- package/dist/types/deepTransformPlugins/getFilterMissingTranslationsContent.d.ts.map +1 -1
- package/dist/types/deepTransformPlugins/getFilterTranslationsOnlyContent.d.ts +1 -0
- package/dist/types/deepTransformPlugins/getFilterTranslationsOnlyContent.d.ts.map +1 -1
- package/dist/types/deepTransformPlugins/getFilteredLocalesContent.d.ts +5 -4
- package/dist/types/deepTransformPlugins/getFilteredLocalesContent.d.ts.map +1 -1
- package/dist/types/deepTransformPlugins/getLocalizedContent.d.ts +1 -0
- package/dist/types/deepTransformPlugins/getLocalizedContent.d.ts.map +1 -1
- package/dist/types/deepTransformPlugins/getMaskContent.d.ts +1 -0
- package/dist/types/deepTransformPlugins/getMaskContent.d.ts.map +1 -1
- package/dist/types/deepTransformPlugins/getMissingLocalesContent.d.ts +1 -0
- package/dist/types/deepTransformPlugins/getMissingLocalesContent.d.ts.map +1 -1
- package/dist/types/deepTransformPlugins/getReplacedValuesContent.d.ts +1 -0
- package/dist/types/deepTransformPlugins/getReplacedValuesContent.d.ts.map +1 -1
- package/dist/types/dictionaryManipulator/orderDictionaries.d.ts +2 -2
- package/dist/types/index.d.ts +6 -0
- package/dist/types/interpreter/getCondition.d.ts +1 -0
- package/dist/types/interpreter/getCondition.d.ts.map +1 -1
- package/dist/types/interpreter/getContent/plugins.d.ts +1 -0
- package/dist/types/interpreter/getContent/plugins.d.ts.map +1 -1
- package/dist/types/interpreter/getDictionary.d.ts +1 -0
- package/dist/types/interpreter/getDictionary.d.ts.map +1 -1
- package/dist/types/interpreter/getEnumeration.d.ts +1 -0
- package/dist/types/interpreter/getEnumeration.d.ts.map +1 -1
- package/dist/types/interpreter/getGender.d.ts +1 -0
- package/dist/types/interpreter/getGender.d.ts.map +1 -1
- package/dist/types/interpreter/getInsertion.d.ts +1 -0
- package/dist/types/interpreter/getInsertion.d.ts.map +1 -1
- package/dist/types/interpreter/getIntlayer.d.ts +1 -0
- package/dist/types/interpreter/getIntlayer.d.ts.map +1 -1
- package/dist/types/interpreter/getNesting.d.ts +2 -0
- package/dist/types/interpreter/getNesting.d.ts.map +1 -1
- package/dist/types/interpreter/index.d.ts +1 -0
- package/dist/types/localization/getLocalizedUrl.d.ts.map +1 -1
- package/dist/types/transpiler/enumeration/enumeration.d.ts.map +1 -1
- package/dist/types/transpiler/index.d.ts +8 -0
- package/dist/types/transpiler/nesting/nesting.d.ts +1 -0
- package/dist/types/transpiler/nesting/nesting.d.ts.map +1 -1
- package/dist/types/transpiler/translation/translation.d.ts +1 -1
- package/dist/types/transpiler/translation/translation.d.ts.map +1 -1
- package/package.json +18 -18
|
@@ -3,7 +3,6 @@ const require_interpreter_getContent_deepTransform = require('../interpreter/get
|
|
|
3
3
|
const require_interpreter_getTranslation = require('../interpreter/getTranslation.cjs');
|
|
4
4
|
const require_transpiler_translation_translation = require('../transpiler/translation/translation.cjs');
|
|
5
5
|
let __intlayer_types = require("@intlayer/types");
|
|
6
|
-
__intlayer_types = require_rolldown_runtime.__toESM(__intlayer_types);
|
|
7
6
|
let __intlayer_config_built = require("@intlayer/config/built");
|
|
8
7
|
__intlayer_config_built = require_rolldown_runtime.__toESM(__intlayer_config_built);
|
|
9
8
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getFilterMissingTranslationsContent.cjs","names":["NodeType","deepTransformNode","configuration","getTranslation","tCore","result: Record<string, any>","arrayKeysIncluded: string[]","primitiveSiblingsToAppend: any[]","plugins: Plugins[]"],"sources":["../../../src/deepTransformPlugins/getFilterMissingTranslationsContent.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type {\n DeclaredLocales,\n Dictionary,\n LocalesValues,\n} from '@intlayer/types';\nimport { type ContentNode, type KeyPath, NodeType } from '@intlayer/types';\nimport {\n type DeepTransformContent,\n getTranslation,\n type NodeProps,\n type Plugins,\n} from '../interpreter';\nimport { deepTransformNode } from '../interpreter/getContent/deepTransform';\nimport { type TranslationContent, t as tCore } from '../transpiler';\n\n/**\n * Helper function to check if a node or its children contain translation nodes\n */\nconst hasTranslationNodes = (node: any): boolean => {\n if (typeof node !== 'object' || node === null) {\n return false;\n }\n\n if (node?.nodeType === NodeType.Translation) {\n return true;\n }\n\n if (Array.isArray(node)) {\n return node.some(hasTranslationNodes);\n }\n\n return Object.values(node).some(hasTranslationNodes);\n};\n\n/**\n * Get all keys from an object, recursively\n */\nconst getObjectKeys = (obj: any): Set<string> => {\n const keys = new Set<string>();\n\n if (typeof obj !== 'object' || obj === null) {\n return keys;\n }\n\n for (const key in obj) {\n keys.add(key);\n }\n\n return keys;\n};\n\n/**\n * Check if two objects have the same structure (same keys)\n */\nconst hasSameStructure = (obj1: any, obj2: any): boolean => {\n if (typeof obj1 !== 'object' || typeof obj2 !== 'object') {\n return typeof obj1 === typeof obj2;\n }\n\n if (obj1 === null || obj2 === null) {\n return obj1 === obj2;\n }\n\n if (Array.isArray(obj1) !== Array.isArray(obj2)) {\n return false;\n }\n\n const keys1 = getObjectKeys(obj1);\n const keys2 = getObjectKeys(obj2);\n\n if (keys1.size !== keys2.size) {\n return false;\n }\n\n for (const key of keys1) {\n if (!keys2.has(key)) {\n return false;\n }\n }\n\n return true;\n};\n\n/**\n * Check if all locales in a translation node have the same structure (recursively)\n * Returns an object with locales that have missing keys\n */\nconst checkTranslationStructureConsistency = (\n translationNode: Record<string, any>\n): { hasInconsistency: boolean; localesWithMissingKeys: Set<string> } => {\n const locales = Object.keys(translationNode);\n const localesWithMissingKeys = new Set<string>();\n\n if (locales.length <= 1) {\n return { hasInconsistency: false, localesWithMissingKeys };\n }\n\n // Helper function to check structure recursively\n const checkStructureRecursive = (\n path: string,\n localeValues: Map<string, any>\n ): Set<string> => {\n const localesWithIssues = new Set<string>();\n\n // Get all unique keys across all locale values at this path\n const allKeys = new Set<string>();\n const objectLocales = new Map<string, any>();\n\n for (const [locale, value] of localeValues.entries()) {\n if (\n typeof value === 'object' &&\n value !== null &&\n !Array.isArray(value)\n ) {\n objectLocales.set(locale, value);\n const keys = getObjectKeys(value);\n for (const key of keys) {\n allKeys.add(key);\n }\n }\n }\n\n // If no objects at this level, no inconsistency\n if (objectLocales.size === 0) {\n return localesWithIssues;\n }\n\n // Check if each locale has all the keys at this level\n for (const [locale, value] of objectLocales.entries()) {\n const keys = getObjectKeys(value);\n if (keys.size !== allKeys.size) {\n localesWithIssues.add(locale);\n }\n }\n\n // Recursively check nested objects\n for (const key of allKeys) {\n const nestedValues = new Map<string, any>();\n for (const [locale, value] of objectLocales.entries()) {\n if (value[key] !== undefined) {\n nestedValues.set(locale, value[key]);\n }\n }\n\n if (nestedValues.size > 1) {\n const nestedIssues = checkStructureRecursive(\n path ? `${path}.${key}` : key,\n nestedValues\n );\n for (const locale of nestedIssues) {\n localesWithIssues.add(locale);\n }\n }\n }\n\n return localesWithIssues;\n };\n\n // Start recursive check from root\n const rootValues = new Map<string, any>();\n for (const locale of locales) {\n rootValues.set(locale, translationNode[locale]);\n }\n\n const issuesFound = checkStructureRecursive('', rootValues);\n const hasInconsistency = issuesFound.size > 0;\n\n for (const locale of issuesFound) {\n localesWithMissingKeys.add(locale);\n }\n\n return { hasInconsistency, localesWithMissingKeys };\n};\n\n/**\n * Check if array elements have consistent structures\n */\nconst checkArrayStructureConsistency = (arr: any[]): boolean => {\n if (arr.length <= 1) {\n return true;\n }\n\n const firstElement = arr[0];\n\n for (let i = 1; i < arr.length; i++) {\n if (!hasSameStructure(firstElement, arr[i])) {\n return false;\n }\n }\n\n return true;\n};\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const filterMissingTranslationsOnlyPlugin = (\n localeToCheck: LocalesValues\n): Plugins => ({\n id: 'filter-missing-translations-only-plugin',\n canHandle: (node: ContentNode) => {\n // Only handle objects and arrays, not primitives\n return typeof node === 'object' && node !== null;\n },\n transform: (node: ContentNode, props, deepTransformNode) => {\n if (typeof node === 'object' && node?.nodeType === NodeType.Translation) {\n const result = structuredClone(\n (node as TranslationContent)[NodeType.Translation]\n );\n\n const hasLocaleTranslation = Object.keys(result).includes(localeToCheck);\n\n // Check for structural inconsistencies across locales\n const { hasInconsistency, localesWithMissingKeys } =\n checkTranslationStructureConsistency(result);\n\n // If there's a structural inconsistency and the locale being checked\n // has missing keys, treat it as a missing translation\n const hasStructuralIssue =\n hasInconsistency && localesWithMissingKeys.has(localeToCheck);\n\n if (hasLocaleTranslation && !hasStructuralIssue) {\n return undefined; // Return undefined to remove the node\n }\n\n // Transform nested content\n for (const key in result) {\n const childProps = {\n ...props,\n children: result[key as unknown as keyof typeof result],\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Translation, key } as KeyPath,\n ],\n };\n result[key as unknown as keyof typeof result] = deepTransformNode(\n result[key as unknown as keyof typeof result],\n {\n ...childProps,\n plugins: [\n ...(props.plugins ?? ([] as Plugins[])).filter(\n (plugin) =>\n plugin.id !== 'filter-missing-translations-only-plugin'\n ),\n ],\n }\n );\n }\n\n // Return the base locale content as a translation node\n // If base locale is missing, use any available locale as fallback\n const baseLocale = configuration?.internationalization?.defaultLocale;\n const availableLocales = Object.keys(result);\n\n if (availableLocales.length === 0) {\n return undefined; // No translations available\n }\n\n // Try to get the base locale first, then any available locale as fallback\n const fallbackLocale = availableLocales.includes(baseLocale)\n ? baseLocale\n : availableLocales[0];\n\n const fallbackValue = getTranslation(result, baseLocale, fallbackLocale);\n\n // Return the translation node structure with only the fallback locale\n return tCore({ [fallbackLocale]: fallbackValue });\n } else if (\n typeof node === 'object' &&\n node !== null &&\n !Array.isArray(node) &&\n !node?.nodeType\n ) {\n // For regular objects, include only children that are related to translations\n // - Keep children that contain translation nodes (directly or nested)\n // - Keep arrays (they may mix translated and non-translated values)\n // - Exclude primitive values (string/number/boolean/null/undefined) at object level\n const result: Record<string, any> = {};\n let hasMissingTranslations = false;\n const arrayKeysIncluded: string[] = [];\n const primitiveSiblingsToAppend: any[] = [];\n\n for (const key in node as any) {\n const originalChild = (node as any)[key];\n const childProps = {\n ...props,\n children: originalChild,\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Object, key } as KeyPath,\n ],\n };\n const transformedChild = deepTransformNode(originalChild, childProps);\n\n const isPrimitiveSibling =\n originalChild === null ||\n (typeof originalChild !== 'object' &&\n typeof originalChild !== 'function');\n\n if (isPrimitiveSibling) {\n // Defer primitives; they may be appended to an array sibling later\n if (originalChild !== undefined) {\n primitiveSiblingsToAppend.push(originalChild);\n }\n continue;\n }\n\n const includeChild =\n transformedChild !== undefined &&\n (hasTranslationNodes(originalChild) || Array.isArray(originalChild));\n\n if (includeChild) {\n result[key] = transformedChild;\n hasMissingTranslations = true;\n if (Array.isArray(transformedChild)) {\n arrayKeysIncluded.push(key);\n }\n }\n }\n\n // If any array child is present, append primitive siblings into the first array\n if (\n arrayKeysIncluded.length > 0 &&\n primitiveSiblingsToAppend.length > 0\n ) {\n const targetArrayKey = arrayKeysIncluded[0];\n // Ensure array exists in result (it should, but be defensive)\n if (Array.isArray(result[targetArrayKey])) {\n result[targetArrayKey] = [\n ...result[targetArrayKey],\n ...primitiveSiblingsToAppend,\n ];\n hasMissingTranslations = true;\n }\n }\n\n // Only return the object if it has missing translations-related content\n return hasMissingTranslations ? result : undefined;\n } else if (Array.isArray(node)) {\n // Check if array elements have consistent structures\n const hasConsistentStructure = checkArrayStructureConsistency(node);\n\n // For arrays, only include items that have missing translations\n const result = node\n .map((child, index) => {\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Array, key: index } as KeyPath,\n ],\n };\n return deepTransformNode(child, childProps);\n })\n .filter((item) => item !== null && item !== undefined);\n\n // If there's structural inconsistency in the array, include it\n // even if it has no missing translations, to flag the issue\n if (!hasConsistentStructure && result.length === 0) {\n // Return a marker to indicate structural inconsistency\n return node; // Return original array to show the issue\n }\n\n // Only return the array if it has items with missing translations\n return result.length > 0 ? result : undefined;\n }\n\n return node; // Return non-translation content as is\n },\n});\n\n/**\n * For each translation node, it compare is both localeToCheck and baseLocale are present.\n *\n * If yes, it should remove the node from the content.\n * If no, it should keep the node\n *\n * In complete mode, for large dictionaries, we want to filter all content that is already translated\n *\n * locale: fr\n *\n * { test1: t({ ar: 'Hello', en: 'Hello', fr: 'Bonjour' } }) -> {}\n * { test2: t({ ar: 'Hello', en: 'Hello' }) } -> { test2: t({ ar: 'Hello', en: 'Hello' }) }\n *\n */\nexport const getFilterMissingTranslationsContent = <\n T extends ContentNode,\n L extends LocalesValues = DeclaredLocales,\n>(\n node: T,\n localeToCheck: L,\n nodeProps: NodeProps\n) => {\n const plugins: Plugins[] = [\n filterMissingTranslationsOnlyPlugin(localeToCheck),\n ...(nodeProps.plugins ?? []),\n ];\n\n const result = deepTransformNode(node, {\n ...nodeProps,\n plugins,\n }) as DeepTransformContent<T>;\n\n // Stringify the result to remove the undefined values\n if (result === undefined) {\n // No missing translations found\n return {} as DeepTransformContent<T>;\n }\n return JSON.parse(JSON.stringify(result));\n};\n\nexport const getFilterMissingTranslationsDictionary = (\n dictionary: Dictionary,\n localeToCheck: LocalesValues\n) => ({\n ...dictionary,\n content: getFilterMissingTranslationsContent(\n dictionary.content,\n localeToCheck,\n {\n dictionaryKey: dictionary.key,\n keyPath: [],\n plugins: [],\n }\n ),\n});\n"],"mappings":";;;;;;;;;;;;;AAmBA,MAAM,uBAAuB,SAAuB;AAClD,KAAI,OAAO,SAAS,YAAY,SAAS,KACvC,QAAO;AAGT,KAAI,MAAM,aAAaA,0BAAS,YAC9B,QAAO;AAGT,KAAI,MAAM,QAAQ,KAAK,CACrB,QAAO,KAAK,KAAK,oBAAoB;AAGvC,QAAO,OAAO,OAAO,KAAK,CAAC,KAAK,oBAAoB;;;;;AAMtD,MAAM,iBAAiB,QAA0B;CAC/C,MAAM,uBAAO,IAAI,KAAa;AAE9B,KAAI,OAAO,QAAQ,YAAY,QAAQ,KACrC,QAAO;AAGT,MAAK,MAAM,OAAO,IAChB,MAAK,IAAI,IAAI;AAGf,QAAO;;;;;AAMT,MAAM,oBAAoB,MAAW,SAAuB;AAC1D,KAAI,OAAO,SAAS,YAAY,OAAO,SAAS,SAC9C,QAAO,OAAO,SAAS,OAAO;AAGhC,KAAI,SAAS,QAAQ,SAAS,KAC5B,QAAO,SAAS;AAGlB,KAAI,MAAM,QAAQ,KAAK,KAAK,MAAM,QAAQ,KAAK,CAC7C,QAAO;CAGT,MAAM,QAAQ,cAAc,KAAK;CACjC,MAAM,QAAQ,cAAc,KAAK;AAEjC,KAAI,MAAM,SAAS,MAAM,KACvB,QAAO;AAGT,MAAK,MAAM,OAAO,MAChB,KAAI,CAAC,MAAM,IAAI,IAAI,CACjB,QAAO;AAIX,QAAO;;;;;;AAOT,MAAM,wCACJ,oBACuE;CACvE,MAAM,UAAU,OAAO,KAAK,gBAAgB;CAC5C,MAAM,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IAAI,SAAS;;AAGtC,SAAO;;CAEV;;;;;;;;;;;;;;;AAgBD,MAAa,uCAIX,MACA,eACA,cACG;CACH,MAAMQ,UAAqB,CACzB,oCAAoC,cAAc,EAClD,GAAI,UAAU,WAAW,EAAE,CAC5B;CAED,MAAM,SAASP,+DAAkB,MAAM;EACrC,GAAG;EACH;EACD,CAAC;AAGF,KAAI,WAAW,OAEb,QAAO,EAAE;AAEX,QAAO,KAAK,MAAM,KAAK,UAAU,OAAO,CAAC;;AAG3C,MAAa,0CACX,YACA,mBACI;CACJ,GAAG;CACH,SAAS,oCACP,WAAW,SACX,eACA;EACE,eAAe,WAAW;EAC1B,SAAS,EAAE;EACX,SAAS,EAAE;EACZ,CACF;CACF"}
|
|
1
|
+
{"version":3,"file":"getFilterMissingTranslationsContent.cjs","names":["NodeType","deepTransformNode","configuration","getTranslation","tCore","result: Record<string, any>","arrayKeysIncluded: string[]","primitiveSiblingsToAppend: any[]","plugins: Plugins[]"],"sources":["../../../src/deepTransformPlugins/getFilterMissingTranslationsContent.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type {\n DeclaredLocales,\n Dictionary,\n LocalesValues,\n} from '@intlayer/types';\nimport { type ContentNode, type KeyPath, NodeType } from '@intlayer/types';\nimport {\n type DeepTransformContent,\n getTranslation,\n type NodeProps,\n type Plugins,\n} from '../interpreter';\nimport { deepTransformNode } from '../interpreter/getContent/deepTransform';\nimport { type TranslationContent, t as tCore } from '../transpiler';\n\n/**\n * Helper function to check if a node or its children contain translation nodes\n */\nconst hasTranslationNodes = (node: any): boolean => {\n if (typeof node !== 'object' || node === null) {\n return false;\n }\n\n if (node?.nodeType === NodeType.Translation) {\n return true;\n }\n\n if (Array.isArray(node)) {\n return node.some(hasTranslationNodes);\n }\n\n return Object.values(node).some(hasTranslationNodes);\n};\n\n/**\n * Get all keys from an object, recursively\n */\nconst getObjectKeys = (obj: any): Set<string> => {\n const keys = new Set<string>();\n\n if (typeof obj !== 'object' || obj === null) {\n return keys;\n }\n\n for (const key in obj) {\n keys.add(key);\n }\n\n return keys;\n};\n\n/**\n * Check if two objects have the same structure (same keys)\n */\nconst hasSameStructure = (obj1: any, obj2: any): boolean => {\n if (typeof obj1 !== 'object' || typeof obj2 !== 'object') {\n return typeof obj1 === typeof obj2;\n }\n\n if (obj1 === null || obj2 === null) {\n return obj1 === obj2;\n }\n\n if (Array.isArray(obj1) !== Array.isArray(obj2)) {\n return false;\n }\n\n const keys1 = getObjectKeys(obj1);\n const keys2 = getObjectKeys(obj2);\n\n if (keys1.size !== keys2.size) {\n return false;\n }\n\n for (const key of keys1) {\n if (!keys2.has(key)) {\n return false;\n }\n }\n\n return true;\n};\n\n/**\n * Check if all locales in a translation node have the same structure (recursively)\n * Returns an object with locales that have missing keys\n */\nconst checkTranslationStructureConsistency = (\n translationNode: Record<string, any>\n): { hasInconsistency: boolean; localesWithMissingKeys: Set<string> } => {\n const locales = Object.keys(translationNode);\n const localesWithMissingKeys = new Set<string>();\n\n if (locales.length <= 1) {\n return { hasInconsistency: false, localesWithMissingKeys };\n }\n\n // Helper function to check structure recursively\n const checkStructureRecursive = (\n path: string,\n localeValues: Map<string, any>\n ): Set<string> => {\n const localesWithIssues = new Set<string>();\n\n // Get all unique keys across all locale values at this path\n const allKeys = new Set<string>();\n const objectLocales = new Map<string, any>();\n\n for (const [locale, value] of localeValues.entries()) {\n if (\n typeof value === 'object' &&\n value !== null &&\n !Array.isArray(value)\n ) {\n objectLocales.set(locale, value);\n const keys = getObjectKeys(value);\n for (const key of keys) {\n allKeys.add(key);\n }\n }\n }\n\n // If no objects at this level, no inconsistency\n if (objectLocales.size === 0) {\n return localesWithIssues;\n }\n\n // Check if each locale has all the keys at this level\n for (const [locale, value] of objectLocales.entries()) {\n const keys = getObjectKeys(value);\n if (keys.size !== allKeys.size) {\n localesWithIssues.add(locale);\n }\n }\n\n // Recursively check nested objects\n for (const key of allKeys) {\n const nestedValues = new Map<string, any>();\n for (const [locale, value] of objectLocales.entries()) {\n if (value[key] !== undefined) {\n nestedValues.set(locale, value[key]);\n }\n }\n\n if (nestedValues.size > 1) {\n const nestedIssues = checkStructureRecursive(\n path ? `${path}.${key}` : key,\n nestedValues\n );\n for (const locale of nestedIssues) {\n localesWithIssues.add(locale);\n }\n }\n }\n\n return localesWithIssues;\n };\n\n // Start recursive check from root\n const rootValues = new Map<string, any>();\n for (const locale of locales) {\n rootValues.set(locale, translationNode[locale]);\n }\n\n const issuesFound = checkStructureRecursive('', rootValues);\n const hasInconsistency = issuesFound.size > 0;\n\n for (const locale of issuesFound) {\n localesWithMissingKeys.add(locale);\n }\n\n return { hasInconsistency, localesWithMissingKeys };\n};\n\n/**\n * Check if array elements have consistent structures\n */\nconst checkArrayStructureConsistency = (arr: any[]): boolean => {\n if (arr.length <= 1) {\n return true;\n }\n\n const firstElement = arr[0];\n\n for (let i = 1; i < arr.length; i++) {\n if (!hasSameStructure(firstElement, arr[i])) {\n return false;\n }\n }\n\n return true;\n};\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const filterMissingTranslationsOnlyPlugin = (\n localeToCheck: LocalesValues\n): Plugins => ({\n id: 'filter-missing-translations-only-plugin',\n canHandle: (node: ContentNode) => {\n // Only handle objects and arrays, not primitives\n return typeof node === 'object' && node !== null;\n },\n transform: (node: ContentNode, props, deepTransformNode) => {\n if (typeof node === 'object' && node?.nodeType === NodeType.Translation) {\n const result = structuredClone(\n (node as TranslationContent)[NodeType.Translation]\n );\n\n const hasLocaleTranslation = Object.keys(result).includes(localeToCheck);\n\n // Check for structural inconsistencies across locales\n const { hasInconsistency, localesWithMissingKeys } =\n checkTranslationStructureConsistency(result);\n\n // If there's a structural inconsistency and the locale being checked\n // has missing keys, treat it as a missing translation\n const hasStructuralIssue =\n hasInconsistency && localesWithMissingKeys.has(localeToCheck);\n\n if (hasLocaleTranslation && !hasStructuralIssue) {\n return undefined; // Return undefined to remove the node\n }\n\n // Transform nested content\n for (const key in result) {\n const childProps = {\n ...props,\n children: result[key as unknown as keyof typeof result],\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Translation, key } as KeyPath,\n ],\n };\n result[key as unknown as keyof typeof result] = deepTransformNode(\n result[key as unknown as keyof typeof result],\n {\n ...childProps,\n plugins: [\n ...(props.plugins ?? ([] as Plugins[])).filter(\n (plugin) =>\n plugin.id !== 'filter-missing-translations-only-plugin'\n ),\n ],\n }\n );\n }\n\n // Return the base locale content as a translation node\n // If base locale is missing, use any available locale as fallback\n const baseLocale = configuration?.internationalization?.defaultLocale;\n const availableLocales = Object.keys(result);\n\n if (availableLocales.length === 0) {\n return undefined; // No translations available\n }\n\n // Try to get the base locale first, then any available locale as fallback\n const fallbackLocale = availableLocales.includes(baseLocale)\n ? baseLocale\n : availableLocales[0];\n\n const fallbackValue = getTranslation(result, baseLocale, fallbackLocale);\n\n // Return the translation node structure with only the fallback locale\n return tCore({ [fallbackLocale]: fallbackValue });\n } else if (\n typeof node === 'object' &&\n node !== null &&\n !Array.isArray(node) &&\n !node?.nodeType\n ) {\n // For regular objects, include only children that are related to translations\n // - Keep children that contain translation nodes (directly or nested)\n // - Keep arrays (they may mix translated and non-translated values)\n // - Exclude primitive values (string/number/boolean/null/undefined) at object level\n const result: Record<string, any> = {};\n let hasMissingTranslations = false;\n const arrayKeysIncluded: string[] = [];\n const primitiveSiblingsToAppend: any[] = [];\n\n for (const key in node as any) {\n const originalChild = (node as any)[key];\n const childProps = {\n ...props,\n children: originalChild,\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Object, key } as KeyPath,\n ],\n };\n const transformedChild = deepTransformNode(originalChild, childProps);\n\n const isPrimitiveSibling =\n originalChild === null ||\n (typeof originalChild !== 'object' &&\n typeof originalChild !== 'function');\n\n if (isPrimitiveSibling) {\n // Defer primitives; they may be appended to an array sibling later\n if (originalChild !== undefined) {\n primitiveSiblingsToAppend.push(originalChild);\n }\n continue;\n }\n\n const includeChild =\n transformedChild !== undefined &&\n (hasTranslationNodes(originalChild) || Array.isArray(originalChild));\n\n if (includeChild) {\n result[key] = transformedChild;\n hasMissingTranslations = true;\n if (Array.isArray(transformedChild)) {\n arrayKeysIncluded.push(key);\n }\n }\n }\n\n // If any array child is present, append primitive siblings into the first array\n if (\n arrayKeysIncluded.length > 0 &&\n primitiveSiblingsToAppend.length > 0\n ) {\n const targetArrayKey = arrayKeysIncluded[0];\n // Ensure array exists in result (it should, but be defensive)\n if (Array.isArray(result[targetArrayKey])) {\n result[targetArrayKey] = [\n ...result[targetArrayKey],\n ...primitiveSiblingsToAppend,\n ];\n hasMissingTranslations = true;\n }\n }\n\n // Only return the object if it has missing translations-related content\n return hasMissingTranslations ? result : undefined;\n } else if (Array.isArray(node)) {\n // Check if array elements have consistent structures\n const hasConsistentStructure = checkArrayStructureConsistency(node);\n\n // For arrays, only include items that have missing translations\n const result = node\n .map((child, index) => {\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Array, key: index } as KeyPath,\n ],\n };\n return deepTransformNode(child, childProps);\n })\n .filter((item) => item !== null && item !== undefined);\n\n // If there's structural inconsistency in the array, include it\n // even if it has no missing translations, to flag the issue\n if (!hasConsistentStructure && result.length === 0) {\n // Return a marker to indicate structural inconsistency\n return node; // Return original array to show the issue\n }\n\n // Only return the array if it has items with missing translations\n return result.length > 0 ? result : undefined;\n }\n\n return node; // Return non-translation content as is\n },\n});\n\n/**\n * For each translation node, it compare is both localeToCheck and baseLocale are present.\n *\n * If yes, it should remove the node from the content.\n * If no, it should keep the node\n *\n * In complete mode, for large dictionaries, we want to filter all content that is already translated\n *\n * locale: fr\n *\n * { test1: t({ ar: 'Hello', en: 'Hello', fr: 'Bonjour' } }) -> {}\n * { test2: t({ ar: 'Hello', en: 'Hello' }) } -> { test2: t({ ar: 'Hello', en: 'Hello' }) }\n *\n */\nexport const getFilterMissingTranslationsContent = <\n T extends ContentNode,\n L extends LocalesValues = DeclaredLocales,\n>(\n node: T,\n localeToCheck: L,\n nodeProps: NodeProps\n) => {\n const plugins: Plugins[] = [\n filterMissingTranslationsOnlyPlugin(localeToCheck),\n ...(nodeProps.plugins ?? []),\n ];\n\n const result = deepTransformNode(node, {\n ...nodeProps,\n plugins,\n }) as DeepTransformContent<T>;\n\n // Stringify the result to remove the undefined values\n if (result === undefined) {\n // No missing translations found\n return {} as DeepTransformContent<T>;\n }\n return JSON.parse(JSON.stringify(result));\n};\n\nexport const getFilterMissingTranslationsDictionary = (\n dictionary: Dictionary,\n localeToCheck: LocalesValues\n) => ({\n ...dictionary,\n content: getFilterMissingTranslationsContent(\n dictionary.content,\n localeToCheck,\n {\n dictionaryKey: dictionary.key,\n keyPath: [],\n plugins: [],\n }\n ),\n});\n"],"mappings":";;;;;;;;;;;;AAmBA,MAAM,uBAAuB,SAAuB;AAClD,KAAI,OAAO,SAAS,YAAY,SAAS,KACvC,QAAO;AAGT,KAAI,MAAM,aAAaA,0BAAS,YAC9B,QAAO;AAGT,KAAI,MAAM,QAAQ,KAAK,CACrB,QAAO,KAAK,KAAK,oBAAoB;AAGvC,QAAO,OAAO,OAAO,KAAK,CAAC,KAAK,oBAAoB;;;;;AAMtD,MAAM,iBAAiB,QAA0B;CAC/C,MAAM,uBAAO,IAAI,KAAa;AAE9B,KAAI,OAAO,QAAQ,YAAY,QAAQ,KACrC,QAAO;AAGT,MAAK,MAAM,OAAO,IAChB,MAAK,IAAI,IAAI;AAGf,QAAO;;;;;AAMT,MAAM,oBAAoB,MAAW,SAAuB;AAC1D,KAAI,OAAO,SAAS,YAAY,OAAO,SAAS,SAC9C,QAAO,OAAO,SAAS,OAAO;AAGhC,KAAI,SAAS,QAAQ,SAAS,KAC5B,QAAO,SAAS;AAGlB,KAAI,MAAM,QAAQ,KAAK,KAAK,MAAM,QAAQ,KAAK,CAC7C,QAAO;CAGT,MAAM,QAAQ,cAAc,KAAK;CACjC,MAAM,QAAQ,cAAc,KAAK;AAEjC,KAAI,MAAM,SAAS,MAAM,KACvB,QAAO;AAGT,MAAK,MAAM,OAAO,MACh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;KACF,CAC0C;KAC3C,CACD,QAAQ,SAAS,SAAS,QAAQ,SAAS,OAAU;AAIxD,OAAI,CAAC,0BAA0B,OAAO,WAAW,EAE/C,QAAO;AAIT,UAAO,OAAO,SAAS,IAAI,SAAS;;AAGtC,SAAO;;CAEV;;;;;;;;;;;;;;;AAgBD,MAAa,uCAIX,MACA,eACA,cACG;CACH,MAAMQ,UAAqB,CACzB,oCAAoC,cAAc,EAClD,GAAI,UAAU,WAAW,EAAE,CAC5B;CAED,MAAM,SAASP,+DAAkB,MAAM;EACrC,GAAG;EACH;EACD,CAAC;AAGF,KAAI,WAAW,OAEb,QAAO,EAAE;AAEX,QAAO,KAAK,MAAM,KAAK,UAAU,OAAO,CAAC;;AAG3C,MAAa,0CACX,YACA,mBACI;CACJ,GAAG;CACH,SAAS,oCACP,WAAW,SACX,eACA;EACE,eAAe,WAAW;EAC1B,SAAS,EAAE;EACX,SAAS,EAAE;EACZ,CACF;CACF"}
|
|
@@ -2,7 +2,6 @@ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
|
2
2
|
const require_interpreter_getContent_deepTransform = require('../interpreter/getContent/deepTransform.cjs');
|
|
3
3
|
const require_interpreter_getTranslation = require('../interpreter/getTranslation.cjs');
|
|
4
4
|
let __intlayer_types = require("@intlayer/types");
|
|
5
|
-
__intlayer_types = require_rolldown_runtime.__toESM(__intlayer_types);
|
|
6
5
|
let __intlayer_config_built = require("@intlayer/config/built");
|
|
7
6
|
__intlayer_config_built = require_rolldown_runtime.__toESM(__intlayer_config_built);
|
|
8
7
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getFilterTranslationsOnlyContent.cjs","names":["NodeType","deepTransformNode","getTranslation","result: Record<string, any>","configuration","plugins: Plugins[]"],"sources":["../../../src/deepTransformPlugins/getFilterTranslationsOnlyContent.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type {\n DeclaredLocales,\n Dictionary,\n LocalesValues,\n} from '@intlayer/types';\nimport { type ContentNode, type KeyPath, NodeType } from '@intlayer/types';\nimport {\n type DeepTransformContent,\n getTranslation,\n type NodeProps,\n type Plugins,\n} from '../interpreter';\nimport { deepTransformNode } from '../interpreter/getContent/deepTransform';\nimport type { TranslationContent } from '../transpiler';\n\n/**\n * Helper function to check if a node or its children contain translation nodes\n */\nconst hasTranslationNodes = (node: any): boolean => {\n if (typeof node !== 'object' || node === null) {\n return false;\n }\n\n if (node?.nodeType === NodeType.Translation) {\n return true;\n }\n\n if (Array.isArray(node)) {\n return node.some(hasTranslationNodes);\n }\n\n return Object.values(node).some(hasTranslationNodes);\n};\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const filterTranslationsOnlyPlugin = (\n locale: LocalesValues,\n fallback?: LocalesValues\n): Plugins => ({\n id: 'filter-translations-only-plugin',\n canHandle: (node: ContentNode) => {\n // Only handle objects and arrays, not primitives\n return typeof node === 'object' && node !== null;\n },\n transform: (node: ContentNode, props, deepTransformNode) => {\n if (typeof node === 'object' && node?.nodeType === NodeType.Translation) {\n const result = structuredClone(\n (node as TranslationContent)[NodeType.Translation]\n );\n\n for (const key in result) {\n const childProps = {\n ...props,\n children: result[key as unknown as keyof typeof result],\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Translation, key } as KeyPath,\n ],\n };\n result[key as unknown as keyof typeof result] = deepTransformNode(\n result[key as unknown as keyof typeof result],\n {\n ...childProps,\n plugins: [\n ...(props.plugins ?? ([] as Plugins[])).filter(\n (plugin) => plugin.id !== 'filter-translations-only-plugin'\n ),\n ],\n }\n );\n }\n return getTranslation(result, locale, fallback);\n } else if (\n typeof node === 'object' &&\n node !== null &&\n !Array.isArray(node) &&\n !node?.nodeType\n ) {\n // For regular objects, filter out properties that don't contain translations\n const result: Record<string, any> = {};\n for (const key in node as any) {\n if (hasTranslationNodes(node[key as unknown as keyof typeof node])) {\n const childProps = {\n ...props,\n children: node[key as unknown as keyof typeof node],\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Object, key } as KeyPath,\n ],\n };\n result[key] = deepTransformNode(\n node[key as unknown as keyof typeof node],\n childProps\n );\n }\n }\n return result;\n } else if (Array.isArray(node)) {\n // For arrays, keep all items but transform them\n return node.map((child, index) => {\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Array, key: index } as KeyPath,\n ],\n };\n return deepTransformNode(child, childProps);\n });\n }\n\n return 'to remove from the object';\n },\n});\n\n/**\n * Return the content of a node with only the translation plugin.\n *\n * @param node The node to transform.\n * @param locale The locale to use if your transformers need it (e.g. for translations).\n */\nexport const getFilterTranslationsOnlyContent = <\n T extends ContentNode,\n L extends LocalesValues = DeclaredLocales,\n>(\n node: T,\n locale: L = configuration?.internationalization?.defaultLocale as L,\n nodeProps: NodeProps,\n fallback?: LocalesValues\n) => {\n const plugins: Plugins[] = [\n filterTranslationsOnlyPlugin(locale, fallback),\n ...(nodeProps.plugins ?? []),\n ];\n\n return deepTransformNode(node, {\n ...nodeProps,\n plugins,\n }) as DeepTransformContent<T>;\n};\n\nexport const getFilterTranslationsOnlyDictionary = (\n dictionary: Dictionary,\n locale: LocalesValues = configuration?.internationalization\n ?.defaultLocale as LocalesValues,\n fallback?: LocalesValues\n) => ({\n ...dictionary,\n content: getFilterTranslationsOnlyContent(\n dictionary.content,\n locale,\n { dictionaryKey: dictionary.key, keyPath: [] },\n fallback\n ),\n});\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"getFilterTranslationsOnlyContent.cjs","names":["NodeType","deepTransformNode","getTranslation","result: Record<string, any>","configuration","plugins: Plugins[]"],"sources":["../../../src/deepTransformPlugins/getFilterTranslationsOnlyContent.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type {\n DeclaredLocales,\n Dictionary,\n LocalesValues,\n} from '@intlayer/types';\nimport { type ContentNode, type KeyPath, NodeType } from '@intlayer/types';\nimport {\n type DeepTransformContent,\n getTranslation,\n type NodeProps,\n type Plugins,\n} from '../interpreter';\nimport { deepTransformNode } from '../interpreter/getContent/deepTransform';\nimport type { TranslationContent } from '../transpiler';\n\n/**\n * Helper function to check if a node or its children contain translation nodes\n */\nconst hasTranslationNodes = (node: any): boolean => {\n if (typeof node !== 'object' || node === null) {\n return false;\n }\n\n if (node?.nodeType === NodeType.Translation) {\n return true;\n }\n\n if (Array.isArray(node)) {\n return node.some(hasTranslationNodes);\n }\n\n return Object.values(node).some(hasTranslationNodes);\n};\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const filterTranslationsOnlyPlugin = (\n locale: LocalesValues,\n fallback?: LocalesValues\n): Plugins => ({\n id: 'filter-translations-only-plugin',\n canHandle: (node: ContentNode) => {\n // Only handle objects and arrays, not primitives\n return typeof node === 'object' && node !== null;\n },\n transform: (node: ContentNode, props, deepTransformNode) => {\n if (typeof node === 'object' && node?.nodeType === NodeType.Translation) {\n const result = structuredClone(\n (node as TranslationContent)[NodeType.Translation]\n );\n\n for (const key in result) {\n const childProps = {\n ...props,\n children: result[key as unknown as keyof typeof result],\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Translation, key } as KeyPath,\n ],\n };\n result[key as unknown as keyof typeof result] = deepTransformNode(\n result[key as unknown as keyof typeof result],\n {\n ...childProps,\n plugins: [\n ...(props.plugins ?? ([] as Plugins[])).filter(\n (plugin) => plugin.id !== 'filter-translations-only-plugin'\n ),\n ],\n }\n );\n }\n return getTranslation(result, locale, fallback);\n } else if (\n typeof node === 'object' &&\n node !== null &&\n !Array.isArray(node) &&\n !node?.nodeType\n ) {\n // For regular objects, filter out properties that don't contain translations\n const result: Record<string, any> = {};\n for (const key in node as any) {\n if (hasTranslationNodes(node[key as unknown as keyof typeof node])) {\n const childProps = {\n ...props,\n children: node[key as unknown as keyof typeof node],\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Object, key } as KeyPath,\n ],\n };\n result[key] = deepTransformNode(\n node[key as unknown as keyof typeof node],\n childProps\n );\n }\n }\n return result;\n } else if (Array.isArray(node)) {\n // For arrays, keep all items but transform them\n return node.map((child, index) => {\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Array, key: index } as KeyPath,\n ],\n };\n return deepTransformNode(child, childProps);\n });\n }\n\n return 'to remove from the object';\n },\n});\n\n/**\n * Return the content of a node with only the translation plugin.\n *\n * @param node The node to transform.\n * @param locale The locale to use if your transformers need it (e.g. for translations).\n */\nexport const getFilterTranslationsOnlyContent = <\n T extends ContentNode,\n L extends LocalesValues = DeclaredLocales,\n>(\n node: T,\n locale: L = configuration?.internationalization?.defaultLocale as L,\n nodeProps: NodeProps,\n fallback?: LocalesValues\n) => {\n const plugins: Plugins[] = [\n filterTranslationsOnlyPlugin(locale, fallback),\n ...(nodeProps.plugins ?? []),\n ];\n\n return deepTransformNode(node, {\n ...nodeProps,\n plugins,\n }) as DeepTransformContent<T>;\n};\n\nexport const getFilterTranslationsOnlyDictionary = (\n dictionary: Dictionary,\n locale: LocalesValues = configuration?.internationalization\n ?.defaultLocale as LocalesValues,\n fallback?: LocalesValues\n) => ({\n ...dictionary,\n content: getFilterTranslationsOnlyContent(\n dictionary.content,\n locale,\n { dictionaryKey: dictionary.key, keyPath: [] },\n fallback\n ),\n});\n"],"mappings":";;;;;;;;;;;AAmBA,MAAM,uBAAuB,SAAuB;AAClD,KAAI,OAAO,SAAS,YAAY,SAAS,KACvC,QAAO;AAGT,KAAI,MAAM,aAAaA,0BAAS,YAC9B,QAAO;AAGT,KAAI,MAAM,QAAQ,KAAK,CACrB,QAAO,KAAK,KAAK,oBAAoB;AAGvC,QAAO,OAAO,OAAO,KAAK,CAAC,KAAK,oBAAoB;;;AAItD,MAAa,gCACX,QACA,cACa;CACb,IAAI;CACJ,YAAY,SAAsB;AAEhC,SAAO,OAAO,SAAS,YAAY,SAAS;;CAE9C,YAAY,MAAmB,OAAO,wBAAsB;AAC1D,MAAI,OAAO,SAAS,YAAY,MAAM,aAAaA,0BAAS,aAAa;GACvE,MAAM,SAAS,gBAC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,SAAS,iCACP,WAAW,SACX,QACA;EAAE,eAAe,WAAW;EAAK,SAAS,EAAE;EAAE,EAC9C,SACD;CACF"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
2
|
const require_interpreter_getContent_deepTransform = require('../interpreter/getContent/deepTransform.cjs');
|
|
3
3
|
let __intlayer_types = require("@intlayer/types");
|
|
4
|
-
__intlayer_types = require_rolldown_runtime.__toESM(__intlayer_types);
|
|
5
4
|
|
|
6
5
|
//#region src/deepTransformPlugins/getFilteredLocalesContent.ts
|
|
7
6
|
const filterTranslationsPlugin = (locales) => ({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getFilteredLocalesContent.cjs","names":["NodeType","deepTransformNode","plugins: Plugins[]"],"sources":["../../../src/deepTransformPlugins/getFilteredLocalesContent.ts"],"sourcesContent":["import {\n type ContentNode,\n type Dictionary,\n type LocalesValues,\n NodeType,\n} from '@intlayer/types';\nimport {\n deepTransformNode,\n type NodeProps,\n type Plugins,\n} from '../interpreter';\n\nconst filterTranslationsPlugin = (locales: LocalesValues[]): Plugins => ({\n id: 'filter-translations-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Translation,\n transform: (node, props, deepTransformNode) => {\n const translationMap = node.translation as Record<LocalesValues, string>;\n\n const filteredTranslationMap = Object.fromEntries(\n Object.entries(translationMap).filter(([key]) =>\n locales.includes(key as LocalesValues)\n )\n );\n\n return {\n ...node,\n translation: deepTransformNode(filteredTranslationMap, {\n ...props,\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Object, key: NodeType.Translation },\n ],\n }),\n };\n },\n});\n\nexport const getFilteredLocalesContent = (\n node: ContentNode,\n locales: LocalesValues | LocalesValues[],\n nodeProps: NodeProps\n) => {\n const localesArray = Array.isArray(locales) ? locales : [locales];\n\n const plugins: Plugins[] = [\n filterTranslationsPlugin(localesArray),\n ...(nodeProps.plugins ?? []),\n ];\n\n return deepTransformNode(node, {\n ...nodeProps,\n plugins,\n });\n};\n\n/*\n * Remove all unneeded translation from translation node\n *\n * locale: fr\n * t({ ar: 'Hello', en: 'Hello', fr: 'Bonjour' }) -> t({ fr: 'Bonjour' })\n *\n * locales: [fr, en]\n * t({ ar: 'Hello', en: 'Hello', fr: 'Bonjour' }) -> t({ en: 'Hello', fr: 'Bonjour' })\n */\nexport const getFilteredLocalesDictionary = (\n dictionary: Dictionary,\n locale: LocalesValues | LocalesValues[]\n) => {\n const localesArray = Array.isArray(locale) ? locale : [locale];\n\n return {\n ...dictionary,\n content: getFilteredLocalesContent(dictionary.content, localesArray, {\n dictionaryKey: dictionary.key,\n keyPath: [],\n }),\n };\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"getFilteredLocalesContent.cjs","names":["NodeType","deepTransformNode","plugins: Plugins[]"],"sources":["../../../src/deepTransformPlugins/getFilteredLocalesContent.ts"],"sourcesContent":["import {\n type ContentNode,\n type Dictionary,\n type LocalesValues,\n NodeType,\n} from '@intlayer/types';\nimport {\n deepTransformNode,\n type NodeProps,\n type Plugins,\n} from '../interpreter';\n\nconst filterTranslationsPlugin = (locales: LocalesValues[]): Plugins => ({\n id: 'filter-translations-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Translation,\n transform: (node, props, deepTransformNode) => {\n const translationMap = node.translation as Record<LocalesValues, string>;\n\n const filteredTranslationMap = Object.fromEntries(\n Object.entries(translationMap).filter(([key]) =>\n locales.includes(key as LocalesValues)\n )\n );\n\n return {\n ...node,\n translation: deepTransformNode(filteredTranslationMap, {\n ...props,\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Object, key: NodeType.Translation },\n ],\n }),\n };\n },\n});\n\nexport const getFilteredLocalesContent = (\n node: ContentNode,\n locales: LocalesValues | LocalesValues[],\n nodeProps: NodeProps\n) => {\n const localesArray = Array.isArray(locales) ? locales : [locales];\n\n const plugins: Plugins[] = [\n filterTranslationsPlugin(localesArray),\n ...(nodeProps.plugins ?? []),\n ];\n\n return deepTransformNode(node, {\n ...nodeProps,\n plugins,\n });\n};\n\n/*\n * Remove all unneeded translation from translation node\n *\n * locale: fr\n * t({ ar: 'Hello', en: 'Hello', fr: 'Bonjour' }) -> t({ fr: 'Bonjour' })\n *\n * locales: [fr, en]\n * t({ ar: 'Hello', en: 'Hello', fr: 'Bonjour' }) -> t({ en: 'Hello', fr: 'Bonjour' })\n */\nexport const getFilteredLocalesDictionary = (\n dictionary: Dictionary,\n locale: LocalesValues | LocalesValues[]\n) => {\n const localesArray = Array.isArray(locale) ? locale : [locale];\n\n return {\n ...dictionary,\n content: getFilteredLocalesContent(dictionary.content, localesArray, {\n dictionaryKey: dictionary.key,\n keyPath: [],\n }),\n };\n};\n"],"mappings":";;;;;AAYA,MAAM,4BAA4B,aAAuC;CACvE,IAAI;CACJ,YAAY,SACV,OAAO,SAAS,YAAY,MAAM,aAAaA,0BAAS;CAC1D,YAAY,MAAM,OAAO,wBAAsB;EAC7C,MAAM,iBAAiB,KAAK;EAE5B,MAAM,yBAAyB,OAAO,YACpC,OAAO,QAAQ,eAAe,CAAC,QAAQ,CAAC,SACtC,QAAQ,SAAS,IAAqB,CACvC,CACF;AAED,SAAO;GACL,GAAG;GACH,aAAaC,oBAAkB,wBAAwB;IACrD,GAAG;IACH,SAAS,CACP,GAAG,MAAM,SACT;KAAE,MAAMD,0BAAS;KAAQ,KAAKA,0BAAS;KAAa,CACrD;IACF,CAAC;GACH;;CAEJ;AAED,MAAa,6BACX,MACA,SACA,cACG;CAGH,MAAME,UAAqB,CACzB,yBAHmB,MAAM,QAAQ,QAAQ,GAAG,UAAU,CAAC,QAAQ,CAGzB,EACtC,GAAI,UAAU,WAAW,EAAE,CAC5B;AAED,QAAOD,+DAAkB,MAAM;EAC7B,GAAG;EACH;EACD,CAAC;;AAYJ,MAAa,gCACX,YACA,WACG;CACH,MAAM,eAAe,MAAM,QAAQ,OAAO,GAAG,SAAS,CAAC,OAAO;AAE9D,QAAO;EACL,GAAG;EACH,SAAS,0BAA0B,WAAW,SAAS,cAAc;GACnE,eAAe,WAAW;GAC1B,SAAS,EAAE;GACZ,CAAC;EACH"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
2
|
const require_interpreter_getContent_deepTransform = require('../interpreter/getContent/deepTransform.cjs');
|
|
3
3
|
let __intlayer_types = require("@intlayer/types");
|
|
4
|
-
__intlayer_types = require_rolldown_runtime.__toESM(__intlayer_types);
|
|
5
4
|
let __intlayer_config_built = require("@intlayer/config/built");
|
|
6
5
|
__intlayer_config_built = require_rolldown_runtime.__toESM(__intlayer_config_built);
|
|
7
6
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getMissingLocalesContent.cjs","names":["NodeType","configuration","plugins: Plugins[]"],"sources":["../../../src/deepTransformPlugins/getMissingLocalesContent.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { Dictionary } from '@intlayer/types';\nimport {\n type ContentNode,\n type Locale,\n type LocalesValues,\n NodeType,\n} from '@intlayer/types';\nimport type { DeepTransformContent, NodeProps, Plugins } from '../interpreter';\nimport { deepTransformNode } from '../interpreter/getContent/deepTransform';\nimport type { TranslationContent } from '../transpiler';\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const checkMissingLocalesPlugin = (\n locales: Locale[],\n onMissingLocale: (locale: Locale) => void\n): Plugins => ({\n id: 'check-missing-locales-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Translation,\n transform: (node: TranslationContent, props, deepTransformNode) => {\n for (const locale of locales) {\n if (\n !node[NodeType.Translation][\n locale as keyof (typeof node)[NodeType.Translation]\n ]\n ) {\n onMissingLocale(locale);\n }\n }\n\n // Continue traversal inside the translation values, but avoid re-applying this plugin on the same node\n const translations = node[NodeType.Translation] as Record<string, any>;\n for (const key in translations) {\n const child = translations[key];\n deepTransformNode(child, {\n ...props,\n children: child,\n });\n }\n\n // Return the original node; the return value is ignored by the caller\n return node;\n },\n});\n\n/**\n * Return the content of a node with only the translation plugin.\n *\n * @param node The node to transform.\n * @param locales The locales to check for missing translations.\n */\nexport const getMissingLocalesContent = <T extends ContentNode>(\n node: T,\n locales: LocalesValues[] = configuration?.internationalization?.locales,\n nodeProps: NodeProps\n): Locale[] => {\n const missingLocales = new Set<Locale>();\n\n const plugins: Plugins[] = [\n checkMissingLocalesPlugin(locales as Locale[], (locale) =>\n missingLocales.add(locale)\n ),\n ...(nodeProps.plugins ?? []),\n ];\n\n deepTransformNode(node, {\n ...nodeProps,\n plugins,\n }) as DeepTransformContent<T>;\n\n return Array.from(missingLocales);\n};\n\nexport const getMissingLocalesContentFromDictionary = (\n dictionary: Dictionary,\n locales: LocalesValues[] = configuration?.internationalization?.locales\n) =>\n getMissingLocalesContent(dictionary.content, locales, {\n dictionaryKey: dictionary.key,\n keyPath: [],\n });\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"getMissingLocalesContent.cjs","names":["NodeType","configuration","plugins: Plugins[]"],"sources":["../../../src/deepTransformPlugins/getMissingLocalesContent.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { Dictionary } from '@intlayer/types';\nimport {\n type ContentNode,\n type Locale,\n type LocalesValues,\n NodeType,\n} from '@intlayer/types';\nimport type { DeepTransformContent, NodeProps, Plugins } from '../interpreter';\nimport { deepTransformNode } from '../interpreter/getContent/deepTransform';\nimport type { TranslationContent } from '../transpiler';\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const checkMissingLocalesPlugin = (\n locales: Locale[],\n onMissingLocale: (locale: Locale) => void\n): Plugins => ({\n id: 'check-missing-locales-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Translation,\n transform: (node: TranslationContent, props, deepTransformNode) => {\n for (const locale of locales) {\n if (\n !node[NodeType.Translation][\n locale as keyof (typeof node)[NodeType.Translation]\n ]\n ) {\n onMissingLocale(locale);\n }\n }\n\n // Continue traversal inside the translation values, but avoid re-applying this plugin on the same node\n const translations = node[NodeType.Translation] as Record<string, any>;\n for (const key in translations) {\n const child = translations[key];\n deepTransformNode(child, {\n ...props,\n children: child,\n });\n }\n\n // Return the original node; the return value is ignored by the caller\n return node;\n },\n});\n\n/**\n * Return the content of a node with only the translation plugin.\n *\n * @param node The node to transform.\n * @param locales The locales to check for missing translations.\n */\nexport const getMissingLocalesContent = <T extends ContentNode>(\n node: T,\n locales: LocalesValues[] = configuration?.internationalization?.locales,\n nodeProps: NodeProps\n): Locale[] => {\n const missingLocales = new Set<Locale>();\n\n const plugins: Plugins[] = [\n checkMissingLocalesPlugin(locales as Locale[], (locale) =>\n missingLocales.add(locale)\n ),\n ...(nodeProps.plugins ?? []),\n ];\n\n deepTransformNode(node, {\n ...nodeProps,\n plugins,\n }) as DeepTransformContent<T>;\n\n return Array.from(missingLocales);\n};\n\nexport const getMissingLocalesContentFromDictionary = (\n dictionary: Dictionary,\n locales: LocalesValues[] = configuration?.internationalization?.locales\n) =>\n getMissingLocalesContent(dictionary.content, locales, {\n dictionaryKey: dictionary.key,\n keyPath: [],\n });\n"],"mappings":";;;;;;;;AAaA,MAAa,6BACX,SACA,qBACa;CACb,IAAI;CACJ,YAAY,SACV,OAAO,SAAS,YAAY,MAAM,aAAaA,0BAAS;CAC1D,YAAY,MAA0B,OAAO,wBAAsB;AACjE,OAAK,MAAM,UAAU,QACnB,KACE,CAAC,KAAKA,0BAAS,aACb,QAGF,iBAAgB,OAAO;EAK3B,MAAM,eAAe,KAAKA,0BAAS;AACnC,OAAK,MAAM,OAAO,cAAc;GAC9B,MAAM,QAAQ,aAAa;AAC3B,uBAAkB,OAAO;IACvB,GAAG;IACH,UAAU;IACX,CAAC;;AAIJ,SAAO;;CAEV;;;;;;;AAQD,MAAa,4BACX,MACA,UAA2BC,iCAAe,sBAAsB,SAChE,cACa;CACb,MAAM,iCAAiB,IAAI,KAAa;CAExC,MAAMC,UAAqB,CACzB,0BAA0B,UAAsB,WAC9C,eAAe,IAAI,OAAO,CAC3B,EACD,GAAI,UAAU,WAAW,EAAE,CAC5B;AAED,gEAAkB,MAAM;EACtB,GAAG;EACH;EACD,CAAC;AAEF,QAAO,MAAM,KAAK,eAAe;;AAGnC,MAAa,0CACX,YACA,UAA2BD,iCAAe,sBAAsB,YAEhE,yBAAyB,WAAW,SAAS,SAAS;CACpD,eAAe,WAAW;CAC1B,SAAS,EAAE;CACZ,CAAC"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
2
|
let __intlayer_types = require("@intlayer/types");
|
|
3
|
-
__intlayer_types = require_rolldown_runtime.__toESM(__intlayer_types);
|
|
4
3
|
|
|
5
4
|
//#region src/deepTransformPlugins/getSplittedContent.ts
|
|
6
5
|
const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getSplittedContent.cjs","names":["result: Record<string, any>","result: SplitResult","NodeType","recomposed: ContentNode | undefined","commonArray: any[]","perLocaleArrays: Record<string, any[]>","accumulated: SplitResult","output: Record<string, ContentNode>"],"sources":["../../../src/deepTransformPlugins/getSplittedContent.ts"],"sourcesContent":["import {\n type ContentNode,\n type DeclaredLocales,\n type Dictionary,\n NodeType,\n} from '@intlayer/types';\n\ntype SplittedContentOutput<T = ContentNode> = Record<DeclaredLocales, T> & {\n common: T;\n};\n\ntype SplitResult = Record<string, ContentNode | undefined> & {\n common?: ContentNode;\n};\n\nconst isObject = (value: unknown): value is Record<string, any> =>\n typeof value === 'object' && value !== null && !Array.isArray(value);\n\nconst hasNodeType = (value: unknown): value is { nodeType: string } =>\n isObject(value) && typeof (value as any).nodeType === 'string';\n\nconst mergeValues = (\n a: ContentNode | undefined,\n b: ContentNode | undefined\n): ContentNode | undefined => {\n if (a === undefined) return b;\n if (b === undefined) return a;\n\n if (Array.isArray(a) && Array.isArray(b)) {\n // Concatenate arrays when merging sibling results\n return [...a, ...b] as unknown as ContentNode;\n }\n\n if (isObject(a) && isObject(b) && !hasNodeType(a) && !hasNodeType(b)) {\n const result: Record<string, any> = { ...a };\n for (const key of Object.keys(b)) {\n result[key] = mergeValues(\n result[key] as unknown as ContentNode | undefined,\n (b as Record<string, any>)[key] as unknown as ContentNode | undefined\n );\n }\n return result as ContentNode;\n }\n\n // For primitives or differing structures, prefer b (more recent)\n return b;\n};\n\nconst mergeSplitResults = (\n base: SplitResult,\n addition: SplitResult\n): SplitResult => {\n const result: SplitResult = { ...base };\n\n // Merge common\n result.common = mergeValues(base.common, addition.common);\n\n // Merge each locale key present in either side\n const localeKeys = new Set<string>([\n ...Object.keys(base).filter((k) => k !== 'common'),\n ...Object.keys(addition).filter((k) => k !== 'common'),\n ]);\n\n for (const key of localeKeys) {\n // @ts-ignore: dynamic keys for locales\n result[key] = mergeValues(\n base[key] as ContentNode | undefined,\n addition[key] as ContentNode | undefined\n );\n }\n\n return result;\n};\n\nconst splitNode = (node: ContentNode): SplitResult => {\n // Translation node: allocate entirely to per-locale buckets\n if (isObject(node) && (node as any)?.nodeType === NodeType.Translation) {\n const translations = (node as any)[NodeType.Translation] as Record<\n string,\n ContentNode\n >;\n\n const result: SplitResult = {};\n for (const locale of Object.keys(translations)) {\n const child = translations[locale];\n const childSplit = splitNode(child);\n\n // The content under a translation belongs to the locale, not common\n // Merge common portion of the child (if any) into the locale as well\n const mergedForLocale = mergeValues(childSplit.common, undefined);\n\n // Compose locale content: prefer the fully rebuilt child by resolving deeper translations recursively\n // which are already split inside childSplit. We need to recompose a single node for this locale.\n // Recompose by merging all keys in childSplit except 'common' into a single node, then merge child's common.\n let recomposed: ContentNode | undefined;\n for (const key of Object.keys(childSplit)) {\n if (key === 'common') continue;\n recomposed = mergeValues(\n recomposed,\n childSplit[key] as ContentNode | undefined\n );\n }\n const finalLocaleNode = mergeValues(mergedForLocale, recomposed);\n\n if (finalLocaleNode !== undefined) {\n // @ts-ignore dynamic locale key\n result[locale] = finalLocaleNode;\n }\n }\n\n return result;\n }\n\n // Arrays: split each element and merge results index-wise\n if (Array.isArray(node)) {\n const commonArray: any[] = [];\n const perLocaleArrays: Record<string, any[]> = {};\n\n node.forEach((child) => {\n const childSplit = splitNode(child as ContentNode);\n\n if (childSplit.common !== undefined) {\n commonArray.push(childSplit.common);\n }\n\n for (const key of Object.keys(childSplit)) {\n if (key === 'common') continue;\n if (!perLocaleArrays[key]) perLocaleArrays[key] = [];\n const value = childSplit[key];\n if (value !== undefined) perLocaleArrays[key].push(value);\n }\n });\n\n const result: SplitResult = {};\n if (commonArray.length > 0)\n result.common = commonArray as unknown as ContentNode;\n for (const key of Object.keys(perLocaleArrays)) {\n // @ts-ignore dynamic locale key\n result[key] = perLocaleArrays[key] as unknown as ContentNode;\n }\n return result;\n }\n\n // Objects (non-typed): recursively split properties\n if (isObject(node) && !hasNodeType(node)) {\n let accumulated: SplitResult = {};\n\n for (const key of Object.keys(node)) {\n const childSplit = splitNode((node as any)[key] as ContentNode);\n\n // Assign property into common\n if (childSplit.common !== undefined) {\n accumulated = mergeSplitResults(accumulated, {\n common: { [key]: childSplit.common } as unknown as ContentNode,\n });\n }\n\n // Assign property into each locale bucket\n for (const locale of Object.keys(childSplit)) {\n if (locale === 'common') continue;\n accumulated = mergeSplitResults(accumulated, {\n // @ts-ignore dynamic locale key\n [locale]: { [key]: childSplit[locale] } as unknown as ContentNode,\n });\n }\n }\n\n return accumulated;\n }\n\n // Primitives or typed nodes (non-translation): entirely common\n return { common: node } as SplitResult;\n};\n\nexport const getSplittedContent = (\n content: ContentNode\n): SplittedContentOutput => {\n const split = splitNode(content);\n\n // Build final output with only defined sections\n const output: Record<string, ContentNode> = {};\n if (split.common !== undefined) {\n output.common = split.common;\n }\n for (const key of Object.keys(split)) {\n if (key === 'common') continue;\n const value = split[key] as ContentNode | undefined;\n if (value !== undefined) {\n output[key] = value;\n }\n }\n\n return output as unknown as SplittedContentOutput;\n};\n\n/**\n * Splits the `content` field of a Dictionary into \"common\" and per-locale buckets.\n *\n * Given a dictionary like:\n * ```js\n * {\n * key: \"my-key\",\n * content: {\n * commonContent: \"common content\",\n * multilingualContent: t({\n * en: \"english content\",\n * fr: \"french content\",\n * de: \"german content\",\n * }),\n * },\n * }\n * ```\n *\n * It produces:\n * ```js\n * {\n * common: { commonContent: \"common content\" },\n * en: { multilingualContent: \"english content\" },\n * fr: { multilingualContent: \"french content\" },\n * de: { multilingualContent: \"german content\" },\n * }\n * ```\n *\n * @param dictionary - The input dictionary object with possible multilingual or common content.\n * @returns An object mapping \"common\" and each locale to their corresponding content subtrees.\n */\nexport const getSplittedDictionaryContent = (\n dictionary: Dictionary\n): SplittedContentOutput<Dictionary['content']> =>\n getSplittedContent(dictionary.content);\n"],"mappings":";;;;;AAeA,MAAM,YAAY,UAChB,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,MAAM;AAEtE,MAAM,eAAe,UACnB,SAAS,MAAM,IAAI,OAAQ,MAAc,aAAa;AAExD,MAAM,eACJ,GACA,MAC4B;AAC5B,KAAI,MAAM,OAAW,QAAO;AAC5B,KAAI,MAAM,OAAW,QAAO;AAE5B,KAAI,MAAM,QAAQ,EAAE,IAAI,MAAM,QAAQ,EAAE,CAEtC,QAAO,CAAC,GAAG,GAAG,GAAG,EAAE;AAGrB,KAAI,SAAS,EAAE,IAAI,SAAS,EAAE,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,YAAY,EAAE,EAAE;EACpE,MAAMA,SAA8B,EAAE,GAAG,GAAG;AAC5C,OAAK,MAAM,OAAO,OAAO,KAAK,EAAE,CAC9B,QAAO,OAAO,YACZ,OAAO,MACN,EAA0B,KAC5B;AAEH,SAAO;;AAIT,QAAO;;AAGT,MAAM,qBACJ,MACA,aACgB;CAChB,MAAMC,SAAsB,EAAE,GAAG,MAAM;AAGvC,QAAO,SAAS,YAAY,KAAK,QAAQ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MAAI,YAAY,SAAS,EACvB,QAAO,SAAS;AAClB,OAAK,MAAM,OAAO,OAAO,KAAK,gBAAgB,CAE5C,QAAO,OAAO,gBAAgB;AAEhC,SAAO;;AAIT,KAAI,SAAS,KAAK,IAAI,CAAC,YAAY,KAAK,EAAE;EACxC,IAAIK,cAA2B,EAAE;AAEjC,OAAK,MAAM,OAAO,OAAO,KAAK,KAAK,EAAE;GACnC,MAAM,aAAa,UAAW,KAAa,KAAoB;AAG/D,OAAI,WAAW,WAAW,OACxB,eAAc,kBAAkB,aAAa,EAC3C,QAAQ,GAAG,MAAM,WAAW,QAAQ,EACrC,CAAC;AAIJ,QAAK,MAAM,UAAU,OAAO,KAAK,WAAW,EAAE;AAC5C,QAAI,WAAW,SAAU;AACzB,kBAAc,kBAAkB,aAAa,GAE1C,SAAS,GAAG,MAAM,WAAW,SAAS,EACxC,CAAC;;;AAIN,SAAO;;AAIT,QAAO,EAAE,QAAQ,MAAM;;AAGzB,MAAa,sBACX,YAC0B;CAC1B,MAAM,QAAQ,UAAU,QAAQ;CAGhC,MAAMC,SAAsC,EAAE;AAC9C,KAAI,MAAM,WAAW,OACnB,QAAO,SAAS,MAAM;AAExB,MAAK,MAAM,OAAO,OAAO,KAAK,MAAM,EAAE;AACpC,MAAI,QAAQ,SAAU;EACtB,MAAM,QAAQ,MAAM;AACpB,MAAI,UAAU,OACZ,QAAO,OAAO;;AAIlB,QAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCT,MAAa,gCACX,eAEA,mBAAmB,WAAW,QAAQ"}
|
|
1
|
+
{"version":3,"file":"getSplittedContent.cjs","names":["result: Record<string, any>","result: SplitResult","NodeType","recomposed: ContentNode | undefined","commonArray: any[]","perLocaleArrays: Record<string, any[]>","accumulated: SplitResult","output: Record<string, ContentNode>"],"sources":["../../../src/deepTransformPlugins/getSplittedContent.ts"],"sourcesContent":["import {\n type ContentNode,\n type DeclaredLocales,\n type Dictionary,\n NodeType,\n} from '@intlayer/types';\n\ntype SplittedContentOutput<T = ContentNode> = Record<DeclaredLocales, T> & {\n common: T;\n};\n\ntype SplitResult = Record<string, ContentNode | undefined> & {\n common?: ContentNode;\n};\n\nconst isObject = (value: unknown): value is Record<string, any> =>\n typeof value === 'object' && value !== null && !Array.isArray(value);\n\nconst hasNodeType = (value: unknown): value is { nodeType: string } =>\n isObject(value) && typeof (value as any).nodeType === 'string';\n\nconst mergeValues = (\n a: ContentNode | undefined,\n b: ContentNode | undefined\n): ContentNode | undefined => {\n if (a === undefined) return b;\n if (b === undefined) return a;\n\n if (Array.isArray(a) && Array.isArray(b)) {\n // Concatenate arrays when merging sibling results\n return [...a, ...b] as unknown as ContentNode;\n }\n\n if (isObject(a) && isObject(b) && !hasNodeType(a) && !hasNodeType(b)) {\n const result: Record<string, any> = { ...a };\n for (const key of Object.keys(b)) {\n result[key] = mergeValues(\n result[key] as unknown as ContentNode | undefined,\n (b as Record<string, any>)[key] as unknown as ContentNode | undefined\n );\n }\n return result as ContentNode;\n }\n\n // For primitives or differing structures, prefer b (more recent)\n return b;\n};\n\nconst mergeSplitResults = (\n base: SplitResult,\n addition: SplitResult\n): SplitResult => {\n const result: SplitResult = { ...base };\n\n // Merge common\n result.common = mergeValues(base.common, addition.common);\n\n // Merge each locale key present in either side\n const localeKeys = new Set<string>([\n ...Object.keys(base).filter((k) => k !== 'common'),\n ...Object.keys(addition).filter((k) => k !== 'common'),\n ]);\n\n for (const key of localeKeys) {\n // @ts-ignore: dynamic keys for locales\n result[key] = mergeValues(\n base[key] as ContentNode | undefined,\n addition[key] as ContentNode | undefined\n );\n }\n\n return result;\n};\n\nconst splitNode = (node: ContentNode): SplitResult => {\n // Translation node: allocate entirely to per-locale buckets\n if (isObject(node) && (node as any)?.nodeType === NodeType.Translation) {\n const translations = (node as any)[NodeType.Translation] as Record<\n string,\n ContentNode\n >;\n\n const result: SplitResult = {};\n for (const locale of Object.keys(translations)) {\n const child = translations[locale];\n const childSplit = splitNode(child);\n\n // The content under a translation belongs to the locale, not common\n // Merge common portion of the child (if any) into the locale as well\n const mergedForLocale = mergeValues(childSplit.common, undefined);\n\n // Compose locale content: prefer the fully rebuilt child by resolving deeper translations recursively\n // which are already split inside childSplit. We need to recompose a single node for this locale.\n // Recompose by merging all keys in childSplit except 'common' into a single node, then merge child's common.\n let recomposed: ContentNode | undefined;\n for (const key of Object.keys(childSplit)) {\n if (key === 'common') continue;\n recomposed = mergeValues(\n recomposed,\n childSplit[key] as ContentNode | undefined\n );\n }\n const finalLocaleNode = mergeValues(mergedForLocale, recomposed);\n\n if (finalLocaleNode !== undefined) {\n // @ts-ignore dynamic locale key\n result[locale] = finalLocaleNode;\n }\n }\n\n return result;\n }\n\n // Arrays: split each element and merge results index-wise\n if (Array.isArray(node)) {\n const commonArray: any[] = [];\n const perLocaleArrays: Record<string, any[]> = {};\n\n node.forEach((child) => {\n const childSplit = splitNode(child as ContentNode);\n\n if (childSplit.common !== undefined) {\n commonArray.push(childSplit.common);\n }\n\n for (const key of Object.keys(childSplit)) {\n if (key === 'common') continue;\n if (!perLocaleArrays[key]) perLocaleArrays[key] = [];\n const value = childSplit[key];\n if (value !== undefined) perLocaleArrays[key].push(value);\n }\n });\n\n const result: SplitResult = {};\n if (commonArray.length > 0)\n result.common = commonArray as unknown as ContentNode;\n for (const key of Object.keys(perLocaleArrays)) {\n // @ts-ignore dynamic locale key\n result[key] = perLocaleArrays[key] as unknown as ContentNode;\n }\n return result;\n }\n\n // Objects (non-typed): recursively split properties\n if (isObject(node) && !hasNodeType(node)) {\n let accumulated: SplitResult = {};\n\n for (const key of Object.keys(node)) {\n const childSplit = splitNode((node as any)[key] as ContentNode);\n\n // Assign property into common\n if (childSplit.common !== undefined) {\n accumulated = mergeSplitResults(accumulated, {\n common: { [key]: childSplit.common } as unknown as ContentNode,\n });\n }\n\n // Assign property into each locale bucket\n for (const locale of Object.keys(childSplit)) {\n if (locale === 'common') continue;\n accumulated = mergeSplitResults(accumulated, {\n // @ts-ignore dynamic locale key\n [locale]: { [key]: childSplit[locale] } as unknown as ContentNode,\n });\n }\n }\n\n return accumulated;\n }\n\n // Primitives or typed nodes (non-translation): entirely common\n return { common: node } as SplitResult;\n};\n\nexport const getSplittedContent = (\n content: ContentNode\n): SplittedContentOutput => {\n const split = splitNode(content);\n\n // Build final output with only defined sections\n const output: Record<string, ContentNode> = {};\n if (split.common !== undefined) {\n output.common = split.common;\n }\n for (const key of Object.keys(split)) {\n if (key === 'common') continue;\n const value = split[key] as ContentNode | undefined;\n if (value !== undefined) {\n output[key] = value;\n }\n }\n\n return output as unknown as SplittedContentOutput;\n};\n\n/**\n * Splits the `content` field of a Dictionary into \"common\" and per-locale buckets.\n *\n * Given a dictionary like:\n * ```js\n * {\n * key: \"my-key\",\n * content: {\n * commonContent: \"common content\",\n * multilingualContent: t({\n * en: \"english content\",\n * fr: \"french content\",\n * de: \"german content\",\n * }),\n * },\n * }\n * ```\n *\n * It produces:\n * ```js\n * {\n * common: { commonContent: \"common content\" },\n * en: { multilingualContent: \"english content\" },\n * fr: { multilingualContent: \"french content\" },\n * de: { multilingualContent: \"german content\" },\n * }\n * ```\n *\n * @param dictionary - The input dictionary object with possible multilingual or common content.\n * @returns An object mapping \"common\" and each locale to their corresponding content subtrees.\n */\nexport const getSplittedDictionaryContent = (\n dictionary: Dictionary\n): SplittedContentOutput<Dictionary['content']> =>\n getSplittedContent(dictionary.content);\n"],"mappings":";;;;AAeA,MAAM,YAAY,UAChB,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,MAAM;AAEtE,MAAM,eAAe,UACnB,SAAS,MAAM,IAAI,OAAQ,MAAc,aAAa;AAExD,MAAM,eACJ,GACA,MAC4B;AAC5B,KAAI,MAAM,OAAW,QAAO;AAC5B,KAAI,MAAM,OAAW,QAAO;AAE5B,KAAI,MAAM,QAAQ,EAAE,IAAI,MAAM,QAAQ,EAAE,CAEtC,QAAO,CAAC,GAAG,GAAG,GAAG,EAAE;AAGrB,KAAI,SAAS,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;;;;;;;;;;;;;;;;;;;;;;;;AAkCT,MAAa,gCACX,eAEA,mBAAmB,WAAW,QAAQ"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
2
|
let __intlayer_types = require("@intlayer/types");
|
|
3
|
-
__intlayer_types = require_rolldown_runtime.__toESM(__intlayer_types);
|
|
4
3
|
|
|
5
4
|
//#region src/deepTransformPlugins/insertContentInDictionary.ts
|
|
6
5
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"insertContentInDictionary.cjs","names":["NodeType","newLocaleContent: any","result: any"],"sources":["../../../src/deepTransformPlugins/insertContentInDictionary.ts"],"sourcesContent":["import { type Dictionary, type LocalesValues, NodeType } from '@intlayer/types';\n\n// {\n// {\n// title: 'このページ',\n// linkLabel: 'セクションへ移動',\n// collapseButton: { label: '折りたたむ' }\n// },\n// }\n// {\n// dictionary: {\n// key: 'aside-navigation',\n// content: {\n// title: {\n// nodeType: 'translation',\n// translation: {\n// ar: 'في هذه الصفحة',\n// de: 'Auf dieser Seite',\n// en: 'In this page',\n// 'en-GB': 'On this page',\n// es: 'En esta página',\n// fr: 'Dans cette page',\n// hi: 'इस पृष्ठ में',\n// it: 'In questa pagina',\n// ko: '이 페이지에서',\n// pt: 'Nesta página',\n// ru: 'На этой странице',\n// tr: 'Bu sayfada',\n// zh: '在此页面'\n// }\n// },\n// linkLabel: {\n// nodeType: 'translation',\n// translation: {\n// ar: 'اذهب إلى القسم',\n// de: 'Gehe zur Sektion',\n// en: 'Go to section',\n// 'en-GB': 'Go to section',\n// es: 'Ir a la sección',\n// fr: 'Aller à la section',\n// hi: 'सेक्शन पर जाएं',\n// it: 'Vai alla sezione',\n// ja: 'セクションへ行く',\n// ko: '섹션으로 이동',\n// pt: 'Ir para a seção',\n// ru: 'Перейти к разделу',\n// tr: 'Bölüme git',\n// zh: '转到节'\n// }\n// },\n// collapseButton: {\n// label: {\n// nodeType: 'translation',\n// translation: {\n// en: 'Collapse',\n// fr: 'Réduire',\n// es: 'Colapsar',\n// 'en-GB': 'Collapse',\n// de: 'Zuklappen',\n// ja: '折りたたむ',\n// ko: '접기',\n// zh: '折叠',\n// it: 'Comprimi',\n// pt: 'Recolher',\n// hi: 'संकुचित करें',\n// ar: 'اطوي التوسيع',\n// ru: 'Свернуть',\n// tr: 'Daralt'\n// }\n// }\n// }\n// },\n// localId: 'aside-navigation::local::src/components/AsideNavigation/asideNavigation.content.ts',\n// location: 'local',\n// filePath: 'src/components/AsideNavigation/asideNavigation.content.ts'\n// }\n// }\n\n/**\n * Deep merge helper that handles translation blocks\n * @param target - The target object (dictionary content)\n * @param source - The source object (new content to merge)\n * @param locale - Optional locale to target specific translation\n * @returns Merged content\n */\nconst deepMergeContent = (\n target: any,\n source: any,\n locale?: LocalesValues\n): any => {\n // If source is null or undefined, return target\n if (source === null || source === undefined) return target;\n\n // If target is null or undefined, initialize based on source type\n if (target === null || target === undefined) {\n if (Array.isArray(source)) {\n target = [];\n } else if (typeof source === 'object') {\n target = {};\n } else {\n return source;\n }\n }\n\n // Handle translation nodes FIRST (before arrays) to support arrays within translations\n if (\n target &&\n typeof target === 'object' &&\n target.nodeType === NodeType.Translation\n ) {\n // Target is a translation block\n if (locale) {\n // Update only the specific locale - create new object to preserve order\n const existingLocaleContent = target.translation[locale];\n let newLocaleContent: any;\n\n if (typeof source === 'object' && !Array.isArray(source)) {\n // Source is an object, need to deep merge for this locale\n newLocaleContent = deepMergeContent(\n existingLocaleContent,\n source,\n undefined // Don't pass locale down for nested content\n );\n } else if (Array.isArray(source)) {\n // Source is an array, set it directly for this locale\n newLocaleContent = source;\n } else {\n // Source is a primitive, directly set it\n newLocaleContent = source;\n }\n\n // Return new object with locale appended at the end (preserve insertion order)\n return {\n ...target,\n translation: {\n ...target.translation,\n [locale]: newLocaleContent,\n },\n };\n } else {\n // No locale specified, replace/merge the entire translation\n if (\n typeof source === 'object' &&\n !Array.isArray(source) &&\n source.nodeType === NodeType.Translation\n ) {\n // Source is also a translation node, merge translations\n return {\n ...target,\n translation: {\n ...target.translation,\n ...source.translation,\n },\n };\n } else {\n // Source is not a translation node, wrap it\n return processNewContent(source, locale);\n }\n }\n }\n\n // Handle arrays\n if (Array.isArray(source)) {\n if (locale && Array.isArray(target)) {\n // When locale is specified and target is also an array, merge element by element\n const result = [];\n const maxLength = Math.max(source.length, target.length);\n\n for (let i = 0; i < maxLength; i++) {\n if (i < source.length) {\n if (i < target.length && target[i] !== undefined) {\n // Both source and target have element at this index - merge them\n result[i] = deepMergeContent(target[i], source[i], locale);\n } else {\n // Only source has element at this index - process new content\n result[i] = processNewContent(source[i], locale);\n }\n } else {\n // Only target has element at this index - keep it\n result[i] = target[i];\n }\n }\n\n return result;\n } else {\n // No locale or target is not an array - replace entirely\n return source.map((item) => {\n // Process each item in case it needs locale wrapping\n if (\n item &&\n typeof item === 'object' &&\n item.nodeType === NodeType.Translation\n ) {\n return item;\n }\n return processNewContent(item, locale);\n });\n }\n }\n\n // Handle objects\n if (typeof source === 'object' && !Array.isArray(source)) {\n if (typeof target !== 'object' || Array.isArray(target)) {\n target = {};\n }\n\n // Create new object to preserve key order and avoid mutation\n const result: any = { ...target };\n\n for (const key in source) {\n if (Object.hasOwn(source, key)) {\n if (target[key] !== undefined) {\n result[key] = deepMergeContent(target[key], source[key], locale);\n } else {\n result[key] = processNewContent(source[key], locale);\n }\n }\n }\n\n return result;\n }\n\n // For primitives, just return the source\n return source;\n};\n\n/**\n * Process new content that doesn't exist in target\n * @param content - New content to process\n * @param locale - Optional locale\n * @returns Processed content\n */\nconst processNewContent = (content: any, locale?: LocalesValues): any => {\n // Handle null and undefined\n if (content === null || content === undefined) {\n return content;\n }\n\n // If content is already a translation node, return as-is\n if (\n content &&\n typeof content === 'object' &&\n content.nodeType === NodeType.Translation\n ) {\n return content;\n }\n\n // Handle arrays\n if (Array.isArray(content)) {\n return content.map((item) => processNewContent(item, locale));\n }\n\n // Handle objects\n if (content && typeof content === 'object') {\n const result: any = {};\n\n for (const key in content) {\n if (Object.hasOwn(content, key)) {\n result[key] = processNewContent(content[key], locale);\n }\n }\n return result;\n }\n\n // Handle primitives\n if (locale) {\n // Wrap in translation node with the specific locale\n return {\n nodeType: NodeType.Translation,\n translation: {\n [locale]: content,\n },\n };\n } else {\n // If no locale, just return the content as-is (don't wrap)\n return content;\n }\n};\n\n/**\n * Insert content into a dictionary with deep merge support\n * Handles translation blocks and nested structures\n *\n * @param dictionary - The dictionary to insert content into\n * @param content - The content to insert\n * @param locale - Optional locale to target specific translation\n * @returns Updated dictionary\n *\n * @example\n * // Without locale - deep merge all content\n * insertContentInDictionary(dictionary, { title: 'New Title' })\n *\n * @example\n * // With locale - insert content for specific locale\n * insertContentInDictionary(dictionary, { title: 'このページ' }, 'ja')\n */\nexport const insertContentInDictionary = (\n dictionary: Dictionary,\n content: Dictionary['content'],\n locale?: LocalesValues\n): Dictionary => {\n const mergedContent = deepMergeContent(\n Array.isArray(dictionary.content)\n ? [...dictionary.content]\n : { ...dictionary.content },\n content,\n locale\n );\n\n return {\n ...dictionary,\n content: mergedContent,\n };\n};\n"],"mappings":";;;;;;;;;;;;AAqFA,MAAM,oBACJ,QACA,QACA,WACQ;AAER,KAAI,WAAW,QAAQ,WAAW,OAAW,QAAO;AAGpD,KAAI,WAAW,QAAQ,WAAW,OAChC,KAAI,MAAM,QAAQ,OAAO,CACvB,UAAS,EAAE;UACF,OAAO,WAAW,SAC3B,UAAS,EAAE;KAEX,QAAO;AAKX,KACE,UACA,OAAO,WAAW,YAClB,OAAO,aAAaA,0BAAS,YAG7B,KAAI,QAAQ;EAEV,MAAM,wBAAwB,OAAO,YAAY;EACjD,IAAIC;AAEJ,MAAI,OAAO,WAAW,YAAY,CAAC,MAAM,QAAQ,OAAO,CAEtD,oBAAmB,iBACjB,uBACA,QACA,OACD;WACQ,MAAM,QAAQ,OAAO,CAE9B,oBAAmB;MAGnB,oBAAmB;AAIrB,SAAO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QAAQ,YAAY,OAClC,QAAO;AAIT,KACE,WACA,OAAO,YAAY,YACnB,QAAQ,aAAaF,0BAAS,YAE9B,QAAO;AAIT,KAAI,MAAM,QAAQ,QAAQ,CACxB,QAAO,QAAQ,KAAK,SAAS,kBAAkB,MAAM,OAAO,CAAC;AAI/D,KAAI,WAAW,OAAO,YAAY,UAAU;EAC1C,MAAME,SAAc,EAAE;AAEtB,OAAK,MAAM,OAAO,QAChB,KAAI,OAAO,OAAO,SAAS,IAAI,CAC7B,QAAO,OAAO,kBAAkB,QAAQ,MAAM,OAAO;AAGzD,SAAO;;AAIT,KAAI,OAEF,QAAO;EACL,UAAUF,0BAAS;EACnB,aAAa,GACV,SAAS,SACX;EACF;KAGD,QAAO;;;;;;;;;;;;;;;;;;;AAqBX,MAAa,6BACX,YACA,SACA,WACe;CACf,MAAM,gBAAgB,iBACpB,MAAM,QAAQ,WAAW,QAAQ,GAC7B,CAAC,GAAG,WAAW,QAAQ,GACvB,EAAE,GAAG,WAAW,SAAS,EAC7B,SACA,OACD;AAED,QAAO;EACL,GAAG;EACH,SAAS;EACV"}
|
|
1
|
+
{"version":3,"file":"insertContentInDictionary.cjs","names":["NodeType","newLocaleContent: any","result: any"],"sources":["../../../src/deepTransformPlugins/insertContentInDictionary.ts"],"sourcesContent":["import { type Dictionary, type LocalesValues, NodeType } from '@intlayer/types';\n\n// {\n// {\n// title: 'このページ',\n// linkLabel: 'セクションへ移動',\n// collapseButton: { label: '折りたたむ' }\n// },\n// }\n// {\n// dictionary: {\n// key: 'aside-navigation',\n// content: {\n// title: {\n// nodeType: 'translation',\n// translation: {\n// ar: 'في هذه الصفحة',\n// de: 'Auf dieser Seite',\n// en: 'In this page',\n// 'en-GB': 'On this page',\n// es: 'En esta página',\n// fr: 'Dans cette page',\n// hi: 'इस पृष्ठ में',\n// it: 'In questa pagina',\n// ko: '이 페이지에서',\n// pt: 'Nesta página',\n// ru: 'На этой странице',\n// tr: 'Bu sayfada',\n// zh: '在此页面'\n// }\n// },\n// linkLabel: {\n// nodeType: 'translation',\n// translation: {\n// ar: 'اذهب إلى القسم',\n// de: 'Gehe zur Sektion',\n// en: 'Go to section',\n// 'en-GB': 'Go to section',\n// es: 'Ir a la sección',\n// fr: 'Aller à la section',\n// hi: 'सेक्शन पर जाएं',\n// it: 'Vai alla sezione',\n// ja: 'セクションへ行く',\n// ko: '섹션으로 이동',\n// pt: 'Ir para a seção',\n// ru: 'Перейти к разделу',\n// tr: 'Bölüme git',\n// zh: '转到节'\n// }\n// },\n// collapseButton: {\n// label: {\n// nodeType: 'translation',\n// translation: {\n// en: 'Collapse',\n// fr: 'Réduire',\n// es: 'Colapsar',\n// 'en-GB': 'Collapse',\n// de: 'Zuklappen',\n// ja: '折りたたむ',\n// ko: '접기',\n// zh: '折叠',\n// it: 'Comprimi',\n// pt: 'Recolher',\n// hi: 'संकुचित करें',\n// ar: 'اطوي التوسيع',\n// ru: 'Свернуть',\n// tr: 'Daralt'\n// }\n// }\n// }\n// },\n// localId: 'aside-navigation::local::src/components/AsideNavigation/asideNavigation.content.ts',\n// location: 'local',\n// filePath: 'src/components/AsideNavigation/asideNavigation.content.ts'\n// }\n// }\n\n/**\n * Deep merge helper that handles translation blocks\n * @param target - The target object (dictionary content)\n * @param source - The source object (new content to merge)\n * @param locale - Optional locale to target specific translation\n * @returns Merged content\n */\nconst deepMergeContent = (\n target: any,\n source: any,\n locale?: LocalesValues\n): any => {\n // If source is null or undefined, return target\n if (source === null || source === undefined) return target;\n\n // If target is null or undefined, initialize based on source type\n if (target === null || target === undefined) {\n if (Array.isArray(source)) {\n target = [];\n } else if (typeof source === 'object') {\n target = {};\n } else {\n return source;\n }\n }\n\n // Handle translation nodes FIRST (before arrays) to support arrays within translations\n if (\n target &&\n typeof target === 'object' &&\n target.nodeType === NodeType.Translation\n ) {\n // Target is a translation block\n if (locale) {\n // Update only the specific locale - create new object to preserve order\n const existingLocaleContent = target.translation[locale];\n let newLocaleContent: any;\n\n if (typeof source === 'object' && !Array.isArray(source)) {\n // Source is an object, need to deep merge for this locale\n newLocaleContent = deepMergeContent(\n existingLocaleContent,\n source,\n undefined // Don't pass locale down for nested content\n );\n } else if (Array.isArray(source)) {\n // Source is an array, set it directly for this locale\n newLocaleContent = source;\n } else {\n // Source is a primitive, directly set it\n newLocaleContent = source;\n }\n\n // Return new object with locale appended at the end (preserve insertion order)\n return {\n ...target,\n translation: {\n ...target.translation,\n [locale]: newLocaleContent,\n },\n };\n } else {\n // No locale specified, replace/merge the entire translation\n if (\n typeof source === 'object' &&\n !Array.isArray(source) &&\n source.nodeType === NodeType.Translation\n ) {\n // Source is also a translation node, merge translations\n return {\n ...target,\n translation: {\n ...target.translation,\n ...source.translation,\n },\n };\n } else {\n // Source is not a translation node, wrap it\n return processNewContent(source, locale);\n }\n }\n }\n\n // Handle arrays\n if (Array.isArray(source)) {\n if (locale && Array.isArray(target)) {\n // When locale is specified and target is also an array, merge element by element\n const result = [];\n const maxLength = Math.max(source.length, target.length);\n\n for (let i = 0; i < maxLength; i++) {\n if (i < source.length) {\n if (i < target.length && target[i] !== undefined) {\n // Both source and target have element at this index - merge them\n result[i] = deepMergeContent(target[i], source[i], locale);\n } else {\n // Only source has element at this index - process new content\n result[i] = processNewContent(source[i], locale);\n }\n } else {\n // Only target has element at this index - keep it\n result[i] = target[i];\n }\n }\n\n return result;\n } else {\n // No locale or target is not an array - replace entirely\n return source.map((item) => {\n // Process each item in case it needs locale wrapping\n if (\n item &&\n typeof item === 'object' &&\n item.nodeType === NodeType.Translation\n ) {\n return item;\n }\n return processNewContent(item, locale);\n });\n }\n }\n\n // Handle objects\n if (typeof source === 'object' && !Array.isArray(source)) {\n if (typeof target !== 'object' || Array.isArray(target)) {\n target = {};\n }\n\n // Create new object to preserve key order and avoid mutation\n const result: any = { ...target };\n\n for (const key in source) {\n if (Object.hasOwn(source, key)) {\n if (target[key] !== undefined) {\n result[key] = deepMergeContent(target[key], source[key], locale);\n } else {\n result[key] = processNewContent(source[key], locale);\n }\n }\n }\n\n return result;\n }\n\n // For primitives, just return the source\n return source;\n};\n\n/**\n * Process new content that doesn't exist in target\n * @param content - New content to process\n * @param locale - Optional locale\n * @returns Processed content\n */\nconst processNewContent = (content: any, locale?: LocalesValues): any => {\n // Handle null and undefined\n if (content === null || content === undefined) {\n return content;\n }\n\n // If content is already a translation node, return as-is\n if (\n content &&\n typeof content === 'object' &&\n content.nodeType === NodeType.Translation\n ) {\n return content;\n }\n\n // Handle arrays\n if (Array.isArray(content)) {\n return content.map((item) => processNewContent(item, locale));\n }\n\n // Handle objects\n if (content && typeof content === 'object') {\n const result: any = {};\n\n for (const key in content) {\n if (Object.hasOwn(content, key)) {\n result[key] = processNewContent(content[key], locale);\n }\n }\n return result;\n }\n\n // Handle primitives\n if (locale) {\n // Wrap in translation node with the specific locale\n return {\n nodeType: NodeType.Translation,\n translation: {\n [locale]: content,\n },\n };\n } else {\n // If no locale, just return the content as-is (don't wrap)\n return content;\n }\n};\n\n/**\n * Insert content into a dictionary with deep merge support\n * Handles translation blocks and nested structures\n *\n * @param dictionary - The dictionary to insert content into\n * @param content - The content to insert\n * @param locale - Optional locale to target specific translation\n * @returns Updated dictionary\n *\n * @example\n * // Without locale - deep merge all content\n * insertContentInDictionary(dictionary, { title: 'New Title' })\n *\n * @example\n * // With locale - insert content for specific locale\n * insertContentInDictionary(dictionary, { title: 'このページ' }, 'ja')\n */\nexport const insertContentInDictionary = (\n dictionary: Dictionary,\n content: Dictionary['content'],\n locale?: LocalesValues\n): Dictionary => {\n const mergedContent = deepMergeContent(\n Array.isArray(dictionary.content)\n ? [...dictionary.content]\n : { ...dictionary.content },\n content,\n locale\n );\n\n return {\n ...dictionary,\n content: mergedContent,\n };\n};\n"],"mappings":";;;;;;;;;;;AAqFA,MAAM,oBACJ,QACA,QACA,WACQ;AAER,KAAI,WAAW,QAAQ,WAAW,OAAW,QAAO;AAGpD,KAAI,WAAW,QAAQ,WAAW,OAChC,KAAI,MAAM,QAAQ,OAAO,CACvB,U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AQ,OAAO,CACrD,UAAS,EAAE;EAIb,MAAME,SAAc,EAAE,GAAG,QAAQ;AAEjC,OAAK,MAAM,OAAO,OAChB,KAAI,OAAO,OAAO,QAAQ,IAAI,CAC5B,KAAI,OAAO,SAAS,OAClB,QAAO,OAAO,iBAAiB,OAAO,MAAM,OAAO,MAAM,OAAO;MAEhE,QAAO,OAAO,kBAAkB,OAAO,MAAM,OAAO;AAK1D,SAAO;;AAIT,QAAO;;;;;;;;AAST,MAAM,qBAAqB,SAAc,WAAgC;AAEvE,KAAI,YAAY,QAAQ,YAAY,OAClC,QAAO;AAIT,KACE,WACA,OAAO,YAAY,YACnB,QAAQ,aAAaF,0BAAS,YAE9B,QAAO;AAIT,KAAI,MAAM,QAAQ,QAAQ,CACxB,QAAO,QAAQ,KAAK,SAAS,kBAAkB,MAAM,OAAO,CAAC;AAI/D,KAAI,WAAW,OAAO,YAAY,UAAU;EAC1C,MAAME,SAAc,EAAE;AAEtB,OAAK,MAAM,OAAO,QAChB,KAAI,OAAO,OAAO,SAAS,IAAI,CAC7B,QAAO,OAAO,kBAAkB,QAAQ,MAAM,OAAO;AAGzD,SAAO;;AAIT,KAAI,OAEF,QAAO;EACL,UAAUF,0BAAS;EACnB,aAAa,GACV,SAAS,SACX;EACF;KAGD,QAAO;;;;;;;;;;;;;;;;;;;AAqBX,MAAa,6BACX,YACA,SACA,WACe;CACf,MAAM,gBAAgB,iBACpB,MAAM,QAAQ,WAAW,QAAQ,GAC7B,CAAC,GAAG,WAAW,QAAQ,GACvB,EAAE,GAAG,WAAW,SAAS,EAC7B,SACA,OACD;AAED,QAAO;EACL,GAAG;EACH,SAAS;EACV"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
2
|
let __intlayer_types = require("@intlayer/types");
|
|
3
|
-
__intlayer_types = require_rolldown_runtime.__toESM(__intlayer_types);
|
|
4
3
|
|
|
5
4
|
//#region src/dictionaryManipulator/editDictionaryByKeyPath.ts
|
|
6
5
|
const editDictionaryByKeyPath = (dictionaryContent, keyPath, newValue) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"editDictionaryByKeyPath.cjs","names":["currentValue: any","parentValue: any","lastKeys: LastKeyType[]","NodeType"],"sources":["../../../src/dictionaryManipulator/editDictionaryByKeyPath.ts"],"sourcesContent":["import { type ContentNode, type KeyPath, NodeType } from '@intlayer/types';\n\ntype LastKeyType = string | number;\n\nexport const editDictionaryByKeyPath = (\n dictionaryContent: ContentNode,\n keyPath: KeyPath[],\n newValue: ContentNode\n): ContentNode => {\n let currentValue: any = dictionaryContent;\n let parentValue: any = null;\n let lastKeys: LastKeyType[] = [];\n\n if (keyPath.length === 0) {\n return newValue;\n }\n\n try {\n for (let i = 0; i < keyPath.length; i++) {\n const keyObj = keyPath[i];\n parentValue = currentValue;\n\n if (keyObj.type === NodeType.Object || keyObj.type === NodeType.Array) {\n lastKeys = [keyObj.key];\n if (\n !currentValue[keyObj.key] ||\n typeof currentValue[keyObj.key] !== 'object'\n ) {\n currentValue[keyObj.key] = {};\n }\n currentValue = currentValue[keyObj.key];\n }\n\n if (\n keyObj.type === NodeType.Translation ||\n keyObj.type === NodeType.Enumeration\n ) {\n lastKeys = [keyObj.type, keyObj.key];\n if (\n !currentValue[keyObj.type] ||\n typeof currentValue[keyObj.type] !== 'object'\n ) {\n currentValue[keyObj.type] = {};\n }\n if (\n !currentValue[keyObj.type][keyObj.key] ||\n typeof currentValue[keyObj.type][keyObj.key] !== 'object'\n ) {\n currentValue[keyObj.type][keyObj.key] = {};\n }\n currentValue = currentValue[keyObj.type][keyObj.key];\n }\n\n if (\n keyObj.type === NodeType.Enumeration ||\n keyObj.type === NodeType.Condition\n ) {\n lastKeys = [keyObj.type, keyObj.key];\n if (\n !currentValue[keyObj.type] ||\n typeof currentValue[keyObj.type] !== 'object'\n ) {\n currentValue[keyObj.type] = {};\n }\n if (\n !currentValue[keyObj.type][keyObj.key] ||\n typeof currentValue[keyObj.type][keyObj.key] !== 'object'\n ) {\n currentValue[keyObj.type][keyObj.key] = {};\n }\n currentValue = currentValue[keyObj.type][keyObj.key];\n }\n\n if (\n keyObj.type === NodeType.Markdown ||\n keyObj.type === NodeType.Insertion\n ) {\n lastKeys = [keyObj.type];\n if (\n !currentValue[keyObj.type] ||\n typeof currentValue[keyObj.type] !== 'object'\n ) {\n currentValue[keyObj.type] = '';\n }\n currentValue = currentValue[keyObj.type];\n }\n\n if (keyObj.type === NodeType.File) {\n lastKeys = ['content'];\n\n currentValue = currentValue.content;\n }\n\n if (keyObj.type) {\n // No treated TypedNode\n }\n\n // Only update the value when processing the last key in the keyPath.\n if (i === keyPath.length - 1 && parentValue && lastKeys.length > 0) {\n let target = parentValue;\n // Drill down if lastKeys contains more than one key.\n for (const key of lastKeys.slice(0, -1)) {\n target = target[key];\n }\n if (typeof newValue === 'undefined') {\n delete target[lastKeys[lastKeys.length - 1]];\n } else {\n target[lastKeys[lastKeys.length - 1]] = newValue;\n }\n }\n }\n\n return dictionaryContent;\n } catch (error) {\n console.error(\n 'Cannot edit dictionary by key path',\n { dictionaryContent, keyPath, newValue },\n error\n );\n return dictionaryContent;\n }\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"editDictionaryByKeyPath.cjs","names":["currentValue: any","parentValue: any","lastKeys: LastKeyType[]","NodeType"],"sources":["../../../src/dictionaryManipulator/editDictionaryByKeyPath.ts"],"sourcesContent":["import { type ContentNode, type KeyPath, NodeType } from '@intlayer/types';\n\ntype LastKeyType = string | number;\n\nexport const editDictionaryByKeyPath = (\n dictionaryContent: ContentNode,\n keyPath: KeyPath[],\n newValue: ContentNode\n): ContentNode => {\n let currentValue: any = dictionaryContent;\n let parentValue: any = null;\n let lastKeys: LastKeyType[] = [];\n\n if (keyPath.length === 0) {\n return newValue;\n }\n\n try {\n for (let i = 0; i < keyPath.length; i++) {\n const keyObj = keyPath[i];\n parentValue = currentValue;\n\n if (keyObj.type === NodeType.Object || keyObj.type === NodeType.Array) {\n lastKeys = [keyObj.key];\n if (\n !currentValue[keyObj.key] ||\n typeof currentValue[keyObj.key] !== 'object'\n ) {\n currentValue[keyObj.key] = {};\n }\n currentValue = currentValue[keyObj.key];\n }\n\n if (\n keyObj.type === NodeType.Translation ||\n keyObj.type === NodeType.Enumeration\n ) {\n lastKeys = [keyObj.type, keyObj.key];\n if (\n !currentValue[keyObj.type] ||\n typeof currentValue[keyObj.type] !== 'object'\n ) {\n currentValue[keyObj.type] = {};\n }\n if (\n !currentValue[keyObj.type][keyObj.key] ||\n typeof currentValue[keyObj.type][keyObj.key] !== 'object'\n ) {\n currentValue[keyObj.type][keyObj.key] = {};\n }\n currentValue = currentValue[keyObj.type][keyObj.key];\n }\n\n if (\n keyObj.type === NodeType.Enumeration ||\n keyObj.type === NodeType.Condition\n ) {\n lastKeys = [keyObj.type, keyObj.key];\n if (\n !currentValue[keyObj.type] ||\n typeof currentValue[keyObj.type] !== 'object'\n ) {\n currentValue[keyObj.type] = {};\n }\n if (\n !currentValue[keyObj.type][keyObj.key] ||\n typeof currentValue[keyObj.type][keyObj.key] !== 'object'\n ) {\n currentValue[keyObj.type][keyObj.key] = {};\n }\n currentValue = currentValue[keyObj.type][keyObj.key];\n }\n\n if (\n keyObj.type === NodeType.Markdown ||\n keyObj.type === NodeType.Insertion\n ) {\n lastKeys = [keyObj.type];\n if (\n !currentValue[keyObj.type] ||\n typeof currentValue[keyObj.type] !== 'object'\n ) {\n currentValue[keyObj.type] = '';\n }\n currentValue = currentValue[keyObj.type];\n }\n\n if (keyObj.type === NodeType.File) {\n lastKeys = ['content'];\n\n currentValue = currentValue.content;\n }\n\n if (keyObj.type) {\n // No treated TypedNode\n }\n\n // Only update the value when processing the last key in the keyPath.\n if (i === keyPath.length - 1 && parentValue && lastKeys.length > 0) {\n let target = parentValue;\n // Drill down if lastKeys contains more than one key.\n for (const key of lastKeys.slice(0, -1)) {\n target = target[key];\n }\n if (typeof newValue === 'undefined') {\n delete target[lastKeys[lastKeys.length - 1]];\n } else {\n target[lastKeys[lastKeys.length - 1]] = newValue;\n }\n }\n }\n\n return dictionaryContent;\n } catch (error) {\n console.error(\n 'Cannot edit dictionary by key path',\n { dictionaryContent, keyPath, newValue },\n error\n );\n return dictionaryContent;\n }\n};\n"],"mappings":";;;;AAIA,MAAa,2BACX,mBACA,SACA,aACgB;CAChB,IAAIA,eAAoB;CACxB,IAAIC,cAAmB;CACvB,IAAIC,WAA0B,EAAE;AAEhC,KAAI,QAAQ,WAAW,EACrB,QAAO;AAGT,KAAI;AACF,OAAK,IAAI,IAAI,GAAG,IAAI,QAAQ,QAAQ,KAAK;GACvC,MAAM,SAAS,QAAQ;AACvB,iBAAc;AAEd,OAAI,OAAO,SAASC,0BAAS,UAAU,OAAO,SAASA,0BAAS,OAAO;AACrE,eAAW,CAAC,OAAO,IAAI;AACvB,QACE,CAAC,aAAa,OAAO,QACrB,OAAO,aAAa,OAAO,SAAS,SAEpC,cAAa,OAAO,OAAO,EAAE;AAE/B,mBAAe,aAAa,OAAO;;AAGrC,OACE,OAAO,SAASA,0BAAS,eACzB,OAAO,SAASA,0BAAS,aACzB;AACA,eAAW,CAAC,OAAO,MAAM,OAAO,IAAI;AACpC,QACE,CAAC,aAAa,OAAO,SACrB,OAAO,aAAa,OAAO,UAAU,SAErC,cAAa,OAAO,QAAQ,EAAE;AAEhC,QACE,CAAC,aAAa,OAAO,MAAM,OAAO,QAClC,OAAO,aAAa,OAAO,MAAM,OAAO,SAAS,SAEjD,cAAa,OAAO,MAAM,OAAO,OAAO,EAAE;AAE5C,mBAAe,aAAa,OAAO,MAAM,OAAO;;AAGlD,OACE,OAAO,SAASA,0BAAS,eACzB,OAAO,SAASA,0BAAS,WACzB;AACA,eAAW,CAAC,OAAO,MAAM,OAAO,IAAI;AACpC,QACE,CAAC,aAAa,OAAO,SACrB,OAAO,aAAa,OAAO,UAAU,SAErC,cAAa,OAAO,QAAQ,EAAE;AAEhC,QACE,CAAC,aAAa,OAAO,MAAM,OAAO,QAClC,OAAO,aAAa,OAAO,MAAM,OAAO,SAAS,SAEjD,cAAa,OAAO,MAAM,OAAO,OAAO,EAAE;AAE5C,mBAAe,aAAa,OAAO,MAAM,OAAO;;AAGlD,OACE,OAAO,SAASA,0BAAS,YACzB,OAAO,SAASA,0BAAS,WACzB;AACA,eAAW,CAAC,OAAO,KAAK;AACxB,QACE,CAAC,aAAa,OAAO,SACrB,OAAO,aAAa,OAAO,UAAU,SAErC,cAAa,OAAO,QAAQ;AAE9B,mBAAe,aAAa,OAAO;;AAGrC,OAAI,OAAO,SAASA,0BAAS,MAAM;AACjC,eAAW,CAAC,UAAU;AAEtB,mBAAe,aAAa;;AAG9B,OAAI,OAAO,MAAM;AAKjB,OAAI,MAAM,QAAQ,SAAS,KAAK,eAAe,SAAS,SAAS,GAAG;IAClE,IAAI,SAAS;AAEb,SAAK,MAAM,OAAO,SAAS,MAAM,GAAG,GAAG,CACrC,UAAS,OAAO;AAElB,QAAI,OAAO,aAAa,YACtB,QAAO,OAAO,SAAS,SAAS,SAAS;QAEzC,QAAO,SAAS,SAAS,SAAS,MAAM;;;AAK9C,SAAO;UACA,OAAO;AACd,UAAQ,MACN,sCACA;GAAE;GAAmB;GAAS;GAAU,EACxC,MACD;AACD,SAAO"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
2
|
let __intlayer_types = require("@intlayer/types");
|
|
3
|
-
__intlayer_types = require_rolldown_runtime.__toESM(__intlayer_types);
|
|
4
3
|
|
|
5
4
|
//#region src/dictionaryManipulator/getContentNodeByKeyPath.ts
|
|
6
5
|
const getContentNodeByKeyPath = (dictionaryContent, keyPath, fallbackLocale) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getContentNodeByKeyPath.cjs","names":["currentValue: any","NodeType"],"sources":["../../../src/dictionaryManipulator/getContentNodeByKeyPath.ts"],"sourcesContent":["import {\n type ContentNode,\n type KeyPath,\n type Locale,\n NodeType,\n} from '@intlayer/types';\n\nexport const getContentNodeByKeyPath = (\n dictionaryContent: ContentNode,\n keyPath: KeyPath[],\n fallbackLocale?: Locale\n): ContentNode => {\n let currentValue: any = structuredClone(dictionaryContent);\n\n for (const keyObj of keyPath) {\n // Auto-resolve translation nodes when fallbackLocale is provided\n if (fallbackLocale && currentValue?.nodeType === NodeType.Translation) {\n currentValue = currentValue?.[NodeType.Translation]?.[fallbackLocale];\n }\n\n if (keyObj.type === NodeType.Object || keyObj.type === NodeType.Array) {\n currentValue = currentValue?.[keyObj.key];\n }\n\n if (\n keyObj.type === NodeType.Translation ||\n keyObj.type === NodeType.Condition ||\n keyObj.type === NodeType.Enumeration\n ) {\n currentValue = currentValue?.[keyObj.type]?.[keyObj.key];\n }\n\n if (\n keyObj.type === NodeType.Markdown ||\n keyObj.type === NodeType.Insertion ||\n keyObj.type === NodeType.File\n ) {\n currentValue = currentValue?.[keyObj.type];\n }\n }\n\n return currentValue as ContentNode;\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"getContentNodeByKeyPath.cjs","names":["currentValue: any","NodeType"],"sources":["../../../src/dictionaryManipulator/getContentNodeByKeyPath.ts"],"sourcesContent":["import {\n type ContentNode,\n type KeyPath,\n type Locale,\n NodeType,\n} from '@intlayer/types';\n\nexport const getContentNodeByKeyPath = (\n dictionaryContent: ContentNode,\n keyPath: KeyPath[],\n fallbackLocale?: Locale\n): ContentNode => {\n let currentValue: any = structuredClone(dictionaryContent);\n\n for (const keyObj of keyPath) {\n // Auto-resolve translation nodes when fallbackLocale is provided\n if (fallbackLocale && currentValue?.nodeType === NodeType.Translation) {\n currentValue = currentValue?.[NodeType.Translation]?.[fallbackLocale];\n }\n\n if (keyObj.type === NodeType.Object || keyObj.type === NodeType.Array) {\n currentValue = currentValue?.[keyObj.key];\n }\n\n if (\n keyObj.type === NodeType.Translation ||\n keyObj.type === NodeType.Condition ||\n keyObj.type === NodeType.Enumeration\n ) {\n currentValue = currentValue?.[keyObj.type]?.[keyObj.key];\n }\n\n if (\n keyObj.type === NodeType.Markdown ||\n keyObj.type === NodeType.Insertion ||\n keyObj.type === NodeType.File\n ) {\n currentValue = currentValue?.[keyObj.type];\n }\n }\n\n return currentValue as ContentNode;\n};\n"],"mappings":";;;;AAOA,MAAa,2BACX,mBACA,SACA,mBACgB;CAChB,IAAIA,eAAoB,gBAAgB,kBAAkB;AAE1D,MAAK,MAAM,UAAU,SAAS;AAE5B,MAAI,kBAAkB,cAAc,aAAaC,0BAAS,YACxD,gBAAe,eAAeA,0BAAS,eAAe;AAGxD,MAAI,OAAO,SAASA,0BAAS,UAAU,OAAO,SAASA,0BAAS,MAC9D,gBAAe,eAAe,OAAO;AAGvC,MACE,OAAO,SAASA,0BAAS,eACzB,OAAO,SAASA,0BAAS,aACzB,OAAO,SAASA,0BAAS,YAEzB,gBAAe,eAAe,OAAO,QAAQ,OAAO;AAGtD,MACE,OAAO,SAASA,0BAAS,YACzB,OAAO,SAASA,0BAAS,aACzB,OAAO,SAASA,0BAAS,KAEzB,gBAAe,eAAe,OAAO;;AAIzC,QAAO"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
2
|
let __intlayer_types = require("@intlayer/types");
|
|
3
|
-
__intlayer_types = require_rolldown_runtime.__toESM(__intlayer_types);
|
|
4
3
|
|
|
5
4
|
//#region src/dictionaryManipulator/getDefaultNode.ts
|
|
6
5
|
const getDefaultNode = (nodeType, locales, content) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getDefaultNode.cjs","names":["NodeType"],"sources":["../../../src/dictionaryManipulator/getDefaultNode.ts"],"sourcesContent":["import {\n type ContentNode,\n type LocalesValues,\n NodeType,\n} from '@intlayer/types';\n\nexport const getDefaultNode = (\n nodeType: NodeType,\n locales: LocalesValues[],\n content?: ContentNode\n): ContentNode => {\n const clonedContent = structuredClone(content);\n switch (nodeType) {\n case NodeType.Translation:\n return {\n nodeType: NodeType.Translation,\n [NodeType.Translation]: Object.assign(\n {},\n ...locales.map((locale) => ({\n [locale]: structuredClone(clonedContent) ?? '',\n }))\n ),\n } as ContentNode;\n\n case NodeType.Enumeration:\n return {\n nodeType: NodeType.Enumeration,\n [NodeType.Enumeration]: {\n '1': clonedContent ?? '',\n },\n } as ContentNode;\n\n case NodeType.Condition:\n return {\n nodeType: NodeType.Condition,\n [NodeType.Condition]: {\n true: clonedContent ?? '',\n false: clonedContent ?? '',\n },\n } as ContentNode;\n\n case NodeType.Insertion:\n return {\n nodeType: NodeType.Insertion,\n [NodeType.Insertion]: {\n insertion: clonedContent ?? '',\n },\n } as unknown as ContentNode;\n\n case NodeType.Nested:\n return {\n nodeType: NodeType.Nested,\n [NodeType.Nested]: {\n dictionaryKey: '',\n },\n } as ContentNode;\n\n case NodeType.Markdown:\n return {\n nodeType: NodeType.Markdown,\n [NodeType.Markdown]: clonedContent ?? '',\n } as ContentNode;\n\n case NodeType.File:\n return {\n nodeType: NodeType.File,\n [NodeType.File]: clonedContent ?? '',\n } as ContentNode;\n\n case NodeType.Object:\n return {\n newKey: clonedContent ?? '',\n } as unknown as ContentNode;\n\n case NodeType.Array:\n return [clonedContent ?? ''] as unknown as ContentNode;\n\n case NodeType.Text:\n return clonedContent ?? '';\n\n case NodeType.Number:\n return clonedContent ?? 0;\n\n case NodeType.Boolean:\n return clonedContent ?? true;\n\n default:\n return clonedContent ?? '';\n }\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"getDefaultNode.cjs","names":["NodeType"],"sources":["../../../src/dictionaryManipulator/getDefaultNode.ts"],"sourcesContent":["import {\n type ContentNode,\n type LocalesValues,\n NodeType,\n} from '@intlayer/types';\n\nexport const getDefaultNode = (\n nodeType: NodeType,\n locales: LocalesValues[],\n content?: ContentNode\n): ContentNode => {\n const clonedContent = structuredClone(content);\n switch (nodeType) {\n case NodeType.Translation:\n return {\n nodeType: NodeType.Translation,\n [NodeType.Translation]: Object.assign(\n {},\n ...locales.map((locale) => ({\n [locale]: structuredClone(clonedContent) ?? '',\n }))\n ),\n } as ContentNode;\n\n case NodeType.Enumeration:\n return {\n nodeType: NodeType.Enumeration,\n [NodeType.Enumeration]: {\n '1': clonedContent ?? '',\n },\n } as ContentNode;\n\n case NodeType.Condition:\n return {\n nodeType: NodeType.Condition,\n [NodeType.Condition]: {\n true: clonedContent ?? '',\n false: clonedContent ?? '',\n },\n } as ContentNode;\n\n case NodeType.Insertion:\n return {\n nodeType: NodeType.Insertion,\n [NodeType.Insertion]: {\n insertion: clonedContent ?? '',\n },\n } as unknown as ContentNode;\n\n case NodeType.Nested:\n return {\n nodeType: NodeType.Nested,\n [NodeType.Nested]: {\n dictionaryKey: '',\n },\n } as ContentNode;\n\n case NodeType.Markdown:\n return {\n nodeType: NodeType.Markdown,\n [NodeType.Markdown]: clonedContent ?? '',\n } as ContentNode;\n\n case NodeType.File:\n return {\n nodeType: NodeType.File,\n [NodeType.File]: clonedContent ?? '',\n } as ContentNode;\n\n case NodeType.Object:\n return {\n newKey: clonedContent ?? '',\n } as unknown as ContentNode;\n\n case NodeType.Array:\n return [clonedContent ?? ''] as unknown as ContentNode;\n\n case NodeType.Text:\n return clonedContent ?? '';\n\n case NodeType.Number:\n return clonedContent ?? 0;\n\n case NodeType.Boolean:\n return clonedContent ?? true;\n\n default:\n return clonedContent ?? '';\n }\n};\n"],"mappings":";;;;AAMA,MAAa,kBACX,UACA,SACA,YACgB;CAChB,MAAM,gBAAgB,gBAAgB,QAAQ;AAC9C,SAAQ,UAAR;EACE,KAAKA,0BAAS,YACZ,QAAO;GACL,UAAUA,0BAAS;IAClBA,0BAAS,cAAc,OAAO,OAC7B,EAAE,EACF,GAAG,QAAQ,KAAK,YAAY,GACzB,SAAS,gBAAgB,cAAc,IAAI,IAC7C,EAAE,CACJ;GACF;EAEH,KAAKA,0BAAS,YACZ,QAAO;GACL,UAAUA,0BAAS;IAClBA,0BAAS,cAAc,EACtB,KAAK,iBAAiB,IACvB;GACF;EAEH,KAAKA,0BAAS,UACZ,QAAO;GACL,UAAUA,0BAAS;IAClBA,0BAAS,YAAY;IACpB,MAAM,iBAAiB;IACvB,OAAO,iBAAiB;IACzB;GACF;EAEH,KAAKA,0BAAS,UACZ,QAAO;GACL,UAAUA,0BAAS;IAClBA,0BAAS,YAAY,EACpB,WAAW,iBAAiB,IAC7B;GACF;EAEH,KAAKA,0BAAS,OACZ,QAAO;GACL,UAAUA,0BAAS;IAClBA,0BAAS,SAAS,EACjB,eAAe,IAChB;GACF;EAEH,KAAKA,0BAAS,SACZ,QAAO;GACL,UAAUA,0BAAS;IAClBA,0BAAS,WAAW,iBAAiB;GACvC;EAEH,KAAKA,0BAAS,KACZ,QAAO;GACL,UAAUA,0BAAS;IAClBA,0BAAS,OAAO,iBAAiB;GACnC;EAEH,KAAKA,0BAAS,OACZ,QAAO,EACL,QAAQ,iBAAiB,IAC1B;EAEH,KAAKA,0BAAS,MACZ,QAAO,CAAC,iBAAiB,GAAG;EAE9B,KAAKA,0BAAS,KACZ,QAAO,iBAAiB;EAE1B,KAAKA,0BAAS,OACZ,QAAO,iBAAiB;EAE1B,KAAKA,0BAAS,QACZ,QAAO,iBAAiB;EAE1B,QACE,QAAO,iBAAiB"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
2
|
let __intlayer_types = require("@intlayer/types");
|
|
3
|
-
__intlayer_types = require_rolldown_runtime.__toESM(__intlayer_types);
|
|
4
3
|
|
|
5
4
|
//#region src/dictionaryManipulator/getEmptyNode.ts
|
|
6
5
|
const getEmptyNode = (section) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getEmptyNode.cjs","names":["NodeType"],"sources":["../../../src/dictionaryManipulator/getEmptyNode.ts"],"sourcesContent":["import { type ContentNode, NodeType, type TypedNode } from '@intlayer/types';\n\nexport const getEmptyNode = (section: ContentNode): ContentNode => {\n if (typeof section === 'string') {\n return '';\n }\n if (typeof section === 'number') {\n return 0;\n }\n if (typeof section === 'boolean') {\n return true;\n }\n if (typeof (section as TypedNode)?.nodeType === 'string') {\n const typedNode = section as TypedNode;\n const content =\n typedNode[typedNode.nodeType as unknown as keyof typeof typedNode];\n\n if (\n typedNode.nodeType === NodeType.Translation ||\n typedNode.nodeType === NodeType.Enumeration ||\n typedNode.nodeType === NodeType.Condition ||\n typedNode.nodeType === NodeType.Insertion\n ) {\n return getEmptyNode(content as ContentNode);\n }\n\n if (typedNode.nodeType === NodeType.Nested) {\n return 'dictionary-key';\n }\n\n if (typedNode.nodeType === NodeType.File) {\n return 'file/path';\n }\n\n if (typedNode.nodeType === NodeType.Markdown) {\n return getEmptyNode(typedNode);\n }\n\n return content;\n }\n\n if (!section || typeof section !== 'object') {\n return section;\n }\n\n if (Array.isArray(section)) {\n return (section as ContentNode[]).map(\n getEmptyNode\n ) as unknown as ContentNode;\n }\n\n const mappedSectionObject = Object.entries(section).map(([key, value]) => [\n key,\n getEmptyNode(value as ContentNode),\n ]);\n\n const mappedSectionArray = Object.fromEntries(mappedSectionObject);\n\n return mappedSectionArray;\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"getEmptyNode.cjs","names":["NodeType"],"sources":["../../../src/dictionaryManipulator/getEmptyNode.ts"],"sourcesContent":["import { type ContentNode, NodeType, type TypedNode } from '@intlayer/types';\n\nexport const getEmptyNode = (section: ContentNode): ContentNode => {\n if (typeof section === 'string') {\n return '';\n }\n if (typeof section === 'number') {\n return 0;\n }\n if (typeof section === 'boolean') {\n return true;\n }\n if (typeof (section as TypedNode)?.nodeType === 'string') {\n const typedNode = section as TypedNode;\n const content =\n typedNode[typedNode.nodeType as unknown as keyof typeof typedNode];\n\n if (\n typedNode.nodeType === NodeType.Translation ||\n typedNode.nodeType === NodeType.Enumeration ||\n typedNode.nodeType === NodeType.Condition ||\n typedNode.nodeType === NodeType.Insertion\n ) {\n return getEmptyNode(content as ContentNode);\n }\n\n if (typedNode.nodeType === NodeType.Nested) {\n return 'dictionary-key';\n }\n\n if (typedNode.nodeType === NodeType.File) {\n return 'file/path';\n }\n\n if (typedNode.nodeType === NodeType.Markdown) {\n return getEmptyNode(typedNode);\n }\n\n return content;\n }\n\n if (!section || typeof section !== 'object') {\n return section;\n }\n\n if (Array.isArray(section)) {\n return (section as ContentNode[]).map(\n getEmptyNode\n ) as unknown as ContentNode;\n }\n\n const mappedSectionObject = Object.entries(section).map(([key, value]) => [\n key,\n getEmptyNode(value as ContentNode),\n ]);\n\n const mappedSectionArray = Object.fromEntries(mappedSectionObject);\n\n return mappedSectionArray;\n};\n"],"mappings":";;;;AAEA,MAAa,gBAAgB,YAAsC;AACjE,KAAI,OAAO,YAAY,SACrB,QAAO;AAET,KAAI,OAAO,YAAY,SACrB,QAAO;AAET,KAAI,OAAO,YAAY,UACrB,QAAO;AAET,KAAI,OAAQ,SAAuB,aAAa,UAAU;EACxD,MAAM,YAAY;EAClB,MAAM,UACJ,UAAU,UAAU;AAEtB,MACE,UAAU,aAAaA,0BAAS,eAChC,UAAU,aAAaA,0BAAS,eAChC,UAAU,aAAaA,0BAAS,aAChC,UAAU,aAAaA,0BAAS,UAEhC,QAAO,aAAa,QAAuB;AAG7C,MAAI,UAAU,aAAaA,0BAAS,OAClC,QAAO;AAGT,MAAI,UAAU,aAAaA,0BAAS,KAClC,QAAO;AAGT,MAAI,UAAU,aAAaA,0BAAS,SAClC,QAAO,aAAa,UAAU;AAGhC,SAAO;;AAGT,KAAI,CAAC,WAAW,OAAO,YAAY,SACjC,QAAO;AAGT,KAAI,MAAM,QAAQ,QAAQ,CACxB,QAAQ,QAA0B,IAChC,aACD;CAGH,MAAM,sBAAsB,OAAO,QAAQ,QAAQ,CAAC,KAAK,CAAC,KAAK,WAAW,CACxE,KACA,aAAa,MAAqB,CACnC,CAAC;AAIF,QAF2B,OAAO,YAAY,oBAAoB"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
2
|
let __intlayer_types = require("@intlayer/types");
|
|
3
|
-
__intlayer_types = require_rolldown_runtime.__toESM(__intlayer_types);
|
|
4
3
|
|
|
5
4
|
//#region src/dictionaryManipulator/getNodeChildren.ts
|
|
6
5
|
const getNodeChildren = (section) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getNodeChildren.cjs","names":["NodeType"],"sources":["../../../src/dictionaryManipulator/getNodeChildren.ts"],"sourcesContent":["import { type ContentNode, NodeType, type TypedNode } from '@intlayer/types';\n\nexport const getNodeChildren = (section: ContentNode): ContentNode => {\n if (typeof section === 'string') {\n return section;\n }\n if (typeof section === 'number') {\n return section;\n }\n if (typeof section === 'boolean') {\n return section;\n }\n if (typeof (section as TypedNode)?.nodeType === 'string') {\n const typedNode = section as TypedNode;\n const content =\n typedNode[typedNode.nodeType as unknown as keyof typeof typedNode];\n\n if (\n typedNode.nodeType === NodeType.Translation ||\n typedNode.nodeType === NodeType.Enumeration ||\n typedNode.nodeType === NodeType.Condition ||\n typedNode.nodeType === NodeType.Insertion ||\n typedNode.nodeType === NodeType.Gender ||\n typedNode.nodeType === NodeType.File ||\n typedNode.nodeType === NodeType.Markdown\n ) {\n const firstKey = Object.keys(content)[0] as keyof typeof content;\n return content[firstKey] as ContentNode;\n }\n\n if (typedNode.nodeType === NodeType.Nested) {\n return undefined;\n }\n\n return content;\n }\n\n if (!section || typeof section !== 'object') {\n return section;\n }\n\n if (Array.isArray(section)) {\n return (section as ContentNode[])[0];\n }\n\n return section;\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"getNodeChildren.cjs","names":["NodeType"],"sources":["../../../src/dictionaryManipulator/getNodeChildren.ts"],"sourcesContent":["import { type ContentNode, NodeType, type TypedNode } from '@intlayer/types';\n\nexport const getNodeChildren = (section: ContentNode): ContentNode => {\n if (typeof section === 'string') {\n return section;\n }\n if (typeof section === 'number') {\n return section;\n }\n if (typeof section === 'boolean') {\n return section;\n }\n if (typeof (section as TypedNode)?.nodeType === 'string') {\n const typedNode = section as TypedNode;\n const content =\n typedNode[typedNode.nodeType as unknown as keyof typeof typedNode];\n\n if (\n typedNode.nodeType === NodeType.Translation ||\n typedNode.nodeType === NodeType.Enumeration ||\n typedNode.nodeType === NodeType.Condition ||\n typedNode.nodeType === NodeType.Insertion ||\n typedNode.nodeType === NodeType.Gender ||\n typedNode.nodeType === NodeType.File ||\n typedNode.nodeType === NodeType.Markdown\n ) {\n const firstKey = Object.keys(content)[0] as keyof typeof content;\n return content[firstKey] as ContentNode;\n }\n\n if (typedNode.nodeType === NodeType.Nested) {\n return undefined;\n }\n\n return content;\n }\n\n if (!section || typeof section !== 'object') {\n return section;\n }\n\n if (Array.isArray(section)) {\n return (section as ContentNode[])[0];\n }\n\n return section;\n};\n"],"mappings":";;;;AAEA,MAAa,mBAAmB,YAAsC;AACpE,KAAI,OAAO,YAAY,SACrB,QAAO;AAET,KAAI,OAAO,YAAY,SACrB,QAAO;AAET,KAAI,OAAO,YAAY,UACrB,QAAO;AAET,KAAI,OAAQ,SAAuB,aAAa,UAAU;EACxD,MAAM,YAAY;EAClB,MAAM,UACJ,UAAU,UAAU;AAEtB,MACE,UAAU,aAAaA,0BAAS,eAChC,UAAU,aAAaA,0BAAS,eAChC,UAAU,aAAaA,0BAAS,aAChC,UAAU,aAAaA,0BAAS,aAChC,UAAU,aAAaA,0BAAS,UAChC,UAAU,aAAaA,0BAAS,QAChC,UAAU,aAAaA,0BAAS,SAGhC,QAAO,QADU,OAAO,KAAK,QAAQ,CAAC;AAIxC,MAAI,UAAU,aAAaA,0BAAS,OAClC;AAGF,SAAO;;AAGT,KAAI,CAAC,WAAW,OAAO,YAAY,SACjC,QAAO;AAGT,KAAI,MAAM,QAAQ,QAAQ,CACxB,QAAQ,QAA0B;AAGpC,QAAO"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
2
|
const require_utils_isValidReactElement = require('../utils/isValidReactElement.cjs');
|
|
3
3
|
let __intlayer_types = require("@intlayer/types");
|
|
4
|
-
__intlayer_types = require_rolldown_runtime.__toESM(__intlayer_types);
|
|
5
4
|
|
|
6
5
|
//#region src/dictionaryManipulator/getNodeType.ts
|
|
7
6
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getNodeType.cjs","names":["NodeType","isValidElement"],"sources":["../../../src/dictionaryManipulator/getNodeType.ts"],"sourcesContent":["import { type ContentNode, NodeType, type TypedNode } from '@intlayer/types';\nimport { isValidElement } from '../utils/isValidReactElement';\n\n/**\n * Type guard to check if content is a TypedNode\n */\nconst isTypedNode = (content: unknown): content is TypedNode => {\n return (\n typeof content === 'object' &&\n content !== null &&\n 'nodeType' in content &&\n typeof (content as TypedNode).nodeType === 'string'\n );\n};\n\n/**\n * Type guard to check if content is a valid NodeType\n */\nconst isValidNodeType = (nodeType: string): nodeType is NodeType => {\n return Object.values(NodeType).includes(nodeType as NodeType);\n};\n\nexport const getNodeType = (content: ContentNode): NodeType => {\n if (typeof content === 'string') {\n return NodeType.Text;\n }\n\n if (isTypedNode(content)) {\n const nodeType = content.nodeType;\n if (isValidNodeType(nodeType)) {\n return nodeType;\n }\n // Fallback for unknown node types\n return NodeType.Unknown;\n }\n\n if (Array.isArray(content)) {\n return NodeType.Array;\n }\n\n if (isValidElement(content)) {\n return NodeType.ReactNode;\n }\n\n if (typeof content === 'number') {\n return NodeType.Number;\n }\n\n if (typeof content === 'boolean') {\n return NodeType.Boolean;\n }\n\n if (content && typeof content === 'object') {\n return NodeType.Object;\n }\n\n if (content === null) {\n return NodeType.Null;\n }\n\n return NodeType.Unknown;\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"getNodeType.cjs","names":["NodeType","isValidElement"],"sources":["../../../src/dictionaryManipulator/getNodeType.ts"],"sourcesContent":["import { type ContentNode, NodeType, type TypedNode } from '@intlayer/types';\nimport { isValidElement } from '../utils/isValidReactElement';\n\n/**\n * Type guard to check if content is a TypedNode\n */\nconst isTypedNode = (content: unknown): content is TypedNode => {\n return (\n typeof content === 'object' &&\n content !== null &&\n 'nodeType' in content &&\n typeof (content as TypedNode).nodeType === 'string'\n );\n};\n\n/**\n * Type guard to check if content is a valid NodeType\n */\nconst isValidNodeType = (nodeType: string): nodeType is NodeType => {\n return Object.values(NodeType).includes(nodeType as NodeType);\n};\n\nexport const getNodeType = (content: ContentNode): NodeType => {\n if (typeof content === 'string') {\n return NodeType.Text;\n }\n\n if (isTypedNode(content)) {\n const nodeType = content.nodeType;\n if (isValidNodeType(nodeType)) {\n return nodeType;\n }\n // Fallback for unknown node types\n return NodeType.Unknown;\n }\n\n if (Array.isArray(content)) {\n return NodeType.Array;\n }\n\n if (isValidElement(content)) {\n return NodeType.ReactNode;\n }\n\n if (typeof content === 'number') {\n return NodeType.Number;\n }\n\n if (typeof content === 'boolean') {\n return NodeType.Boolean;\n }\n\n if (content && typeof content === 'object') {\n return NodeType.Object;\n }\n\n if (content === null) {\n return NodeType.Null;\n }\n\n return NodeType.Unknown;\n};\n"],"mappings":";;;;;;;;AAMA,MAAM,eAAe,YAA2C;AAC9D,QACE,OAAO,YAAY,YACnB,YAAY,QACZ,cAAc,WACd,OAAQ,QAAsB,aAAa;;;;;AAO/C,MAAM,mBAAmB,aAA2C;AAClE,QAAO,OAAO,OAAOA,0BAAS,CAAC,SAAS,SAAqB;;AAG/D,MAAa,eAAe,YAAmC;AAC7D,KAAI,OAAO,YAAY,SACrB,QAAOA,0BAAS;AAGlB,KAAI,YAAY,QAAQ,EAAE;EACxB,MAAM,WAAW,QAAQ;AACzB,MAAI,gBAAgB,SAAS,CAC3B,QAAO;AAGT,SAAOA,0BAAS;;AAGlB,KAAI,MAAM,QAAQ,QAAQ,CACxB,QAAOA,0BAAS;AAGlB,KAAIC,iDAAe,QAAQ,CACzB,QAAOD,0BAAS;AAGlB,KAAI,OAAO,YAAY,SACrB,QAAOA,0BAAS;AAGlB,KAAI,OAAO,YAAY,UACrB,QAAOA,0BAAS;AAGlB,KAAI,WAAW,OAAO,YAAY,SAChC,QAAOA,0BAAS;AAGlB,KAAI,YAAY,KACd,QAAOA,0BAAS;AAGlB,QAAOA,0BAAS"}
|
|
@@ -2,7 +2,6 @@ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
|
2
2
|
const require_deepTransformPlugins_getMultilingualDictionary = require('../deepTransformPlugins/getMultilingualDictionary.cjs');
|
|
3
3
|
const require_dictionaryManipulator_getNodeType = require('./getNodeType.cjs');
|
|
4
4
|
let __intlayer_config_client = require("@intlayer/config/client");
|
|
5
|
-
__intlayer_config_client = require_rolldown_runtime.__toESM(__intlayer_config_client);
|
|
6
5
|
let __intlayer_config_built = require("@intlayer/config/built");
|
|
7
6
|
__intlayer_config_built = require_rolldown_runtime.__toESM(__intlayer_config_built);
|
|
8
7
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mergeDictionaries.cjs","names":["configuration","getNodeType","result: Record<string, MergeableContent>","result: MergeableContent[]","mergedContent: Dictionary['content']","getMultilingualDictionary"],"sources":["../../../src/dictionaryManipulator/mergeDictionaries.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { colorizeKey, getAppLogger } from '@intlayer/config/client';\nimport type {\n ContentNode,\n Dictionary,\n LocalDictionaryId,\n} from '@intlayer/types';\nimport { getMultilingualDictionary } from '../deepTransformPlugins';\nimport { getNodeType } from './getNodeType';\n\n// Extended type that includes arrays for internal merge operations\ntype MergeableContent = ContentNode | ContentNode[];\n\nconst checkTypesMatch = (\n object1: ContentNode,\n object2: ContentNode,\n object2LocalId: LocalDictionaryId | undefined,\n dictionaryKey: string,\n path: string[] = []\n): void => {\n const appLogger = getAppLogger(configuration);\n\n // If either side is missing/undefined, allow merge without error\n if (\n object1 === undefined ||\n object1 === null ||\n object2 === undefined ||\n object2 === null\n )\n return;\n\n const type1 = getNodeType(object1);\n const type2 = getNodeType(object2);\n\n // Unknown types are treated as flexible; skip strict mismatch reporting\n if (type1 === 'unknown' || type2 === 'unknown') return;\n\n if (type1 !== type2) {\n appLogger(\n [\n `Error: Dictionary ${colorizeKey(dictionaryKey)} has a multiple content files with type mismatch at path \"${path.join('.')}\": Cannot merge ${type1} with ${type2} while merging ${object2LocalId}`,\n ],\n {\n level: 'error',\n }\n );\n\n return;\n }\n};\n\n// Custom merge function that prefers destination (first dictionary) values\nconst customMerge = (\n destination: ContentNode,\n source: ContentNode\n): MergeableContent => {\n // If destination is undefined/null, use source\n if (destination === undefined || destination === null) {\n return source;\n }\n\n // If source is undefined/null, use destination\n if (source === undefined || source === null) {\n return destination;\n }\n\n // For primitive values, prefer destination (first dictionary)\n if (typeof destination !== 'object' || typeof source !== 'object') {\n return destination;\n }\n\n // For arrays, use our custom array merge\n if (Array.isArray(destination) && Array.isArray(source)) {\n return arrayMerge(\n destination as ContentNode[],\n source as ContentNode[]\n ) as MergeableContent;\n }\n\n // For objects, recursively merge with our custom logic\n if (typeof destination === 'object' && typeof source === 'object') {\n const result: Record<string, MergeableContent> = {};\n const allKeys = new Set([\n ...Object.keys(destination as unknown as Record<string, ContentNode>),\n ...Object.keys(source as unknown as Record<string, ContentNode>),\n ]);\n\n for (const key of allKeys) {\n result[key] = customMerge(\n (destination as unknown as Record<string, ContentNode>)[key],\n (source as unknown as Record<string, ContentNode>)[key]\n );\n }\n\n return result as unknown as MergeableContent;\n }\n\n // Fallback to destination\n return destination;\n};\n\n// Custom array merge strategy that merges arrays by key when present, otherwise by index\nconst arrayMerge = (\n destinationArray: ContentNode[],\n sourceArray: ContentNode[]\n): MergeableContent[] => {\n // Check if both arrays contain only primitives\n const destHasOnlyPrimitives = destinationArray.every(\n (item) => typeof item !== 'object' || item === null\n );\n const sourceHasOnlyPrimitives = sourceArray.every(\n (item) => typeof item !== 'object' || item === null\n );\n\n // If both arrays contain only primitives, use the source array (second dictionary)\n if (destHasOnlyPrimitives && sourceHasOnlyPrimitives) {\n return sourceArray;\n }\n\n // Otherwise, merge by index with object merging logic\n const result: MergeableContent[] = [];\n const maxLength = Math.max(destinationArray.length, sourceArray.length);\n\n for (let i = 0; i < maxLength; i++) {\n const destItem = destinationArray[i];\n const sourceItem = sourceArray[i];\n\n if (destItem === undefined && sourceItem === undefined) {\n } else if (destItem === undefined) {\n // Only source exists, add it\n result.push(sourceItem);\n } else if (sourceItem === undefined) {\n // Only destination exists, add it\n result.push(destItem);\n } else {\n // Both exist, merge them\n if (\n typeof destItem === 'object' &&\n typeof sourceItem === 'object' &&\n destItem !== null &&\n sourceItem !== null\n ) {\n // Check if both objects have a 'key' property for keyed merging\n if (\n 'key' in destItem &&\n 'key' in sourceItem &&\n (destItem as Record<string, string>).key ===\n (sourceItem as Record<string, string>).key\n ) {\n // Merge objects with same key, preferring destination (first dictionary) values\n result.push(customMerge(destItem, sourceItem));\n } else {\n // Merge objects by index, preferring destination (first dictionary) values\n result.push(customMerge(destItem, sourceItem));\n }\n } else {\n // For primitives or non-objects, use destination value (first dictionary)\n result.push(destItem);\n }\n }\n }\n\n return result;\n};\n\nexport const mergeDictionaries = (dictionaries: Dictionary[]): Dictionary => {\n const localIds = Array.from(\n new Set<LocalDictionaryId>(\n dictionaries.filter((dict) => dict.localId).map((dict) => dict.localId!)\n )\n );\n\n const dictionariesKeys = dictionaries.map((dict) => dict.key);\n\n // Check if all dictionaries have the same key\n if (new Set(dictionariesKeys).size !== 1) {\n throw new Error('All dictionaries must have the same key');\n }\n\n let mergedContent: Dictionary['content'] = dictionaries[0].content;\n\n for (let i = 1; i < dictionaries.length; i++) {\n // If the dictionary is a per-locale dictionary, transform it to a partial multilingual dictionary\n const currentDictionary = getMultilingualDictionary(dictionaries[i]);\n\n // Check types before merging\n checkTypesMatch(\n mergedContent,\n currentDictionary.content,\n currentDictionary.localId,\n currentDictionary.key,\n []\n );\n\n mergedContent = customMerge(\n mergedContent,\n currentDictionary.content\n ) as ContentNode;\n }\n\n const mergedDictionary: Dictionary = {\n key: dictionaries[0].key,\n content: mergedContent,\n localIds,\n };\n\n return mergedDictionary;\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"mergeDictionaries.cjs","names":["configuration","getNodeType","result: Record<string, MergeableContent>","result: MergeableContent[]","mergedContent: Dictionary['content']","getMultilingualDictionary"],"sources":["../../../src/dictionaryManipulator/mergeDictionaries.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { colorizeKey, getAppLogger } from '@intlayer/config/client';\nimport type {\n ContentNode,\n Dictionary,\n LocalDictionaryId,\n} from '@intlayer/types';\nimport { getMultilingualDictionary } from '../deepTransformPlugins';\nimport { getNodeType } from './getNodeType';\n\n// Extended type that includes arrays for internal merge operations\ntype MergeableContent = ContentNode | ContentNode[];\n\nconst checkTypesMatch = (\n object1: ContentNode,\n object2: ContentNode,\n object2LocalId: LocalDictionaryId | undefined,\n dictionaryKey: string,\n path: string[] = []\n): void => {\n const appLogger = getAppLogger(configuration);\n\n // If either side is missing/undefined, allow merge without error\n if (\n object1 === undefined ||\n object1 === null ||\n object2 === undefined ||\n object2 === null\n )\n return;\n\n const type1 = getNodeType(object1);\n const type2 = getNodeType(object2);\n\n // Unknown types are treated as flexible; skip strict mismatch reporting\n if (type1 === 'unknown' || type2 === 'unknown') return;\n\n if (type1 !== type2) {\n appLogger(\n [\n `Error: Dictionary ${colorizeKey(dictionaryKey)} has a multiple content files with type mismatch at path \"${path.join('.')}\": Cannot merge ${type1} with ${type2} while merging ${object2LocalId}`,\n ],\n {\n level: 'error',\n }\n );\n\n return;\n }\n};\n\n// Custom merge function that prefers destination (first dictionary) values\nconst customMerge = (\n destination: ContentNode,\n source: ContentNode\n): MergeableContent => {\n // If destination is undefined/null, use source\n if (destination === undefined || destination === null) {\n return source;\n }\n\n // If source is undefined/null, use destination\n if (source === undefined || source === null) {\n return destination;\n }\n\n // For primitive values, prefer destination (first dictionary)\n if (typeof destination !== 'object' || typeof source !== 'object') {\n return destination;\n }\n\n // For arrays, use our custom array merge\n if (Array.isArray(destination) && Array.isArray(source)) {\n return arrayMerge(\n destination as ContentNode[],\n source as ContentNode[]\n ) as MergeableContent;\n }\n\n // For objects, recursively merge with our custom logic\n if (typeof destination === 'object' && typeof source === 'object') {\n const result: Record<string, MergeableContent> = {};\n const allKeys = new Set([\n ...Object.keys(destination as unknown as Record<string, ContentNode>),\n ...Object.keys(source as unknown as Record<string, ContentNode>),\n ]);\n\n for (const key of allKeys) {\n result[key] = customMerge(\n (destination as unknown as Record<string, ContentNode>)[key],\n (source as unknown as Record<string, ContentNode>)[key]\n );\n }\n\n return result as unknown as MergeableContent;\n }\n\n // Fallback to destination\n return destination;\n};\n\n// Custom array merge strategy that merges arrays by key when present, otherwise by index\nconst arrayMerge = (\n destinationArray: ContentNode[],\n sourceArray: ContentNode[]\n): MergeableContent[] => {\n // Check if both arrays contain only primitives\n const destHasOnlyPrimitives = destinationArray.every(\n (item) => typeof item !== 'object' || item === null\n );\n const sourceHasOnlyPrimitives = sourceArray.every(\n (item) => typeof item !== 'object' || item === null\n );\n\n // If both arrays contain only primitives, use the source array (second dictionary)\n if (destHasOnlyPrimitives && sourceHasOnlyPrimitives) {\n return sourceArray;\n }\n\n // Otherwise, merge by index with object merging logic\n const result: MergeableContent[] = [];\n const maxLength = Math.max(destinationArray.length, sourceArray.length);\n\n for (let i = 0; i < maxLength; i++) {\n const destItem = destinationArray[i];\n const sourceItem = sourceArray[i];\n\n if (destItem === undefined && sourceItem === undefined) {\n } else if (destItem === undefined) {\n // Only source exists, add it\n result.push(sourceItem);\n } else if (sourceItem === undefined) {\n // Only destination exists, add it\n result.push(destItem);\n } else {\n // Both exist, merge them\n if (\n typeof destItem === 'object' &&\n typeof sourceItem === 'object' &&\n destItem !== null &&\n sourceItem !== null\n ) {\n // Check if both objects have a 'key' property for keyed merging\n if (\n 'key' in destItem &&\n 'key' in sourceItem &&\n (destItem as Record<string, string>).key ===\n (sourceItem as Record<string, string>).key\n ) {\n // Merge objects with same key, preferring destination (first dictionary) values\n result.push(customMerge(destItem, sourceItem));\n } else {\n // Merge objects by index, preferring destination (first dictionary) values\n result.push(customMerge(destItem, sourceItem));\n }\n } else {\n // For primitives or non-objects, use destination value (first dictionary)\n result.push(destItem);\n }\n }\n }\n\n return result;\n};\n\nexport const mergeDictionaries = (dictionaries: Dictionary[]): Dictionary => {\n const localIds = Array.from(\n new Set<LocalDictionaryId>(\n dictionaries.filter((dict) => dict.localId).map((dict) => dict.localId!)\n )\n );\n\n const dictionariesKeys = dictionaries.map((dict) => dict.key);\n\n // Check if all dictionaries have the same key\n if (new Set(dictionariesKeys).size !== 1) {\n throw new Error('All dictionaries must have the same key');\n }\n\n let mergedContent: Dictionary['content'] = dictionaries[0].content;\n\n for (let i = 1; i < dictionaries.length; i++) {\n // If the dictionary is a per-locale dictionary, transform it to a partial multilingual dictionary\n const currentDictionary = getMultilingualDictionary(dictionaries[i]);\n\n // Check types before merging\n checkTypesMatch(\n mergedContent,\n currentDictionary.content,\n currentDictionary.localId,\n currentDictionary.key,\n []\n );\n\n mergedContent = customMerge(\n mergedContent,\n currentDictionary.content\n ) as ContentNode;\n }\n\n const mergedDictionary: Dictionary = {\n key: dictionaries[0].key,\n content: mergedContent,\n localIds,\n };\n\n return mergedDictionary;\n};\n"],"mappings":";;;;;;;;AAaA,MAAM,mBACJ,SACA,SACA,gBACA,eACA,OAAiB,EAAE,KACV;CACT,MAAM,uDAAyBA,gCAAc;AAG7C,KACE,YAAY,UACZ,YAAY,QACZ,YAAY,UACZ,YAAY,KAEZ;CAEF,MAAM,QAAQC,sDAAY,QAAQ;CAClC,MAAM,QAAQA,sDAAY,QAAQ;AAGlC,KAAI,UAAU,aAAa,UAAU,UAAW;AAEhD,KAAI,UAAU,OAAO;AACnB,YACE,CACE,+DAAiC,cAAc,CAAC,4DAA4D,KAAK,KAAK,IAAI,CAAC,kBAAkB,MAAM,QAAQ,MAAM,iBAAiB,iBACnL,E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G9C,QAAO,KAAK,YAAY,UAAU,WAAW,CAAC;MAIhD,QAAO,KAAK,SAAS;;AAK3B,QAAO;;AAGT,MAAa,qBAAqB,iBAA2C;CAC3E,MAAM,WAAW,MAAM,KACrB,IAAI,IACF,aAAa,QAAQ,SAAS,KAAK,QAAQ,CAAC,KAAK,SAAS,KAAK,QAAS,CACzE,CACF;CAED,MAAM,mBAAmB,aAAa,KAAK,SAAS,KAAK,IAAI;AAG7D,KAAI,IAAI,IAAI,iBAAiB,CAAC,SAAS,EACrC,OAAM,IAAI,MAAM,0CAA0C;CAG5D,IAAIC,gBAAuC,aAAa,GAAG;AAE3D,MAAK,IAAI,IAAI,GAAG,IAAI,aAAa,QAAQ,KAAK;EAE5C,MAAM,oBAAoBC,iFAA0B,aAAa,GAAG;AAGpE,kBACE,eACA,kBAAkB,SAClB,kBAAkB,SAClB,kBAAkB,KAClB,EAAE,CACH;AAED,kBAAgB,YACd,eACA,kBAAkB,QACnB;;AASH,QANqC;EACnC,KAAK,aAAa,GAAG;EACrB,SAAS;EACT;EACD"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
2
|
let __intlayer_types = require("@intlayer/types");
|
|
3
|
-
__intlayer_types = require_rolldown_runtime.__toESM(__intlayer_types);
|
|
4
3
|
|
|
5
4
|
//#region src/dictionaryManipulator/removeContentNodeByKeyPath.ts
|
|
6
5
|
const removeContentNodeByKeyPath = (dictionaryContent, keyPath) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"removeContentNodeByKeyPath.cjs","names":["currentValue: any","parentValue: any","lastKey: string | number | null","NodeType"],"sources":["../../../src/dictionaryManipulator/removeContentNodeByKeyPath.ts"],"sourcesContent":["import { type ContentNode, type KeyPath, NodeType } from '@intlayer/types';\n\nexport const removeContentNodeByKeyPath = (\n dictionaryContent: ContentNode,\n keyPath: KeyPath[]\n): ContentNode => {\n let currentValue: any = dictionaryContent;\n let parentValue: any = null;\n let lastKey: string | number | null = null;\n\n for (const keyObj of keyPath) {\n parentValue = currentValue;\n\n if (keyObj.type === NodeType.Object || keyObj.type === NodeType.Array) {\n lastKey = keyObj.key;\n currentValue = currentValue[keyObj.key];\n }\n\n if (\n keyObj.type === NodeType.Translation ||\n keyObj.type === NodeType.Enumeration ||\n keyObj.type === NodeType.Condition\n ) {\n lastKey = keyObj.type;\n currentValue = currentValue[keyObj.type][keyObj.key];\n }\n\n if (\n keyObj.type === NodeType.Markdown ||\n keyObj.type === NodeType.ReactNode ||\n keyObj.type === NodeType.Insertion ||\n keyObj.type === NodeType.File\n ) {\n lastKey = keyObj.type;\n currentValue = currentValue[keyObj.type];\n }\n }\n\n if (parentValue && lastKey !== null) {\n if (Array.isArray(parentValue)) {\n parentValue.splice(lastKey as unknown as number, 1);\n } else {\n delete parentValue[lastKey];\n }\n }\n\n return dictionaryContent;\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"removeContentNodeByKeyPath.cjs","names":["currentValue: any","parentValue: any","lastKey: string | number | null","NodeType"],"sources":["../../../src/dictionaryManipulator/removeContentNodeByKeyPath.ts"],"sourcesContent":["import { type ContentNode, type KeyPath, NodeType } from '@intlayer/types';\n\nexport const removeContentNodeByKeyPath = (\n dictionaryContent: ContentNode,\n keyPath: KeyPath[]\n): ContentNode => {\n let currentValue: any = dictionaryContent;\n let parentValue: any = null;\n let lastKey: string | number | null = null;\n\n for (const keyObj of keyPath) {\n parentValue = currentValue;\n\n if (keyObj.type === NodeType.Object || keyObj.type === NodeType.Array) {\n lastKey = keyObj.key;\n currentValue = currentValue[keyObj.key];\n }\n\n if (\n keyObj.type === NodeType.Translation ||\n keyObj.type === NodeType.Enumeration ||\n keyObj.type === NodeType.Condition\n ) {\n lastKey = keyObj.type;\n currentValue = currentValue[keyObj.type][keyObj.key];\n }\n\n if (\n keyObj.type === NodeType.Markdown ||\n keyObj.type === NodeType.ReactNode ||\n keyObj.type === NodeType.Insertion ||\n keyObj.type === NodeType.File\n ) {\n lastKey = keyObj.type;\n currentValue = currentValue[keyObj.type];\n }\n }\n\n if (parentValue && lastKey !== null) {\n if (Array.isArray(parentValue)) {\n parentValue.splice(lastKey as unknown as number, 1);\n } else {\n delete parentValue[lastKey];\n }\n }\n\n return dictionaryContent;\n};\n"],"mappings":";;;;AAEA,MAAa,8BACX,mBACA,YACgB;CAChB,IAAIA,eAAoB;CACxB,IAAIC,cAAmB;CACvB,IAAIC,UAAkC;AAEtC,MAAK,MAAM,UAAU,SAAS;AAC5B,gBAAc;AAEd,MAAI,OAAO,SAASC,0BAAS,UAAU,OAAO,SAASA,0BAAS,OAAO;AACrE,aAAU,OAAO;AACjB,kBAAe,aAAa,OAAO;;AAGrC,MACE,OAAO,SAASA,0BAAS,eACzB,OAAO,SAASA,0BAAS,eACzB,OAAO,SAASA,0BAAS,WACzB;AACA,aAAU,OAAO;AACjB,kBAAe,aAAa,OAAO,MAAM,OAAO;;AAGlD,MACE,OAAO,SAASA,0BAAS,YACzB,OAAO,SAASA,0BAAS,aACzB,OAAO,SAASA,0BAAS,aACzB,OAAO,SAASA,0BAAS,MACzB;AACA,aAAU,OAAO;AACjB,kBAAe,aAAa,OAAO;;;AAIvC,KAAI,eAAe,YAAY,KAC7B,KAAI,MAAM,QAAQ,YAAY,CAC5B,aAAY,OAAO,SAA8B,EAAE;KAEnD,QAAO,YAAY;AAIvB,QAAO"}
|