@intlayer/core 5.4.2 → 5.5.0-canary.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. package/dist/cjs/interpreter/getContent/getLocalisedContent.cjs +51 -0
  2. package/dist/cjs/interpreter/getContent/getLocalisedContent.cjs.map +1 -0
  3. package/dist/cjs/interpreter/getContent/index.cjs +5 -3
  4. package/dist/cjs/interpreter/getContent/index.cjs.map +1 -1
  5. package/dist/cjs/interpreter/getContent/plugins.cjs +3 -3
  6. package/dist/cjs/interpreter/getContent/plugins.cjs.map +1 -1
  7. package/dist/cjs/interpreter/getTranslation.cjs +5 -2
  8. package/dist/cjs/interpreter/getTranslation.cjs.map +1 -1
  9. package/dist/cjs/types/dictionary.cjs.map +1 -1
  10. package/dist/esm/interpreter/getContent/getLocalisedContent.mjs +19 -0
  11. package/dist/esm/interpreter/getContent/getLocalisedContent.mjs.map +1 -0
  12. package/dist/esm/interpreter/getContent/index.mjs +2 -1
  13. package/dist/esm/interpreter/getContent/index.mjs.map +1 -1
  14. package/dist/esm/interpreter/getContent/plugins.mjs +3 -3
  15. package/dist/esm/interpreter/getContent/plugins.mjs.map +1 -1
  16. package/dist/esm/interpreter/getTranslation.mjs +5 -2
  17. package/dist/esm/interpreter/getTranslation.mjs.map +1 -1
  18. package/dist/types/interpreter/getContent/getLocalisedContent.d.ts +13 -0
  19. package/dist/types/interpreter/getContent/getLocalisedContent.d.ts.map +1 -0
  20. package/dist/types/interpreter/getContent/index.d.ts +2 -1
  21. package/dist/types/interpreter/getContent/index.d.ts.map +1 -1
  22. package/dist/types/interpreter/getContent/plugins.d.ts +1 -1
  23. package/dist/types/interpreter/getContent/plugins.d.ts.map +1 -1
  24. package/dist/types/interpreter/getTranslation.d.ts +1 -1
  25. package/dist/types/interpreter/getTranslation.d.ts.map +1 -1
  26. package/dist/types/types/dictionary.d.ts +6 -1
  27. package/dist/types/types/dictionary.d.ts.map +1 -1
  28. package/package.json +8 -8
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
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
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var getLocalisedContent_exports = {};
30
+ __export(getLocalisedContent_exports, {
31
+ getLocalisedContent: () => getLocalisedContent
32
+ });
33
+ module.exports = __toCommonJS(getLocalisedContent_exports);
34
+ var import_built = __toESM(require("@intlayer/config/built"));
35
+ var import_deepTransform = require('./deepTransform.cjs');
36
+ var import_plugins = require('./plugins.cjs');
37
+ const getLocalisedContent = (node, locale = import_built.default.internationalization.defaultLocale, nodeProps, fallback = false) => {
38
+ const plugins = [
39
+ (0, import_plugins.translationPlugin)(locale, fallback),
40
+ ...nodeProps.plugins ?? []
41
+ ];
42
+ return (0, import_deepTransform.deepTransformNode)(node, {
43
+ ...nodeProps,
44
+ plugins
45
+ });
46
+ };
47
+ // Annotate the CommonJS export names for ESM import in node:
48
+ 0 && (module.exports = {
49
+ getLocalisedContent
50
+ });
51
+ //# sourceMappingURL=getLocalisedContent.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/interpreter/getContent/getLocalisedContent.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { Locales, LocalesValues } from '@intlayer/config/client';\nimport type { ContentNode } from '../../types';\nimport { deepTransformNode } from './deepTransform';\nimport {\n translationPlugin,\n type DeepTransformContent,\n type NodeProps,\n type Plugins,\n} from './plugins';\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: boolean = false\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;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA0B;AAG1B,2BAAkC;AAClC,qBAKO;AAUA,MAAM,sBAAsB,CAIjC,MACA,SAAY,aAAAA,QAAc,qBAAqB,eAC/C,WACA,WAAoB,UACjB;AACH,QAAM,UAAqB;AAAA,QACzB,kCAAkB,QAAQ,QAAQ;AAAA,IAClC,GAAI,UAAU,WAAW,CAAC;AAAA,EAC5B;AAEA,aAAO,wCAAkB,MAAM;AAAA,IAC7B,GAAG;AAAA,IACH;AAAA,EACF,CAAC;AACH;","names":["configuration"]}
@@ -16,12 +16,14 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
16
16
  var getContent_exports = {};
