@intlayer/core 5.8.1 → 6.0.0-canary.1

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.
Files changed (118) hide show
  1. package/dist/cjs/deepTranformPlugins/getFilterTranslationsOnlyContent.cjs +130 -0
  2. package/dist/cjs/deepTranformPlugins/getFilterTranslationsOnlyContent.cjs.map +1 -0
  3. package/dist/cjs/deepTranformPlugins/getFilteredLocalesContent.cjs +62 -0
  4. package/dist/cjs/deepTranformPlugins/getFilteredLocalesContent.cjs.map +1 -0
  5. package/dist/cjs/{interpreter/getContent → deepTranformPlugins}/getLocalisedContent.cjs +3 -3
  6. package/dist/cjs/deepTranformPlugins/getLocalisedContent.cjs.map +1 -0
  7. package/dist/cjs/deepTranformPlugins/getMissingLocalesContent.cjs +78 -0
  8. package/dist/cjs/deepTranformPlugins/getMissingLocalesContent.cjs.map +1 -0
  9. package/dist/cjs/deepTranformPlugins/getReplacedValuesContent.cjs +82 -0
  10. package/dist/cjs/deepTranformPlugins/getReplacedValuesContent.cjs.map +1 -0
  11. package/dist/cjs/deepTranformPlugins/index.cjs +31 -0
  12. package/dist/cjs/deepTranformPlugins/index.cjs.map +1 -0
  13. package/dist/cjs/dictionaryManipulator/getNodeChildren.cjs +1 -1
  14. package/dist/cjs/dictionaryManipulator/getNodeChildren.cjs.map +1 -1
  15. package/dist/cjs/dictionaryManipulator/getUnmergedDictionaryByKeyPath.cjs +52 -0
  16. package/dist/cjs/dictionaryManipulator/getUnmergedDictionaryByKeyPath.cjs.map +1 -0
  17. package/dist/cjs/dictionaryManipulator/index.cjs +9 -7
  18. package/dist/cjs/dictionaryManipulator/index.cjs.map +1 -1
  19. package/dist/cjs/index.cjs +2 -0
  20. package/dist/cjs/index.cjs.map +1 -1
  21. package/dist/cjs/interpreter/getContent/index.cjs +0 -2
  22. package/dist/cjs/interpreter/getContent/index.cjs.map +1 -1
  23. package/dist/cjs/interpreter/getContent/plugins.cjs +1 -1
  24. package/dist/cjs/interpreter/getContent/plugins.cjs.map +1 -1
  25. package/dist/cjs/interpreter/getIntlayer.cjs.map +1 -1
  26. package/dist/cjs/interpreter/getTranslation.cjs +3 -15
  27. package/dist/cjs/interpreter/getTranslation.cjs.map +1 -1
  28. package/dist/cjs/transpiler/enumeration/enumeration.cjs.map +1 -1
  29. package/dist/cjs/transpiler/file/file.cjs +4 -1
  30. package/dist/cjs/transpiler/file/file.cjs.map +1 -1
  31. package/dist/cjs/types/dictionary.cjs.map +1 -1
  32. package/dist/cjs/types/intlayer.cjs +35 -0
  33. package/dist/cjs/types/intlayer.cjs.map +1 -0
  34. package/dist/cjs/types/translation.cjs.map +1 -1
  35. package/dist/cjs/utils/intl.cjs +2 -15
  36. package/dist/cjs/utils/intl.cjs.map +1 -1
  37. package/dist/esm/deepTranformPlugins/getFilterTranslationsOnlyContent.mjs +95 -0
  38. package/dist/esm/deepTranformPlugins/getFilterTranslationsOnlyContent.mjs.map +1 -0
  39. package/dist/esm/deepTranformPlugins/getFilteredLocalesContent.mjs +40 -0
  40. package/dist/esm/deepTranformPlugins/getFilteredLocalesContent.mjs.map +1 -0
  41. package/dist/esm/{interpreter/getContent → deepTranformPlugins}/getLocalisedContent.mjs +3 -3
  42. package/dist/esm/deepTranformPlugins/getLocalisedContent.mjs.map +1 -0
  43. package/dist/esm/deepTranformPlugins/getMissingLocalesContent.mjs +43 -0
  44. package/dist/esm/deepTranformPlugins/getMissingLocalesContent.mjs.map +1 -0
  45. package/dist/esm/deepTranformPlugins/getReplacedValuesContent.mjs +60 -0
  46. package/dist/esm/deepTranformPlugins/getReplacedValuesContent.mjs.map +1 -0
  47. package/dist/esm/deepTranformPlugins/index.mjs +6 -0
  48. package/dist/esm/deepTranformPlugins/index.mjs.map +1 -0
  49. package/dist/esm/dictionaryManipulator/getNodeChildren.mjs +1 -1
  50. package/dist/esm/dictionaryManipulator/getNodeChildren.mjs.map +1 -1
  51. package/dist/esm/dictionaryManipulator/getUnmergedDictionaryByKeyPath.mjs +18 -0
  52. package/dist/esm/dictionaryManipulator/getUnmergedDictionaryByKeyPath.mjs.map +1 -0
  53. package/dist/esm/dictionaryManipulator/index.mjs +4 -3
  54. package/dist/esm/dictionaryManipulator/index.mjs.map +1 -1
  55. package/dist/esm/index.mjs +1 -0
  56. package/dist/esm/index.mjs.map +1 -1
  57. package/dist/esm/interpreter/getContent/index.mjs +0 -1
  58. package/dist/esm/interpreter/getContent/index.mjs.map +1 -1
  59. package/dist/esm/interpreter/getContent/plugins.mjs +1 -1
  60. package/dist/esm/interpreter/getContent/plugins.mjs.map +1 -1
  61. package/dist/esm/interpreter/getIntlayer.mjs.map +1 -1
  62. package/dist/esm/interpreter/getTranslation.mjs +3 -5
  63. package/dist/esm/interpreter/getTranslation.mjs.map +1 -1
  64. package/dist/esm/transpiler/enumeration/enumeration.mjs.map +1 -1
  65. package/dist/esm/transpiler/file/file.mjs +5 -2
  66. package/dist/esm/transpiler/file/file.mjs.map +1 -1
  67. package/dist/esm/types/intlayer.mjs +13 -0
  68. package/dist/esm/types/intlayer.mjs.map +1 -0
  69. package/dist/esm/utils/intl.mjs +2 -5
  70. package/dist/esm/utils/intl.mjs.map +1 -1
  71. package/dist/types/deepTranformPlugins/getFilterTranslationsOnlyContent.d.ts +13 -0
  72. package/dist/types/deepTranformPlugins/getFilterTranslationsOnlyContent.d.ts.map +1 -0
  73. package/dist/types/deepTranformPlugins/getFilterTranslationsOnlyContent.test.d.ts +2 -0
  74. package/dist/types/deepTranformPlugins/getFilterTranslationsOnlyContent.test.d.ts.map +1 -0
  75. package/dist/types/deepTranformPlugins/getFilteredLocalesContent.d.ts +5 -0
  76. package/dist/types/deepTranformPlugins/getFilteredLocalesContent.d.ts.map +1 -0
  77. package/dist/types/{interpreter/getContent → deepTranformPlugins}/getLocalisedContent.d.ts +3 -3
  78. package/dist/types/deepTranformPlugins/getLocalisedContent.d.ts.map +1 -0
  79. package/dist/types/deepTranformPlugins/getMissingLocalesContent.d.ts +13 -0
  80. package/dist/types/deepTranformPlugins/getMissingLocalesContent.d.ts.map +1 -0
  81. package/dist/types/deepTranformPlugins/getMissingLocalesContent.test.d.ts +2 -0
  82. package/dist/types/deepTranformPlugins/getMissingLocalesContent.test.d.ts.map +1 -0
  83. package/dist/types/deepTranformPlugins/getReplacedValuesContent.d.ts +4 -0
  84. package/dist/types/deepTranformPlugins/getReplacedValuesContent.d.ts.map +1 -0
  85. package/dist/types/deepTranformPlugins/getReplacedValuesContent.test.d.ts +2 -0
  86. package/dist/types/deepTranformPlugins/getReplacedValuesContent.test.d.ts.map +1 -0
  87. package/dist/types/deepTranformPlugins/index.d.ts +6 -0
  88. package/dist/types/deepTranformPlugins/index.d.ts.map +1 -0
  89. package/dist/types/dictionaryManipulator/getNodeChildren.d.ts.map +1 -1
  90. package/dist/types/dictionaryManipulator/getUnmergedDictionaryByKeyPath.d.ts +4 -0
  91. package/dist/types/dictionaryManipulator/getUnmergedDictionaryByKeyPath.d.ts.map +1 -0
  92. package/dist/types/dictionaryManipulator/index.d.ts +4 -3
  93. package/dist/types/dictionaryManipulator/index.d.ts.map +1 -1
  94. package/dist/types/index.d.ts +1 -0
  95. package/dist/types/index.d.ts.map +1 -1
  96. package/dist/types/interpreter/getContent/index.d.ts +0 -1
  97. package/dist/types/interpreter/getContent/index.d.ts.map +1 -1
  98. package/dist/types/interpreter/getContent/plugins.d.ts +1 -1
  99. package/dist/types/interpreter/getContent/plugins.d.ts.map +1 -1
  100. package/dist/types/interpreter/getIntlayer.d.ts +1 -1
  101. package/dist/types/interpreter/getIntlayer.d.ts.map +1 -1
  102. package/dist/types/interpreter/getTranslation.d.ts +1 -1
  103. package/dist/types/interpreter/getTranslation.d.ts.map +1 -1
  104. package/dist/types/transpiler/enumeration/enumeration.d.ts +3 -3
  105. package/dist/types/transpiler/enumeration/enumeration.d.ts.map +1 -1
  106. package/dist/types/transpiler/file/file.d.ts.map +1 -1
  107. package/dist/types/types/dictionary.d.ts +252 -2
  108. package/dist/types/types/dictionary.d.ts.map +1 -1
  109. package/dist/types/types/intlayer.d.ts +5 -0
  110. package/dist/types/types/intlayer.d.ts.map +1 -0
  111. package/dist/types/types/translation.d.ts +1 -2
  112. package/dist/types/types/translation.d.ts.map +1 -1
  113. package/dist/types/utils/intl.d.ts +1 -1
  114. package/dist/types/utils/intl.d.ts.map +1 -1
  115. package/package.json +13 -11
  116. package/dist/cjs/interpreter/getContent/getLocalisedContent.cjs.map +0 -1
  117. package/dist/esm/interpreter/getContent/getLocalisedContent.mjs.map +0 -1
  118. package/dist/types/interpreter/getContent/getLocalisedContent.d.ts.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/interpreter/getContent/plugins.ts"],"sourcesContent":["import type { Locales, LocalesValues } from '@intlayer/config/client';\nimport type {\n ConditionContent,\n EnumerationContent,\n FileContent,\n Gender,\n GenderContent,\n InsertionContent,\n NestedContent,\n TranslationContent,\n} from '../../transpiler';\nimport { type DictionaryKeys, type KeyPath, NodeType } from '../../types/index';\nimport { getCondition } from '../getCondition';\nimport { getEnumeration } from '../getEnumeration';\nimport { getGender } from '../getGender';\nimport { getInsertion } from '../getInsertion';\nimport { type GetNestingResult, getNesting } from '../getNesting';\nimport { getTranslation } from '../getTranslation';\n\n/** ---------------------------------------------\n * PLUGIN DEFINITION\n * --------------------------------------------- */\n\n/**\n * A plugin/transformer that can optionally transform a node during a single DFS pass.\n * - `canHandle` decides if the node is transformable by this plugin.\n * - `transform` returns the transformed node (and does not recurse further).\n *\n * > `transformFn` is a function that can be used to deeply transform inside the plugin.\n */\nexport type Plugins = {\n id: string;\n canHandle: (node: any) => boolean;\n transform: (\n node: any,\n props: NodeProps,\n transformFn: (node: any, props: NodeProps) => any\n ) => any;\n};\n\n/** ---------------------------------------------\n * TRANSLATION PLUGIN\n * --------------------------------------------- */\n\nexport type TranslationCond<T, S> = T extends {\n nodeType: NodeType | string;\n [NodeType.Translation]: object;\n}\n ? DeepTransformContent<\n T[NodeType.Translation][keyof T[NodeType.Translation]],\n S\n >\n : never;\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const translationPlugin = (\n locale: LocalesValues,\n fallback: boolean = true\n): Plugins => ({\n id: 'translation-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Translation,\n transform: (node: TranslationContent, props, deepTransformNode) => {\n const result = structuredClone(node[NodeType.Translation]);\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 childProps\n );\n }\n return getTranslation(result, locale, fallback);\n },\n});\n\n/** ---------------------------------------------\n * ENUMERATION PLUGIN\n * --------------------------------------------- */\n\nexport type EnumerationCond<T, S> = T extends {\n nodeType: NodeType | string;\n [NodeType.Enumeration]: object;\n}\n ? (\n quantity: number\n ) => DeepTransformContent<\n T[NodeType.Enumeration][keyof T[NodeType.Enumeration]],\n S\n >\n : never;\n\n/** Enumeration plugin. Replaces node with a function that takes quantity => string. */\nexport const enumerationPlugin: Plugins = {\n id: 'enumeration-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Enumeration,\n transform: (node: EnumerationContent, props, deepTransformNode) => {\n const result = structuredClone(node[NodeType.Enumeration]);\n\n for (const key in result) {\n const child = result[key as unknown as keyof typeof result];\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Enumeration, key } as KeyPath,\n ],\n };\n result[key as unknown as keyof typeof result] = deepTransformNode(\n child,\n childProps\n );\n }\n\n return (quantity: number) => getEnumeration(result, quantity);\n },\n};\n\n/** ---------------------------------------------\n * CONDITION PLUGIN\n * --------------------------------------------- */\n\nexport type ConditionCond<T, S> = T extends {\n nodeType: NodeType | string;\n [NodeType.Condition]: object;\n}\n ? (\n value: boolean\n ) => DeepTransformContent<\n T[NodeType.Condition][keyof T[NodeType.Condition]],\n S\n >\n : never;\n\n/** Condition plugin. Replaces node with a function that takes boolean => string. */\nexport const conditionPlugin: Plugins = {\n id: 'condition-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Condition,\n transform: (node: ConditionContent, props, deepTransformNode) => {\n const result = structuredClone(node[NodeType.Condition]);\n\n for (const key in result) {\n const child = result[key as keyof typeof result];\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Condition, key } as KeyPath,\n ],\n };\n result[key as unknown as keyof typeof result] = deepTransformNode(\n child,\n childProps\n );\n }\n\n return (value: boolean) => getCondition(result, value);\n },\n};\n\n/** ---------------------------------------------\n * GENDER PLUGIN\n * --------------------------------------------- */\n\nexport type GenderCond<T, S> = T extends {\n nodeType: NodeType | string;\n [NodeType.Gender]: object;\n}\n ? (\n value: Gender\n ) => DeepTransformContent<T[NodeType.Gender][keyof T[NodeType.Gender]], S>\n : never;\n\n/** Gender plugin. Replaces node with a function that takes gender => string. */\nexport const genderPlugin: Plugins = {\n id: 'gender-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Gender,\n transform: (node: GenderContent, props, deepTransformNode) => {\n const result = structuredClone(node[NodeType.Gender]);\n\n for (const key in result) {\n const child = result[key as keyof typeof result];\n const childProps = {\n ...props,\n children: child,\n keyPath: [...props.keyPath, { type: NodeType.Gender, key } as KeyPath],\n };\n result[key as unknown as keyof typeof result] = deepTransformNode(\n child,\n childProps\n );\n }\n\n return (value: Gender) => getGender(result, value);\n },\n};\n\n/** ---------------------------------------------\n * INSERTION PLUGIN\n * --------------------------------------------- */\n\nexport type InsertionCond<T, S> = T extends {\n nodeType: NodeType | string;\n [NodeType.Insertion]: infer I;\n fields?: infer U;\n}\n ? U extends readonly string[]\n ? (data: Record<U[number], string | number>) => DeepTransformContent<I, S>\n : (data: Record<string, string | number>) => DeepTransformContent<I, S>\n : never;\n\nexport const insertionPlugin: Plugins = {\n id: 'insertion-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Insertion,\n transform: (node: InsertionContent, props, deepTransformNode) => {\n const newKeyPath: KeyPath[] = [\n ...props.keyPath,\n {\n type: NodeType.Insertion,\n },\n ];\n\n const children = node[NodeType.Insertion];\n\n /** Insertion string plugin. Replaces string node with a component that render the insertion. */\n const insertionStringPlugin: Plugins = {\n id: 'insertion-string-plugin',\n canHandle: (node) => typeof node === 'string',\n transform: (node: string, subProps, deepTransformNode) => {\n const transformedResult = deepTransformNode(node, {\n ...subProps,\n children: node,\n plugins: [\n ...(props.plugins ?? ([] as Plugins[])).filter(\n (plugin) => plugin.id !== 'intlayer-node-plugin'\n ),\n ],\n });\n\n return (values: {\n [K in InsertionContent['fields'][number]]: string | number;\n }) => {\n const children = getInsertion(transformedResult, values);\n\n return deepTransformNode(children, {\n ...subProps,\n plugins: props.plugins,\n children,\n });\n };\n },\n };\n\n return deepTransformNode(children, {\n ...props,\n children,\n keyPath: newKeyPath,\n plugins: [insertionStringPlugin, ...(props.plugins ?? [])],\n });\n },\n};\n\n/** ---------------------------------------------\n * NESTED PLUGIN\n * --------------------------------------------- */\n\nexport type NestedCond<T, S> = T extends {\n nodeType: NodeType | string;\n [NodeType.Nested]: infer U;\n}\n ? U extends {\n dictionaryKey: infer K extends DictionaryKeys;\n path?: infer P;\n }\n ? GetNestingResult<K, P, S>\n : never\n : never;\n\n/** Nested plugin. Replaces node with the result of `getNesting`. */\nexport const nestedPlugin: Plugins = {\n id: 'nested-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Nested,\n transform: (node: NestedContent, props) =>\n getNesting(node.nested.dictionaryKey, node.nested.path, props),\n};\n\n// /** ---------------------------------------------\n// * FILE PLUGIN\n// * --------------------------------------------- */\n\nexport type FileCond<T> = T extends {\n nodeType: NodeType | string;\n [NodeType.File]: string;\n content?: string;\n}\n ? string\n : never;\n\n/** File plugin. Replaces node with the result of `getNesting`. */\nexport const filePlugin: Plugins = {\n id: 'file-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.File,\n transform: (node: FileContent, props, deepTransform) =>\n deepTransform(node.content, {\n ...props,\n children: node.content,\n }),\n};\n\n/**\n * PLUGIN RESULT\n */\n\n/**\n * Interface that defines the properties of a node.\n * This interface can be augmented in other packages, such as `react-intlayer`.\n */\nexport interface NodeProps {\n dictionaryKey: string;\n keyPath: KeyPath[];\n plugins?: Plugins[];\n locale?: Locales;\n dictionaryPath?: string;\n children?: any;\n}\n\n/**\n * Interface that defines the plugins that can be used to transform a node.\n * This interface can be augmented in other packages, such as `react-intlayer`.\n */\nexport interface IInterpreterPlugin<T, S> {\n translation: TranslationCond<T, S>;\n insertion: InsertionCond<T, S>;\n enumeration: EnumerationCond<T, S>;\n condition: ConditionCond<T, S>;\n nested: NestedCond<T, S>;\n // file: FileCond<T>;\n}\n\n/**\n * Allow to avoid overwriting import from `intlayer` package when `IInterpreterPlugin<T>` interface is augmented in another package, such as `react-intlayer`.\n */\nexport type IInterpreterPluginState = {\n translation: true;\n enumeration: true;\n condition: true;\n insertion: true;\n nested: true;\n // file: true;\n};\n\n/**\n * Utility type to check if a plugin can be applied to a node.\n */\ntype CheckApplyPlugin<T, K extends keyof IInterpreterPlugin<T, S>, S> =\n // Test if the key is a key of S.\n K extends keyof S\n ? // Test if the key of S is true. Then the plugin can be applied.\n S[K] extends true\n ? // Test if the key of S exist\n IInterpreterPlugin<T, S>[K] extends never\n ? never\n : // Test if the plugin condition is true (if it's not, the plugin is skipped for this node)\n IInterpreterPlugin<T, S>[K]\n : never\n : never;\n\n/**\n * Traverse recursively through an object or array, applying each plugin as needed.\n */\ntype Traverse<T, S> =\n // Turn any read-only array into a plain mutable array\n T extends ReadonlyArray<infer U>\n ? Array<DeepTransformContent<U, S>>\n : T extends object\n ? { [K in keyof T]: DeepTransformContent<T[K], S> }\n : T;\n\n/**\n * Traverse recursively through an object or array, applying each plugin as needed.\n */\nexport type DeepTransformContent<T, S = IInterpreterPluginState> =\n // Check if there is a plugin for T:\n CheckApplyPlugin<T, keyof IInterpreterPlugin<T, S>, S> extends never\n ? // No plugin was found, so try to transform T recursively:\n Traverse<T, S>\n : // A plugin was found – use the plugin’s transformation.\n IInterpreterPlugin<T, S>[keyof IInterpreterPlugin<T, S>];\n"],"mappings":"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","names":["node","deepTransformNode","children"]}
