@intlayer/core 5.1.8 → 5.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/interpreter/getContent/getContent.cjs +13 -5
- package/dist/cjs/interpreter/getContent/getContent.cjs.map +1 -1
- package/dist/cjs/interpreter/getContent/plugins.cjs.map +1 -1
- package/dist/cjs/interpreter/getTranslation.cjs +12 -2
- package/dist/cjs/interpreter/getTranslation.cjs.map +1 -1
- package/dist/cjs/localization/getLocalizedUrl.cjs +12 -5
- package/dist/cjs/localization/getLocalizedUrl.cjs.map +1 -1
- package/dist/cjs/localization/getMultilingualUrls.cjs +12 -5
- package/dist/cjs/localization/getMultilingualUrls.cjs.map +1 -1
- package/dist/cjs/localization/getPathWithoutLocale.cjs +12 -4
- package/dist/cjs/localization/getPathWithoutLocale.cjs.map +1 -1
- package/dist/cjs/localization/index.cjs +5 -2
- package/dist/cjs/localization/index.cjs.map +1 -1
- package/dist/cjs/localization/localeDetector.cjs +3 -9
- package/dist/cjs/localization/localeDetector.cjs.map +1 -1
- package/dist/cjs/localization/localeResolver.cjs +63 -0
- package/dist/cjs/localization/localeResolver.cjs.map +1 -0
- package/dist/esm/interpreter/getContent/getContent.mjs +3 -7
- package/dist/esm/interpreter/getContent/getContent.mjs.map +1 -1
- package/dist/esm/interpreter/getContent/plugins.mjs.map +1 -1
- package/dist/esm/interpreter/getTranslation.mjs +2 -2
- package/dist/esm/interpreter/getTranslation.mjs.map +1 -1
- package/dist/esm/localization/getLocalizedUrl.mjs +2 -5
- package/dist/esm/localization/getLocalizedUrl.mjs.map +1 -1
- package/dist/esm/localization/getMultilingualUrls.mjs +2 -5
- package/dist/esm/localization/getMultilingualUrls.mjs.map +1 -1
- package/dist/esm/localization/getPathWithoutLocale.mjs +2 -6
- package/dist/esm/localization/getPathWithoutLocale.mjs.map +1 -1
- package/dist/esm/localization/index.mjs +3 -1
- package/dist/esm/localization/index.mjs.map +1 -1
- package/dist/esm/localization/localeDetector.mjs +3 -9
- package/dist/esm/localization/localeDetector.mjs.map +1 -1
- package/dist/esm/localization/localeResolver.mjs +29 -0
- package/dist/esm/localization/localeResolver.mjs.map +1 -0
- package/dist/types/dictionaryManipulator/editDictionaryByKeyPath.d.ts.map +1 -1
- package/dist/types/dictionaryManipulator/getContentNodeByKeyPath.d.ts.map +1 -1
- package/dist/types/dictionaryManipulator/getDefaultNode.d.ts.map +1 -1
- package/dist/types/dictionaryManipulator/getEmptyNode.d.ts.map +1 -1
- package/dist/types/dictionaryManipulator/getNodeChildren.d.ts.map +1 -1
- package/dist/types/dictionaryManipulator/getNodeType.d.ts.map +1 -1
- package/dist/types/dictionaryManipulator/removeContentNodeByKeyPath.d.ts.map +1 -1
- package/dist/types/dictionaryManipulator/renameContentNodeByKeyPath.d.ts.map +1 -1
- package/dist/types/dictionaryManipulator/updateNodeChildren.d.ts.map +1 -1
- package/dist/types/interpreter/getCondition.d.ts.map +1 -1
- package/dist/types/interpreter/getContent/deepTransform.d.ts.map +1 -1
- package/dist/types/interpreter/getContent/getContent.d.ts.map +1 -1
- package/dist/types/interpreter/getContent/plugins.d.ts.map +1 -1
- package/dist/types/interpreter/getDictionary.d.ts.map +1 -1
- package/dist/types/interpreter/getEnumeration.d.ts.map +1 -1
- package/dist/types/interpreter/getIntlayer.d.ts.map +1 -1
- package/dist/types/interpreter/getIntlayerAsync.d.ts.map +1 -1
- package/dist/types/interpreter/getNesting.d.ts.map +1 -1
- package/dist/types/interpreter/getTranslation.d.ts +1 -1
- package/dist/types/interpreter/getTranslation.d.ts.map +1 -1
- package/dist/types/localization/getHTMLTextDir.d.ts.map +1 -1
- package/dist/types/localization/getLocaleLang.d.ts.map +1 -1
- package/dist/types/localization/getLocaleName.d.ts.map +1 -1
- package/dist/types/localization/getLocalizedUrl.d.ts +1 -1
- package/dist/types/localization/getLocalizedUrl.d.ts.map +1 -1
- package/dist/types/localization/getMultilingualUrls.d.ts +1 -1
- package/dist/types/localization/getMultilingualUrls.d.ts.map +1 -1
- package/dist/types/localization/getPathWithoutLocale.d.ts.map +1 -1
- package/dist/types/localization/index.d.ts +1 -0
- package/dist/types/localization/index.d.ts.map +1 -1
- package/dist/types/localization/localeDetector.d.ts +2 -2
- package/dist/types/localization/localeDetector.d.ts.map +1 -1
- package/dist/types/localization/localeResolver.d.ts +7 -0
- package/dist/types/localization/localeResolver.d.ts.map +1 -0
- package/dist/types/transpiler/condition/condition.d.ts.map +1 -1
- package/dist/types/transpiler/enumeration/enumeration.d.ts.map +1 -1
- package/dist/types/transpiler/markdown/markdown.d.ts.map +1 -1
- package/dist/types/transpiler/nesting/nesting.d.ts.map +1 -1
- package/dist/types/transpiler/translation/translation.d.ts +1 -1
- package/dist/types/transpiler/translation/translation.d.ts.map +1 -1
- package/dist/types/types/nodeType.d.ts.map +1 -1
- package/dist/types/utils/checkIsURLAbsolute.d.ts.map +1 -1
- package/dist/types/utils/isSameKeyPath.d.ts.map +1 -1
- package/dist/types/utils/isValidReactElement.d.ts.map +1 -1
- package/package.json +8 -9
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,20 +17,26 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
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
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
var getContent_exports = {};
|
|
20
30
|
__export(getContent_exports, {
|
|
21
31
|
getContent: () => getContent
|
|
22
32
|
});
|
|
23
33
|
module.exports = __toCommonJS(getContent_exports);
|
|
24
|
-
var
|
|
34
|
+
var import_built = __toESM(require("@intlayer/config/built"));
|
|
25
35
|
var import_deepTransform = require('./deepTransform.cjs');
|
|
26
36
|
var import_plugins = require('./plugins.cjs');
|
|
27
|
-
const getContent = (node, nodeProps, locale) => {
|
|
37
|
+
const getContent = (node, nodeProps, locale = import_built.default.internationalization.defaultLocale) => {
|
|
28
38
|
const plugins = [
|
|
29
|
-
(0, import_plugins.translationPlugin)(
|
|
30
|
-
locale ?? (0, import_client.getConfiguration)().internationalization.defaultLocale
|
|
31
|
-
),
|
|
39
|
+
(0, import_plugins.translationPlugin)(locale),
|
|
32
40
|
import_plugins.enumerationPlugin,
|
|
33
41
|
import_plugins.conditionPlugin,
|
|
34
42
|
import_plugins.nestedPlugin,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/interpreter/getContent/getContent.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../../../src/interpreter/getContent/getContent.ts"],"sourcesContent":["import { type Locales, type LocalesValues } from '@intlayer/config/client';\nimport configuration from '@intlayer/config/built';\n\nimport type { ContentNode } from '../../types';\nimport { deepTransformNode } from './deepTransform';\nimport {\n translationPlugin,\n enumerationPlugin,\n conditionPlugin,\n nestedPlugin,\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 *\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 getContent = <\n T extends ContentNode,\n L extends LocalesValues = Locales,\n>(\n node: T,\n nodeProps: NodeProps,\n locale: L = configuration.internationalization.defaultLocale as L\n) => {\n const plugins: Plugins[] = [\n translationPlugin(locale),\n enumerationPlugin,\n conditionPlugin,\n nestedPlugin,\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;AACA,mBAA0B;AAG1B,2BAAkC;AAClC,qBAQO;AAQA,MAAM,aAAa,CAIxB,MACA,WACA,SAAY,aAAAA,QAAc,qBAAqB,kBAC5C;AACH,QAAM,UAAqB;AAAA,QACzB,kCAAkB,MAAM;AAAA,IACxB;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAI,UAAU,WAAW,CAAC;AAAA,EAC5B;AAEA,aAAO,wCAAkB,MAAM;AAAA,IAC7B,GAAG;AAAA,IACH;AAAA,EACF,CAAC;AACH;","names":["configuration"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/interpreter/getContent/plugins.ts"],"sourcesContent":["import type { Locales, LocalesValues } from '@intlayer/config/client';\
|
|
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} 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';\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 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 canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Translation,\n transform: (node: TranslationContent, props, deepTransformNode) => {\n const result = structuredClone(node.translation);\n\n for (const key in result) {\n const childProps = {\n ...props,\n content: 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 canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Enumeration,\n transform: (node: EnumerationContent, props, deepTransformNode) => {\n const result = structuredClone(node.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 content: 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 canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Condition,\n transform: (node: ConditionContent, props, deepTransformNode) => {\n const result = structuredClone(node.condition);\n\n for (const key in result) {\n const child = result[key as keyof typeof result];\n const childProps = {\n ...props,\n content: 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 * 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 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 * 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 content?: 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 enumeration: EnumerationCond<T, S>;\n condition: ConditionCond<T, S>;\n nested: NestedCond<T, S>;\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 nested: 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;AAOA,mBAA4D;AAC5D,0BAA6B;AAC7B,4BAA+B;AAC/B,wBAAkD;AAClD,4BAA+B;AAqCxB,MAAM,oBAAoB,CAAC,YAAoC;AAAA,EACpE,WAAW,CAAC,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,sBAAS;AAAA,EAC1D,WAAW,CAAC,MAA0B,OAAO,sBAAsB;AACjE,UAAM,SAAS,gBAAgB,KAAK,WAAW;AAE/C,eAAW,OAAO,QAAQ;AACxB,YAAM,aAAa;AAAA,QACjB,GAAG;AAAA,QACH,SAAS,OAAO,GAAqC;AAAA,QACrD,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,MAAM;AAAA,EACtC;AACF;AAmBO,MAAM,oBAA6B;AAAA,EACxC,WAAW,CAAC,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,sBAAS;AAAA,EAC1D,WAAW,CAAC,MAA0B,OAAO,sBAAsB;AACjE,UAAM,SAAS,gBAAgB,KAAK,WAAW;AAE/C,eAAW,OAAO,QAAQ;AACxB,YAAM,QAAQ,OAAO,GAAqC;AAC1D,YAAM,aAAa;AAAA,QACjB,GAAG;AAAA,QACH,SAAS;AAAA,QACT,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,WAAW,CAAC,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,sBAAS;AAAA,EAC1D,WAAW,CAAC,MAAwB,OAAO,sBAAsB;AAC/D,UAAM,SAAS,gBAAgB,KAAK,SAAS;AAE7C,eAAW,OAAO,QAAQ;AACxB,YAAM,QAAQ,OAAO,GAA0B;AAC/C,YAAM,aAAa;AAAA,QACjB,GAAG;AAAA,QACH,SAAS;AAAA,QACT,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;AAmBO,MAAM,eAAwB;AAAA,EACnC,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;","names":[]}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,15 +17,23 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
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
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
var getTranslation_exports = {};
|
|
20
30
|
__export(getTranslation_exports, {
|
|
21
31
|
getTranslation: () => getTranslation
|
|
22
32
|
});
|
|
23
33
|
module.exports = __toCommonJS(getTranslation_exports);
|
|
24
|
-
var
|
|
34
|
+
var import_built = __toESM(require("@intlayer/config/built"));
|
|
25
35
|
const getTranslation = (languageContent, locale) => {
|
|
26
|
-
const { defaultLocale } =
|
|
36
|
+
const { defaultLocale } = import_built.default?.internationalization;
|
|
27
37
|
const result = languageContent[locale ?? defaultLocale] ?? languageContent[defaultLocale];
|
|
28
38
|
return result;
|
|
29
39
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/interpreter/getTranslation.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../../src/interpreter/getTranslation.ts"],"sourcesContent":["import type { LocalesValues } from '@intlayer/config/client';\nimport configuration from '@intlayer/config/built';\n\nimport type { LanguageContent } from '../transpiler/translation/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;AAyBnB,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,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,18 +17,23 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
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
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
var getLocalizedUrl_exports = {};
|
|
20
30
|
__export(getLocalizedUrl_exports, {
|
|
21
31
|
getLocalizedUrl: () => getLocalizedUrl
|
|
22
32
|
});
|
|
23
33
|
module.exports = __toCommonJS(getLocalizedUrl_exports);
|
|
24
|
-
var
|
|
34
|
+
var import_built = __toESM(require("@intlayer/config/built"));
|
|
25
35
|
var import_getMultilingualUrls = require('./getMultilingualUrls.cjs');
|
|
26
|
-
const
|
|
27
|
-
const { locales: localesDefault, defaultLocale: defaultLocaleDefault } = internationalization;
|
|
28
|
-
const { prefixDefault: prefixDefaultDefault } = middleware;
|
|
29
|
-
const getLocalizedUrl = (url, currentLocale, locales = localesDefault, defaultLocale = defaultLocaleDefault, prefixDefault = prefixDefaultDefault) => {
|
|
36
|
+
const getLocalizedUrl = (url, currentLocale, locales = import_built.default.internationalization.locales, defaultLocale = import_built.default.internationalization.defaultLocale, prefixDefault = import_built.default.middleware.prefixDefault) => {
|
|
30
37
|
const urlWithoutLocale = (0, import_getMultilingualUrls.getMultilingualUrls)(
|
|
31
38
|
url,
|
|
32
39
|
locales,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/localization/getLocalizedUrl.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../../src/localization/getLocalizedUrl.ts"],"sourcesContent":["import type { LocalesValues } from '@intlayer/config/client';\nimport configuration from '@intlayer/config/built';\n\nimport { getMultilingualUrls } from './getMultilingualUrls';\n\n/**\n * Generate URL by prefixing the given URL with the referenced locale.\n * Handles both absolute and relative URLs appropriately.\n *\n * This function get the locales, default locale, and prefix default from the configuration if not provided.\n *\n * Example:\n *\n * ```ts\n * getCurrentUrl('/about', currentLocale, ['en', 'fr'], 'en', false);\n * // Returns '/fr/about' for the French locale\n * // Returns '/about' for the default locale\n * // Returns '/about' for the Italian locale\n *\n * getCurrentUrl('https://example.com/about', currentLocale, ['en', 'fr'], 'en', false);\n * // Returns 'https://example.com/fr/about' for the French locale\n * // Returns 'https://example.com/about' for the default locale\n * // Returns 'https://example.com/about' for the Italian locale\n * ```\n *\n * @param url - The original URL string to be prefixed with locales.\n * @param currentLocale - The current locale.\n * @param locales - Optional array of supported locales. Defaults to `localesDefault`.\n * @param defaultLocale - The default locale. Defaults to `defaultLocaleDefault`.\n * @param prefixDefault - Whether to prefix the default locale. Defaults to `prefixDefaultDefault`.\n * @returns An object mapping each locale to its corresponding multilingual URL.\n */\nexport const getLocalizedUrl = (\n url: string,\n currentLocale: LocalesValues,\n locales: LocalesValues[] = configuration.internationalization.locales,\n defaultLocale: LocalesValues = configuration.internationalization\n .defaultLocale,\n prefixDefault: boolean = configuration.middleware.prefixDefault\n): string => {\n // Remove any existing locale segment from the URL\n const urlWithoutLocale = getMultilingualUrls(\n url,\n locales,\n defaultLocale,\n prefixDefault\n );\n\n return urlWithoutLocale[\n currentLocale as unknown as keyof typeof urlWithoutLocale\n ];\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAA0B;AAE1B,iCAAoC;AA6B7B,MAAM,kBAAkB,CAC7B,KACA,eACA,UAA2B,aAAAA,QAAc,qBAAqB,SAC9D,gBAA+B,aAAAA,QAAc,qBAC1C,eACH,gBAAyB,aAAAA,QAAc,WAAW,kBACvC;AAEX,QAAM,uBAAmB;AAAA,IACvB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAEA,SAAO,iBACL,aACF;AACF;","names":["configuration"]}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,19 +17,24 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
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
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
var getMultilingualUrls_exports = {};
|
|
20
30
|
__export(getMultilingualUrls_exports, {
|
|
21
31
|
getMultilingualUrls: () => getMultilingualUrls
|
|
22
32
|
});
|
|
23
33
|
module.exports = __toCommonJS(getMultilingualUrls_exports);
|
|
24
|
-
var
|
|
34
|
+
var import_built = __toESM(require("@intlayer/config/built"));
|
|
25
35
|
var import_checkIsURLAbsolute = require('../utils/checkIsURLAbsolute.cjs');
|
|
26
36
|
var import_getPathWithoutLocale = require('./getPathWithoutLocale.cjs');
|
|
27
|
-
const
|
|
28
|
-
const { locales: localesDefault, defaultLocale: defaultLocaleDefault } = internationalization;
|
|
29
|
-
const { prefixDefault: prefixDefaultDefault } = middleware;
|
|
30
|
-
const getMultilingualUrls = (url, locales = localesDefault, defaultLocale = defaultLocaleDefault, prefixDefault = prefixDefaultDefault) => {
|
|
37
|
+
const getMultilingualUrls = (url, locales = import_built.default.internationalization.locales, defaultLocale = import_built.default.internationalization.defaultLocale, prefixDefault = import_built.default.middleware.prefixDefault) => {
|
|
31
38
|
const urlWithoutLocale = (0, import_getPathWithoutLocale.getPathWithoutLocale)(url, locales);
|
|
32
39
|
const isAbsoluteUrl = (0, import_checkIsURLAbsolute.checkIsURLAbsolute)(urlWithoutLocale);
|
|
33
40
|
const parsedUrl = isAbsoluteUrl ? new URL(urlWithoutLocale) : new URL(urlWithoutLocale, "http://example.com");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/localization/getMultilingualUrls.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../../src/localization/getMultilingualUrls.ts"],"sourcesContent":["import type { LocalesValues } from '@intlayer/config/client';\nimport configuration from '@intlayer/config/built';\n\n// @ts-ignore intlayer declared for module augmentation\nimport type { IConfigLocales } from 'intlayer';\nimport { checkIsURLAbsolute } from '../utils/checkIsURLAbsolute';\nimport { getPathWithoutLocale } from './getPathWithoutLocale';\n\n/**\n * Generates multilingual URLs by prefixing the given URL with each supported locale.\n * Handles both absolute and relative URLs appropriately.\n *\n * This function get the locales, default locale, and prefix default from the configuration if not provided.\n *\n * Example:\n *\n * ```ts\n * getMultilingualUrls('/dashboard', ['en', 'fr'], 'en', false)\n * // Returns { en: '/dashboard', fr: '/fr/dashboard' }\n * getMultilingualUrls('https://example.com/dashboard', ['en', 'fr'], 'en', true)\n * // Returns { en: 'https://example.com/en/dashboard', fr: 'https://example.com/fr/dashboard' }\n * ```\n *\n * @param url - The original URL string to be prefixed with locales.\n * @param locales - Optional array of supported locales. Defaults to `localesDefault`.\n * @param defaultLocale - The default locale. Defaults to `defaultLocaleDefault`.\n * @param prefixDefault - Whether to prefix the default locale. Defaults to `prefixDefaultDefault`.\n * @returns An object mapping each locale to its corresponding multilingual URL.\n */\nexport const getMultilingualUrls = (\n url: string,\n locales: LocalesValues[] = configuration.internationalization.locales,\n defaultLocale: LocalesValues = configuration.internationalization\n .defaultLocale,\n prefixDefault: boolean = configuration.middleware.prefixDefault\n): IConfigLocales<string> => {\n // Remove any existing locale segment from the URL\n const urlWithoutLocale = getPathWithoutLocale(url, locales);\n\n // Determine if the original URL is absolute (includes protocol)\n const isAbsoluteUrl = checkIsURLAbsolute(urlWithoutLocale);\n\n // Initialize a URL object if the URL is absolute\n // For relative URLs, use a dummy base to leverage the URL API\n const parsedUrl = isAbsoluteUrl\n ? new URL(urlWithoutLocale)\n : new URL(urlWithoutLocale, 'http://example.com');\n\n // Extract the pathname from the parsed URL\n let pathname = parsedUrl.pathname;\n\n // Ensure the pathname starts with a '/'\n if (!pathname.startsWith('/')) {\n pathname = `/${pathname}`;\n }\n\n // Prepare the base URL (protocol + host) if it's absolute\n const baseUrl = isAbsoluteUrl\n ? `${parsedUrl.protocol}//${parsedUrl.host}`\n : '';\n\n // Generate multilingual URLs by iterating over each locale\n const multilingualUrls = locales.reduce<IConfigLocales<string>>(\n (acc, locale) => {\n // Determine if the current locale is the default locale\n const isDefaultLocale = locale.toString() === defaultLocale.toString();\n\n // Decide whether to prefix the default locale based on `prefixDefault`\n const shouldPrefix = prefixDefault || !isDefaultLocale;\n\n // Construct the new pathname with or without the locale prefix\n let localizedPath = shouldPrefix ? `/${locale}${pathname}` : pathname;\n\n if (localizedPath.length > 1 && localizedPath.endsWith('/')) {\n localizedPath = localizedPath.slice(0, -1);\n }\n\n // Combine with the base URL if the original URL was absolute\n const localizedUrl = isAbsoluteUrl\n ? `${baseUrl}${localizedPath}${parsedUrl.search}${parsedUrl.hash}`\n : `${localizedPath}${parsedUrl.search}${parsedUrl.hash}`;\n\n // Assign the constructed URL to the corresponding locale key\n acc[locale as unknown as keyof typeof acc] = localizedUrl;\n\n return acc;\n },\n {} as IConfigLocales<string> // Initialize an empty object\n );\n\n return multilingualUrls;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAA0B;AAI1B,gCAAmC;AACnC,kCAAqC;AAuB9B,MAAM,sBAAsB,CACjC,KACA,UAA2B,aAAAA,QAAc,qBAAqB,SAC9D,gBAA+B,aAAAA,QAAc,qBAC1C,eACH,gBAAyB,aAAAA,QAAc,WAAW,kBACvB;AAE3B,QAAM,uBAAmB,kDAAqB,KAAK,OAAO;AAG1D,QAAM,oBAAgB,8CAAmB,gBAAgB;AAIzD,QAAM,YAAY,gBACd,IAAI,IAAI,gBAAgB,IACxB,IAAI,IAAI,kBAAkB,oBAAoB;AAGlD,MAAI,WAAW,UAAU;AAGzB,MAAI,CAAC,SAAS,WAAW,GAAG,GAAG;AAC7B,eAAW,IAAI,QAAQ;AAAA,EACzB;AAGA,QAAM,UAAU,gBACZ,GAAG,UAAU,QAAQ,KAAK,UAAU,IAAI,KACxC;AAGJ,QAAM,mBAAmB,QAAQ;AAAA,IAC/B,CAAC,KAAK,WAAW;AAEf,YAAM,kBAAkB,OAAO,SAAS,MAAM,cAAc,SAAS;AAGrE,YAAM,eAAe,iBAAiB,CAAC;AAGvC,UAAI,gBAAgB,eAAe,IAAI,MAAM,GAAG,QAAQ,KAAK;AAE7D,UAAI,cAAc,SAAS,KAAK,cAAc,SAAS,GAAG,GAAG;AAC3D,wBAAgB,cAAc,MAAM,GAAG,EAAE;AAAA,MAC3C;AAGA,YAAM,eAAe,gBACjB,GAAG,OAAO,GAAG,aAAa,GAAG,UAAU,MAAM,GAAG,UAAU,IAAI,KAC9D,GAAG,aAAa,GAAG,UAAU,MAAM,GAAG,UAAU,IAAI;AAGxD,UAAI,MAAqC,IAAI;AAE7C,aAAO;AAAA,IACT;AAAA,IACA,CAAC;AAAA;AAAA,EACH;AAEA,SAAO;AACT;","names":["configuration"]}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,17 +17,23 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
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
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
var getPathWithoutLocale_exports = {};
|
|
20
30
|
__export(getPathWithoutLocale_exports, {
|
|
21
31
|
getPathWithoutLocale: () => getPathWithoutLocale
|
|
22
32
|
});
|
|
23
33
|
module.exports = __toCommonJS(getPathWithoutLocale_exports);
|
|
24
|
-
var
|
|
34
|
+
var import_built = __toESM(require("@intlayer/config/built"));
|
|
25
35
|
var import_checkIsURLAbsolute = require('../utils/checkIsURLAbsolute.cjs');
|
|
26
|
-
const
|
|
27
|
-
const { locales: localesDefault } = internationalization;
|
|
28
|
-
const getPathWithoutLocale = (inputUrl, locales = localesDefault) => {
|
|
36
|
+
const getPathWithoutLocale = (inputUrl, locales = import_built.default.internationalization.locales) => {
|
|
29
37
|
const isAbsoluteUrl = (0, import_checkIsURLAbsolute.checkIsURLAbsolute)(inputUrl);
|
|
30
38
|
let fixedInputUrl = inputUrl;
|
|
31
39
|
if (inputUrl.endsWith("/")) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/localization/getPathWithoutLocale.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../../src/localization/getPathWithoutLocale.ts"],"sourcesContent":["import { type Locales, type LocalesValues } from '@intlayer/config/client';\nimport configuration from '@intlayer/config/built';\n\nimport { checkIsURLAbsolute } from '../utils/checkIsURLAbsolute';\n\n/**\n * Removes the locale segment from the given URL or pathname if present.\n *\n * This function get the locales from the configuration if not provided.\n *\n * Example:\n *\n * ```ts\n * getPathWithoutLocale('/en/dashboard') // Returns '/dashboard'\n * getPathWithoutLocale('/fr/dashboard') // Returns '/dashboard'\n * getPathWithoutLocale('/dashboard') // Returns '/dashboard'\n * getPathWithoutLocale('dashboard') // Returns 'dashboard'\n * getPathWithoutLocale('https://example.com/en/dashboard') // Returns 'https://example.com/dashboard'\n * getPathWithoutLocale('https://example.com/fr/dashboard') // Returns 'https://example.com/dashboard'\n * getPathWithoutLocale('https://example.com/dashboard') // Returns 'https://example.com/dashboard'\n * ```\n *\n * @param inputUrl - The complete URL string or pathname to process.\n * @param locales - Optional array of supported locales. Defaults to `localesDefault`.\n * @returns The URL string or pathname without the locale segment.\n */\nexport const getPathWithoutLocale = (\n inputUrl: string,\n locales: LocalesValues[] = configuration.internationalization\n .locales as LocalesValues[]\n): string => {\n // Determine if the original URL is absolute (includes protocol)\n const isAbsoluteUrl = checkIsURLAbsolute(inputUrl);\n\n let fixedInputUrl = inputUrl;\n\n if (inputUrl.endsWith('/')) {\n fixedInputUrl = inputUrl.slice(0, -1);\n }\n\n // Initialize a URL object if the URL is absolute\n // For relative URLs, use a dummy base to leverage the URL API\n const url = isAbsoluteUrl\n ? new URL(fixedInputUrl)\n : new URL(fixedInputUrl, 'http://example.com');\n\n const pathname = url.pathname;\n\n // Ensure the pathname starts with '/'\n if (!pathname.startsWith('/')) {\n // If not, return the URL as is\n url.pathname = `/${pathname}`;\n }\n\n // Split the pathname to extract the first segment\n const pathSegments = pathname.split('/');\n const firstSegment = pathSegments[1]; // The segment after the first '/'\n\n // Check if the first segment is a supported locale\n if (locales.includes(firstSegment as Locales)) {\n // Remove the locale segment from the pathname\n pathSegments.splice(1, 1); // Remove the first segment\n\n // Reconstruct the pathname\n const newPathname = pathSegments.join('/') ?? '/';\n url.pathname = newPathname;\n }\n\n if (isAbsoluteUrl) {\n // Return the modified URL as a string\n return url.toString();\n }\n\n // Return the modified URL as a string\n return url.toString().replace('http://example.com', '');\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAA0B;AAE1B,gCAAmC;AAuB5B,MAAM,uBAAuB,CAClC,UACA,UAA2B,aAAAA,QAAc,qBACtC,YACQ;AAEX,QAAM,oBAAgB,8CAAmB,QAAQ;AAEjD,MAAI,gBAAgB;AAEpB,MAAI,SAAS,SAAS,GAAG,GAAG;AAC1B,oBAAgB,SAAS,MAAM,GAAG,EAAE;AAAA,EACtC;AAIA,QAAM,MAAM,gBACR,IAAI,IAAI,aAAa,IACrB,IAAI,IAAI,eAAe,oBAAoB;AAE/C,QAAM,WAAW,IAAI;AAGrB,MAAI,CAAC,SAAS,WAAW,GAAG,GAAG;AAE7B,QAAI,WAAW,IAAI,QAAQ;AAAA,EAC7B;AAGA,QAAM,eAAe,SAAS,MAAM,GAAG;AACvC,QAAM,eAAe,aAAa,CAAC;AAGnC,MAAI,QAAQ,SAAS,YAAuB,GAAG;AAE7C,iBAAa,OAAO,GAAG,CAAC;AAGxB,UAAM,cAAc,aAAa,KAAK,GAAG,KAAK;AAC9C,QAAI,WAAW;AAAA,EACjB;AAEA,MAAI,eAAe;AAEjB,WAAO,IAAI,SAAS;AAAA,EACtB;AAGA,SAAO,IAAI,SAAS,EAAE,QAAQ,sBAAsB,EAAE;AACxD;","names":["configuration"]}
|
|
@@ -25,13 +25,15 @@ __export(localization_exports, {
|
|
|
25
25
|
getMultilingualUrls: () => import_getMultilingualUrls.getMultilingualUrls,
|
|
26
26
|
getPathWithoutLocale: () => import_getPathWithoutLocale.getPathWithoutLocale,
|
|
27
27
|
localeDetector: () => import_localeDetector.localeDetector,
|
|
28
|
-
localeList: () => import_localeList.localeList
|
|
28
|
+
localeList: () => import_localeList.localeList,
|
|
29
|
+
localeResolver: () => import_localeResolver.localeResolver
|
|
29
30
|
});
|
|
30
31
|
module.exports = __toCommonJS(localization_exports);
|
|
31
32
|
var import_getLocaleName = require('./getLocaleName.cjs');
|
|
32
33
|
var import_getHTMLTextDir = require('./getHTMLTextDir.cjs');
|
|
33
34
|
var import_getLocaleLang = require('./getLocaleLang.cjs');
|
|
34
35
|
var import_localeList = require('./localeList.cjs');
|
|
36
|
+
var import_localeResolver = require('./localeResolver.cjs');
|
|
35
37
|
var import_localeDetector = require('./localeDetector.cjs');
|
|
36
38
|
var import_getPathWithoutLocale = require('./getPathWithoutLocale.cjs');
|
|
37
39
|
var import_getMultilingualUrls = require('./getMultilingualUrls.cjs');
|
|
@@ -45,6 +47,7 @@ var import_getLocalizedUrl = require('./getLocalizedUrl.cjs');
|
|
|
45
47
|
getMultilingualUrls,
|
|
46
48
|
getPathWithoutLocale,
|
|
47
49
|
localeDetector,
|
|
48
|
-
localeList
|
|
50
|
+
localeList,
|
|
51
|
+
localeResolver
|
|
49
52
|
});
|
|
50
53
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/localization/index.ts"],"sourcesContent":["export { getLocaleName } from './getLocaleName';\nexport { getHTMLTextDir } from './getHTMLTextDir';\nexport { getLocaleLang } from './getLocaleLang';\nexport { localeList } from './localeList';\nexport { localeDetector } from './localeDetector';\nexport { getPathWithoutLocale } from './getPathWithoutLocale';\nexport { getMultilingualUrls } from './getMultilingualUrls';\nexport { getLocalizedUrl } from './getLocalizedUrl';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,2BAA8B;AAC9B,4BAA+B;AAC/B,2BAA8B;AAC9B,wBAA2B;AAC3B,4BAA+B;AAC/B,kCAAqC;AACrC,iCAAoC;AACpC,6BAAgC;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/localization/index.ts"],"sourcesContent":["export { getLocaleName } from './getLocaleName';\nexport { getHTMLTextDir } from './getHTMLTextDir';\nexport { getLocaleLang } from './getLocaleLang';\nexport { localeList } from './localeList';\nexport { localeResolver } from './localeResolver';\nexport { localeDetector } from './localeDetector';\nexport { getPathWithoutLocale } from './getPathWithoutLocale';\nexport { getMultilingualUrls } from './getMultilingualUrls';\nexport { getLocalizedUrl } from './getLocalizedUrl';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,2BAA8B;AAC9B,4BAA+B;AAC/B,2BAA8B;AAC9B,wBAA2B;AAC3B,4BAA+B;AAC/B,4BAA+B;AAC/B,kCAAqC;AACrC,iCAAoC;AACpC,6BAAgC;","names":[]}
|
|
@@ -31,17 +31,11 @@ __export(localeDetector_exports, {
|
|
|
31
31
|
localeDetector: () => localeDetector
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(localeDetector_exports);
|
|
34
|
-
var import_intl_localematcher = require("@formatjs/intl-localematcher");
|
|
35
|
-
var import_client = require("@intlayer/config/client");
|
|
36
34
|
var import_negotiator = __toESM(require("negotiator"));
|
|
37
|
-
|
|
38
|
-
const localeDetector = (headers, locales
|
|
35
|
+
var import_localeResolver = require('./localeResolver.cjs');
|
|
36
|
+
const localeDetector = (headers, locales, defaultLocale) => {
|
|
39
37
|
const languages = new import_negotiator.default({ headers }).languages();
|
|
40
|
-
|
|
41
|
-
return (0, import_intl_localematcher.match)(languages, locales, defaultLocale);
|
|
42
|
-
} catch (_error) {
|
|
43
|
-
return defaultLocale;
|
|
44
|
-
}
|
|
38
|
+
return (0, import_localeResolver.localeResolver)(languages, locales, defaultLocale);
|
|
45
39
|
};
|
|
46
40
|
// Annotate the CommonJS export names for ESM import in node:
|
|
47
41
|
0 && (module.exports = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/localization/localeDetector.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../../src/localization/localeDetector.ts"],"sourcesContent":["import { LocalesValues, type Locales } from '@intlayer/config/client';\nimport Negotiator from 'negotiator';\nimport { localeResolver } from './localeResolver';\n\n/**\n * Detects the locale from the request headers\n *\n * Headers are provided by the browser and can be used to determine the user's preferred language\n */\nexport const localeDetector = (\n headers: Record<string, string | undefined>,\n locales?: Locales[],\n defaultLocale?: Locales\n): LocalesValues => {\n const languages = new Negotiator({ headers }).languages();\n\n return localeResolver(languages as Locales[], locales, defaultLocale);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,wBAAuB;AACvB,4BAA+B;AAOxB,MAAM,iBAAiB,CAC5B,SACA,SACA,kBACkB;AAClB,QAAM,YAAY,IAAI,kBAAAA,QAAW,EAAE,QAAQ,CAAC,EAAE,UAAU;AAExD,aAAO,sCAAe,WAAwB,SAAS,aAAa;AACtE;","names":["Negotiator"]}
|
|
@@ -0,0 +1,63 @@
|
|
|
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 localeResolver_exports = {};
|
|
30
|
+
__export(localeResolver_exports, {
|
|
31
|
+
localeResolver: () => localeResolver
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(localeResolver_exports);
|
|
34
|
+
var import_built = __toESM(require("@intlayer/config/built"));
|
|
35
|
+
const localeResolver = (selectedLocale, locales = import_built.default.internationalization.locales, defaultLocale = import_built.default.internationalization.defaultLocale) => {
|
|
36
|
+
const requestedLocales = [selectedLocale].flat();
|
|
37
|
+
const normalize = (locale) => locale.trim().toLowerCase();
|
|
38
|
+
try {
|
|
39
|
+
for (const requested of requestedLocales) {
|
|
40
|
+
const normalizedRequested = normalize(requested);
|
|
41
|
+
const exactMatch = locales.find(
|
|
42
|
+
(loc) => normalize(loc) === normalizedRequested
|
|
43
|
+
);
|
|
44
|
+
if (exactMatch) {
|
|
45
|
+
return exactMatch;
|
|
46
|
+
}
|
|
47
|
+
const [requestedLang] = normalizedRequested.split("-");
|
|
48
|
+
const partialMatch = locales.find(
|
|
49
|
+
(loc) => normalize(loc).split("-")[0] === requestedLang
|
|
50
|
+
);
|
|
51
|
+
if (partialMatch) {
|
|
52
|
+
return partialMatch;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
} catch (_error) {
|
|
56
|
+
}
|
|
57
|
+
return defaultLocale;
|
|
58
|
+
};
|
|
59
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
60
|
+
0 && (module.exports = {
|
|
61
|
+
localeResolver
|
|
62
|
+
});
|
|
63
|
+
//# sourceMappingURL=localeResolver.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/localization/localeResolver.ts"],"sourcesContent":["import type { LocalesValues } from '@intlayer/config/client';\nimport configuration from '@intlayer/config/built';\n\n/**\n * Resolves the most specific locale from a user-provided list,\n * or falls back to the default locale if no match is found.\n */\nexport const localeResolver = (\n selectedLocale: LocalesValues | LocalesValues[],\n locales: LocalesValues[] = configuration.internationalization.locales,\n defaultLocale: LocalesValues = configuration.internationalization\n .defaultLocale\n): LocalesValues => {\n // Ensure we can handle both a single locale or an array of locales uniformly\n const requestedLocales = [selectedLocale].flat();\n\n // Simple helper to normalize locale strings (e.g. \"en-US\" => \"en-us\")\n const normalize = (locale: string): string => locale.trim().toLowerCase();\n\n try {\n // Check each requested locale in order\n for (const requested of requestedLocales) {\n const normalizedRequested = normalize(requested);\n\n // 1) Attempt exact match\n const exactMatch = locales.find(\n (loc) => normalize(loc) === normalizedRequested\n );\n if (exactMatch) {\n return exactMatch;\n }\n\n // 2) Attempt partial match on language subtag\n // e.g. if requested is \"en-US\" and not found,\n // see if \"en\" is available among locales\n const [requestedLang] = normalizedRequested.split('-');\n const partialMatch = locales.find(\n (loc) => normalize(loc).split('-')[0] === requestedLang\n );\n if (partialMatch) {\n return partialMatch;\n }\n }\n } catch (_error) {\n // If anything unexpected happened, fall back to default\n }\n\n // If no match was found, return the default\n return defaultLocale;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAA0B;AAMnB,MAAM,iBAAiB,CAC5B,gBACA,UAA2B,aAAAA,QAAc,qBAAqB,SAC9D,gBAA+B,aAAAA,QAAc,qBAC1C,kBACe;AAElB,QAAM,mBAAmB,CAAC,cAAc,EAAE,KAAK;AAG/C,QAAM,YAAY,CAAC,WAA2B,OAAO,KAAK,EAAE,YAAY;AAExE,MAAI;AAEF,eAAW,aAAa,kBAAkB;AACxC,YAAM,sBAAsB,UAAU,SAAS;AAG/C,YAAM,aAAa,QAAQ;AAAA,QACzB,CAAC,QAAQ,UAAU,GAAG,MAAM;AAAA,MAC9B;AACA,UAAI,YAAY;AACd,eAAO;AAAA,MACT;AAKA,YAAM,CAAC,aAAa,IAAI,oBAAoB,MAAM,GAAG;AACrD,YAAM,eAAe,QAAQ;AAAA,QAC3B,CAAC,QAAQ,UAAU,GAAG,EAAE,MAAM,GAAG,EAAE,CAAC,MAAM;AAAA,MAC5C;AACA,UAAI,cAAc;AAChB,eAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF,SAAS,QAAQ;AAAA,EAEjB;AAGA,SAAO;AACT;","names":["configuration"]}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
getConfiguration
|
|
3
|
-
} from "@intlayer/config/client";
|
|
1
|
+
import configuration from "@intlayer/config/built";
|
|
4
2
|
import { deepTransformNode } from "./deepTransform.mjs";
|
|
5
3
|
import {
|
|
6
4
|
translationPlugin,
|
|
@@ -8,11 +6,9 @@ import {
|
|
|
8
6
|
conditionPlugin,
|
|
9
7
|
nestedPlugin
|
|
10
8
|
} from "./plugins.mjs";
|
|
11
|
-
const getContent = (node, nodeProps, locale) => {
|
|
9
|
+
const getContent = (node, nodeProps, locale = configuration.internationalization.defaultLocale) => {
|
|
12
10
|
const plugins = [
|
|
13
|
-
translationPlugin(
|
|
14
|
-
locale ?? getConfiguration().internationalization.defaultLocale
|
|
15
|
-
),
|
|
11
|
+
translationPlugin(locale),
|
|
16
12
|
enumerationPlugin,
|
|
17
13
|
conditionPlugin,
|
|
18
14
|
nestedPlugin,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/interpreter/getContent/getContent.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../../../src/interpreter/getContent/getContent.ts"],"sourcesContent":["import { type Locales, type LocalesValues } from '@intlayer/config/client';\nimport configuration from '@intlayer/config/built';\n\nimport type { ContentNode } from '../../types';\nimport { deepTransformNode } from './deepTransform';\nimport {\n translationPlugin,\n enumerationPlugin,\n conditionPlugin,\n nestedPlugin,\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 *\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 getContent = <\n T extends ContentNode,\n L extends LocalesValues = Locales,\n>(\n node: T,\n nodeProps: NodeProps,\n locale: L = configuration.internationalization.defaultLocale as L\n) => {\n const plugins: Plugins[] = [\n translationPlugin(locale),\n enumerationPlugin,\n conditionPlugin,\n nestedPlugin,\n ...(nodeProps.plugins ?? []),\n ];\n\n return deepTransformNode(node, {\n ...nodeProps,\n plugins,\n }) as DeepTransformContent<T>;\n};\n"],"mappings":"AACA,OAAO,mBAAmB;AAG1B,SAAS,yBAAyB;AAClC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AAQA,MAAM,aAAa,CAIxB,MACA,WACA,SAAY,cAAc,qBAAqB,kBAC5C;AACH,QAAM,UAAqB;AAAA,IACzB,kBAAkB,MAAM;AAAA,IACxB;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAI,UAAU,WAAW,CAAC;AAAA,EAC5B;AAEA,SAAO,kBAAkB,MAAM;AAAA,IAC7B,GAAG;AAAA,IACH;AAAA,EACF,CAAC;AACH;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/interpreter/getContent/plugins.ts"],"sourcesContent":["import type { Locales, LocalesValues } from '@intlayer/config/client';\
|
|
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} 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';\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 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 canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Translation,\n transform: (node: TranslationContent, props, deepTransformNode) => {\n const result = structuredClone(node.translation);\n\n for (const key in result) {\n const childProps = {\n ...props,\n content: 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 canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Enumeration,\n transform: (node: EnumerationContent, props, deepTransformNode) => {\n const result = structuredClone(node.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 content: 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 canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Condition,\n transform: (node: ConditionContent, props, deepTransformNode) => {\n const result = structuredClone(node.condition);\n\n for (const key in result) {\n const child = result[key as keyof typeof result];\n const childProps = {\n ...props,\n content: 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 * 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 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 * 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 content?: 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 enumeration: EnumerationCond<T, S>;\n condition: ConditionCond<T, S>;\n nested: NestedCond<T, S>;\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 nested: 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":"AAOA,SAA4C,gBAAgB;AAC5D,SAAS,oBAAoB;AAC7B,SAAS,sBAAsB;AAC/B,SAAgC,kBAAkB;AAClD,SAAS,sBAAsB;AAqCxB,MAAM,oBAAoB,CAAC,YAAoC;AAAA,EACpE,WAAW,CAAC,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,SAAS;AAAA,EAC1D,WAAW,CAAC,MAA0B,OAAO,sBAAsB;AACjE,UAAM,SAAS,gBAAgB,KAAK,WAAW;AAE/C,eAAW,OAAO,QAAQ;AACxB,YAAM,aAAa;AAAA,QACjB,GAAG;AAAA,QACH,SAAS,OAAO,GAAqC;AAAA,QACrD,SAAS;AAAA,UACP,GAAG,MAAM;AAAA,UACT,EAAE,MAAM,SAAS,aAAa,IAAI;AAAA,QACpC;AAAA,MACF;AACA,aAAO,GAAqC,IAAI;AAAA,QAC9C,OAAO,GAAqC;AAAA,QAC5C;AAAA,MACF;AAAA,IACF;AACA,WAAO,eAAe,QAAQ,MAAM;AAAA,EACtC;AACF;AAmBO,MAAM,oBAA6B;AAAA,EACxC,WAAW,CAAC,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,SAAS;AAAA,EAC1D,WAAW,CAAC,MAA0B,OAAO,sBAAsB;AACjE,UAAM,SAAS,gBAAgB,KAAK,WAAW;AAE/C,eAAW,OAAO,QAAQ;AACxB,YAAM,QAAQ,OAAO,GAAqC;AAC1D,YAAM,aAAa;AAAA,QACjB,GAAG;AAAA,QACH,SAAS;AAAA,QACT,SAAS;AAAA,UACP,GAAG,MAAM;AAAA,UACT,EAAE,MAAM,SAAS,aAAa,IAAI;AAAA,QACpC;AAAA,MACF;AACA,aAAO,GAAqC,IAAI;AAAA,QAC9C;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAEA,WAAO,CAAC,aAAqB,eAAe,QAAQ,QAAQ;AAAA,EAC9D;AACF;AAmBO,MAAM,kBAA2B;AAAA,EACtC,WAAW,CAAC,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,SAAS;AAAA,EAC1D,WAAW,CAAC,MAAwB,OAAO,sBAAsB;AAC/D,UAAM,SAAS,gBAAgB,KAAK,SAAS;AAE7C,eAAW,OAAO,QAAQ;AACxB,YAAM,QAAQ,OAAO,GAA0B;AAC/C,YAAM,aAAa;AAAA,QACjB,GAAG;AAAA,QACH,SAAS;AAAA,QACT,SAAS;AAAA,UACP,GAAG,MAAM;AAAA,UACT,EAAE,MAAM,SAAS,WAAW,IAAI;AAAA,QAClC;AAAA,MACF;AACA,aAAO,GAAqC,IAAI;AAAA,QAC9C;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAEA,WAAO,CAAC,UAAmB,aAAa,QAAQ,KAAK;AAAA,EACvD;AACF;AAmBO,MAAM,eAAwB;AAAA,EACnC,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;","names":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import configuration from "@intlayer/config/built";
|
|
2
2
|
const getTranslation = (languageContent, locale) => {
|
|
3
|
-
const { defaultLocale } =
|
|
3
|
+
const { defaultLocale } = configuration?.internationalization;
|
|
4
4
|
const result = languageContent[locale ?? defaultLocale] ?? languageContent[defaultLocale];
|
|
5
5
|
return result;
|
|
6
6
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/interpreter/getTranslation.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../../src/interpreter/getTranslation.ts"],"sourcesContent":["import type { LocalesValues } from '@intlayer/config/client';\nimport configuration from '@intlayer/config/built';\n\nimport type { LanguageContent } from '../transpiler/translation/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;AAyBnB,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,9 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import configuration from "@intlayer/config/built";
|
|
2
2
|
import { getMultilingualUrls } from "./getMultilingualUrls.mjs";
|
|
3
|
-
const
|
|
4
|
-
const { locales: localesDefault, defaultLocale: defaultLocaleDefault } = internationalization;
|
|
5
|
-
const { prefixDefault: prefixDefaultDefault } = middleware;
|
|
6
|
-
const getLocalizedUrl = (url, currentLocale, locales = localesDefault, defaultLocale = defaultLocaleDefault, prefixDefault = prefixDefaultDefault) => {
|
|
3
|
+
const getLocalizedUrl = (url, currentLocale, locales = configuration.internationalization.locales, defaultLocale = configuration.internationalization.defaultLocale, prefixDefault = configuration.middleware.prefixDefault) => {
|
|
7
4
|
const urlWithoutLocale = getMultilingualUrls(
|
|
8
5
|
url,
|
|
9
6
|
locales,
|