17
17
  module.exports = __toCommonJS(getContent_exports);
18
18
  __reExport(getContent_exports, require('./deepTransform.cjs'), module.exports);
19
- __reExport(getContent_exports, require('./plugins.cjs'), module.exports);
20
19
  __reExport(getContent_exports, require('./getContent.cjs'), module.exports);
20
+ __reExport(getContent_exports, require('./getLocalisedContent.cjs'), module.exports);
21
+ __reExport(getContent_exports, require('./plugins.cjs'), module.exports);
21
22
  // Annotate the CommonJS export names for ESM import in node:
22
23
  0 && (module.exports = {
23
24
  ...require('./deepTransform.cjs'),
24
- ...require('./plugins.cjs'),
25
- ...require('./getContent.cjs')
25
+ ...require('./getContent.cjs'),
26
+ ...require('./getLocalisedContent.cjs'),
27
+ ...require('./plugins.cjs')
26
28
  });
27
29
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/interpreter/getContent/index.ts"],"sourcesContent":["export * from './deepTransform';\nexport * from './plugins';\nexport * from './getContent';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,+BAAc,4BAAd;AACA,+BAAc,sBADd;AAEA,+BAAc,yBAFd;","names":[]}
1
+ {"version":3,"sources":["../../../../src/interpreter/getContent/index.ts"],"sourcesContent":["export * from './deepTransform';\nexport * from './getContent';\nexport * from './getLocalisedContent';\nexport * from './plugins';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,+BAAc,4BAAd;AACA,+BAAc,yBADd;AAEA,+BAAc,kCAFd;AAGA,+BAAc,sBAHd;","names":[]}
@@ -29,10 +29,10 @@ module.exports = __toCommonJS(plugins_exports);
29
29
  var import_types = require('../../types/index.cjs');
30
30
  var import_getCondition = require('../getCondition.cjs');
31
31
  var import_getEnumeration = require('../getEnumeration.cjs');
32
+ var import_getInsertion = require('../getInsertion.cjs');
32
33
  var import_getNesting = require('../getNesting.cjs');
33
34
  var import_getTranslation = require('../getTranslation.cjs');
34
- var import_getInsertion = require('../getInsertion.cjs');
35
- const translationPlugin = (locale) => ({
35
+ const translationPlugin = (locale, fallback = true) => ({
36
36
  id: "translation-plugin",
37
37
  canHandle: (node) => typeof node === "object" && node?.nodeType === import_types.NodeType.Translation,
38
38
  transform: (node, props, deepTransformNode) => {
@@ -51,7 +51,7 @@ const translationPlugin = (locale) => ({
51
51
  childProps
52
52
  );
53
53
  }
54
- return (0, import_getTranslation.getTranslation)(result, locale);
54
+ return (0, import_getTranslation.getTranslation)(result, locale, fallback);
55
55
  }
56
56
  });
57
57
  const enumerationPlugin = {
@@ -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 NestedContent,\n TranslationContent,\n InsertionContent,\n FileContent,\n} from '../../transpiler';\nimport { type DictionaryKeys, type KeyPath, NodeType } from '../../types/index';\nimport { getCondition } from '../getCondition';\nimport { getEnumeration } from '../getEnumeration';\nimport { type GetNestingResult, getNesting } from '../getNesting';\nimport { getTranslation } from '../getTranslation';\nimport { getInsertion } from '../getInsertion';\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 = (locale: LocalesValues): 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);\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 * 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;AASA,mBAA4D;AAC5D,0BAA6B;AAC7B,4BAA+B;AAC/B,wBAAkD;AAClD,4BAA+B;AAC/B,0BAA6B;AAsCtB,MAAM,oBAAoB,CAAC,YAAoC;AAAA,EACpE,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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;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
+ {"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 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 { 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 * 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;AASA,mBAA4D;AAC5D,0BAA6B;AAC7B,4BAA+B;AAC/B,0BAA6B;AAC7B,wBAAkD;AAClD,4BAA+B;AAsCxB,MAAM,oBAAoB,CAC/B,QACA,WAAoB,UACP;AAAA,EACb,IAAI;AAAA,EACJ,WAAW,CAAC,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,sBAAS;AAAA,EAC1D,WAAW,CAAC,MAA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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"]}
@@ -32,9 +32,12 @@ __export(getTranslation_exports, {
32
32
  });
33
33
  module.exports = __toCommonJS(getTranslation_exports);
34
34
  var import_built = __toESM(require("@intlayer/config/built"));
35
- const getTranslation = (languageContent, locale) => {
35
+ const getTranslation = (languageContent, locale, fallback = true) => {
36
36
  const { defaultLocale } = import_built.default?.internationalization;
37
- const result = languageContent[locale ?? defaultLocale] ?? languageContent[defaultLocale];
37
+ let result = languageContent[locale ?? defaultLocale];
38
+ if (fallback && !result) {
39
+ result = languageContent[defaultLocale];
40
+ }
38
41
  return result;
39
42
  };
40
43
  // Annotate the CommonJS export names for ESM import in node:
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/interpreter/getTranslation.ts"],"sourcesContent":["import type { LocalesValues } from '@intlayer/config/client';\nimport configuration from '@intlayer/config/built';\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): Content => {\n const { defaultLocale } = configuration?.internationalization;\n\n const result =\n languageContent[\n (locale ?? defaultLocale) as unknown as keyof typeof languageContent\n ] ??\n (languageContent[\n defaultLocale as unknown as keyof typeof languageContent\n ] as Content);\n\n return result;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAA0B;AAwBnB,MAAM,iBAAiB,CAC5B,iBACA,WACY;AACZ,QAAM,EAAE,cAAc,IAAI,aAAAA,SAAe;AAEzC,QAAM,SACJ,gBACG,UAAU,aACb,KACC,gBACC,aACF;AAEF,SAAO;AACT;","names":["configuration"]}
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 +1 @@
1
- {"version":3,"sources":["../../../src/types/dictionary.ts"],"sourcesContent":["// @ts-ignore intlayer declared for module augmentation\nimport type { IntlayerDictionaryTypesConnector } from 'intlayer';\nimport type { ConditionContent } from '../transpiler/condition';\nimport type { EnumerationContent } from '../transpiler/enumeration';\nimport type { FileContent } from '../transpiler/file';\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 | 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 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 content: ContentType extends undefined // Applying the generic to replace ContentValue with Replacement\n ? any\n : ReplaceContentValue<ContentType, FetchableNode> | ContentType;\n};\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
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 { 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 | 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 | 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"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -0,0 +1,19 @@
1
+ import configuration from "@intlayer/config/built";
2
+ import { deepTransformNode } from "./deepTransform.mjs";
3
+ import {
4
+ translationPlugin
5
+ } from "./plugins.mjs";
6
+ const getLocalisedContent = (node, locale = configuration.internationalization.defaultLocale, nodeProps, fallback = false) => {
7
+ const plugins = [
8
+ translationPlugin(locale, fallback),
9
+ ...nodeProps.plugins ?? []
10
+ ];
11
+ return deepTransformNode(node, {
12
+ ...nodeProps,
13
+ plugins
14
+ });
15
+ };
16
+ export {
17
+ getLocalisedContent
18
+ };
19
+ //# sourceMappingURL=getLocalisedContent.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/interpreter/getContent/getLocalisedContent.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { Locales, LocalesValues } from '@intlayer/config/client';\nimport type { ContentNode } from '../../types';\nimport { deepTransformNode } from './deepTransform';\nimport {\n translationPlugin,\n type DeepTransformContent,\n type NodeProps,\n type Plugins,\n} from './plugins';\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: boolean = false\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;AAG1B,SAAS,yBAAyB;AAClC;AAAA,EACE;AAAA,OAIK;AAUA,MAAM,sBAAsB,CAIjC,MACA,SAAY,cAAc,qBAAqB,eAC/C,WACA,WAAoB,UACjB;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":[]}
@@ -1,4 +1,5 @@
1
1
  export * from "./deepTransform.mjs";
2
- export * from "./plugins.mjs";
3
2
  export * from "./getContent.mjs";
3
+ export * from "./getLocalisedContent.mjs";
4
+ export * from "./plugins.mjs";
4
5
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/interpreter/getContent/index.ts"],"sourcesContent":["export * from './deepTransform';\nexport * from './plugins';\nexport * from './getContent';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
1
+ {"version":3,"sources":["../../../../src/interpreter/getContent/index.ts"],"sourcesContent":["export * from './deepTransform';\nexport * from './getContent';\nexport * from './getLocalisedContent';\nexport * from './plugins';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
@@ -1,10 +1,10 @@
1
1
  import { NodeType } from "../../types/index.mjs";
2
2
  import { getCondition } from "../getCondition.mjs";
3
3
  import { getEnumeration } from "../getEnumeration.mjs";
4
+ import { getInsertion } from "../getInsertion.mjs";
4
5
  import { getNesting } from "../getNesting.mjs";
5
6
  import { getTranslation } from "../getTranslation.mjs";
6
- import { getInsertion } from "../getInsertion.mjs";
7
- const translationPlugin = (locale) => ({
7
+ const translationPlugin = (locale, fallback = true) => ({
8
8
  id: "translation-plugin",
9
9
  canHandle: (node) => typeof node === "object" && node?.nodeType === NodeType.Translation,
10
10
  transform: (node, props, deepTransformNode) => {
@@ -23,7 +23,7 @@ const translationPlugin = (locale) => ({
23
23
  childProps
24
24
  );
25
25
  }
26
- return getTranslation(result, locale);
26
+ return getTranslation(result, locale, fallback);
27
27
  }
28
28
  });
29
29
  const enumerationPlugin = {
@@ -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 NestedContent,\n TranslationContent,\n InsertionContent,\n FileContent,\n} from '../../transpiler';\nimport { type DictionaryKeys, type KeyPath, NodeType } from '../../types/index';\nimport { getCondition } from '../getCondition';\nimport { getEnumeration } from '../getEnumeration';\nimport { type GetNestingResult, getNesting } from '../getNesting';\nimport { getTranslation } from '../getTranslation';\nimport { getInsertion } from '../getInsertion';\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 = (locale: LocalesValues): 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);\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 * 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":"AASA,SAA4C,gBAAgB;AAC5D,SAAS,oBAAoB;AAC7B,SAAS,sBAAsB;AAC/B,SAAgC,kBAAkB;AAClD,SAAS,sBAAsB;AAC/B,SAAS,oBAAoB;AAsCtB,MAAM,oBAAoB,CAAC,YAAoC;AAA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U;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,SAAS;AAAA,EAC1D,WAAW,CAAC,MAAqB,UAC/B,WAAW,KAAK,OAAO,eAAe,KAAK,OAAO,MAAM,KAAK;AACjE;AAeO,MAAM,aAAsB;AAAA,EACjC,IAAI;AAAA,EACJ,WAAW,CAAC,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,SAAS;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
+ {"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 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 { 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 * 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":"AASA,SAA4C,gBAAgB;AAC5D,SAAS,oBAAoB;AAC7B,SAAS,sBAAsB;AAC/B,SAAS,oBAAoB;AAC7B,SAAgC,kBAAkB;AAClD,SAAS,sBAAsB;AAsCxB,MAAM,oBAAoB,CAC/B,QACA,WAAoB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AAO,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,SAAS;AAAA,EAC1D,WAAW,CAAC,MAAqB,UAC/B,WAAW,KAAK,OAAO,eAAe,KAAK,OAAO,MAAM,KAAK;AACjE;AAeO,MAAM,aAAsB;AAAA,EACjC,IAAI;AAAA,EACJ,WAAW,CAAC,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,SAAS;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,7 +1,10 @@
1
1
  import configuration from "@intlayer/config/built";
2
- const getTranslation = (languageContent, locale) => {
2
+ const getTranslation = (languageContent, locale, fallback = true) => {
3
3
  const { defaultLocale } = configuration?.internationalization;
4
- const result = languageContent[locale ?? defaultLocale] ?? languageContent[defaultLocale];
4
+ let result = languageContent[locale ?? defaultLocale];
5
+ if (fallback && !result) {
6
+ result = languageContent[defaultLocale];
7
+ }
5
8
  return result;
6
9
  };
7
10
  export {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/interpreter/getTranslation.ts"],"sourcesContent":["import type { LocalesValues } from '@intlayer/config/client';\nimport configuration from '@intlayer/config/built';\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): Content => {\n const { defaultLocale } = configuration?.internationalization;\n\n const result =\n languageContent[\n (locale ?? defaultLocale) as unknown as keyof typeof languageContent\n ] ??\n (languageContent[\n defaultLocale as unknown as keyof typeof languageContent\n ] as Content);\n\n return result;\n};\n"],"mappings":"AACA,OAAO,mBAAmB;AAwBnB,MAAM,iBAAiB,CAC5B,iBACA,WACY;AACZ,QAAM,EAAE,cAAc,IAAI,eAAe;AAEzC,QAAM,SACJ,gBACG,UAAU,aACb,KACC,gBACC,aACF;AAEF,SAAO;AACT;","names":[]}
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,OAAO,mBAAmB;AAyBnB,MAAM,iBAAiB,CAC5B,iBACA,QACA,WAAoB,SACR;AACZ,QAAM,EAAE,cAAc,IAAI,eAAe;AAEzC,MAAI,SACF,gBACG,UAAU,aACb;AAEF,MAAI,YAAY,CAAC,QAAQ;AACvB,aACE,gBAAgB,aAAwD;AAAA,EAC5E;AAEA,SAAO;AACT;","names":[]}
@@ -0,0 +1,13 @@
1
+ import type { Locales, LocalesValues } from '@intlayer/config/client';
2
+ import type { ContentNode } from '../../types';
3
+ import { type DeepTransformContent, type NodeProps } from './plugins';
4
+ /**
5
+ * Transforms a node in a single pass, applying each plugin as needed.
6
+ * In comparison to `getContent`, this function will only apply the translation plugin.
7
+ * It will not transform enumerations, insertions, or other content types.
8
+ *
9
+ * @param node The node to transform.
10
+ * @param locale The locale to use if your transformers need it (e.g. for translations).
11
+ */
12
+ export declare const getLocalisedContent: <T extends ContentNode, L extends LocalesValues = Locales>(node: T, locale: L, nodeProps: NodeProps, fallback?: boolean) => DeepTransformContent<T>;
13
+ //# sourceMappingURL=getLocalisedContent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getLocalisedContent.d.ts","sourceRoot":"","sources":["../../../../src/interpreter/getContent/getLocalisedContent.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACtE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,OAAO,EAEL,KAAK,oBAAoB,EACzB,KAAK,SAAS,EAEf,MAAM,WAAW,CAAC;AAEnB;;;;;;;GAOG;AACH,eAAO,MAAM,mBAAmB,GAC9B,CAAC,SAAS,WAAW,EACrB,CAAC,SAAS,aAAa,GAAG,OAAO,EAEjC,MAAM,CAAC,EACP,QAAQ,CAAyD,EACjE,WAAW,SAAS,EACpB,WAAU,OAAe,KAUnB,oBAAoB,CAAC,CAAC,CAC7B,CAAC"}
@@ -1,4 +1,5 @@
1
1
  export * from './deepTransform';
2
- export * from './plugins';
3
2
  export * from './getContent';
3
+ export * from './getLocalisedContent';
4
+ export * from './plugins';
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/interpreter/getContent/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/interpreter/getContent/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,uBAAuB,CAAC;AACtC,cAAc,WAAW,CAAC"}
@@ -24,7 +24,7 @@ export type TranslationCond<T, S> = T extends {
24
24
  [NodeType.Translation]: object;
25
25
  } ? DeepTransformContent<T[NodeType.Translation][keyof T[NodeType.Translation]], S> : never;
26
26
  /** Translation plugin. Replaces node with a locale string if nodeType = Translation. */
27
- export declare const translationPlugin: (locale: LocalesValues) => Plugins;
27
+ export declare const translationPlugin: (locale: LocalesValues, fallback?: boolean) => Plugins;
28
28
  /** ---------------------------------------------
29
29
  * ENUMERATION PLUGIN
30
30
  * --------------------------------------------- */
@@ -1 +1 @@
1
- {"version":3,"file":"plugins.d.ts","sourceRoot":"","sources":["../../../../src/interpreter/getContent/plugins.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAStE,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAGhF,OAAO,EAAE,KAAK,gBAAgB,EAAc,MAAM,eAAe,CAAC;AAIlE;;oDAEoD;AAEpD;;;;;;GAMG;AACH,MAAM,MAAM,OAAO,GAAG;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC;IAClC,SAAS,EAAE,CACT,IAAI,EAAE,GAAG,EACT,K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S,EAAE,IAAI,CAAC;IAChB,MAAM,EAAE,IAAI,CAAC;CAEd,CAAC;AAEF;;GAEG;AACH,KAAK,gBAAgB,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,kBAAkB,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,IAElE,CAAC,SAAS,MAAM,CAAC,GAEb,CAAC,CAAC,CAAC,CAAC,SAAS,IAAI,GAEf,kBAAkB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,KAAK,GACvC,KAAK,GAEL,kBAAkB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,GAC7B,KAAK,GACP,KAAK,CAAC;AAEZ;;GAEG;AACH,KAAK,QAAQ,CAAC,CAAC,EAAE,CAAC,IAEhB,CAAC,SAAS,aAAa,CAAC,MAAM,CAAC,CAAC,GAC5B,KAAK,CAAC,oBAAoB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GACjC,CAAC,SAAS,MAAM,GACd;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;CAAE,GACjD,CAAC,CAAC;AAEV;;GAEG;AACH,MAAM,MAAM,oBAAoB,CAAC,CAAC,EAAE,CAAC,GAAG,uBAAuB,IAE7D,gBAAgB,CAAC,CAAC,EAAE,MAAM,kBAAkB,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,SAAS,KAAK,GAEhE,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,GAEd,kBAAkB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,kBAAkB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC"}
@@ -21,5 +21,5 @@ import { LanguageContent } from '../types';
21
21
  * - this function will require each locale to be defined if defined in the project configuration.
22
22
  * - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.
23
23
  */
24
- export declare const getTranslation: <Content = string>(languageContent: LanguageContent<Content>, locale?: LocalesValues) => Content;
24
+ export declare const getTranslation: <Content = string>(languageContent: LanguageContent<Content>, locale?: LocalesValues, fallback?: boolean) => Content;
25
25
  //# sourceMappingURL=getTranslation.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getTranslation.d.ts","sourceRoot":"","sources":["../../../src/interpreter/getTranslation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAE7D,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAE3C;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,cAAc,GAAI,OAAO,GAAG,MAAM,EAC7C,iBAAiB,eAAe,CAAC,OAAO,CAAC,EACzC,SAAS,aAAa,KACrB,OAYF,CAAC"}
1
+ {"version":3,"file":"getTranslation.d.ts","sourceRoot":"","sources":["../../../src/interpreter/getTranslation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAE3C;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,cAAc,GAAI,OAAO,GAAG,MAAM,EAC7C,iBAAiB,eAAe,CAAC,OAAO,CAAC,EACzC,SAAS,aAAa,EACtB,WAAU,OAAc,KACvB,OAcF,CAAC"}
@@ -1,4 +1,4 @@
1
- import type { IntlayerDictionaryTypesConnector } from 'intlayer';
1
+ import type { IntlayerDictionaryTypesConnector, LanguageContent, LocalesValues } from 'intlayer';
2
2
  import type { ConditionContent } from '../transpiler/condition';
3
3
  import type { EnumerationContent } from '../transpiler/enumeration';
4
4
  import type { FileContent } from '../transpiler/file';
@@ -35,6 +35,7 @@ type ReplaceContentValueObject<T, FetchableNode> = {
35
35
  [K in keyof T]: ReplaceContentValue<T[K], FetchableNode>;
36
36
  };
37
37
  type ReplaceContentValue<NodeType, FetchableNode = true> = NodeType extends object ? IsArray<NodeType> extends true ? ReplaceContentValueArray<NodeType, FetchableNode> : ContentNode<NodeType, FetchableNode> | ReplaceContentValueObject<NodeType, FetchableNode> : ContentNode<NodeType, FetchableNode>;
38
+ export type AutoFill = true | string | LanguageContent<string>;
38
39
  export type Dictionary<ContentType = undefined, FetchableNode = false> = {
39
40
  $schema?: string;
40
41
  key: string;
@@ -44,6 +45,10 @@ export type Dictionary<ContentType = undefined, FetchableNode = false> = {
44
45
  version?: string;
45
46
  filePath?: string;
46
47
  tags?: string[];
48
+ locale?: LocalesValues;
49
+ autoFill?: AutoFill;
50
+ autoFilled?: true;
51
+ location?: 'distant' | 'locale';
47
52
  content: ContentType extends undefined ? any : ReplaceContentValue<ContentType, FetchableNode> | ContentType;
48
53
  };
49
54
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"dictionary.d.ts","sourceRoot":"","sources":["../../../src/types/dictionary.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,UAAU,CAAC;AACjE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAEpE;;;;GAIG;AACH,MAAM,MAAM,cAAc,CAAC,CAAC,IAAI,CAAC,SAAS,SAAS,GAAG,MAAM,GAAG,CAAC,CAAC;AAEjE;;;;;;;;;;GAUG;AACH,MAAM,MAAM,cAAc,GAAG,cAAc,CACzC,MAAM,g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AAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,UAAU,CAAC,EAAE,IAAI,CAAC;IAClB,QAAQ,CAAC,EAAE,SAAS,GAAG,QAAQ,CAAC;IAChC,OAAO,EAAE,WAAW,SAAS,SAAS,GAClC,GAAG,GACH,mBAAmB,CAAC,WAAW,EAAE,aAAa,CAAC,GAAG,WAAW,CAAC;CACnE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intlayer/core",
3
- "version": "5.4.2",
3
+ "version": "5.5.0-canary.0",
4
4
  "private": false,
5
5
  "description": "Includes core Intlayer functions like translation, dictionary, and utility functions shared across multiple packages.",
6
6
  "keywords": [
@@ -75,9 +75,9 @@
75
75
  ],
76
76
  "dependencies": {
77
77
  "negotiator": "^1.0.0",
78
- "@intlayer/api": "5.4.2",
79
- "@intlayer/config": "5.4.2",
80
- "@intlayer/dictionaries-entry": "5.4.2"
78
+ "@intlayer/api": "5.5.0-canary.0",
79
+ "@intlayer/config": "5.5.0-canary.0",
80
+ "@intlayer/dictionaries-entry": "5.5.0-canary.0"
81
81
  },
82
82
  "devDependencies": {
83
83
  "@types/negotiator": "^0.6.3",
@@ -96,10 +96,10 @@
96
96
  "@utils/tsup-config": "1.0.4"
97
97
  },
98
98
  "peerDependencies": {
99
- "@intlayer/api": "5.4.2",
100
- "@intlayer/dictionaries-entry": "5.4.2",
101
- "intlayer": "5.4.2",
102
- "@intlayer/config": "5.4.2"
99
+ "@intlayer/api": "5.5.0-canary.0",
100
+ "intlayer": "5.5.0-canary.0",
101
+ "@intlayer/dictionaries-entry": "5.5.0-canary.0",
102
+ "@intlayer/config": "5.5.0-canary.0"
103
103
  },
104
104
  "engines": {
105
105
  "node": ">=14.18"