1
+ {"version":3,"sources":["../../../../src/interpreter/getContent/plugins.ts"],"sourcesContent":["import type { Locales, LocalesValues } from '@intlayer/config/client';\nimport type {\n ConditionContent,\n EnumerationContent,\n FileContent,\n Gender,\n GenderContent,\n InsertionContent,\n NestedContent,\n TranslationContent,\n} from '../../transpiler';\nimport { type DictionaryKeys, type KeyPath, NodeType } from '../../types/index';\nimport { getCondition } from '../getCondition';\nimport { getEnumeration } from '../getEnumeration';\nimport { getGender } from '../getGender';\nimport { getInsertion } from '../getInsertion';\nimport { type GetNestingResult, getNesting } from '../getNesting';\nimport { getTranslation } from '../getTranslation';\n\n/** ---------------------------------------------\n * PLUGIN DEFINITION\n * --------------------------------------------- */\n\n/**\n * A plugin/transformer that can optionally transform a node during a single DFS pass.\n * - `canHandle` decides if the node is transformable by this plugin.\n * - `transform` returns the transformed node (and does not recurse further).\n *\n * > `transformFn` is a function that can be used to deeply transform inside the plugin.\n */\nexport type Plugins = {\n id: string;\n canHandle: (node: any) => boolean;\n transform: (\n node: any,\n props: NodeProps,\n transformFn: (node: any, props: NodeProps) => any\n ) => any;\n};\n\n/** ---------------------------------------------\n * TRANSLATION PLUGIN\n * --------------------------------------------- */\n\nexport type TranslationCond<T, S> = T extends {\n nodeType: NodeType | string;\n [NodeType.Translation]: object;\n}\n ? DeepTransformContent<\n T[NodeType.Translation][keyof T[NodeType.Translation]],\n S\n >\n : never;\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const translationPlugin = (\n locale: LocalesValues,\n fallback?: LocalesValues\n): Plugins => ({\n id: 'translation-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Translation,\n transform: (node: TranslationContent, props, deepTransformNode) => {\n const result = structuredClone(node[NodeType.Translation]);\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 childProps\n );\n }\n return getTranslation(result, locale, fallback);\n },\n});\n\n/** ---------------------------------------------\n * ENUMERATION PLUGIN\n * --------------------------------------------- */\n\nexport type EnumerationCond<T, S> = T extends {\n nodeType: NodeType | string;\n [NodeType.Enumeration]: object;\n}\n ? (\n quantity: number\n ) => DeepTransformContent<\n T[NodeType.Enumeration][keyof T[NodeType.Enumeration]],\n S\n >\n : never;\n\n/** Enumeration plugin. Replaces node with a function that takes quantity => string. */\nexport const enumerationPlugin: Plugins = {\n id: 'enumeration-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Enumeration,\n transform: (node: EnumerationContent, props, deepTransformNode) => {\n const result = structuredClone(node[NodeType.Enumeration]);\n\n for (const key in result) {\n const child = result[key as unknown as keyof typeof result];\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Enumeration, key } as KeyPath,\n ],\n };\n result[key as unknown as keyof typeof result] = deepTransformNode(\n child,\n childProps\n );\n }\n\n return (quantity: number) => getEnumeration(result, quantity);\n },\n};\n\n/** ---------------------------------------------\n * CONDITION PLUGIN\n * --------------------------------------------- */\n\nexport type ConditionCond<T, S> = T extends {\n nodeType: NodeType | string;\n [NodeType.Condition]: object;\n}\n ? (\n value: boolean\n ) => DeepTransformContent<\n T[NodeType.Condition][keyof T[NodeType.Condition]],\n S\n >\n : never;\n\n/** Condition plugin. Replaces node with a function that takes boolean => string. */\nexport const conditionPlugin: Plugins = {\n id: 'condition-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Condition,\n transform: (node: ConditionContent, props, deepTransformNode) => {\n const result = structuredClone(node[NodeType.Condition]);\n\n for (const key in result) {\n const child = result[key as keyof typeof result];\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Condition, key } as KeyPath,\n ],\n };\n result[key as unknown as keyof typeof result] = deepTransformNode(\n child,\n childProps\n );\n }\n\n return (value: boolean) => getCondition(result, value);\n },\n};\n\n/** ---------------------------------------------\n * GENDER PLUGIN\n * --------------------------------------------- */\n\nexport type GenderCond<T, S> = T extends {\n nodeType: NodeType | string;\n [NodeType.Gender]: object;\n}\n ? (\n value: Gender\n ) => DeepTransformContent<T[NodeType.Gender][keyof T[NodeType.Gender]], S>\n : never;\n\n/** Gender plugin. Replaces node with a function that takes gender => string. */\nexport const genderPlugin: Plugins = {\n id: 'gender-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Gender,\n transform: (node: GenderContent, props, deepTransformNode) => {\n const result = structuredClone(node[NodeType.Gender]);\n\n for (const key in result) {\n const child = result[key as keyof typeof result];\n const childProps = {\n ...props,\n children: child,\n keyPath: [...props.keyPath, { type: NodeType.Gender, key } as KeyPath],\n };\n result[key as unknown as keyof typeof result] = deepTransformNode(\n child,\n childProps\n );\n }\n\n return (value: Gender) => getGender(result, value);\n },\n};\n\n/** ---------------------------------------------\n * INSERTION PLUGIN\n * --------------------------------------------- */\n\nexport type InsertionCond<T, S> = T extends {\n nodeType: NodeType | string;\n [NodeType.Insertion]: infer I;\n fields?: infer U;\n}\n ? U extends readonly string[]\n ? (data: Record<U[number], string | number>) => DeepTransformContent<I, S>\n : (data: Record<string, string | number>) => DeepTransformContent<I, S>\n : never;\n\nexport const insertionPlugin: Plugins = {\n id: 'insertion-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Insertion,\n transform: (node: InsertionContent, props, deepTransformNode) => {\n const newKeyPath: KeyPath[] = [\n ...props.keyPath,\n {\n type: NodeType.Insertion,\n },\n ];\n\n const children = node[NodeType.Insertion];\n\n /** Insertion string plugin. Replaces string node with a component that render the insertion. */\n const insertionStringPlugin: Plugins = {\n id: 'insertion-string-plugin',\n canHandle: (node) => typeof node === 'string',\n transform: (node: string, subProps, deepTransformNode) => {\n const transformedResult = deepTransformNode(node, {\n ...subProps,\n children: node,\n plugins: [\n ...(props.plugins ?? ([] as Plugins[])).filter(\n (plugin) => plugin.id !== 'intlayer-node-plugin'\n ),\n ],\n });\n\n return (values: {\n [K in InsertionContent['fields'][number]]: string | number;\n }) => {\n const children = getInsertion(transformedResult, values);\n\n return deepTransformNode(children, {\n ...subProps,\n plugins: props.plugins,\n children,\n });\n };\n },\n };\n\n return deepTransformNode(children, {\n ...props,\n children,\n keyPath: newKeyPath,\n plugins: [insertionStringPlugin, ...(props.plugins ?? [])],\n });\n },\n};\n\n/** ---------------------------------------------\n * NESTED PLUGIN\n * --------------------------------------------- */\n\nexport type NestedCond<T, S> = T extends {\n nodeType: NodeType | string;\n [NodeType.Nested]: infer U;\n}\n ? U extends {\n dictionaryKey: infer K extends DictionaryKeys;\n path?: infer P;\n }\n ? GetNestingResult<K, P, S>\n : never\n : never;\n\n/** Nested plugin. Replaces node with the result of `getNesting`. */\nexport const nestedPlugin: Plugins = {\n id: 'nested-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Nested,\n transform: (node: NestedContent, props) =>\n getNesting(node.nested.dictionaryKey, node.nested.path, props),\n};\n\n// /** ---------------------------------------------\n// * FILE PLUGIN\n// * --------------------------------------------- */\n\nexport type FileCond<T> = T extends {\n nodeType: NodeType | string;\n [NodeType.File]: string;\n content?: string;\n}\n ? string\n : never;\n\n/** File plugin. Replaces node with the result of `getNesting`. */\nexport const filePlugin: Plugins = {\n id: 'file-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.File,\n transform: (node: FileContent, props, deepTransform) =>\n deepTransform(node.content, {\n ...props,\n children: node.content,\n }),\n};\n\n/**\n * PLUGIN RESULT\n */\n\n/**\n * Interface that defines the properties of a node.\n * This interface can be augmented in other packages, such as `react-intlayer`.\n */\nexport interface NodeProps {\n dictionaryKey: string;\n keyPath: KeyPath[];\n plugins?: Plugins[];\n locale?: Locales;\n dictionaryPath?: string;\n children?: any;\n}\n\n/**\n * Interface that defines the plugins that can be used to transform a node.\n * This interface can be augmented in other packages, such as `react-intlayer`.\n */\nexport interface IInterpreterPlugin<T, S> {\n translation: TranslationCond<T, S>;\n insertion: InsertionCond<T, S>;\n enumeration: EnumerationCond<T, S>;\n condition: ConditionCond<T, S>;\n nested: NestedCond<T, S>;\n // file: FileCond<T>;\n}\n\n/**\n * Allow to avoid overwriting import from `intlayer` package when `IInterpreterPlugin<T>` interface is augmented in another package, such as `react-intlayer`.\n */\nexport type IInterpreterPluginState = {\n translation: true;\n enumeration: true;\n condition: true;\n insertion: true;\n nested: true;\n // file: true;\n};\n\n/**\n * Utility type to check if a plugin can be applied to a node.\n */\ntype CheckApplyPlugin<T, K extends keyof IInterpreterPlugin<T, S>, S> =\n // Test if the key is a key of S.\n K extends keyof S\n ? // Test if the key of S is true. Then the plugin can be applied.\n S[K] extends true\n ? // Test if the key of S exist\n IInterpreterPlugin<T, S>[K] extends never\n ? never\n : // Test if the plugin condition is true (if it's not, the plugin is skipped for this node)\n IInterpreterPlugin<T, S>[K]\n : never\n : never;\n\n/**\n * Traverse recursively through an object or array, applying each plugin as needed.\n */\ntype Traverse<T, S> =\n // Turn any read-only array into a plain mutable array\n T extends ReadonlyArray<infer U>\n ? Array<DeepTransformContent<U, S>>\n : T extends object\n ? { [K in keyof T]: DeepTransformContent<T[K], S> }\n : T;\n\n/**\n * Traverse recursively through an object or array, applying each plugin as needed.\n */\nexport type DeepTransformContent<T, S = IInterpreterPluginState> =\n // Check if there is a plugin for T:\n CheckApplyPlugin<T, keyof IInterpreterPlugin<T, S>, S> extends never\n ? // No plugin was found, so try to transform T recursively:\n Traverse<T, S>\n : // A plugin was found – use the plugin’s transformation.\n IInterpreterPlugin<T, S>[keyof IInterpreterPlugin<T, S>];\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWA,mBAA4D;AAC5D,0BAA6B;AAC7B,4BAA+B;AAC/B,uBAA0B;AAC1B,0BAA6B;AAC7B,wBAAkD;AAClD,4BAA+B;AAsCxB,MAAM,oBAAoB,CAC/B,QACA,cACa;AAAA,EACb,IAAI;AAAA,EACJ,WAAW,CAAC,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,sBAAS;AAAA,EAC1D,WAAW,CAAC,MAA0B,OAAO,sBAAsB;AACjE,UAAM,SAAS,gBAAgB,KAAK,sBAAS,WAAW,CAAC;AAEzD,eAAW,OAAO,QAAQ;AACxB,YAAM,aAAa;AAAA,QACjB,GAAG;AAAA,QACH,UAAU,OAAO,GAAqC;AAAA,QACtD,SAAS;AAAA,UACP,GAAG,MAAM;AAAA,UACT,EAAE,MAAM,sBAAS,aAAa,IAAI;AAAA,QACpC;AAAA,MACF;AACA,aAAO,GAAqC,IAAI;AAAA,QAC9C,OAAO,GAAqC;AAAA,QAC5C;AAAA,MACF;AAAA,IACF;AACA,eAAO,sCAAe,QAAQ,QAAQ,QAAQ;AAAA,EAChD;AACF;AAmBO,MAAM,oBAA6B;AAAA,EACxC,IAAI;AAAA,EACJ,WAAW,CAAC,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,sBAAS;AAAA,EAC1D,WAAW,CAAC,MAA0B,OAAO,sBAAsB;AACjE,UAAM,SAAS,gBAAgB,KAAK,sBAAS,WAAW,CAAC;AAEzD,eAAW,OAAO,QAAQ;AACxB,YAAM,QAAQ,OAAO,GAAqC;AAC1D,YAAM,aAAa;AAAA,QACjB,GAAG;AAAA,QACH,UAAU;AAAA,QACV,SAAS;AAAA,UACP,GAAG,MAAM;AAAA,UACT,EAAE,MAAM,sBAAS,aAAa,IAAI;AAAA,QACpC;AAAA,MACF;AACA,aAAO,GAAqC,IAAI;AAAA,QAC9C;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAEA,WAAO,CAAC,iBAAqB,sCAAe,QAAQ,QAAQ;AAAA,EAC9D;AACF;AAmBO,MAAM,kBAA2B;AAAA,EACtC,IAAI;AAAA,EACJ,WAAW,CAAC,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,sBAAS;AAAA,EAC1D,WAAW,CAAC,MAAwB,OAAO,sBAAsB;AAC/D,UAAM,SAAS,gBAAgB,KAAK,sBAAS,SAAS,CAAC;AAEvD,eAAW,OAAO,QAAQ;AACxB,YAAM,QAAQ,OAAO,GAA0B;AAC/C,YAAM,aAAa;AAAA,QACjB,GAAG;AAAA,QACH,UAAU;AAAA,QACV,SAAS;AAAA,UACP,GAAG,MAAM;AAAA,UACT,EAAE,MAAM,sBAAS,WAAW,IAAI;AAAA,QAClC;AAAA,MACF;AACA,aAAO,GAAqC,IAAI;AAAA,QAC9C;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAEA,WAAO,CAAC,cAAmB,kCAAa,QAAQ,KAAK;AAAA,EACvD;AACF;AAgBO,MAAM,eAAwB;AAAA,EACnC,IAAI;AAAA,EACJ,WAAW,CAAC,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,sBAAS;AAAA,EAC1D,WAAW,CAAC,MAAqB,OAAO,sBAAsB;AAC5D,UAAM,SAAS,gBAAgB,KAAK,sBAAS,MAAM,CAAC;AAEpD,eAAW,OAAO,QAAQ;AACxB,YAAM,QAAQ,OAAO,GAA0B;AAC/C,YAAM,aAAa;AAAA,QACjB,GAAG;AAAA,QACH,UAAU;AAAA,QACV,SAAS,CAAC,GAAG,MAAM,SAAS,EAAE,MAAM,sBAAS,QAAQ,IAAI,CAAY;AAAA,MACvE;AACA,aAAO,GAAqC,IAAI;AAAA,QAC9C;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAEA,WAAO,CAAC,cAAkB,4BAAU,QAAQ,KAAK;AAAA,EACnD;AACF;AAgBO,MAAM,kBAA2B;AAAA,EACtC,IAAI;AAAA,EACJ,WAAW,CAAC,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,sBAAS;AAAA,EAC1D,WAAW,CAAC,MAAwB,OAAO,sBAAsB;AAC/D,UAAM,aAAwB;AAAA,MAC5B,GAAG,MAAM;AAAA,MACT;AAAA,QACE,MAAM,sBAAS;AAAA,MACjB;AAAA,IACF;AAEA,UAAM,WAAW,KAAK,sBAAS,SAAS;AAGxC,UAAM,wBAAiC;AAAA,MACrC,IAAI;AAAA,MACJ,WAAW,CAACA,UAAS,OAAOA,UAAS;AAAA,MACrC,WAAW,CAACA,OAAc,UAAUC,uBAAsB;AACxD,cAAM,oBAAoBA,mBAAkBD,OAAM;AAAA,UAChD,GAAG;AAAA,UACH,UAAUA;AAAA,UACV,SAAS;AAAA,YACP,IAAI,MAAM,WAAY,CAAC,GAAiB;AAAA,cACtC,CAAC,WAAW,OAAO,OAAO;AAAA,YAC5B;AAAA,UACF;AAAA,QACF,CAAC;AAED,eAAO,CAAC,WAEF;AACJ,gBAAME,gBAAW,kCAAa,mBAAmB,MAAM;AAEvD,iBAAOD,mBAAkBC,WAAU;AAAA,YACjC,GAAG;AAAA,YACH,SAAS,MAAM;AAAA,YACf,UAAAA;AAAA,UACF,CAAC;AAAA,QACH;AAAA,MACF;AAAA,IACF;AAEA,WAAO,kBAAkB,UAAU;AAAA,MACjC,GAAG;AAAA,MACH;AAAA,MACA,SAAS;AAAA,MACT,SAAS,CAAC,uBAAuB,GAAI,MAAM,WAAW,CAAC,CAAE;AAAA,IAC3D,CAAC;AAAA,EACH;AACF;AAmBO,MAAM,eAAwB;AAAA,EACnC,IAAI;AAAA,EACJ,WAAW,CAAC,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,sBAAS;AAAA,EAC1D,WAAW,CAAC,MAAqB,cAC/B,8BAAW,KAAK,OAAO,eAAe,KAAK,OAAO,MAAM,KAAK;AACjE;AAeO,MAAM,aAAsB;AAAA,EACjC,IAAI;AAAA,EACJ,WAAW,CAAC,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,sBAAS;AAAA,EAC1D,WAAW,CAAC,MAAmB,OAAO,kBACpC,cAAc,KAAK,SAAS;AAAA,IAC1B,GAAG;AAAA,IACH,UAAU,KAAK;AAAA,EACjB,CAAC;AACL;","names":["node","deepTransformNode","children"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/interpreter/getIntlayer.ts"],"sourcesContent":["import type { LocalesValues } from '@intlayer/config';\n/**\n * @intlayer/dictionaries-entry is a package that only returns the dictionary entry path.\n * Using an external package allow to alias it in the bundle configuration (such as webpack).\n * The alias allow hot reload the app (such as nextjs) on any dictionary change.\n */\nimport dictionaries from '@intlayer/dictionaries-entry';\n// @ts-ignore intlayer declared for module augmentation\nimport type { IntlayerDictionaryTypesConnector } from 'intlayer';\nimport type { Dictionary, DictionaryKeys } from '../types';\nimport type { DeepTransformContent, Plugins } from './getContent/plugins';\nimport { getDictionary } from './getDictionary';\n\nexport const getIntlayer = <T extends DictionaryKeys, L extends LocalesValues>(\n key: T,\n locale?: L,\n plugins?: Plugins[]\n) => {\n const dictionary = dictionaries[key as T];\n\n if (!dictionary) {\n throw new Error(`Dictionary ${key as string} not found`, dictionaries);\n }\n\n return getDictionary(\n dictionary as Dictionary,\n locale,\n plugins\n ) as any as DeepTransformContent<\n IntlayerDictionaryTypesConnector[T]['content']\n >;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,gCAAyB;AAKzB,2BAA8B;AAEvB,MAAM,cAAc,CACzB,KACA,QACA,YACG;AACH,QAAM,aAAa,0BAAAA,QAAa,GAAQ;AAExC,MAAI,CAAC,YAAY;AACf,UAAM,IAAI,MAAM,cAAc,GAAa,cAAc,0BAAAA,OAAY;AAAA,EACvE;AAEA,aAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAGF;","names":["dictionaries"]}
1
+ {"version":3,"sources":["../../../src/interpreter/getIntlayer.ts"],"sourcesContent":["import type { LocalesValues } from '@intlayer/config/client';\n/**\n * @intlayer/dictionaries-entry is a package that only returns the dictionary entry path.\n * Using an external package allow to alias it in the bundle configuration (such as webpack).\n * The alias allow hot reload the app (such as nextjs) on any dictionary change.\n */\nimport dictionaries from '@intlayer/dictionaries-entry';\n// @ts-ignore intlayer declared for module augmentation\nimport type { IntlayerDictionaryTypesConnector } from 'intlayer';\nimport type { Dictionary, DictionaryKeys } from '../types';\nimport type { DeepTransformContent, Plugins } from './getContent/plugins';\nimport { getDictionary } from './getDictionary';\n\nexport const getIntlayer = <T extends DictionaryKeys, L extends LocalesValues>(\n key: T,\n locale?: L,\n plugins?: Plugins[]\n) => {\n const dictionary = dictionaries[key as T];\n\n if (!dictionary) {\n throw new Error(`Dictionary ${key as string} not found`, dictionaries);\n }\n\n return getDictionary(\n dictionary as Dictionary,\n locale,\n plugins\n ) as any as DeepTransformContent<\n IntlayerDictionaryTypesConnector[T]['content']\n >;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,gCAAyB;AAKzB,2BAA8B;AAEvB,MAAM,cAAc,CACzB,KACA,QACA,YACG;AACH,QAAM,aAAa,0BAAAA,QAAa,GAAQ;AAExC,MAAI,CAAC,YAAY;AACf,UAAM,IAAI,MAAM,cAAc,GAAa,cAAc,0BAAAA,OAAY;AAAA,EACvE;AAEA,aAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAGF;","names":["dictionaries"]}
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,26 +15,16 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
  var getTranslation_exports = {};
30
20
  __export(getTranslation_exports, {
31
21
  getTranslation: () => getTranslation
32
22
  });
33
23
  module.exports = __toCommonJS(getTranslation_exports);
34
- var import_built = __toESM(require("@intlayer/config/built"));
35
- const getTranslation = (languageContent, locale, fallback = true) => {
36
- const { defaultLocale } = import_built.default?.internationalization;
37
- let result = languageContent[locale ?? defaultLocale];
24
+ const getTranslation = (languageContent, locale, fallback) => {
25
+ let result = languageContent[locale ?? fallback];
38
26
  if (fallback && !result) {
39
- result = languageContent[defaultLocale];
27
+ result = languageContent[fallback];
40
28
  }
41
29
  return result;
42
30
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/interpreter/getTranslation.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/config/client';\nimport { LanguageContent } from '../types';\n\n/**\n *\n * Allow to pick a content based on a locale.\n * If not locale found, it will return the content related to the default locale.\n *\n * Return either the content editor, or the content itself depending on the configuration.\n *\n * Usage:\n *\n * ```ts\n * const content = getTranslation<string>({\n * en: 'Hello',\n * fr: 'Bonjour',\n * }, 'fr');\n * // 'Bonjour'\n * ```\n *\n * Using TypeScript:\n * - this function will require each locale to be defined if defined in the project configuration.\n * - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.\n */\nexport const getTranslation = <Content = string>(\n languageContent: LanguageContent<Content>,\n locale?: LocalesValues,\n fallback: boolean = true\n): Content => {\n const { defaultLocale } = configuration?.internationalization;\n\n let result =\n languageContent[\n (locale ?? defaultLocale) as unknown as keyof typeof languageContent\n ];\n\n if (fallback && !result) {\n result =\n languageContent[defaultLocale as unknown as keyof typeof languageContent];\n }\n\n return result as unknown as Content;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA0B;AAyBnB,MAAM,iBAAiB,CAC5B,iBACA,QACA,WAAoB,SACR;AACZ,QAAM,EAAE,cAAc,IAAI,aAAAA,SAAe;AAEzC,MAAI,SACF,gBACG,UAAU,aACb;AAEF,MAAI,YAAY,CAAC,QAAQ;AACvB,aACE,gBAAgB,aAAwD;AAAA,EAC5E;AAEA,SAAO;AACT;","names":["configuration"]}
1
+ {"version":3,"sources":["../../../src/interpreter/getTranslation.ts"],"sourcesContent":["import type { LocalesValues } from '@intlayer/config/client';\nimport { LanguageContent } from '../types';\n\n/**\n *\n * Allow to pick a content based on a locale.\n * If not locale found, it will return the content related to the default locale.\n *\n * Return either the content editor, or the content itself depending on the configuration.\n *\n * Usage:\n *\n * ```ts\n * const content = getTranslation<string>({\n * en: 'Hello',\n * fr: 'Bonjour',\n * }, 'fr');\n * // 'Bonjour'\n * ```\n *\n * Using TypeScript:\n * - this function will require each locale to be defined if defined in the project configuration.\n * - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.\n */\nexport const getTranslation = <Content = string>(\n languageContent: LanguageContent<Content>,\n locale?: LocalesValues,\n fallback?: LocalesValues\n): Content => {\n let result =\n languageContent[\n (locale ?? fallback) as unknown as keyof typeof languageContent\n ];\n\n if (fallback && !result) {\n result =\n languageContent[fallback as unknown as keyof typeof languageContent];\n }\n\n return result as unknown as Content;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAwBO,MAAM,iBAAiB,CAC5B,iBACA,QACA,aACY;AACZ,MAAI,SACF,gBACG,UAAU,QACb;AAEF,MAAI,YAAY,CAAC,QAAQ;AACvB,aACE,gBAAgB,QAAmD;AAAA,EACvE;AAEA,SAAO;AACT;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/transpiler/enumeration/enumeration.ts"],"sourcesContent":["import {\n type TypedNodeModel,\n formatNodeType,\n NodeType,\n} from '../../types/index';\n\ntype Positif = number | `${number}`;\ntype Negatif = `-${number}`;\ntype Numbers = Positif | Negatif;\n\ntype Equal = Numbers;\ntype EqualString = `=${Numbers}`;\ntype Superior = `>${Numbers}`;\ntype SuperiorOrEqual = `>=${Numbers}`;\ntype Inferior = `<${Numbers}`;\ntype InferiorOrEqual = `<=${Numbers}`;\n\nexport type EnterFormat =\n | Equal\n | EqualString\n | Superior\n | SuperiorOrEqual\n | Inferior\n | InferiorOrEqual;\n\nexport type EnumerationContentState<Content> = Partial<\n Record<EnterFormat, Content>\n> & {\n fallback?: Content;\n};\n\nexport type EnumerationContent<Content = unknown> = TypedNodeModel<\n NodeType.Enumeration,\n EnumerationContentState<Content>\n>;\n\n/**\n * Function intended to be used to build intlayer dictionaries.\n *\n * Allow to pick a content based on a quantity.\n *\n * Usage:\n *\n * ```ts\n * enu({\n * '<=-2.3': 'You have less than -2.3',\n * '<1': 'You have less than one',\n * '2': 'You have two',\n * '>=3': 'You have three or more',\n * });\n * ```\n *\n * > The order of the keys will define the priority of the content.\n *\n */\nconst enumeration = <Content>(content?: EnumerationContentState<Content>) =>\n formatNodeType(NodeType.Enumeration, content);\n\nexport { enumeration as enu };\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAIO;AAmDP,MAAM,cAAc,CAAU,gBAC5B,6BAAe,sBAAS,aAAa,OAAO;","names":[]}
1
+ {"version":3,"sources":["../../../../src/transpiler/enumeration/enumeration.ts"],"sourcesContent":["import {\n type TypedNodeModel,\n formatNodeType,\n NodeType,\n} from '../../types/index';\n\ntype Positive = number | `${number}`;\ntype Negative = `-${number}`;\ntype Numbers = Positive | Negative;\n\ntype Equal = Numbers;\ntype EqualString = `=${Numbers}`;\ntype Superior = `>${Numbers}`;\ntype SuperiorOrEqual = `>=${Numbers}`;\ntype Inferior = `<${Numbers}`;\ntype InferiorOrEqual = `<=${Numbers}`;\n\nexport type EnterFormat =\n | Equal\n | EqualString\n | Superior\n | SuperiorOrEqual\n | Inferior\n | InferiorOrEqual;\n\nexport type EnumerationContentState<Content> = Partial<\n Record<EnterFormat, Content>\n> & {\n fallback?: Content;\n};\n\nexport type EnumerationContent<Content = unknown> = TypedNodeModel<\n NodeType.Enumeration,\n EnumerationContentState<Content>\n>;\n\n/**\n * Function intended to be used to build intlayer dictionaries.\n *\n * Allow to pick a content based on a quantity.\n *\n * Usage:\n *\n * ```ts\n * enu({\n * '<=-2.3': 'You have less than -2.3',\n * '<1': 'You have less than one',\n * '2': 'You have two',\n * '>=3': 'You have three or more',\n * });\n * ```\n *\n * > The order of the keys will define the priority of the content.\n *\n */\nconst enumeration = <Content>(content?: EnumerationContentState<Content>) =>\n formatNodeType(NodeType.Enumeration, content);\n\nexport { enumeration as enu };\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAIO;AAmDP,MAAM,cAAc,CAAU,gBAC5B,6BAAe,sBAAS,aAAa,OAAO;","names":[]}
@@ -57,7 +57,10 @@ const file = (path) => {
57
57
  if ((0, import_fs.existsSync)(filePath)) {
58
58
  content = (0, import_fs.readFileSync)(filePath, "utf8");
59
59
  } else {
60
- appLogger(`File not found: ${filePath}`, { level: "warn" });
60
+ appLogger(
61
+ `File not found: ${(0, import_config.colorizePath)((0, import_path.relative)(import_built.default.content.baseDir, filePath))}`,
62
+ { level: "warn" }
63
+ );
61
64
  content = `File not found`;
62
65
  }
63
66
  return (0, import_types.formatNodeType)(import_types.NodeType.File, path, {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/transpiler/file/file.ts"],"sourcesContent":["import { getAppLogger } from '@intlayer/config';\nimport configuration from '@intlayer/config/built';\nimport { existsSync, readFileSync } from 'fs';\nimport { relative, resolve } from 'path';\nimport {\n formatNodeType,\n NodeType,\n type TypedNodeModel,\n} from '../../types/index';\n\nexport type FileContentConstructor<T extends Record<string, any> = {}> =\n TypedNodeModel<NodeType.File, string, T>;\n\nexport type FileContent = FileContentConstructor<{\n content: string;\n fixedPath?: string;\n}>;\n\ndeclare const intlayer_file_path: string; // Injected by esbuild to track the file content\ndeclare const intlayer_file_dir: string; // Injected by esbuild to track the file path\n\n/**\n * Function intended to be used to build intlayer dictionaries.\n *\n * Allow identify the usage of an external resource.\n *\n * Usage:\n *\n * ```ts\n * file('/path/to/file.md') // absolute path\n *\n * // or\n *\n * file('path/to/file.md') // relative path\n * ```\n */\nexport const file = (path: string): FileContent => {\n const callerDir = intlayer_file_dir ?? process.cwd();\n\n const isAbsolutePath = path.startsWith('/');\n const isRelativePath = path.startsWith('./') || path.startsWith('../');\n const appLogger = getAppLogger(configuration);\n\n let filePath: string;\n if (isAbsolutePath) {\n appLogger(\n `Using absolute path for file is not recommended. Use relative paths instead. Path: ${path}, imported from: ${intlayer_file_path}`,\n { level: 'warn' }\n );\n filePath = path;\n } else if (isRelativePath) {\n filePath = resolve(callerDir, path);\n } else {\n filePath = resolve(process.cwd(), path);\n }\n\n let content: string;\n\n if (existsSync(filePath)) {\n content = readFileSync(filePath, 'utf8');\n } else {\n appLogger(`File not found: ${filePath}`, { level: 'warn' });\n\n content = `File not found`;\n }\n\n return formatNodeType(NodeType.File, path, {\n content,\n fixedPath: relative(process.cwd(), filePath),\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA6B;AAC7B,mBAA0B;AAC1B,gBAAyC;AACzC,kBAAkC;AAClC,mBAIO;AA4BA,MAAM,OAAO,CAAC,SAA8B;AACjD,QAAM,YAAY,qBAAqB,QAAQ,IAAI;AAEnD,QAAM,iBAAiB,KAAK,WAAW,GAAG;AAC1C,QAAM,iBAAiB,KAAK,WAAW,IAAI,KAAK,KAAK,WAAW,KAAK;AACrE,QAAM,gBAAY,4BAAa,aAAAA,OAAa;AAE5C,MAAI;AACJ,MAAI,gBAAgB;AAClB;AAAA,MACE,sFAAsF,IAAI,oBAAoB,kBAAkB;AAAA,MAChI,EAAE,OAAO,OAAO;AAAA,IAClB;AACA,eAAW;AAAA,EACb,WAAW,gBAAgB;AACzB,mBAAW,qBAAQ,WAAW,IAAI;AAAA,EACpC,OAAO;AACL,mBAAW,qBAAQ,QAAQ,IAAI,GAAG,IAAI;AAAA,EACxC;AAEA,MAAI;AAEJ,UAAI,sBAAW,QAAQ,GAAG;AACxB,kBAAU,wBAAa,UAAU,MAAM;AAAA,EACzC,OAAO;AACL,cAAU,mBAAmB,QAAQ,IAAI,EAAE,OAAO,OAAO,CAAC;AAE1D,cAAU;AAAA,EACZ;AAEA,aAAO,6BAAe,sBAAS,MAAM,MAAM;AAAA,IACzC;AAAA,IACA,eAAW,sBAAS,QAAQ,IAAI,GAAG,QAAQ;AAAA,EAC7C,CAAC;AACH;","names":["configuration"]}
1
+ {"version":3,"sources":["../../../../src/transpiler/file/file.ts"],"sourcesContent":["import { colorizePath, getAppLogger } from '@intlayer/config';\nimport configuration from '@intlayer/config/built';\nimport { existsSync, readFileSync } from 'fs';\nimport { relative, resolve } from 'path';\nimport {\n formatNodeType,\n NodeType,\n type TypedNodeModel,\n} from '../../types/index';\n\nexport type FileContentConstructor<T extends Record<string, any> = {}> =\n TypedNodeModel<NodeType.File, string, T>;\n\nexport type FileContent = FileContentConstructor<{\n content: string;\n fixedPath?: string;\n}>;\n\ndeclare const intlayer_file_path: string; // Injected by esbuild to track the file content\ndeclare const intlayer_file_dir: string; // Injected by esbuild to track the file path\n\n/**\n * Function intended to be used to build intlayer dictionaries.\n *\n * Allow identify the usage of an external resource.\n *\n * Usage:\n *\n * ```ts\n * file('/path/to/file.md') // absolute path\n *\n * // or\n *\n * file('path/to/file.md') // relative path\n * ```\n */\nexport const file = (path: string): FileContent => {\n const callerDir = intlayer_file_dir ?? process.cwd();\n\n const isAbsolutePath = path.startsWith('/');\n const isRelativePath = path.startsWith('./') || path.startsWith('../');\n const appLogger = getAppLogger(configuration);\n\n let filePath: string;\n if (isAbsolutePath) {\n appLogger(\n `Using absolute path for file is not recommended. Use relative paths instead. Path: ${path}, imported from: ${intlayer_file_path}`,\n { level: 'warn' }\n );\n filePath = path;\n } else if (isRelativePath) {\n filePath = resolve(callerDir, path);\n } else {\n filePath = resolve(process.cwd(), path);\n }\n\n let content: string;\n\n if (existsSync(filePath)) {\n content = readFileSync(filePath, 'utf8');\n } else {\n appLogger(\n `File not found: ${colorizePath(relative(configuration.content.baseDir, filePath))}`,\n { level: 'warn' }\n );\n\n content = `File not found`;\n }\n\n return formatNodeType(NodeType.File, path, {\n content,\n fixedPath: relative(process.cwd(), filePath),\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA2C;AAC3C,mBAA0B;AAC1B,gBAAyC;AACzC,kBAAkC;AAClC,mBAIO;AA4BA,MAAM,OAAO,CAAC,SAA8B;AACjD,QAAM,YAAY,qBAAqB,QAAQ,IAAI;AAEnD,QAAM,iBAAiB,KAAK,WAAW,GAAG;AAC1C,QAAM,iBAAiB,KAAK,WAAW,IAAI,KAAK,KAAK,WAAW,KAAK;AACrE,QAAM,gBAAY,4BAAa,aAAAA,OAAa;AAE5C,MAAI;AACJ,MAAI,gBAAgB;AAClB;AAAA,MACE,sFAAsF,IAAI,oBAAoB,kBAAkB;AAAA,MAChI,EAAE,OAAO,OAAO;AAAA,IAClB;AACA,eAAW;AAAA,EACb,WAAW,gBAAgB;AACzB,mBAAW,qBAAQ,WAAW,IAAI;AAAA,EACpC,OAAO;AACL,mBAAW,qBAAQ,QAAQ,IAAI,GAAG,IAAI;AAAA,EACxC;AAEA,MAAI;AAEJ,UAAI,sBAAW,QAAQ,GAAG;AACxB,kBAAU,wBAAa,UAAU,MAAM;AAAA,EACzC,OAAO;AACL;AAAA,MACE,uBAAmB,gCAAa,sBAAS,aAAAA,QAAc,QAAQ,SAAS,QAAQ,CAAC,CAAC;AAAA,MAClF,EAAE,OAAO,OAAO;AAAA,IAClB;AAEA,cAAU;AAAA,EACZ;AAEA,aAAO,6BAAe,sBAAS,MAAM,MAAM;AAAA,IACzC;AAAA,IACA,eAAW,sBAAS,QAAQ,IAAI,GAAG,QAAQ;AAAA,EAC7C,CAAC;AACH;","names":["configuration"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/types/dictionary.ts"],"sourcesContent":["// @ts-ignore intlayer declared for module augmentation\nimport type {\n IntlayerDictionaryTypesConnector,\n // @ts-ignore intlayer declared for module augmentation\n LanguageContent,\n // @ts-ignore intlayer declared for module augmentation\n LocalesValues,\n // @ts-ignore intlayer declared for module augmentation\n} from 'intlayer';\nimport type { ConditionContent } from '../transpiler/condition';\nimport type { EnumerationContent } from '../transpiler/enumeration';\nimport type { FileContent } from '../transpiler/file';\nimport type { GenderContent } from '../transpiler/gender';\nimport type { InsertionContent } from '../transpiler/insertion';\nimport type { MarkdownContent } from '../transpiler/markdown';\nimport type { NestedContent } from '../transpiler/nesting';\nimport type { TranslationContent } from '../transpiler/translation';\n\n/**\n * Provides a fallback to string type if the generic type T is undefined,\n * otherwise returns T. This is useful for handling cases where no keys are found.\n * Example: StringFallback<undefined> -> string; StringFallback<'key'> -> 'key'\n */\nexport type StringFallback<T> = T extends undefined ? string : T; // If no keys are found, return string to disable error, and accept any string as dictionary key\n\n/**\n * Represents the keys of the IntlayerDictionaryTypesConnector,\n * ensuring they are valid dictionary keys or fallback to string if none exist.\n *\n * Example:\n * ```ts\n * DictionaryKeys -> 'key1' | 'key2'\n * // or if IntlayerDictionaryTypesConnector is not defined,\n * DictionaryKeys -> string\n * ```\n */\nexport type DictionaryKeys = StringFallback<\n keyof IntlayerDictionaryTypesConnector\n>;\n\ntype BaseNode = number | string | boolean | null | undefined;\n\nexport type TypedNode<NodeType = undefined> =\n | TranslationContent<NodeType>\n | EnumerationContent<NodeType>\n | ConditionContent<NodeType>\n | InsertionContent<NodeType>\n | MarkdownContent<NodeType>\n | NestedContent<DictionaryKeys>\n | GenderContent<NodeType>\n | FileContent;\n\ntype FetchableContentNode<NodeType> = (\n args?: any\n) => ContentNode<NodeType> | Promise<ContentNode<NodeType>>;\n\nexport type ContentNode<\n T = undefined,\n FetchableNode = false,\n NodeType = T extends undefined ? BaseNode : T,\n> =\n | NodeType\n | TypedNode<NodeType>\n | ((args?: any) => ContentNode<NodeType>)\n | (FetchableNode extends true ? FetchableContentNode<NodeType> : undefined);\n\n// Utility types (unchanged)\ntype IsArray<T> = T extends any[] ? true : false;\n\ntype ReplaceContentValueArray<T, FetchableNode> = T extends (infer U)[]\n ? // Allow either a *single* typed node returning the entire array\n // or an array of typed nodes (or scalar nodes).\n ContentNode<T, FetchableNode> | ReplaceContentValue<U, FetchableNode>[]\n : never;\n\ntype ReplaceContentValueObject<T, FetchableNode> = {\n [K in keyof T]: ReplaceContentValue<T[K], FetchableNode>;\n};\n\n// Modified: allow a full ContentNode wrapper OR an object shape when T is an object\ntype ReplaceContentValue<\n NodeType,\n FetchableNode = true,\n> = NodeType extends object\n ? IsArray<NodeType> extends true\n ? ReplaceContentValueArray<NodeType, FetchableNode>\n :\n | ContentNode<NodeType, FetchableNode>\n | ReplaceContentValueObject<NodeType, FetchableNode>\n : ContentNode<NodeType, FetchableNode>;\n\nexport type AutoFill = true | string | Partial<LanguageContent<string>>;\n\nexport type Dictionary<ContentType = undefined, FetchableNode = false> = {\n $schema?: string;\n key: string;\n title?: string;\n description?: string;\n availableVersions?: string[];\n version?: string;\n filePath?: string;\n tags?: string[];\n locale?: LocalesValues;\n autoFill?: AutoFill;\n autoFilled?: true;\n location?: 'distant' | 'locale';\n content: ContentType extends undefined // Applying the generic to replace ContentValue with Replacement\n ? any\n : ReplaceContentValue<ContentType, FetchableNode> | ContentType;\n};\n\nexport type GetSubPath<T, P> = P extends `${infer K}.${infer Rest}`\n ? K extends keyof T\n ? GetSubPath<T[K], Rest>\n : never\n : P extends keyof T\n ? T[P]\n : T;\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
1
+ {"version":3,"sources":["../../../src/types/dictionary.ts"],"sourcesContent":["import type { ConditionContent } from '../transpiler/condition';\nimport type { EnumerationContent } from '../transpiler/enumeration';\nimport type { FileContent } from '../transpiler/file';\nimport type { GenderContent } from '../transpiler/gender';\nimport type { InsertionContent } from '../transpiler/insertion';\nimport type { MarkdownContent } from '../transpiler/markdown';\nimport type { NestedContent } from '../transpiler/nesting';\nimport type { TranslationContent } from '../transpiler/translation';\nimport type {\n IntlayerDictionaryTypesConnector,\n LanguageContent,\n LocalesValues,\n} from './intlayer';\n\n/**\n * Provides a fallback to string type if the generic type T is undefined,\n * otherwise returns T. This is useful for handling cases where no keys are found.\n * Example: StringFallback<undefined> -> string; StringFallback<'key'> -> 'key'\n */\nexport type StringFallback<T> = T extends undefined ? string : T; // If no keys are found, return string to disable error, and accept any string as dictionary key\n\n/**\n * Represents the keys of the IntlayerDictionaryTypesConnector,\n * ensuring they are valid dictionary keys or fallback to string if none exist.\n *\n * Example:\n * ```ts\n * DictionaryKeys -> 'key1' | 'key2'\n * // or if IntlayerDictionaryTypesConnector is not defined,\n * DictionaryKeys -> string\n * ```\n */\nexport type DictionaryKeys = StringFallback<\n keyof IntlayerDictionaryTypesConnector\n>;\n\ntype BaseNode = number | string | boolean | null | undefined;\n\nexport type TypedNode<NodeType = undefined> =\n | TranslationContent<NodeType>\n | EnumerationContent<NodeType>\n | ConditionContent<NodeType>\n | InsertionContent<NodeType>\n | MarkdownContent<NodeType>\n | NestedContent<DictionaryKeys>\n | GenderContent<NodeType>\n | FileContent;\n\ntype FetchableContentNode<NodeType> = (\n args?: any\n) => ContentNode<NodeType> | Promise<ContentNode<NodeType>>;\n\nexport type ContentNode<\n T = undefined,\n FetchableNode = false,\n NodeType = T extends undefined ? BaseNode : T,\n> =\n | NodeType\n | TypedNode<NodeType>\n | ((args?: any) => ContentNode<NodeType>)\n | (FetchableNode extends true ? FetchableContentNode<NodeType> : undefined);\n\n// Utility types (unchanged)\ntype IsArray<T> = T extends any[] ? true : false;\n\ntype ReplaceContentValueArray<T, FetchableNode> = T extends (infer U)[]\n ? // Allow either a *single* typed node returning the entire array\n // or an array of typed nodes (or scalar nodes).\n ContentNode<T, FetchableNode> | ReplaceContentValue<U, FetchableNode>[]\n : never;\n\ntype ReplaceContentValueObject<T, FetchableNode> = {\n [K in keyof T]: ReplaceContentValue<T[K], FetchableNode>;\n};\n\n// Modified: allow a full ContentNode wrapper OR an object shape when T is an object\ntype ReplaceContentValue<\n NodeType,\n FetchableNode = true,\n> = NodeType extends object\n ? IsArray<NodeType> extends true\n ? ReplaceContentValueArray<NodeType, FetchableNode>\n :\n | ContentNode<NodeType, FetchableNode>\n | ReplaceContentValueObject<NodeType, FetchableNode>\n : ContentNode<NodeType, FetchableNode>;\n\nexport type AutoFill = true | string | Partial<LanguageContent<string>>;\n\nexport type LocalDictionaryId = string;\n\nexport type Dictionary<ContentType = undefined, FetchableNode = false> = {\n /**\n * _Auto generated by the intlayer, do not modify it_\n *\n * The schema of the dictionary, used for JSON validation\n */\n $schema?: string;\n /**\n * _Auto generated by the intlayer, do not modify it_\n *\n * For remote dictionaries, the id is the id of the dictionary in the remote server\n */\n id?: string;\n /**\n * _Auto generated by the intlayer, do not modify it_\n *\n * Unique Identifier for the dictionaries. Auto generated by the intlayer, it helps to identify the dictionary and know if it is a local or remote dictionary, and his location.\n */\n localId?: LocalDictionaryId;\n /**\n * _Auto generated by the intlayer, do not modify it_\n *\n * For merged dictionaries, the localIds is the ids of the dictionaries that are merged\n */\n localIds?: LocalDictionaryId[];\n /**\n * The key of the dictionary. If multiple dictionaries have the same key, intlayer will merge them.\n *\n * As convention, use '-' to separate the words in the key.\n *\n * Example:\n * ```json\n * {\n * \"key\": \"about-page-meta\",\n * \"content\": { ... }\n * }\n * ```\n */\n key: string;\n /**\n * The title of the dictionary. Helps to identify the dictionary in the editor, and the CMS.\n *\n * Example:\n * ```json\n * {\n * \"key\": \"about-page-meta\",\n * \"title\": \"About Page\",\n * \"content\": { ... }\n * }\n * ```\n */\n title?: string;\n /**\n * The description of the dictionary. Helps to understand the purpose of the dictionary in the editor, and the CMS.\n * The descrtion is also used as context for translations generation.\n *\n * Example:\n * ```ts\n * {\n * \"key\": \"about-page-meta\",\n * \"description\":[\n * \"This dictionary is manage the metadata of the About Page\",\n * \"Consider good practices for SEO:\",\n * \"- The title should be between 50 and 60 characters\",\n * \"- The description should be between 150 and 160 characters\",\n * ].join('\\n'),\n * \"content\": { ... }\n * }\n * ```\n */\n description?: string;\n /**\n * _Auto generated by the intlayer, do not modify it_\n *\n * The available versions of the remote dictionary. Helps to know the versions of the dictionary that are available.\n */\n versions?: string[];\n /**\n * _Managable on the CMS, do not modify it locally_\n *\n * The version of the remote dictionary. Helps to know the version of the dictionary that is currently used.\n */\n version?: string;\n /**\n * _Auto generated by the intlayer, do not modify it_\n *\n * The file path of the local dictionary. Helps to know from what .content file the dictionary has been generated.\n */\n filePath?: string;\n /**\n * Helps to categorize the dictionaries. The tags can provide more context and instructions for the dictionary.\n *\n * Example:\n * ```json\n * {\n * \"key\": \"about-page-meta\",\n * \"tags\": [\"metadata\",\"about-page\"]\n * }\n * ```\n */\n tags?: string[];\n /**\n * Transform the dictionary in a per-locale dictionary.\n * Each field declared in a per-locale dictionary will be transformed in a translation node.\n * If missing, the dictionary will be treated as a multilingual dictionary.\n * If declared, do not use translation nodes in the content.\n *\n * Example:\n * ```json\n * {\n * \"key\": \"about-page\",\n * \"locale\": \"en\",\n * \"content\": {\n * \"multilingualContent\": \"English content\"\n * }\n * }\n * ```\n */\n locale?: LocalesValues;\n /**\n * Instruction to auto fill the dictionary.\n * Can also be declared globally in the `intlayer.config.ts` file.\n *\n * Example:\n * ```json\n * {\n * \"key\": \"about-page\",\n * \"autoFill\": true\n * }\n * ```\n * ```json\n * {\n * \"key\": \"about-page\",\n * \"autoFill\": \"./aboutPage.content.json\"\n * }\n * ```\n * ```json\n * {\n * \"key\": \"about-page\",\n * \"autoFill\": \"/messages/{{locale}}/{{key}}/{{fileName}}.content.json\"\n * }\n * ```\n * ```json\n * {\n * \"key\": \"about-page\",\n * \"autoFill\": {\n * \"fr\": \"./aboutPage.fr.content.json\",\n * \"es\": \"./aboutPage.es.content.json\"\n * }\n * }\n * ```\n *\n */\n autoFill?: AutoFill;\n /**\n * _Auto generated by the intlayer, do not modify it_\n *\n * Indicates if the dictionary has been auto filled.\n * In the case of conflicts, base dictionaryed will override auto filled dictionary.\n */\n autoFilled?: true;\n /**\n * Indicates the priority of the dictionary.\n * In the case of conflicts, the dictionary with the highest priority will override the other dictionaries.\n */\n priority?: number;\n /**\n * _Managable on the CMS, do not modify it locally_\n *\n * For remote dictionaries, indicates if the dictionary is live.\n *\n * Will need the `importMode` to be \"live\" to be effective in the `intlayer.config.ts` file. Will also need the live server to be running.\n *\n * A live dictionary will be fetched at runtime using the live sync API.\n *\n * If live, the dictionary will by transformed to include fetch functions.\n * If not live, the dictionary will be transformed at build time using \"dynamic\" mode to optimize the number of fetch queries, and load performance.\n *\n * If live but the fetch request fails, the dictionary will return the dynamic value of the dictionary as fallback.\n *\n */\n live?: boolean;\n /**\n * _Auto generated by the intlayer, do not modify it_\n *\n * Indicates the location of the dictionary.\n */\n location?: 'distant' | 'locale';\n /**\n * The content of the dictionary.\n *\n * Example:\n * ```tsx\n * import { t, enu, cond, nest, md, insert, file } from \"intlayer\";\n *\n * export default {\n * key: \"about-page-meta\",\n * content: {\n * stringContent: \"About Page Meta\",\n * numberContent: 123,\n * booleanContent: true,\n * multilingualContent: t({\n * en: \"About Page Meta\",\n * fr: \"Meta de la page About\",\n * es: \"Meta de la página About\",\n * }),\n * conditionalContent: cond({\n * true: \"About Page Meta\",\n * false: \"About Page Meta\",\n * }),\n * insertionContent: insert(\"About Page Meta\"),\n * nestedContent: nest(\"about-page\"),\n * markdownContent: md(\"# About Page Meta\"),\n * fileContent: file(\"./path/to/file.txt\"),\n * jsxContent: <h1>About Page Meta</h1>,\n * },\n *\n * } satisfies Dictionary<Content>;\n * ```\n *\n * ```json\n * {\n * \"key\": \"about-page-meta\",\n * \"content\": {\n * \"stringContent\": \"About Page Meta\",\n * \"numberContent\": 123,\n * \"booleanContent\": true,\n * \"multilingualContent\": {\n * \"nodeType\": \"translation\",\n * \"translation\": {\n * \"en\": \"About Page Meta\",\n * \"fr\": \"Meta de la page About\",\n * \"es\": \"Meta de la página About\",\n * },\n * },\n * \"conditionalContent\": {\n * \"nodeType\": \"condition\",\n * \"condition\": {\n * \"true\": \"About Page Meta\",\n * \"false\": \"About Page Meta\",\n * },\n * },\n * \"insertionContent\": {\n * \"nodeType\": \"insertion\",\n * \"insertion\": \"About Page Meta\",\n * },\n * \"nestedContent\": {\n * \"nodeType\": \"nested\",\n * \"nested\": { \"dictionaryKey\": \"about-page\" },\n * },\n * \"markdownContent\": {\n * \"nodeType\": \"markdown\",\n * \"markdown\": \"# About Page Meta\",\n * },\n * \"fileContent\": {\n * \"nodeType\": \"file\",\n * \"file\": \"./path/to/file.txt\",\n * },\n * }\n * }\n * ```\n */\n content: ContentType extends undefined // Applying the generic to replace ContentValue with Replacement\n ? any\n : ReplaceContentValue<ContentType, FetchableNode> | ContentType;\n};\n\nexport type GetSubPath<T, P> = P extends `${infer K}.${infer Rest}`\n ? K extends keyof T\n ? GetSubPath<T[K], Rest>\n : never\n : P extends keyof T\n ? T[P]\n : T;\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var intlayer_exports = {};
20
+ __export(intlayer_exports, {
21
+ IConfigLocales: () => import_intlayer.IConfigLocales,
22
+ IntlayerDictionaryTypesConnector: () => import_intlayer.IntlayerDictionaryTypesConnector,
23
+ LanguageContent: () => import_intlayer.LanguageContent,
24
+ LocalesValues: () => import_intlayer.LocalesValues
25
+ });
26
+ module.exports = __toCommonJS(intlayer_exports);
27
+ var import_intlayer = require("intlayer");
28
+ // Annotate the CommonJS export names for ESM import in node:
29
+ 0 && (module.exports = {
30
+ IConfigLocales,
31
+ IntlayerDictionaryTypesConnector,
32
+ LanguageContent,
33
+ LocalesValues
34
+ });
35
+ //# sourceMappingURL=intlayer.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/types/intlayer.ts"],"sourcesContent":["// @ts-nocheck\n/**\n * Reexport the intlayer module with the module augmentation because of typescript error\n */\n\nexport {\n IConfigLocales,\n IntlayerDictionaryTypesConnector,\n LanguageContent,\n LocalesValues,\n} from 'intlayer';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,sBAKO;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/types/translation.ts"],"sourcesContent":["/** @ts-nocheck */\n\nimport type { LocalesValues } from '@intlayer/config/client';\n// @ts-ignore intlayer declared for module augmentation\nimport type { IConfigLocales } from 'intlayer';\n\n/**\n * If module augmented, it will return the configured locales such as Locales.ENGLISH | Locales.FRENCH | Locales.SPANISH | ...\n * If not, it will return never\n */\nexport type ConfigLocales = keyof IConfigLocales<unknown>;\n\n/**\n * Record of locales and content\n *\n * const myVar1: TranslationContentState<string> = {\n * \"en\": \"\",\n * \"fr\": \"\"\n * }\n *\n * const myVar2: TranslationContentState<{age: number, name: string}> = {\n * \"en\": {age: 1, name: \"test\"},\n * \"fr\": {age: 1, name: \"test\"}\n * }\n */\nexport type TranslationContentState<Content = unknown> = {\n [locale in LocalesValues]?: Content;\n};\n\nexport type LanguageContent<Content = unknown> =\n keyof IConfigLocales<unknown> extends never\n ? TranslationContentState<Content> // Fall including all locales as optional\n : IConfigLocales<Content>;\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
1
+ {"version":3,"sources":["../../../src/types/translation.ts"],"sourcesContent":["import type { LocalesValues } from '@intlayer/config/client';\nimport type { IConfigLocales } from './intlayer';\n\n/**\n * If module augmented, it will return the configured locales such as Locales.ENGLISH | Locales.FRENCH | Locales.SPANISH | ...\n * If not, it will return never\n */\nexport type ConfigLocales = keyof IConfigLocales<unknown>;\n\n/**\n * Record of locales and content\n *\n * const myVar1: TranslationContentState<string> = {\n * \"en\": \"\",\n * \"fr\": \"\"\n * }\n *\n * const myVar2: TranslationContentState<{age: number, name: string}> = {\n * \"en\": {age: 1, name: \"test\"},\n * \"fr\": {age: 1, name: \"test\"}\n * }\n */\nexport type TranslationContentState<Content = unknown> = {\n [locale in LocalesValues]?: Content;\n};\n\nexport type LanguageContent<Content = unknown> =\n keyof IConfigLocales<unknown> extends never\n ? TranslationContentState<Content> // Fall including all locales as optional\n : IConfigLocales<Content>;\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
  var intl_exports = {};
30
20
  __export(intl_exports, {
@@ -32,7 +22,7 @@ __export(intl_exports, {
32
22
  createCachedIntl: () => createCachedIntl
33
23
  });
34
24
  module.exports = __toCommonJS(intl_exports);
35
- var import_built = __toESM(require("@intlayer/config/built"));
25
+ var import_client = require("@intlayer/config/client");
36
26
  const cacheKey = (locales, options) => JSON.stringify([locales, options]);
37
27
  const createCachedConstructor = (Ctor) => {
38
28
  const cache = /* @__PURE__ */ new Map();
@@ -45,10 +35,7 @@ const createCachedConstructor = (Ctor) => {
45
35
  }
46
36
  return locales;
47
37
  }
48
- const key = cacheKey(
49
- locales ?? import_built.default.internationalization.defaultLocale,
50
- options
51
- );
38
+ const key = cacheKey(locales ?? import_client.Locales.ENGLISH, options);
52
39
  let instance = cache.get(key);
53
40
  if (!instance) {
54
41
  instance = new Ctor(locales, options);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/utils/intl.ts"],"sourcesContent":["// Cached Intl helper – drop‑in replacement for the global `Intl` object.\n// ‑‑‑\n// • Uses a `Proxy` to lazily wrap every *constructor* hanging off `Intl` (NumberFormat, DateTimeFormat, …).\n// • Each wrapped constructor keeps an in‑memory cache keyed by `[locales, options]` so that identical requests\n// reuse the same heavy instance instead of reparsing CLDR data every time.\n// • A polyfill warning for `Intl.DisplayNames` is emitted only once and only in dev.\n// • The public API is fully type‑safe and mirrors the native `Intl` surface exactly –\n// you can treat `CachedIntl` just like the built‑in `Intl`.\n//\n// Usage examples:\n// ---------------\n// import { CachedIntl } from \"./cached-intl\";\n//\n// const nf = CachedIntl.NumberFormat(\"en-US\", { style: \"currency\", currency: \"USD\" });\n// console.log(nf.format(1234));\n//\n// const dn = CachedIntl.DisplayNames([\"fr\"], { type: \"language\" });\n// console.log(dn.of(\"en\")); // → \"anglais\"\n//\n// You can also spin up an isolated instance with its own caches (handy in test suites):\n// const TestIntl = createCachedIntl();\n//\n// ---------------------------------------------------------------------\n\nimport { LocalesValues } from '@intlayer/config';\nimport configuration from '@intlayer/config/built';\n\n// Helper type that picks just the constructor members off `typeof Intl`.\n// The \"capital‑letter\" heuristic is 100 % accurate today and keeps the\n// mapping short‑lived, so we don't have to manually list every constructor.\ntype IntlConstructors = {\n [K in keyof typeof Intl as (typeof Intl)[K] extends new (...args: any) => any\n ? K\n : never]: (typeof Intl)[K];\n};\n\n// Type wrapper to replace locale arguments with LocalesValues\ntype ReplaceLocaleWithLocalesValues<T> = T extends new (\n locales: any,\n options?: infer Options\n) => infer Instance\n ? new (locales?: LocalesValues, options?: Options) => Instance\n : T extends new (locales: any) => infer Instance\n ? new (locales?: LocalesValues) => Instance\n : T;\n\n// Wrapped Intl type with LocalesValues\ntype WrappedIntl = {\n [K in keyof typeof Intl]: K extends keyof IntlConstructors\n ? ReplaceLocaleWithLocalesValues<(typeof Intl)[K]>\n : (typeof Intl)[K];\n};\n\n// Generic cache key – JSON.stringify is fine because locale strings are short\n// and option objects are small and deterministic.\nconst cacheKey = (locales: LocalesValues, options: unknown) =>\n JSON.stringify([locales, options]);\n\n// Generic wrapper for any `new Intl.*()` constructor.\n// Returns a constructable function (usable with or without `new`) that\n// pulls instances from a Map cache when possible.\nconst createCachedConstructor = <T extends new (...args: any[]) => any>(\n Ctor: T\n) => {\n const cache = new Map<string, InstanceType<T>>();\n\n function Wrapped(locales?: LocalesValues, options?: any) {\n // Special case – guard older runtimes missing DisplayNames.\n if (\n Ctor.name === 'DisplayNames' &&\n typeof (Intl as any)?.DisplayNames !== 'function'\n ) {\n if (process.env.NODE_ENV === 'development') {\n console.warn(\n `Intl.DisplayNames is not supported; falling back to raw locale (${locales}). ` +\n `Consider adding a polyfill as https://formatjs.io/docs/polyfills/intl-displaynames/`\n );\n }\n return locales as any;\n }\n\n const key = cacheKey(\n locales ?? configuration.internationalization.defaultLocale,\n options\n );\n let instance: InstanceType<T> | undefined = cache.get(key);\n\n if (!instance) {\n instance = new Ctor(locales as never, options as never);\n cache.set(key, instance as InstanceType<T>);\n }\n\n return instance as InstanceType<T>;\n }\n\n // Ensure it behaves like a constructor when used with `new`.\n (Wrapped as any).prototype = (Ctor as any).prototype;\n\n return Wrapped as unknown as ReplaceLocaleWithLocalesValues<T>;\n};\n\n// Factory that turns the global `Intl` into a cached clone.\nexport const createCachedIntl = (): WrappedIntl =>\n new Proxy(Intl as IntlConstructors, {\n get: (target, prop, receiver) => {\n const value = Reflect.get(target, prop, receiver);\n\n // Wrap *only* constructor functions (safest heuristic: they start with a capital letter).\n return typeof value === 'function' && /^[A-Z]/.test(String(prop))\n ? createCachedConstructor(value)\n : value;\n },\n }) as unknown as WrappedIntl;\n\n// Singleton – import this in application code if you just want shared caches.\nconst CachedIntl = createCachedIntl();\n\n// new CachedIntl.DisplayNames(Locales.FRENCH, { type: 'language' });\n// new CachedIntl.DisplayNames('fr', { type: 'language' });\n// new CachedIntl.DateTimeFormat('fr', {\n// year: 'numeric',\n// month: 'long',\n// day: 'numeric',\n// });\n// new CachedIntl.NumberFormat('fr', {\n// style: 'currency',\n// currency: 'EUR',\n// });\n// new CachedIntl.Collator('fr', { sensitivity: 'base' });\n// new CachedIntl.PluralRules('fr');\n// new CachedIntl.RelativeTimeFormat('fr', { numeric: 'auto' });\n// new CachedIntl.ListFormat('fr', { type: 'conjunction' });\n\nexport { CachedIntl as Intl };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAyBA,mBAA0B;AA8B1B,MAAM,WAAW,CAAC,SAAwB,YACxC,KAAK,UAAU,CAAC,SAAS,OAAO,CAAC;AAKnC,MAAM,0BAA0B,CAC9B,SACG;AACH,QAAM,QAAQ,oBAAI,IAA6B;AAE/C,WAAS,QAAQ,SAAyB,SAAe;AAEvD,QACE,KAAK,SAAS,kBACd,OAAQ,MAAc,iBAAiB,YACvC;AACA,UAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,gBAAQ;AAAA,UACN,mEAAmE,OAAO;AAAA,QAE5E;AAAA,MACF;AACA,aAAO;AAAA,IACT;AAEA,UAAM,MAAM;AAAA,MACV,WAAW,aAAAA,QAAc,qBAAqB;AAAA,MAC9C;AAAA,IACF;AACA,QAAI,WAAwC,MAAM,IAAI,GAAG;AAEzD,QAAI,CAAC,UAAU;AACb,iBAAW,IAAI,KAAK,SAAkB,OAAgB;AACtD,YAAM,IAAI,KAAK,QAA2B;AAAA,IAC5C;AAEA,WAAO;AAAA,EACT;AAGA,EAAC,QAAgB,YAAa,KAAa;AAE3C,SAAO;AACT;AAGO,MAAM,mBAAmB,MAC9B,IAAI,MAAM,MAA0B;AAAA,EAClC,KAAK,CAAC,QAAQ,MAAM,aAAa;AAC/B,UAAM,QAAQ,QAAQ,IAAI,QAAQ,MAAM,QAAQ;AAGhD,WAAO,OAAO,UAAU,cAAc,SAAS,KAAK,OAAO,IAAI,CAAC,IAC5D,wBAAwB,KAAK,IAC7B;AAAA,EACN;AACF,CAAC;AAGH,MAAM,aAAa,iBAAiB;","names":["configuration"]}
1
+ {"version":3,"sources":["../../../src/utils/intl.ts"],"sourcesContent":["// Cached Intl helper – drop‑in replacement for the global `Intl` object.\n// ‑‑‑\n// • Uses a `Proxy` to lazily wrap every *constructor* hanging off `Intl` (NumberFormat, DateTimeFormat, …).\n// • Each wrapped constructor keeps an in‑memory cache keyed by `[locales, options]` so that identical requests\n// reuse the same heavy instance instead of reparsing CLDR data every time.\n// • A polyfill warning for `Intl.DisplayNames` is emitted only once and only in dev.\n// • The public API is fully type‑safe and mirrors the native `Intl` surface exactly –\n// you can treat `CachedIntl` just like the built‑in `Intl`.\n//\n// Usage examples:\n// ---------------\n// import { CachedIntl } from \"./cached-intl\";\n//\n// const nf = CachedIntl.NumberFormat(\"en-US\", { style: \"currency\", currency: \"USD\" });\n// console.log(nf.format(1234));\n//\n// const dn = CachedIntl.DisplayNames([\"fr\"], { type: \"language\" });\n// console.log(dn.of(\"en\")); // → \"anglais\"\n//\n// You can also spin up an isolated instance with its own caches (handy in test suites):\n// const TestIntl = createCachedIntl();\n//\n// ---------------------------------------------------------------------\n\nimport { Locales, type LocalesValues } from '@intlayer/config/client';\n\n// Helper type that picks just the constructor members off `typeof Intl`.\n// The \"capital‑letter\" heuristic is 100 % accurate today and keeps the\n// mapping short‑lived, so we don't have to manually list every constructor.\ntype IntlConstructors = {\n [K in keyof typeof Intl as (typeof Intl)[K] extends new (...args: any) => any\n ? K\n : never]: (typeof Intl)[K];\n};\n\n// Type wrapper to replace locale arguments with LocalesValues\ntype ReplaceLocaleWithLocalesValues<T> = T extends new (\n locales: any,\n options?: infer Options\n) => infer Instance\n ? new (locales?: LocalesValues, options?: Options) => Instance\n : T extends new (locales: any) => infer Instance\n ? new (locales?: LocalesValues) => Instance\n : T;\n\n// Wrapped Intl type with LocalesValues\ntype WrappedIntl = {\n [K in keyof typeof Intl]: K extends keyof IntlConstructors\n ? ReplaceLocaleWithLocalesValues<(typeof Intl)[K]>\n : (typeof Intl)[K];\n};\n\n// Generic cache key – JSON.stringify is fine because locale strings are short\n// and option objects are small and deterministic.\nconst cacheKey = (locales: LocalesValues, options: unknown) =>\n JSON.stringify([locales, options]);\n\n// Generic wrapper for any `new Intl.*()` constructor.\n// Returns a constructable function (usable with or without `new`) that\n// pulls instances from a Map cache when possible.\nconst createCachedConstructor = <T extends new (...args: any[]) => any>(\n Ctor: T\n) => {\n const cache = new Map<string, InstanceType<T>>();\n\n function Wrapped(locales?: LocalesValues, options?: any) {\n // Special case – guard older runtimes missing DisplayNames.\n if (\n Ctor.name === 'DisplayNames' &&\n typeof (Intl as any)?.DisplayNames !== 'function'\n ) {\n if (process.env.NODE_ENV === 'development') {\n console.warn(\n `Intl.DisplayNames is not supported; falling back to raw locale (${locales}). ` +\n `Consider adding a polyfill as https://formatjs.io/docs/polyfills/intl-displaynames/`\n );\n }\n return locales as any;\n }\n\n const key = cacheKey(locales ?? Locales.ENGLISH, options);\n let instance: InstanceType<T> | undefined = cache.get(key);\n\n if (!instance) {\n instance = new Ctor(locales as never, options as never);\n cache.set(key, instance as InstanceType<T>);\n }\n\n return instance as InstanceType<T>;\n }\n\n // Ensure it behaves like a constructor when used with `new`.\n (Wrapped as any).prototype = (Ctor as any).prototype;\n\n return Wrapped as unknown as ReplaceLocaleWithLocalesValues<T>;\n};\n\n// Factory that turns the global `Intl` into a cached clone.\nexport const createCachedIntl = (): WrappedIntl =>\n new Proxy(Intl as IntlConstructors, {\n get: (target, prop, receiver) => {\n const value = Reflect.get(target, prop, receiver);\n\n // Wrap *only* constructor functions (safest heuristic: they start with a capital letter).\n return typeof value === 'function' && /^[A-Z]/.test(String(prop))\n ? createCachedConstructor(value)\n : value;\n },\n }) as unknown as WrappedIntl;\n\n// Singleton – import this in application code if you just want shared caches.\nconst CachedIntl = createCachedIntl();\n\n// new CachedIntl.DisplayNames(Locales.FRENCH, { type: 'language' });\n// new CachedIntl.DisplayNames('fr', { type: 'language' });\n// new CachedIntl.DateTimeFormat('fr', {\n// year: 'numeric',\n// month: 'long',\n// day: 'numeric',\n// });\n// new CachedIntl.NumberFormat('fr', {\n// style: 'currency',\n// currency: 'EUR',\n// });\n// new CachedIntl.Collator('fr', { sensitivity: 'base' });\n// new CachedIntl.PluralRules('fr');\n// new CachedIntl.RelativeTimeFormat('fr', { numeric: 'auto' });\n// new CachedIntl.ListFormat('fr', { type: 'conjunction' });\n\nexport { CachedIntl as Intl };\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAwBA,oBAA4C;AA8B5C,MAAM,WAAW,CAAC,SAAwB,YACxC,KAAK,UAAU,CAAC,SAAS,OAAO,CAAC;AAKnC,MAAM,0BAA0B,CAC9B,SACG;AACH,QAAM,QAAQ,oBAAI,IAA6B;AAE/C,WAAS,QAAQ,SAAyB,SAAe;AAEvD,QACE,KAAK,SAAS,kBACd,OAAQ,MAAc,iBAAiB,YACvC;AACA,UAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,gBAAQ;AAAA,UACN,mEAAmE,OAAO;AAAA,QAE5E;AAAA,MACF;AACA,aAAO;AAAA,IACT;AAEA,UAAM,MAAM,SAAS,WAAW,sBAAQ,SAAS,OAAO;AACxD,QAAI,WAAwC,MAAM,IAAI,GAAG;AAEzD,QAAI,CAAC,UAAU;AACb,iBAAW,IAAI,KAAK,SAAkB,OAAgB;AACtD,YAAM,IAAI,KAAK,QAA2B;AAAA,IAC5C;AAEA,WAAO;AAAA,EACT;AAGA,EAAC,QAAgB,YAAa,KAAa;AAE3C,SAAO;AACT;AAGO,MAAM,mBAAmB,MAC9B,IAAI,MAAM,MAA0B;AAAA,EAClC,KAAK,CAAC,QAAQ,MAAM,aAAa;AAC/B,UAAM,QAAQ,QAAQ,IAAI,QAAQ,MAAM,QAAQ;AAGhD,WAAO,OAAO,UAAU,cAAc,SAAS,KAAK,OAAO,IAAI,CAAC,IAC5D,wBAAwB,KAAK,IAC7B;AAAA,EACN;AACF,CAAC;AAGH,MAAM,aAAa,iBAAiB;","names":[]}
@@ -0,0 +1,95 @@
1
+ import configuration from "@intlayer/config/built";
2
+ import { getTranslation } from "../interpreter/index.mjs";
3
+ import { deepTransformNode } from "../interpreter/getContent/deepTransform.mjs";
4
+ import { NodeType } from "../types/index.mjs";
5
+ const hasTranslationNodes = (node) => {
6
+ if (typeof node !== "object" || node === null) {
7
+ return false;
8
+ }
9
+ if (node?.nodeType === NodeType.Translation) {
10
+ return true;
11
+ }
12
+ if (Array.isArray(node)) {
13
+ return node.some(hasTranslationNodes);
14
+ }
15
+ return Object.values(node).some(hasTranslationNodes);
16
+ };
17
+ const filterTranslationsOnlyPlugin = (locale, fallback) => ({
18
+ id: "filter-translations-only-plugin",
19
+ canHandle: (node) => {
20
+ return typeof node === "object" && node !== null;
21
+ },
22
+ transform: (node, props, deepTransformNode2) => {
23
+ if (typeof node === "object" && node?.nodeType === NodeType.Translation) {
24
+ const result = structuredClone(
25
+ node[NodeType.Translation]
26
+ );
27
+ for (const key in result) {
28
+ const childProps = {
29
+ ...props,
30
+ children: result[key],
31
+ keyPath: [
32
+ ...props.keyPath,
33
+ { type: NodeType.Translation, key }
34
+ ]
35
+ };
36
+ result[key] = deepTransformNode2(
37
+ result[key],
38
+ {
39
+ ...childProps,
40
+ plugins: [
41
+ ...(props.plugins ?? []).filter(
42
+ (plugin) => plugin.id !== "filter-translations-only-plugin"
43
+ )
44
+ ]
45
+ }
46
+ );
47
+ }
48
+ return getTranslation(result, locale, fallback);
49
+ } else if (typeof node === "object" && node !== null && !Array.isArray(node) && !node?.nodeType) {
50
+ const result = {};
51
+ for (const key in node) {
52
+ if (hasTranslationNodes(node[key])) {
53
+ const childProps = {
54
+ ...props,
55
+ children: node[key],
56
+ keyPath: [
57
+ ...props.keyPath,
58
+ { type: NodeType.Object, key }
59
+ ]
60
+ };
61
+ result[key] = deepTransformNode2(node[key], childProps);
62
+ }
63
+ }
64
+ return result;
65
+ } else if (Array.isArray(node)) {
66
+ return node.map((child, index) => {
67
+ const childProps = {
68
+ ...props,
69
+ children: child,
70
+ keyPath: [
71
+ ...props.keyPath,
72
+ { type: NodeType.Array, key: index }
73
+ ]
74
+ };
75
+ return deepTransformNode2(child, childProps);
76
+ });
77
+ }
78
+ return "to remove from the object";
79
+ }
80
+ });
81
+ const getFilterTranslationsOnlyContent = (node, locale = configuration?.internationalization.defaultLocale, nodeProps, fallback) => {
82
+ const plugins = [
83
+ filterTranslationsOnlyPlugin(locale, fallback),
84
+ ...nodeProps.plugins ?? []
85
+ ];
86
+ return deepTransformNode(node, {
87
+ ...nodeProps,
88
+ plugins
89
+ });
90
+ };
91
+ export {
92
+ filterTranslationsOnlyPlugin,
93
+ getFilterTranslationsOnlyContent
94
+ };
95
+ //# sourceMappingURL=getFilterTranslationsOnlyContent.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/deepTranformPlugins/getFilterTranslationsOnlyContent.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { Locales, LocalesValues } from '@intlayer/config/client';\nimport { getTranslation } from '../interpreter';\nimport { deepTransformNode } from '../interpreter/getContent/deepTransform';\nimport {\n type DeepTransformContent,\n type NodeProps,\n type Plugins,\n} from '../interpreter/getContent/plugins';\nimport { TranslationContent } from '../transpiler';\nimport { KeyPath, NodeType, type ContentNode } from '../types';\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])) {\n const childProps = {\n ...props,\n children: node[key],\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Object, key } as KeyPath,\n ],\n };\n result[key] = deepTransformNode(node[key], childProps);\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 = Locales,\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"],"mappings":"AAAA,OAAO,mBAAmB;AAE1B,SAAS,sBAAsB;AAC/B,SAAS,yBAAyB;AAOlC,SAAkB,gBAAkC;AAKpD,MAAM,sBAAsB,CAAC,SAAuB;AAClD,MAAI,OAAO,SAAS,YAAY,SAAS,MAAM;AAC7C,WAAO;AAAA,EACT;AAEA,MAAI,MAAM,aAAa,SAAS,aAAa;AAC3C,WAAO;AAAA,EACT;AAEA,MAAI,MAAM,QAAQ,IAAI,GAAG;AACvB,WAAO,KAAK,KAAK,mBAAmB;AAAA,EACtC;AAEA,SAAO,OAAO,OAAO,IAAI,EAAE,KAAK,mBAAmB;AACrD;AAGO,MAAM,+BAA+B,CAC1C,QACA,cACa;AAAA,EACb,IAAI;AAAA,EACJ,WAAW,CAAC,SAAsB;AAEhC,WAAO,OAAO,SAAS,YAAY,SAAS;AAAA,EAC9C;AAAA,EACA,WAAW,CAAC,MAAmB,OAAOA,uBAAsB;AAC1D,QAAI,OAAO,SAAS,YAAY,MAAM,aAAa,SAAS,aAAa;AACvE,YAAM,SAAS;AAAA,QACZ,KAA4B,SAAS,WAAW;AAAA,MACnD;AAEA,iBAAW,OAAO,QAAQ;AACxB,cAAM,aAAa;AAAA,UACjB,GAAG;AAAA,UACH,UAAU,OAAO,GAAqC;AAAA,UACtD,SAAS;AAAA,YACP,GAAG,MAAM;AAAA,YACT,EAAE,MAAM,SAAS,aAAa,IAAI;AAAA,UACpC;AAAA,QACF;AACA,eAAO,GAAqC,IAAIA;AAAA,UAC9C,OAAO,GAAqC;AAAA,UAC5C;AAAA,YACE,GAAG;AAAA,YACH,SAAS;AAAA,cACP,IAAI,MAAM,WAAY,CAAC,GAAiB;AAAA,gBACtC,CAAC,WAAW,OAAO,OAAO;AAAA,cAC5B;AAAA,YACF;AAAA,UACF;AAAA,QACF;AAAA,MACF;AACA,aAAO,eAAe,QAAQ,QAAQ,QAAQ;AAAA,IAChD,WACE,OAAO,SAAS,YAChB,SAAS,QACT,CAAC,MAAM,QAAQ,IAAI,KACnB,CAAC,MAAM,UACP;AAEA,YAAM,SAA8B,CAAC;AACrC,iBAAW,OAAO,MAAa;AAC7B,YAAI,oBAAoB,KAAK,GAAG,CAAC,GAAG;AAClC,gBAAM,aAAa;AAAA,YACjB,GAAG;AAAA,YACH,UAAU,KAAK,GAAG;AAAA,YAClB,SAAS;AAAA,cACP,GAAG,MAAM;AAAA,cACT,EAAE,MAAM,SAAS,QAAQ,IAAI;AAAA,YAC/B;AAAA,UACF;AACA,iBAAO,GAAG,IAAIA,mBAAkB,KAAK,GAAG,GAAG,UAAU;AAAA,QACvD;AAAA,MACF;AACA,aAAO;AAAA,IACT,WAAW,MAAM,QAAQ,IAAI,GAAG;AAE9B,aAAO,KAAK,IAAI,CAAC,OAAO,UAAU;AAChC,cAAM,aAAa;AAAA,UACjB,GAAG;AAAA,UACH,UAAU;AAAA,UACV,SAAS;AAAA,YACP,GAAG,MAAM;AAAA,YACT,EAAE,MAAM,SAAS,OAAO,KAAK,MAAM;AAAA,UACrC;AAAA,QACF;AACA,eAAOA,mBAAkB,OAAO,UAAU;AAAA,MAC5C,CAAC;AAAA,IACH;AAEA,WAAO;AAAA,EACT;AACF;AAQO,MAAM,mCAAmC,CAI9C,MACA,SAAY,eAAe,qBAAqB,eAChD,WACA,aACG;AACH,QAAM,UAAqB;AAAA,IACzB,6BAA6B,QAAQ,QAAQ;AAAA,IAC7C,GAAI,UAAU,WAAW,CAAC;AAAA,EAC5B;AAEA,SAAO,kBAAkB,MAAM;AAAA,IAC7B,GAAG;AAAA,IACH;AAAA,EACF,CAAC;AACH;","names":["deepTransformNode"]}
@@ -0,0 +1,40 @@
1
+ import {
2
+ deepTransformNode
3
+ } from "../interpreter/index.mjs";
4
+ import { NodeType } from "../types/index.mjs";
5
+ const filterTranlationsPlugin = (locales) => ({
6
+ id: "filter-translations-plugin",
7
+ canHandle: (node) => typeof node === "object" && node?.nodeType === NodeType.Translation,
8
+ transform: (node, props, deepTransformNode2) => {
9
+ const translationMap = node.translation;
10
+ const filteredTranslationMap = Object.fromEntries(
11
+ Object.entries(translationMap).filter(
12
+ ([key]) => locales.includes(key)
13
+ )
14
+ );
15
+ return {
16
+ ...node,
17
+ translation: deepTransformNode2(filteredTranslationMap, {
18
+ ...props,
19
+ keyPath: [
20
+ ...props.keyPath,
21
+ { type: NodeType.Object, key: NodeType.Translation }
22
+ ]
23
+ })
24
+ };
25
+ }
26
+ });
27
+ const getFilteredLocalesContent = (node, locale, nodeProps) => {
28
+ const plugins = [
29
+ filterTranlationsPlugin(locale),
30
+ ...nodeProps.plugins ?? []
31
+ ];
32
+ return deepTransformNode(node, {
33
+ ...nodeProps,
34
+ plugins
35
+ });
36
+ };
37
+ export {
38
+ getFilteredLocalesContent
39
+ };
40
+ //# sourceMappingURL=getFilteredLocalesContent.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/deepTranformPlugins/getFilteredLocalesContent.ts"],"sourcesContent":["import type { Locales, LocalesValues } from '@intlayer/config/client';\nimport {\n type NodeProps,\n type Plugins,\n deepTransformNode,\n} from '../interpreter';\nimport { type ContentNode, NodeType } from '../types';\n\nconst filterTranlationsPlugin = (\n locales: LocalesValues[] | LocalesValues\n): 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<Locales, string>;\n\n const filteredTranslationMap = Object.fromEntries(\n Object.entries(translationMap).filter(([key]) =>\n locales.includes(key as Locales)\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 locale: LocalesValues | LocalesValues[],\n nodeProps: NodeProps\n) => {\n const plugins: Plugins[] = [\n filterTranlationsPlugin(locale),\n ...(nodeProps.plugins ?? []),\n ];\n\n return deepTransformNode(node, {\n ...nodeProps,\n plugins,\n });\n};\n"],"mappings":"AACA;AAAA,EAGE;AAAA,OACK;AACP,SAA2B,gBAAgB;AAE3C,MAAM,0BAA0B,CAC9B,aACa;AAAA,EACb,IAAI;AAAA,EACJ,WAAW,CAAC,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,SAAS;AAAA,EAC1D,WAAW,CAAC,MAAM,OAAOA,uBAAsB;AAC7C,UAAM,iBAAiB,KAAK;AAE5B,UAAM,yBAAyB,OAAO;AAAA,MACpC,OAAO,QAAQ,cAAc,EAAE;AAAA,QAAO,CAAC,CAAC,GAAG,MACzC,QAAQ,SAAS,GAAc;AAAA,MACjC;AAAA,IACF;AAEA,WAAO;AAAA,MACL,GAAG;AAAA,MACH,aAAaA,mBAAkB,wBAAwB;AAAA,QACrD,GAAG;AAAA,QACH,SAAS;AAAA,UACP,GAAG,MAAM;AAAA,UACT,EAAE,MAAM,SAAS,QAAQ,KAAK,SAAS,YAAY;AAAA,QACrD;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF;AAEO,MAAM,4BAA4B,CACvC,MACA,QACA,cACG;AACH,QAAM,UAAqB;AAAA,IACzB,wBAAwB,MAAM;AAAA,IAC9B,GAAI,UAAU,WAAW,CAAC;AAAA,EAC5B;AAEA,SAAO,kBAAkB,MAAM;AAAA,IAC7B,GAAG;AAAA,IACH;AAAA,EACF,CAAC;AACH;","names":["deepTransformNode"]}
@@ -1,9 +1,9 @@
1
1
  import configuration from "@intlayer/config/built";
2
- import { deepTransformNode } from "./deepTransform.mjs";
2
+ import { deepTransformNode } from "../interpreter/getContent/deepTransform.mjs";
3
3
  import {
4
4
  translationPlugin
5
- } from "./plugins.mjs";
6
- const getLocalisedContent = (node, locale = configuration?.internationalization.defaultLocale, nodeProps, fallback = false) => {
5
+ } from "../interpreter/getContent/plugins.mjs";
6
+ const getLocalisedContent = (node, locale = configuration?.internationalization.defaultLocale, nodeProps, fallback) => {
7
7
  const plugins = [
8
8
  translationPlugin(locale, fallback),
9
9
  ...nodeProps.plugins ?? []
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/deepTranformPlugins/getLocalisedContent.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { Locales, LocalesValues } from '@intlayer/config/client';\nimport { deepTransformNode } from '../interpreter/getContent/deepTransform';\nimport {\n translationPlugin,\n type DeepTransformContent,\n type NodeProps,\n type Plugins,\n} from '../interpreter/getContent/plugins';\nimport type { ContentNode } from '../types';\n\n/**\n * Transforms a node in a single pass, applying each plugin as needed.\n * In comparison to `getContent`, this function will only apply the translation plugin.\n * It will not transform enumerations, insertions, or other content types.\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 getLocalisedContent = <\n T extends ContentNode,\n L extends LocalesValues = Locales,\n>(\n node: T,\n locale: L = configuration?.internationalization.defaultLocale as L,\n nodeProps: NodeProps,\n fallback?: LocalesValues // fallback mean that if field is not translated, it will use the default locale\n) => {\n const plugins: Plugins[] = [\n translationPlugin(locale, fallback),\n ...(nodeProps.plugins ?? []),\n ];\n\n return deepTransformNode(node, {\n ...nodeProps,\n plugins,\n }) as DeepTransformContent<T>;\n};\n"],"mappings":"AAAA,OAAO,mBAAmB;AAE1B,SAAS,yBAAyB;AAClC;AAAA,EACE;AAAA,OAIK;AAWA,MAAM,sBAAsB,CAIjC,MACA,SAAY,eAAe,qBAAqB,eAChD,WACA,aACG;AACH,QAAM,UAAqB;AAAA,IACzB,kBAAkB,QAAQ,QAAQ;AAAA,IAClC,GAAI,UAAU,WAAW,CAAC;AAAA,EAC5B;AAEA,SAAO,kBAAkB,MAAM;AAAA,IAC7B,GAAG;AAAA,IACH;AAAA,EACF,CAAC;AACH;","names":[]}
@@ -0,0 +1,43 @@
1
+ import configuration from "@intlayer/config/built";
2
+ import { deepTransformNode } from "../interpreter/getContent/deepTransform.mjs";
3
+ import { NodeType } from "../types/index.mjs";
4
+ const checkMissingLocalesPlugin = (locales, onMissingLocale) => ({
5
+ id: "check-missing-locales-plugin",
6
+ canHandle: (node) => typeof node === "object" && node?.nodeType === NodeType.Translation,
7
+ transform: (node, props, deepTransformNode2) => {
8
+ for (const locale of locales) {
9
+ if (!node[NodeType.Translation][locale]) {
10
+ onMissingLocale(locale);
11
+ }
12
+ }
13
+ const translations = node[NodeType.Translation];
14
+ for (const key in translations) {
15
+ const child = translations[key];
16
+ deepTransformNode2(child, {
17
+ ...props,
18
+ children: child
19
+ });
20
+ }
21
+ return node;
22
+ }
23
+ });
24
+ const getMissingLocalesContent = (node, locales = configuration?.internationalization.locales, nodeProps) => {
25
+ const missingLocales = /* @__PURE__ */ new Set();
26
+ const plugins = [
27
+ checkMissingLocalesPlugin(
28
+ locales,
29
+ (locale) => missingLocales.add(locale)
30
+ ),
31
+ ...nodeProps.plugins ?? []
32
+ ];
33
+ deepTransformNode(node, {
34
+ ...nodeProps,
35
+ plugins
36
+ });
37
+ return Array.from(missingLocales);
38
+ };
39
+ export {
40
+ checkMissingLocalesPlugin,
41
+ getMissingLocalesContent
42
+ };
43
+ //# sourceMappingURL=getMissingLocalesContent.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/deepTranformPlugins/getMissingLocalesContent.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { Locales, LocalesValues } from '@intlayer/config/client';\nimport { deepTransformNode } from '../interpreter/getContent/deepTransform';\nimport {\n type DeepTransformContent,\n type NodeProps,\n type Plugins,\n} from '../interpreter/getContent/plugins';\nimport { TranslationContent } from '../transpiler';\nimport { NodeType, type ContentNode } from '../types';\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const checkMissingLocalesPlugin = (\n locales: Locales[],\n onMissingLocale: (locale: Locales) => 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): Locales[] => {\n const missingLocales = new Set<Locales>();\n\n const plugins: Plugins[] = [\n checkMissingLocalesPlugin(locales as Locales[], (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"],"mappings":"AAAA,OAAO,mBAAmB;AAE1B,SAAS,yBAAyB;AAOlC,SAAS,gBAAkC;AAGpC,MAAM,4BAA4B,CACvC,SACA,qBACa;AAAA,EACb,IAAI;AAAA,EACJ,WAAW,CAAC,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,SAAS;AAAA,EAC1D,WAAW,CAAC,MAA0B,OAAOA,uBAAsB;AACjE,eAAW,UAAU,SAAS;AAC5B,UACE,CAAC,KAAK,SAAS,WAAW,EACxB,MACF,GACA;AACA,wBAAgB,MAAM;AAAA,MACxB;AAAA,IACF;AAGA,UAAM,eAAe,KAAK,SAAS,WAAW;AAC9C,eAAW,OAAO,cAAc;AAC9B,YAAM,QAAQ,aAAa,GAAG;AAC9B,MAAAA,mBAAkB,OAAO;AAAA,QACvB,GAAG;AAAA,QACH,UAAU;AAAA,MACZ,CAAC;AAAA,IACH;AAGA,WAAO;AAAA,EACT;AACF;AAQO,MAAM,2BAA2B,CACtC,MACA,UAA2B,eAAe,qBAAqB,SAC/D,cACc;AACd,QAAM,iBAAiB,oBAAI,IAAa;AAExC,QAAM,UAAqB;AAAA,IACzB;AAAA,MAA0B;AAAA,MAAsB,CAAC,WAC/C,eAAe,IAAI,MAAM;AAAA,IAC3B;AAAA,IACA,GAAI,UAAU,WAAW,CAAC;AAAA,EAC5B;AAEA,oBAAkB,MAAM;AAAA,IACtB,GAAG;AAAA,IACH;AAAA,EACF,CAAC;AAED,SAAO,MAAM,KAAK,cAAc;AAClC;","names":["deepTransformNode"]}