react-intlayer 4.1.10 → 5.0.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/README.md +2 -2
- package/dist/cjs/{getEnumeration.cjs → IntlayerNode.cjs} +14 -13
- package/dist/cjs/IntlayerNode.cjs.map +1 -0
- package/dist/cjs/UI/ContentSelector.cjs.map +1 -1
- package/dist/cjs/client/IntlayerProvider.cjs.map +1 -1
- package/dist/cjs/client/index.cjs +2 -5
- package/dist/cjs/client/index.cjs.map +1 -1
- package/dist/cjs/client/t.cjs +2 -2
- package/dist/cjs/client/t.cjs.map +1 -1
- package/dist/cjs/client/useContent.cjs +2 -2
- package/dist/cjs/client/useContent.cjs.map +1 -1
- package/dist/cjs/client/useDictionary.cjs +3 -3
- package/dist/cjs/client/useDictionary.cjs.map +1 -1
- package/dist/cjs/client/useIntlayer.cjs +7 -4
- package/dist/cjs/client/useIntlayer.cjs.map +1 -1
- package/dist/cjs/client/useIntlayerAsync.cjs +3 -4
- package/dist/cjs/client/useIntlayerAsync.cjs.map +1 -1
- package/dist/cjs/client/useLocale.cjs +1 -1
- package/dist/cjs/client/useLocale.cjs.map +1 -1
- package/dist/cjs/client/useLocaleCookie.cjs.map +1 -1
- package/dist/cjs/client/useTraduction.cjs +5 -5
- package/dist/cjs/client/useTraduction.cjs.map +1 -1
- package/dist/cjs/editor/ContentSelectorWrapper.cjs +1 -3
- package/dist/cjs/editor/ContentSelectorWrapper.cjs.map +1 -1
- package/dist/cjs/editor/IntlayerEditorProvider.cjs +3 -1
- package/dist/cjs/editor/IntlayerEditorProvider.cjs.map +1 -1
- package/dist/cjs/editor/renderContentEditor.cjs +5 -4
- package/dist/cjs/editor/renderContentEditor.cjs.map +1 -1
- package/dist/cjs/getDictionary.cjs +13 -13
- package/dist/cjs/getDictionary.cjs.map +1 -1
- package/dist/cjs/getIntlayer.cjs +10 -29
- package/dist/cjs/getIntlayer.cjs.map +1 -1
- package/dist/cjs/index.cjs +5 -13
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/{getIntlayerAsync.cjs → markdown/MarkdownProvider.cjs} +18 -19
- package/dist/cjs/markdown/MarkdownProvider.cjs.map +1 -0
- package/dist/cjs/{server/useTraduction.cjs → markdown/MarkdownRenderer.cjs} +17 -12
- package/dist/cjs/markdown/MarkdownRenderer.cjs.map +1 -0
- package/dist/cjs/markdown/index.cjs +27 -0
- package/dist/cjs/markdown/index.cjs.map +1 -0
- package/dist/cjs/{getTranslation.cjs → markdown/renderMarkdown.cjs} +13 -16
- package/dist/cjs/markdown/renderMarkdown.cjs.map +1 -0
- package/dist/cjs/plugins.cjs +85 -0
- package/dist/cjs/plugins.cjs.map +1 -0
- package/dist/cjs/server/IntlayerServerProvider.cjs.map +1 -1
- package/dist/cjs/server/index.cjs +2 -8
- package/dist/cjs/server/index.cjs.map +1 -1
- package/dist/cjs/server/t.cjs +5 -3
- package/dist/cjs/server/t.cjs.map +1 -1
- package/dist/cjs/server/useDictionary.cjs +2 -2
- package/dist/cjs/server/useDictionary.cjs.map +1 -1
- package/dist/cjs/server/useIntlayer.cjs +2 -2
- package/dist/cjs/server/useIntlayer.cjs.map +1 -1
- package/dist/esm/IntlayerNode.mjs +16 -0
- package/dist/esm/IntlayerNode.mjs.map +1 -0
- package/dist/esm/UI/ContentSelector.mjs.map +1 -1
- package/dist/esm/client/IntlayerProvider.mjs.map +1 -1
- package/dist/esm/client/index.mjs +1 -3
- package/dist/esm/client/index.mjs.map +1 -1
- package/dist/esm/client/t.mjs +1 -1
- package/dist/esm/client/t.mjs.map +1 -1
- package/dist/esm/client/useContent.mjs +3 -3
- package/dist/esm/client/useContent.mjs.map +1 -1
- package/dist/esm/client/useDictionary.mjs +3 -3
- package/dist/esm/client/useDictionary.mjs.map +1 -1
- package/dist/esm/client/useIntlayer.mjs +8 -7
- package/dist/esm/client/useIntlayer.mjs.map +1 -1
- package/dist/esm/client/useIntlayerAsync.mjs +5 -5
- package/dist/esm/client/useIntlayerAsync.mjs.map +1 -1
- package/dist/esm/client/useLocale.mjs +1 -1
- package/dist/esm/client/useLocale.mjs.map +1 -1
- package/dist/esm/client/useLocaleCookie.mjs.map +1 -1
- package/dist/esm/client/useTraduction.mjs +3 -3
- package/dist/esm/client/useTraduction.mjs.map +1 -1
- package/dist/esm/editor/ContentSelectorWrapper.mjs +1 -3
- package/dist/esm/editor/ContentSelectorWrapper.mjs.map +1 -1
- package/dist/esm/editor/IntlayerEditorProvider.mjs +3 -1
- package/dist/esm/editor/IntlayerEditorProvider.mjs.map +1 -1
- package/dist/esm/editor/renderContentEditor.mjs +5 -4
- package/dist/esm/editor/renderContentEditor.mjs.map +1 -1
- package/dist/esm/getDictionary.mjs +18 -14
- package/dist/esm/getDictionary.mjs.map +1 -1
- package/dist/esm/getIntlayer.mjs +15 -20
- package/dist/esm/getIntlayer.mjs.map +1 -1
- package/dist/esm/index.mjs +3 -9
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/markdown/MarkdownProvider.mjs +19 -0
- package/dist/esm/markdown/MarkdownProvider.mjs.map +1 -0
- package/dist/esm/markdown/MarkdownRenderer.mjs +16 -0
- package/dist/esm/markdown/MarkdownRenderer.mjs.map +1 -0
- package/dist/esm/markdown/index.mjs +4 -0
- package/dist/esm/markdown/index.mjs.map +1 -0
- package/dist/esm/markdown/renderMarkdown.mjs +11 -0
- package/dist/esm/markdown/renderMarkdown.mjs.map +1 -0
- package/dist/esm/plugins.mjs +61 -0
- package/dist/esm/plugins.mjs.map +1 -0
- package/dist/esm/server/IntlayerServerProvider.mjs.map +1 -1
- package/dist/esm/server/index.mjs +1 -5
- package/dist/esm/server/index.mjs.map +1 -1
- package/dist/esm/server/t.mjs +4 -2
- package/dist/esm/server/t.mjs.map +1 -1
- package/dist/esm/server/useDictionary.mjs +2 -2
- package/dist/esm/server/useDictionary.mjs.map +1 -1
- package/dist/esm/server/useIntlayer.mjs +2 -4
- package/dist/esm/server/useIntlayer.mjs.map +1 -1
- package/dist/types/IntlayerNode.d.ts +9 -0
- package/dist/types/IntlayerNode.d.ts.map +1 -0
- package/dist/types/UI/ContentSelector.d.ts +1 -1
- package/dist/types/UI/ContentSelector.d.ts.map +1 -1
- package/dist/types/client/IntlayerProvider.d.ts +4 -4
- package/dist/types/client/IntlayerProvider.d.ts.map +1 -1
- package/dist/types/client/index.d.ts +0 -1
- package/dist/types/client/index.d.ts.map +1 -1
- package/dist/types/client/t.d.ts +1 -1
- package/dist/types/client/t.d.ts.map +1 -1
- package/dist/types/client/useContent.d.ts +1 -1
- package/dist/types/client/useDictionary.d.ts +3 -2
- package/dist/types/client/useDictionary.d.ts.map +1 -1
- package/dist/types/client/useIntlayer.d.ts +4 -2
- package/dist/types/client/useIntlayer.d.ts.map +1 -1
- package/dist/types/client/useIntlayerAsync.d.ts +4 -5
- package/dist/types/client/useIntlayerAsync.d.ts.map +1 -1
- package/dist/types/client/useLocale.d.ts +3 -3
- package/dist/types/client/useLocale.d.ts.map +1 -1
- package/dist/types/client/useLocaleBase.d.ts +2 -2
- package/dist/types/client/useLocaleCookie.d.ts +4 -4
- package/dist/types/client/useLocaleCookie.d.ts.map +1 -1
- package/dist/types/client/useTraduction.d.ts +3 -3
- package/dist/types/client/useTraduction.d.ts.map +1 -1
- package/dist/types/editor/ContentSelectorWrapper.d.ts +2 -8
- package/dist/types/editor/ContentSelectorWrapper.d.ts.map +1 -1
- package/dist/types/editor/IntlayerEditorProvider.d.ts.map +1 -1
- package/dist/types/editor/renderContentEditor.d.ts +3 -7
- package/dist/types/editor/renderContentEditor.d.ts.map +1 -1
- package/dist/types/getDictionary.d.ts +4 -12
- package/dist/types/getDictionary.d.ts.map +1 -1
- package/dist/types/getIntlayer.d.ts +4 -34
- package/dist/types/getIntlayer.d.ts.map +1 -1
- package/dist/types/index.d.ts +8 -5
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/markdown/MarkdownProvider.d.ts +9 -0
- package/dist/types/markdown/MarkdownProvider.d.ts.map +1 -0
- package/dist/types/markdown/MarkdownRenderer.d.ts +5 -0
- package/dist/types/markdown/MarkdownRenderer.d.ts.map +1 -0
- package/dist/types/markdown/index.d.ts +4 -0
- package/dist/types/markdown/index.d.ts.map +1 -0
- package/dist/types/markdown/renderMarkdown.d.ts +3 -0
- package/dist/types/markdown/renderMarkdown.d.ts.map +1 -0
- package/dist/types/plugins.d.ts +48 -0
- package/dist/types/plugins.d.ts.map +1 -0
- package/dist/types/server/IntlayerServerProvider.d.ts +7 -7
- package/dist/types/server/IntlayerServerProvider.d.ts.map +1 -1
- package/dist/types/server/index.d.ts +0 -2
- package/dist/types/server/index.d.ts.map +1 -1
- package/dist/types/server/t.d.ts +20 -4
- package/dist/types/server/t.d.ts.map +1 -1
- package/dist/types/server/useDictionary.d.ts +3 -2
- package/dist/types/server/useDictionary.d.ts.map +1 -1
- package/dist/types/server/useIntlayer.d.ts +3 -2
- package/dist/types/server/useIntlayer.d.ts.map +1 -1
- package/package.json +16 -16
- package/dist/cjs/getEnumeration.cjs.map +0 -1
- package/dist/cjs/getIntlayerAsync.cjs.map +0 -1
- package/dist/cjs/getTranslation.cjs.map +0 -1
- package/dist/cjs/processDictionary/contentDictionary.cjs +0 -17
- package/dist/cjs/processDictionary/contentDictionary.cjs.map +0 -1
- package/dist/cjs/processDictionary/index.cjs +0 -201
- package/dist/cjs/processDictionary/index.cjs.map +0 -1
- package/dist/cjs/recursiveTransformContent.cjs +0 -54
- package/dist/cjs/recursiveTransformContent.cjs.map +0 -1
- package/dist/cjs/server/getLocaleTranslation.cjs +0 -43
- package/dist/cjs/server/getLocaleTranslation.cjs.map +0 -1
- package/dist/cjs/server/useTraduction.cjs.map +0 -1
- package/dist/esm/getEnumeration.mjs +0 -12
- package/dist/esm/getEnumeration.mjs.map +0 -1
- package/dist/esm/getIntlayerAsync.mjs +0 -18
- package/dist/esm/getIntlayerAsync.mjs.map +0 -1
- package/dist/esm/getTranslation.mjs +0 -14
- package/dist/esm/getTranslation.mjs.map +0 -1
- package/dist/esm/processDictionary/contentDictionary.mjs +0 -1
- package/dist/esm/processDictionary/contentDictionary.mjs.map +0 -1
- package/dist/esm/processDictionary/index.mjs +0 -179
- package/dist/esm/processDictionary/index.mjs.map +0 -1
- package/dist/esm/recursiveTransformContent.mjs +0 -32
- package/dist/esm/recursiveTransformContent.mjs.map +0 -1
- package/dist/esm/server/getLocaleTranslation.mjs +0 -19
- package/dist/esm/server/getLocaleTranslation.mjs.map +0 -1
- package/dist/esm/server/useTraduction.mjs +0 -11
- package/dist/esm/server/useTraduction.mjs.map +0 -1
- package/dist/types/getEnumeration.d.ts +0 -31
- package/dist/types/getEnumeration.d.ts.map +0 -1
- package/dist/types/getIntlayerAsync.d.ts +0 -13
- package/dist/types/getIntlayerAsync.d.ts.map +0 -1
- package/dist/types/getTranslation.d.ts +0 -25
- package/dist/types/getTranslation.d.ts.map +0 -1
- package/dist/types/processDictionary/contentDictionary.d.ts +0 -14
- package/dist/types/processDictionary/contentDictionary.d.ts.map +0 -1
- package/dist/types/processDictionary/index.d.ts +0 -9
- package/dist/types/processDictionary/index.d.ts.map +0 -1
- package/dist/types/recursiveTransformContent.d.ts +0 -27
- package/dist/types/recursiveTransformContent.d.ts.map +0 -1
- package/dist/types/server/getLocaleTranslation.d.ts +0 -9
- package/dist/types/server/getLocaleTranslation.d.ts.map +0 -1
- package/dist/types/server/useTraduction.d.ts +0 -24
- package/dist/types/server/useTraduction.d.ts.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/markdown/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderMarkdown.d.ts","sourceRoot":"","sources":["../../../src/markdown/renderMarkdown.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAwB,MAAM,iBAAiB,CAAC;AAG1E,eAAO,MAAM,cAAc,aAAc,MAAM,KAAG,YAI9C,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { type Plugins, type IInterpreterPluginState as IInterpreterPluginStateCore, type DeepTransformContent as DeepTransformContentCore, NodeType } from '@intlayer/core';
|
|
2
|
+
import { type ReactNode } from 'react';
|
|
3
|
+
import type { IntlayerNode } from './IntlayerNode';
|
|
4
|
+
/** ---------------------------------------------
|
|
5
|
+
* INTLAYER NODE PLUGIN
|
|
6
|
+
* --------------------------------------------- */
|
|
7
|
+
export type IntlayerNodeCond<T, _S> = T extends number | string ? IntlayerNode<T> : never;
|
|
8
|
+
/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */
|
|
9
|
+
export declare const intlayerNodePlugins: Plugins;
|
|
10
|
+
/** ---------------------------------------------
|
|
11
|
+
* REACT NODE PLUGIN
|
|
12
|
+
* --------------------------------------------- */
|
|
13
|
+
export type ReactNodeCond<T, _S> = T extends {
|
|
14
|
+
ref: any;
|
|
15
|
+
props: any;
|
|
16
|
+
key: any;
|
|
17
|
+
} ? ReactNode : never;
|
|
18
|
+
/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */
|
|
19
|
+
export declare const reactNodePlugins: Plugins;
|
|
20
|
+
/**
|
|
21
|
+
* MARKDOWN PLUGIN
|
|
22
|
+
*/
|
|
23
|
+
export type MarkdownCond<T, _S> = T extends {
|
|
24
|
+
nodeType: NodeType | string;
|
|
25
|
+
[NodeType.Markdown]: string;
|
|
26
|
+
} ? IntlayerNode<string> : never;
|
|
27
|
+
/** Markdown plugin. Replaces node with a function that takes quantity => string. */
|
|
28
|
+
export declare const markdownPlugin: Plugins;
|
|
29
|
+
/** ---------------------------------------------
|
|
30
|
+
* PLUGINS RESULT
|
|
31
|
+
* --------------------------------------------- */
|
|
32
|
+
export interface IInterpreterPluginReact<T, _S> {
|
|
33
|
+
reactNode: ReactNodeCond<T, _S>;
|
|
34
|
+
intlayerNode: IntlayerNodeCond<T, _S>;
|
|
35
|
+
markdown: MarkdownCond<T, _S>;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Insert this type as param of `DeepTransformContent` to avoid `intlayer` package pollution.
|
|
39
|
+
*
|
|
40
|
+
* Otherwise the the `react-intlayer` plugins will override the types of `intlayer` functions.
|
|
41
|
+
*/
|
|
42
|
+
export type IInterpreterPluginState = IInterpreterPluginStateCore & {
|
|
43
|
+
reactNode: true;
|
|
44
|
+
intlayerNode: true;
|
|
45
|
+
markdown: true;
|
|
46
|
+
};
|
|
47
|
+
export type DeepTransformContent<T> = DeepTransformContentCore<T, IInterpreterPluginState>;
|
|
48
|
+
//# sourceMappingURL=plugins.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugins.d.ts","sourceRoot":"","sources":["../../src/plugins.tsx"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,uBAAuB,IAAI,2BAA2B,EAC3D,KAAK,oBAAoB,IAAI,wBAAwB,EAErD,QAAQ,EACT,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAqB,KAAK,SAAS,EAAiB,MAAM,OAAO,CAAC;AAEzE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAGnD;;oDAEoD;AAEpD,MAAM,MAAM,gBAAgB,CAAC,CAAC,EAAE,EAAE,IAAI,CAAC,SAAS,MAAM,GAAG,MAAM,GAC3D,YAAY,CAAC,CAAC,CAAC,GACf,KAAK,CAAC;AAEV,wFAAwF;AACxF,eAAO,MAAM,mBAAmB,EAAE,OAYjC,CAAC;AAEF;;oDAEoD;AAEpD,MAAM,MAAM,aAAa,CAAC,CAAC,EAAE,EAAE,IAAI,CAAC,SAAS;IAC3C,GAAG,EAAE,GAAG,CAAC;IACT,KAAK,EAAE,GAAG,CAAC;IACX,GAAG,EAAE,GAAG,CAAC;CACV,GACG,SAAS,GACT,KAAK,CAAC;AAiDV,wFAAwF;AACxF,eAAO,MAAM,gBAAgB,EAAE,OAQ9B,CAAC;AAEF;;GAEG;AAEH,MAAM,MAAM,YAAY,CAAC,CAAC,EAAE,EAAE,IAAI,CAAC,SAAS;IAC1C,QAAQ,EAAE,QAAQ,GAAG,MAAM,CAAC;IAC5B,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;CAC7B,GACG,YAAY,CAAC,MAAM,CAAC,GACpB,KAAK,CAAC;AAEV,oFAAoF;AACpF,eAAO,MAAM,cAAc,EAAE,OAI5B,CAAC;AAEF;;oDAEoD;AAEpD,MAAM,WAAW,uBAAuB,CAAC,CAAC,EAAE,EAAE;IAC5C,SAAS,EAAE,aAAa,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAChC,YAAY,EAAE,gBAAgB,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IACtC,QAAQ,EAAE,YAAY,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;CAC/B;AAED;;;;GAIG;AACH,MAAM,MAAM,uBAAuB,GAAG,2BAA2B,GAAG;IAClE,SAAS,EAAE,IAAI,CAAC;IAChB,YAAY,EAAE,IAAI,CAAC;IACnB,QAAQ,EAAE,IAAI,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,oBAAoB,CAAC,CAAC,IAAI,wBAAwB,CAC5D,CAAC,EACD,uBAAuB,CACxB,CAAC"}
|
|
@@ -6,26 +6,26 @@ import type { FC, PropsWithChildren } from 'react';
|
|
|
6
6
|
export declare const IntlayerServerContext: {
|
|
7
7
|
Provider: ({ children, value, }: {
|
|
8
8
|
children: React.ReactNode;
|
|
9
|
-
value: Locales;
|
|
9
|
+
value: "hr" | "th" | "tr" | "id" | "is" | Locales | "af" | "af-ZA" | "ar" | "ar-AE" | "ar-BH" | "ar-DZ" | "ar-EG" | "ar-IQ" | "ar-JO" | "ar-KW" | "ar-LB" | "ar-LY" | "ar-MA" | "ar-OM" | "ar-QA" | "ar-SA" | "ar-SY" | "ar-TN" | "ar-YE" | "az" | "az-AZ" | "be" | "be-BY" | "bg" | "bg-BG" | "bs" | "bs-BA" | "ca" | "ca-ES" | "cs" | "cs-CZ" | "cy" | "cy-GB" | "da" | "da-DK" | "de" | "de-AT" | "de-CH" | "de-DE" | "de-LI" | "de-LU" | "dv" | "dv-MV" | "el" | "el-GR" | "en" | "en-AU" | "en-BZ" | "en-CA" | "en-CB" | "en-GB" | "en-IE" | "en-JM" | "en-NZ" | "en-PH" | "en-TT" | "en-US" | "en-ZA" | "en-ZW" | "eo" | "es" | "es-AR" | "es-BO" | "es-CL" | "es-CO" | "es-CR" | "es-DO" | "es-EC" | "es-ES" | "es-GT" | "es-HN" | "es-MX" | "es-NI" | "es-PA" | "es-PE" | "es-PR" | "es-PY" | "es-SV" | "es-UY" | "es-VE" | "et" | "et-EE" | "eu" | "eu-ES" | "fa" | "fa-IR" | "fi" | "fi-FI" | "fo" | "fo-FO" | "fr" | "fr-BE" | "fr-CA" | "fr-CH" | "fr-FR" | "fr-LU" | "fr-MC" | "gl" | "gl-ES" | "gu" | "gu-IN" | "he" | "he-IL" | "hi" | "hi-IN" | "hr-BA" | "hr-HR" | "hu" | "hu-HU" | "hy" | "hy-AM" | "id-ID" | "is-IS" | "it" | "it-CH" | "it-IT" | "ja" | "ja-JP" | "ka" | "ka-GE" | "kk" | "kk-KZ" | "kn" | "kn-IN" | "ko" | "ko-KR" | "kok" | "kok-IN" | "ky" | "ky-KG" | "lt" | "lt-LT" | "lv" | "lv-LV" | "mi" | "mi-NZ" | "mk" | "mk-MK" | "mn" | "mn-MN" | "mr" | "mr-IN" | "ms" | "ms-BN" | "ms-MY" | "mt" | "mt-MT" | "nb" | "nb-NO" | "nl" | "nl-BE" | "nl-NL" | "nn-NO" | "ns" | "ns-ZA" | "pa" | "pa-IN" | "pl" | "pl-PL" | "ps" | "ps-AR" | "pt" | "pt-BR" | "pt-PT" | "qu" | "qu-BO" | "qu-EC" | "qu-PE" | "ro" | "ro-RO" | "ru" | "ru-RU" | "sa" | "sa-IN" | "se" | "se-FI" | "se-NO" | "se-SE" | "sk" | "sk-SK" | "sl" | "sl-SI" | "sq" | "sq-AL" | "sr" | "sr-BA" | "sr-SP" | "sv" | "sv-FI" | "sv-SE" | "sw" | "sw-KE" | "syr" | "syr-SY" | "ta" | "ta-IN" | "te" | "te-IN" | "th-TH" | "tl" | "tl-PH" | "tn" | "tn-ZA" | "tr-TR" | "tt" | "tt-RU" | "ts" | "uk" | "uk-UA" | "ur" | "ur-PK" | "uz" | "uz-UZ" | "vi" | "vi-VN" | "xh" | "xh-ZA" | "zh" | "zh-Hans" | "zh-CN" | "zh-HK" | "zh-MO" | "zh-SG" | "zh-Hant" | "zu" | "zu-ZA";
|
|
10
10
|
}) => React.ReactNode;
|
|
11
11
|
Consumer: ({ children, }: {
|
|
12
|
-
children: (context: Locales) => React.ReactNode;
|
|
12
|
+
children: (context: "hr" | "th" | "tr" | "id" | "is" | Locales | "af" | "af-ZA" | "ar" | "ar-AE" | "ar-BH" | "ar-DZ" | "ar-EG" | "ar-IQ" | "ar-JO" | "ar-KW" | "ar-LB" | "ar-LY" | "ar-MA" | "ar-OM" | "ar-QA" | "ar-SA" | "ar-SY" | "ar-TN" | "ar-YE" | "az" | "az-AZ" | "be" | "be-BY" | "bg" | "bg-BG" | "bs" | "bs-BA" | "ca" | "ca-ES" | "cs" | "cs-CZ" | "cy" | "cy-GB" | "da" | "da-DK" | "de" | "de-AT" | "de-CH" | "de-DE" | "de-LI" | "de-LU" | "dv" | "dv-MV" | "el" | "el-GR" | "en" | "en-AU" | "en-BZ" | "en-CA" | "en-CB" | "en-GB" | "en-IE" | "en-JM" | "en-NZ" | "en-PH" | "en-TT" | "en-US" | "en-ZA" | "en-ZW" | "eo" | "es" | "es-AR" | "es-BO" | "es-CL" | "es-CO" | "es-CR" | "es-DO" | "es-EC" | "es-ES" | "es-GT" | "es-HN" | "es-MX" | "es-NI" | "es-PA" | "es-PE" | "es-PR" | "es-PY" | "es-SV" | "es-UY" | "es-VE" | "et" | "et-EE" | "eu" | "eu-ES" | "fa" | "fa-IR" | "fi" | "fi-FI" | "fo" | "fo-FO" | "fr" | "fr-BE" | "fr-CA" | "fr-CH" | "fr-FR" | "fr-LU" | "fr-MC" | "gl" | "gl-ES" | "gu" | "gu-IN" | "he" | "he-IL" | "hi" | "hi-IN" | "hr-BA" | "hr-HR" | "hu" | "hu-HU" | "hy" | "hy-AM" | "id-ID" | "is-IS" | "it" | "it-CH" | "it-IT" | "ja" | "ja-JP" | "ka" | "ka-GE" | "kk" | "kk-KZ" | "kn" | "kn-IN" | "ko" | "ko-KR" | "kok" | "kok-IN" | "ky" | "ky-KG" | "lt" | "lt-LT" | "lv" | "lv-LV" | "mi" | "mi-NZ" | "mk" | "mk-MK" | "mn" | "mn-MN" | "mr" | "mr-IN" | "ms" | "ms-BN" | "ms-MY" | "mt" | "mt-MT" | "nb" | "nb-NO" | "nl" | "nl-BE" | "nl-NL" | "nn-NO" | "ns" | "ns-ZA" | "pa" | "pa-IN" | "pl" | "pl-PL" | "ps" | "ps-AR" | "pt" | "pt-BR" | "pt-PT" | "qu" | "qu-BO" | "qu-EC" | "qu-PE" | "ro" | "ro-RO" | "ru" | "ru-RU" | "sa" | "sa-IN" | "se" | "se-FI" | "se-NO" | "se-SE" | "sk" | "sk-SK" | "sl" | "sl-SI" | "sq" | "sq-AL" | "sr" | "sr-BA" | "sr-SP" | "sv" | "sv-FI" | "sv-SE" | "sw" | "sw-KE" | "syr" | "syr-SY" | "ta" | "ta-IN" | "te" | "te-IN" | "th-TH" | "tl" | "tl-PH" | "tn" | "tn-ZA" | "tr-TR" | "tt" | "tt-RU" | "ts" | "uk" | "uk-UA" | "ur" | "ur-PK" | "uz" | "uz-UZ" | "vi" | "vi-VN" | "xh" | "xh-ZA" | "zh" | "zh-Hans" | "zh-CN" | "zh-HK" | "zh-MO" | "zh-SG" | "zh-Hant" | "zu" | "zu-ZA") => React.ReactNode;
|
|
13
13
|
}) => React.ReactNode;
|
|
14
14
|
_storage: () => {
|
|
15
|
-
value: Locales;
|
|
15
|
+
value: "hr" | "th" | "tr" | "id" | "is" | Locales | "af" | "af-ZA" | "ar" | "ar-AE" | "ar-BH" | "ar-DZ" | "ar-EG" | "ar-IQ" | "ar-JO" | "ar-KW" | "ar-LB" | "ar-LY" | "ar-MA" | "ar-OM" | "ar-QA" | "ar-SA" | "ar-SY" | "ar-TN" | "ar-YE" | "az" | "az-AZ" | "be" | "be-BY" | "bg" | "bg-BG" | "bs" | "bs-BA" | "ca" | "ca-ES" | "cs" | "cs-CZ" | "cy" | "cy-GB" | "da" | "da-DK" | "de" | "de-AT" | "de-CH" | "de-DE" | "de-LI" | "de-LU" | "dv" | "dv-MV" | "el" | "el-GR" | "en" | "en-AU" | "en-BZ" | "en-CA" | "en-CB" | "en-GB" | "en-IE" | "en-JM" | "en-NZ" | "en-PH" | "en-TT" | "en-US" | "en-ZA" | "en-ZW" | "eo" | "es" | "es-AR" | "es-BO" | "es-CL" | "es-CO" | "es-CR" | "es-DO" | "es-EC" | "es-ES" | "es-GT" | "es-HN" | "es-MX" | "es-NI" | "es-PA" | "es-PE" | "es-PR" | "es-PY" | "es-SV" | "es-UY" | "es-VE" | "et" | "et-EE" | "eu" | "eu-ES" | "fa" | "fa-IR" | "fi" | "fi-FI" | "fo" | "fo-FO" | "fr" | "fr-BE" | "fr-CA" | "fr-CH" | "fr-FR" | "fr-LU" | "fr-MC" | "gl" | "gl-ES" | "gu" | "gu-IN" | "he" | "he-IL" | "hi" | "hi-IN" | "hr-BA" | "hr-HR" | "hu" | "hu-HU" | "hy" | "hy-AM" | "id-ID" | "is-IS" | "it" | "it-CH" | "it-IT" | "ja" | "ja-JP" | "ka" | "ka-GE" | "kk" | "kk-KZ" | "kn" | "kn-IN" | "ko" | "ko-KR" | "kok" | "kok-IN" | "ky" | "ky-KG" | "lt" | "lt-LT" | "lv" | "lv-LV" | "mi" | "mi-NZ" | "mk" | "mk-MK" | "mn" | "mn-MN" | "mr" | "mr-IN" | "ms" | "ms-BN" | "ms-MY" | "mt" | "mt-MT" | "nb" | "nb-NO" | "nl" | "nl-BE" | "nl-NL" | "nn-NO" | "ns" | "ns-ZA" | "pa" | "pa-IN" | "pl" | "pl-PL" | "ps" | "ps-AR" | "pt" | "pt-BR" | "pt-PT" | "qu" | "qu-BO" | "qu-EC" | "qu-PE" | "ro" | "ro-RO" | "ru" | "ru-RU" | "sa" | "sa-IN" | "se" | "se-FI" | "se-NO" | "se-SE" | "sk" | "sk-SK" | "sl" | "sl-SI" | "sq" | "sq-AL" | "sr" | "sr-BA" | "sr-SP" | "sv" | "sv-FI" | "sv-SE" | "sw" | "sw-KE" | "syr" | "syr-SY" | "ta" | "ta-IN" | "te" | "te-IN" | "th-TH" | "tl" | "tl-PH" | "tn" | "tn-ZA" | "tr-TR" | "tt" | "tt-RU" | "ts" | "uk" | "uk-UA" | "ur" | "ur-PK" | "uz" | "uz-UZ" | "vi" | "vi-VN" | "xh" | "xh-ZA" | "zh" | "zh-Hans" | "zh-CN" | "zh-HK" | "zh-MO" | "zh-SG" | "zh-Hant" | "zu" | "zu-ZA";
|
|
16
16
|
};
|
|
17
|
-
_defaultValue: Locales;
|
|
17
|
+
_defaultValue: "hr" | "th" | "tr" | "id" | "is" | Locales | "af" | "af-ZA" | "ar" | "ar-AE" | "ar-BH" | "ar-DZ" | "ar-EG" | "ar-IQ" | "ar-JO" | "ar-KW" | "ar-LB" | "ar-LY" | "ar-MA" | "ar-OM" | "ar-QA" | "ar-SA" | "ar-SY" | "ar-TN" | "ar-YE" | "az" | "az-AZ" | "be" | "be-BY" | "bg" | "bg-BG" | "bs" | "bs-BA" | "ca" | "ca-ES" | "cs" | "cs-CZ" | "cy" | "cy-GB" | "da" | "da-DK" | "de" | "de-AT" | "de-CH" | "de-DE" | "de-LI" | "de-LU" | "dv" | "dv-MV" | "el" | "el-GR" | "en" | "en-AU" | "en-BZ" | "en-CA" | "en-CB" | "en-GB" | "en-IE" | "en-JM" | "en-NZ" | "en-PH" | "en-TT" | "en-US" | "en-ZA" | "en-ZW" | "eo" | "es" | "es-AR" | "es-BO" | "es-CL" | "es-CO" | "es-CR" | "es-DO" | "es-EC" | "es-ES" | "es-GT" | "es-HN" | "es-MX" | "es-NI" | "es-PA" | "es-PE" | "es-PR" | "es-PY" | "es-SV" | "es-UY" | "es-VE" | "et" | "et-EE" | "eu" | "eu-ES" | "fa" | "fa-IR" | "fi" | "fi-FI" | "fo" | "fo-FO" | "fr" | "fr-BE" | "fr-CA" | "fr-CH" | "fr-FR" | "fr-LU" | "fr-MC" | "gl" | "gl-ES" | "gu" | "gu-IN" | "he" | "he-IL" | "hi" | "hi-IN" | "hr-BA" | "hr-HR" | "hu" | "hu-HU" | "hy" | "hy-AM" | "id-ID" | "is-IS" | "it" | "it-CH" | "it-IT" | "ja" | "ja-JP" | "ka" | "ka-GE" | "kk" | "kk-KZ" | "kn" | "kn-IN" | "ko" | "ko-KR" | "kok" | "kok-IN" | "ky" | "ky-KG" | "lt" | "lt-LT" | "lv" | "lv-LV" | "mi" | "mi-NZ" | "mk" | "mk-MK" | "mn" | "mn-MN" | "mr" | "mr-IN" | "ms" | "ms-BN" | "ms-MY" | "mt" | "mt-MT" | "nb" | "nb-NO" | "nl" | "nl-BE" | "nl-NL" | "nn-NO" | "ns" | "ns-ZA" | "pa" | "pa-IN" | "pl" | "pl-PL" | "ps" | "ps-AR" | "pt" | "pt-BR" | "pt-PT" | "qu" | "qu-BO" | "qu-EC" | "qu-PE" | "ro" | "ro-RO" | "ru" | "ru-RU" | "sa" | "sa-IN" | "se" | "se-FI" | "se-NO" | "se-SE" | "sk" | "sk-SK" | "sl" | "sl-SI" | "sq" | "sq-AL" | "sr" | "sr-BA" | "sr-SP" | "sv" | "sv-FI" | "sv-SE" | "sw" | "sw-KE" | "syr" | "syr-SY" | "ta" | "ta-IN" | "te" | "te-IN" | "th-TH" | "tl" | "tl-PH" | "tn" | "tn-ZA" | "tr-TR" | "tt" | "tt-RU" | "ts" | "uk" | "uk-UA" | "ur" | "ur-PK" | "uz" | "uz-UZ" | "vi" | "vi-VN" | "xh" | "xh-ZA" | "zh" | "zh-Hans" | "zh-CN" | "zh-HK" | "zh-MO" | "zh-SG" | "zh-Hant" | "zu" | "zu-ZA";
|
|
18
18
|
};
|
|
19
19
|
/**
|
|
20
20
|
* Hook that provides the current locale
|
|
21
21
|
*/
|
|
22
|
-
export declare const useIntlayer: () => Locales;
|
|
22
|
+
export declare const useIntlayer: () => "hr" | "th" | "tr" | "id" | "is" | Locales | "af" | "af-ZA" | "ar" | "ar-AE" | "ar-BH" | "ar-DZ" | "ar-EG" | "ar-IQ" | "ar-JO" | "ar-KW" | "ar-LB" | "ar-LY" | "ar-MA" | "ar-OM" | "ar-QA" | "ar-SA" | "ar-SY" | "ar-TN" | "ar-YE" | "az" | "az-AZ" | "be" | "be-BY" | "bg" | "bg-BG" | "bs" | "bs-BA" | "ca" | "ca-ES" | "cs" | "cs-CZ" | "cy" | "cy-GB" | "da" | "da-DK" | "de" | "de-AT" | "de-CH" | "de-DE" | "de-LI" | "de-LU" | "dv" | "dv-MV" | "el" | "el-GR" | "en" | "en-AU" | "en-BZ" | "en-CA" | "en-CB" | "en-GB" | "en-IE" | "en-JM" | "en-NZ" | "en-PH" | "en-TT" | "en-US" | "en-ZA" | "en-ZW" | "eo" | "es" | "es-AR" | "es-BO" | "es-CL" | "es-CO" | "es-CR" | "es-DO" | "es-EC" | "es-ES" | "es-GT" | "es-HN" | "es-MX" | "es-NI" | "es-PA" | "es-PE" | "es-PR" | "es-PY" | "es-SV" | "es-UY" | "es-VE" | "et" | "et-EE" | "eu" | "eu-ES" | "fa" | "fa-IR" | "fi" | "fi-FI" | "fo" | "fo-FO" | "fr" | "fr-BE" | "fr-CA" | "fr-CH" | "fr-FR" | "fr-LU" | "fr-MC" | "gl" | "gl-ES" | "gu" | "gu-IN" | "he" | "he-IL" | "hi" | "hi-IN" | "hr-BA" | "hr-HR" | "hu" | "hu-HU" | "hy" | "hy-AM" | "id-ID" | "is-IS" | "it" | "it-CH" | "it-IT" | "ja" | "ja-JP" | "ka" | "ka-GE" | "kk" | "kk-KZ" | "kn" | "kn-IN" | "ko" | "ko-KR" | "kok" | "kok-IN" | "ky" | "ky-KG" | "lt" | "lt-LT" | "lv" | "lv-LV" | "mi" | "mi-NZ" | "mk" | "mk-MK" | "mn" | "mn-MN" | "mr" | "mr-IN" | "ms" | "ms-BN" | "ms-MY" | "mt" | "mt-MT" | "nb" | "nb-NO" | "nl" | "nl-BE" | "nl-NL" | "nn-NO" | "ns" | "ns-ZA" | "pa" | "pa-IN" | "pl" | "pl-PL" | "ps" | "ps-AR" | "pt" | "pt-BR" | "pt-PT" | "qu" | "qu-BO" | "qu-EC" | "qu-PE" | "ro" | "ro-RO" | "ru" | "ru-RU" | "sa" | "sa-IN" | "se" | "se-FI" | "se-NO" | "se-SE" | "sk" | "sk-SK" | "sl" | "sl-SI" | "sq" | "sq-AL" | "sr" | "sr-BA" | "sr-SP" | "sv" | "sv-FI" | "sv-SE" | "sw" | "sw-KE" | "syr" | "syr-SY" | "ta" | "ta-IN" | "te" | "te-IN" | "th-TH" | "tl" | "tl-PH" | "tn" | "tn-ZA" | "tr-TR" | "tt" | "tt-RU" | "ts" | "uk" | "uk-UA" | "ur" | "ur-PK" | "uz" | "uz-UZ" | "vi" | "vi-VN" | "xh" | "xh-ZA" | "zh" | "zh-Hans" | "zh-CN" | "zh-HK" | "zh-MO" | "zh-SG" | "zh-Hant" | "zu" | "zu-ZA";
|
|
23
23
|
/**
|
|
24
24
|
* Get the current locale
|
|
25
25
|
*/
|
|
26
|
-
export declare const locale: Locales;
|
|
26
|
+
export declare const locale: "hr" | "th" | "tr" | "id" | "is" | Locales | "af" | "af-ZA" | "ar" | "ar-AE" | "ar-BH" | "ar-DZ" | "ar-EG" | "ar-IQ" | "ar-JO" | "ar-KW" | "ar-LB" | "ar-LY" | "ar-MA" | "ar-OM" | "ar-QA" | "ar-SA" | "ar-SY" | "ar-TN" | "ar-YE" | "az" | "az-AZ" | "be" | "be-BY" | "bg" | "bg-BG" | "bs" | "bs-BA" | "ca" | "ca-ES" | "cs" | "cs-CZ" | "cy" | "cy-GB" | "da" | "da-DK" | "de" | "de-AT" | "de-CH" | "de-DE" | "de-LI" | "de-LU" | "dv" | "dv-MV" | "el" | "el-GR" | "en" | "en-AU" | "en-BZ" | "en-CA" | "en-CB" | "en-GB" | "en-IE" | "en-JM" | "en-NZ" | "en-PH" | "en-TT" | "en-US" | "en-ZA" | "en-ZW" | "eo" | "es" | "es-AR" | "es-BO" | "es-CL" | "es-CO" | "es-CR" | "es-DO" | "es-EC" | "es-ES" | "es-GT" | "es-HN" | "es-MX" | "es-NI" | "es-PA" | "es-PE" | "es-PR" | "es-PY" | "es-SV" | "es-UY" | "es-VE" | "et" | "et-EE" | "eu" | "eu-ES" | "fa" | "fa-IR" | "fi" | "fi-FI" | "fo" | "fo-FO" | "fr" | "fr-BE" | "fr-CA" | "fr-CH" | "fr-FR" | "fr-LU" | "fr-MC" | "gl" | "gl-ES" | "gu" | "gu-IN" | "he" | "he-IL" | "hi" | "hi-IN" | "hr-BA" | "hr-HR" | "hu" | "hu-HU" | "hy" | "hy-AM" | "id-ID" | "is-IS" | "it" | "it-CH" | "it-IT" | "ja" | "ja-JP" | "ka" | "ka-GE" | "kk" | "kk-KZ" | "kn" | "kn-IN" | "ko" | "ko-KR" | "kok" | "kok-IN" | "ky" | "ky-KG" | "lt" | "lt-LT" | "lv" | "lv-LV" | "mi" | "mi-NZ" | "mk" | "mk-MK" | "mn" | "mn-MN" | "mr" | "mr-IN" | "ms" | "ms-BN" | "ms-MY" | "mt" | "mt-MT" | "nb" | "nb-NO" | "nl" | "nl-BE" | "nl-NL" | "nn-NO" | "ns" | "ns-ZA" | "pa" | "pa-IN" | "pl" | "pl-PL" | "ps" | "ps-AR" | "pt" | "pt-BR" | "pt-PT" | "qu" | "qu-BO" | "qu-EC" | "qu-PE" | "ro" | "ro-RO" | "ru" | "ru-RU" | "sa" | "sa-IN" | "se" | "se-FI" | "se-NO" | "se-SE" | "sk" | "sk-SK" | "sl" | "sl-SI" | "sq" | "sq-AL" | "sr" | "sr-BA" | "sr-SP" | "sv" | "sv-FI" | "sv-SE" | "sw" | "sw-KE" | "syr" | "syr-SY" | "ta" | "ta-IN" | "te" | "te-IN" | "th-TH" | "tl" | "tl-PH" | "tn" | "tn-ZA" | "tr-TR" | "tt" | "tt-RU" | "ts" | "uk" | "uk-UA" | "ur" | "ur-PK" | "uz" | "uz-UZ" | "vi" | "vi-VN" | "xh" | "xh-ZA" | "zh" | "zh-Hans" | "zh-CN" | "zh-HK" | "zh-MO" | "zh-SG" | "zh-Hant" | "zu" | "zu-ZA";
|
|
27
27
|
export type IntlayerServerProviderProps = PropsWithChildren & {
|
|
28
|
-
locale?: Locales
|
|
28
|
+
locale?: Locales | `${Locales}`;
|
|
29
29
|
};
|
|
30
30
|
/**
|
|
31
31
|
* Provider that store the current locale on the server side
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IntlayerServerProvider.d.ts","sourceRoot":"","sources":["../../../src/server/IntlayerServerProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAoB,MAAM,yBAAyB,CAAC;AACzE,OAAO,KAAK,EAAE,EAAE,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAKnD;;GAEG;AACH,eAAO,MAAM,qBAAqB;;
|
|
1
|
+
{"version":3,"file":"IntlayerServerProvider.d.ts","sourceRoot":"","sources":["../../../src/server/IntlayerServerProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAoB,MAAM,yBAAyB,CAAC;AACzE,OAAO,KAAK,EAAE,EAAE,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAKnD;;GAEG;AACH,eAAO,MAAM,qBAAqB;;kBA6B4a,MAAO,SAAS;;UAAuB,MAAO,SAAS;;mkEAA+E,MAAO,SAAS;UAAS,MAAO,SAAS;;;;;CA3B7mB,CAAC;AAEjB;;GAEG;AACH,eAAO,MAAM,WAAW,0iEAAgD,CAAC;AAEzE;;GAEG;AACH,eAAO,MAAM,MAAM,oiEAA0C,CAAC;AAE9D,MAAM,MAAM,2BAA2B,GAAG,iBAAiB,GAAG;IAC5D,MAAM,CAAC,EAAE,OAAO,GAAG,GAAG,OAAO,EAAE,CAAC;CACjC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,sBAAsB,EAAE,EAAE,CAAC,2BAA2B,CAOlE,CAAC"}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
export { getLocaleTranslation as getLocaleContent } from './getLocaleTranslation';
|
|
2
|
-
export { useTraduction } from './useTraduction';
|
|
3
1
|
export { IntlayerServerContext as IntlayerServer, locale, IntlayerServerProvider, } from './IntlayerServerProvider';
|
|
4
2
|
export { useIntlayer } from './useIntlayer';
|
|
5
3
|
export { useDictionary } from './useDictionary';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,IAAI,cAAc,EACvC,MAAM,EACN,sBAAsB,GACvB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC"}
|
package/dist/types/server/t.d.ts
CHANGED
|
@@ -1,9 +1,25 @@
|
|
|
1
1
|
import type { Locales } from '@intlayer/config/client';
|
|
2
|
-
import type
|
|
2
|
+
import { type LanguageContent } from '@intlayer/core';
|
|
3
3
|
/**
|
|
4
|
-
* On the
|
|
4
|
+
* On the server side, hook to get the translation content based on the locale
|
|
5
5
|
*
|
|
6
|
-
* If
|
|
6
|
+
* If not locale found, it will return the content related to the default locale.
|
|
7
|
+
*
|
|
8
|
+
* Return either the content editor, or the content itself depending on the configuration.
|
|
9
|
+
*
|
|
10
|
+
* Usage:
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* const content = t<string>({
|
|
14
|
+
* en: 'Hello',
|
|
15
|
+
* fr: 'Bonjour',
|
|
16
|
+
* }, 'fr');
|
|
17
|
+
* // 'Bonjour'
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* Using TypeScript:
|
|
21
|
+
* - this function will require each locale to be defined if defined in the project configuration.
|
|
22
|
+
* - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.
|
|
7
23
|
*/
|
|
8
|
-
export declare const t: <Content = string>(multilangContent: LanguageContent<Content>, locale?: Locales) => Content;
|
|
24
|
+
export declare const t: <Content = string>(multilangContent: LanguageContent<Content>, locale?: Locales | `${Locales}`) => Content;
|
|
9
25
|
//# sourceMappingURL=t.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"t.d.ts","sourceRoot":"","sources":["../../../src/server/t.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"t.d.ts","sourceRoot":"","sources":["../../../src/server/t.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAGvD,OAAO,EAAE,KAAK,eAAe,EAAkB,MAAM,gBAAgB,CAAC;AAEtE;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,CAAC,GAAI,OAAO,6BACL,eAAe,CAAC,OAAO,CAAC,WACjC,OAAO,GAAG,GAAG,OAAO,EAAE,YAQhC,CAAC"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Locales } from '@intlayer/config/client';
|
|
2
|
+
import { type Dictionary } from '@intlayer/core';
|
|
2
3
|
/**
|
|
3
4
|
* On the server side, Hook that transform a dictionary and return the content
|
|
4
5
|
*
|
|
5
6
|
* If the locale is not provided, it will use the locale from the server context
|
|
6
7
|
*/
|
|
7
|
-
export declare const useDictionary:
|
|
8
|
+
export declare const useDictionary: <T extends Dictionary>(dictionary: T, locale?: Locales | `${Locales}`, isRenderEditor?: boolean) => import("@intlayer/core").DeepTransformContent<T["content"], import("../plugins").IInterpreterPluginState>;
|
|
8
9
|
//# sourceMappingURL=useDictionary.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionary.d.ts","sourceRoot":"","sources":["../../../src/server/useDictionary.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useDictionary.d.ts","sourceRoot":"","sources":["../../../src/server/useDictionary.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAKjD;;;;GAIG;AACH,eAAO,MAAM,aAAa,GAAI,CAAC,SAAS,UAAU,cACpC,CAAC,WACJ,OAAO,GAAG,GAAG,OAAO,EAAE,wIAOhC,CAAC"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Locales } from '@intlayer/config/client';
|
|
2
|
+
import { type DictionaryKeys } from '@intlayer/core';
|
|
2
3
|
/**
|
|
3
4
|
* On the server side, Hook that picking one dictionary by its key and return the content
|
|
4
5
|
*
|
|
5
6
|
* If the locale is not provided, it will use the locale from the server context
|
|
6
7
|
*/
|
|
7
|
-
export declare const useIntlayer:
|
|
8
|
+
export declare const useIntlayer: <T extends DictionaryKeys, K extends Locales | `${Locales}`>(key: T, locale?: K, isRenderEditor?: boolean) => import("@intlayer/core").DeepTransformContent<import("intlayer").IntlayerDictionaryTypesConnector[T]["content"], import("../plugins").IInterpreterPluginState>;
|
|
8
9
|
//# sourceMappingURL=useIntlayer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIntlayer.d.ts","sourceRoot":"","sources":["../../../src/server/useIntlayer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useIntlayer.d.ts","sourceRoot":"","sources":["../../../src/server/useIntlayer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAGvD,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAGrD;;;;GAIG;AACH,eAAO,MAAM,WAAW,GACtB,CAAC,SAAS,cAAc,EACxB,CAAC,SAAS,OAAO,GAAG,GAAG,OAAO,EAAE,OAE3B,CAAC,WACG,CAAC,6LAOX,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-intlayer",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Easily internationalize i18n your React applications with type-safe multilingual content management.",
|
|
6
6
|
"keywords": [
|
|
@@ -68,11 +68,11 @@
|
|
|
68
68
|
],
|
|
69
69
|
"dependencies": {
|
|
70
70
|
"js-cookie": "^3.0.5",
|
|
71
|
-
"@intlayer/api": "
|
|
72
|
-
"@intlayer/config": "
|
|
73
|
-
"@intlayer/core": "
|
|
74
|
-
"@intlayer/dictionaries-entry": "
|
|
75
|
-
"@intlayer/editor-react": "
|
|
71
|
+
"@intlayer/api": "5.0.0",
|
|
72
|
+
"@intlayer/config": "5.0.0",
|
|
73
|
+
"@intlayer/core": "5.0.0",
|
|
74
|
+
"@intlayer/dictionaries-entry": "5.0.0",
|
|
75
|
+
"@intlayer/editor-react": "5.0.0"
|
|
76
76
|
},
|
|
77
77
|
"devDependencies": {
|
|
78
78
|
"@craco/types": "^7.1.0",
|
|
@@ -87,21 +87,21 @@
|
|
|
87
87
|
"tsc-alias": "^1.8.10",
|
|
88
88
|
"tsup": "^8.3.5",
|
|
89
89
|
"typescript": "^5.7.3",
|
|
90
|
-
"@
|
|
91
|
-
"@
|
|
90
|
+
"@utils/eslint-config": "1.0.4",
|
|
91
|
+
"@intlayer/backend": "5.0.0",
|
|
92
92
|
"@utils/ts-config-types": "1.0.4",
|
|
93
|
-
"@utils/
|
|
94
|
-
"@utils/
|
|
93
|
+
"@utils/ts-config": "1.0.4",
|
|
94
|
+
"@utils/tsup-config": "1.0.4"
|
|
95
95
|
},
|
|
96
96
|
"peerDependencies": {
|
|
97
97
|
"react": ">=16.0.0",
|
|
98
98
|
"react-dom": ">=16.0.0",
|
|
99
|
-
"@intlayer/api": "
|
|
100
|
-
"@intlayer/config": "
|
|
101
|
-
"@intlayer/
|
|
102
|
-
"@intlayer/
|
|
103
|
-
"intlayer": "
|
|
104
|
-
"@intlayer/
|
|
99
|
+
"@intlayer/api": "5.0.0",
|
|
100
|
+
"@intlayer/config": "5.0.0",
|
|
101
|
+
"@intlayer/core": "5.0.0",
|
|
102
|
+
"@intlayer/dictionaries-entry": "5.0.0",
|
|
103
|
+
"intlayer": "5.0.0",
|
|
104
|
+
"@intlayer/editor-react": "5.0.0"
|
|
105
105
|
},
|
|
106
106
|
"engines": {
|
|
107
107
|
"node": ">=14.18"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/getEnumeration.ts"],"sourcesContent":["import { type QuantityContent, getEnumerationContent } from '@intlayer/core';\n\n/**\n * Allow to pick a content based on a quantity.\n *\n * Return either the content editor, or the content itself depending on the configuration.\n *\n * Usage:\n *\n * ```ts\n * const content = getEnumeration({\n * '<=-2.3': 'You have less than -2.3',\n * '<1': 'You have less than one',\n * '2': 'You have two',\n * '>=3': 'You have three or more',\n * }, 2);\n * // 'You have two'\n * ```\n *\n * The order of the keys will define the priority of the content.\n *\n * ```ts\n * const content = getEnumeration({\n * '<4': 'You have less than four',\n * '2': 'You have two',\n * }, 2);\n * // 'You have less than four'\n * ```\n *\n */\nexport const getEnumeration = <Content>(\n enumerationContent: QuantityContent<Content>,\n quantity: number\n): Content => {\n const result: Content = getEnumerationContent<Content>(\n enumerationContent,\n quantity\n );\n\n return result;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA4D;AA8BrD,MAAM,iBAAiB,CAC5B,oBACA,aACY;AACZ,QAAM,aAAkB;AAAA,IACtB;AAAA,IACA;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/getIntlayerAsync.ts"],"sourcesContent":["'use client';\n\nimport { fetchDistantDictionary } from '@intlayer/api';\nimport type { Locales } from '@intlayer/config/client';\nimport { DeclarationContent } from 'intlayer';\nimport { getDictionary } from './getDictionary';\nimport { DictionaryKeys, DataFromDictionaryKey } from './getIntlayer';\n\nexport type GetIntlayerAsync = <\n T extends DictionaryKeys,\n L extends Locales,\n R extends boolean = true,\n>(\n key: T,\n locale?: L,\n isRenderEditor?: R\n) => Promise<DataFromDictionaryKey<T, L, R> | null>;\n\n/**\n * On the client side, Hook that picking one dictionary by its key and return the content\n *\n * This hook will prerender the locale dictionary and fetch simultaneously the distant dictionaries to hydrate it.\n *\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const getIntlayerAsync: GetIntlayerAsync = async <\n T extends DictionaryKeys,\n L extends Locales,\n R extends boolean = true,\n>(\n key: T,\n locale?: L,\n isRenderEditor = true as R\n) => {\n const jsonDistantDictionary = await fetchDistantDictionary(key);\n\n if (jsonDistantDictionary) {\n return getDictionary(\n jsonDistantDictionary as unknown as DeclarationContent,\n locale,\n isRenderEditor\n ) as DataFromDictionaryKey<T, L, R>;\n }\n\n return null;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,iBAAuC;AAGvC,2BAA8B;AAqBvB,MAAM,mBAAqC,OAKhD,KACA,QACA,iBAAiB,SACd;AACH,QAAM,wBAAwB,UAAM,mCAAuB,GAAG;AAE9D,MAAI,uBAAuB;AACzB,eAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/getTranslation.ts"],"sourcesContent":["import { type Locales, getConfiguration } from '@intlayer/config/client';\nimport { type LanguageContent, getTranslationContent } from '@intlayer/core';\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?: Locales\n): Content => {\n const { defaultLocale } = getConfiguration().internationalization;\n\n const result: Content = getTranslationContent<Content>(\n languageContent,\n locale ?? defaultLocale\n );\n\n return result;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA+C;AAC/C,kBAA4D;AAuBrD,MAAM,iBAAiB,CAC5B,iBACA,WACY;AACZ,QAAM,EAAE,cAAc,QAAI,gCAAiB,EAAE;AAE7C,QAAM,aAAkB;AAAA,IACtB;AAAA,IACA,UAAU;AAAA,EACZ;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __copyProps = (to, from, except, desc) => {
|
|
7
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
-
for (let key of __getOwnPropNames(from))
|
|
9
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
-
}
|
|
12
|
-
return to;
|
|
13
|
-
};
|
|
14
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
-
var contentDictionary_exports = {};
|
|
16
|
-
module.exports = __toCommonJS(contentDictionary_exports);
|
|
17
|
-
//# sourceMappingURL=contentDictionary.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/processDictionary/contentDictionary.ts"],"sourcesContent":["import type { KeyPath, Locales } from '@intlayer/core';\nimport type { ReactNode } from 'react';\n\nexport type TransformedContentValue =\n | string\n | ReactNode\n | {\n [key: string]: TransformedContentValue;\n }\n | undefined\n | ((quantity: number) => TransformedContentValue);\n\nexport type TransformedContentObject = {\n dictionaryKey: string;\n dictionaryPath: string;\n keyPath: KeyPath[];\n locale: Locales;\n content: TransformedContentValue | TransformedContentValue[] | undefined;\n};\n\nexport type TransformedContent =\n | Record<\n string,\n | TransformedContentValue\n | TransformedContentValue[]\n | TransformedContentObject\n | undefined\n >\n | ReactNode;\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var processDictionary_exports = {};
|
|
20
|
-
__export(processDictionary_exports, {
|
|
21
|
-
processDictionary: () => processDictionary,
|
|
22
|
-
processNode: () => processNode
|
|
23
|
-
});
|
|
24
|
-
module.exports = __toCommonJS(processDictionary_exports);
|
|
25
|
-
var import_client = require("@intlayer/config/client");
|
|
26
|
-
var import_core = require("@intlayer/core");
|
|
27
|
-
var import_react = require("react");
|
|
28
|
-
var import_getEnumeration = require('../getEnumeration.cjs');
|
|
29
|
-
var import_getTranslation = require('../getTranslation.cjs');
|
|
30
|
-
const {
|
|
31
|
-
internationalization: { defaultLocale }
|
|
32
|
-
} = (0, import_client.getConfiguration)();
|
|
33
|
-
const processTranslation = (languageContent, locale, dictionaryKey, dictionaryPath, keyPath = []) => {
|
|
34
|
-
const translationResult = (0, import_getTranslation.getTranslation)(
|
|
35
|
-
languageContent,
|
|
36
|
-
locale
|
|
37
|
-
);
|
|
38
|
-
const resultKeyPath = [
|
|
39
|
-
...keyPath,
|
|
40
|
-
{ type: import_core.NodeType.Translation, key: locale }
|
|
41
|
-
];
|
|
42
|
-
return processDictionary(
|
|
43
|
-
translationResult,
|
|
44
|
-
dictionaryKey,
|
|
45
|
-
dictionaryPath,
|
|
46
|
-
resultKeyPath,
|
|
47
|
-
locale
|
|
48
|
-
);
|
|
49
|
-
};
|
|
50
|
-
const processEnumeration = (enumerationContent, locale, dictionaryKey, dictionaryPath, keyPath = []) => (quantity) => {
|
|
51
|
-
const enumerationResult = (0, import_getEnumeration.getEnumeration)(
|
|
52
|
-
enumerationContent,
|
|
53
|
-
quantity
|
|
54
|
-
);
|
|
55
|
-
const matchingCondition = (0, import_core.findMatchingCondition)(
|
|
56
|
-
enumerationContent,
|
|
57
|
-
quantity
|
|
58
|
-
);
|
|
59
|
-
const resultKeyPath = [
|
|
60
|
-
...keyPath,
|
|
61
|
-
{ type: import_core.NodeType.Enumeration, key: matchingCondition.toString() }
|
|
62
|
-
];
|
|
63
|
-
return processDictionary(
|
|
64
|
-
enumerationResult,
|
|
65
|
-
dictionaryKey,
|
|
66
|
-
dictionaryPath,
|
|
67
|
-
resultKeyPath,
|
|
68
|
-
locale
|
|
69
|
-
);
|
|
70
|
-
};
|
|
71
|
-
const isReactNode = (node) => typeof node?.key !== "undefined" && typeof node?.props !== "undefined";
|
|
72
|
-
const processNode = (field, locale, dictionaryKey, dictionaryPath, keyPath = []) => {
|
|
73
|
-
if (typeof field === "object") {
|
|
74
|
-
if (field.nodeType === import_core.NodeType.Translation) {
|
|
75
|
-
return processTranslation(
|
|
76
|
-
field[import_core.NodeType.Translation],
|
|
77
|
-
locale,
|
|
78
|
-
dictionaryKey,
|
|
79
|
-
dictionaryPath,
|
|
80
|
-
keyPath
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
|
-
if (field.nodeType === import_core.NodeType.Enumeration) {
|
|
84
|
-
return processEnumeration(
|
|
85
|
-
field[import_core.NodeType.Enumeration],
|
|
86
|
-
locale,
|
|
87
|
-
dictionaryKey,
|
|
88
|
-
dictionaryPath,
|
|
89
|
-
keyPath
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
return processDictionary(
|
|
94
|
-
field,
|
|
95
|
-
dictionaryKey,
|
|
96
|
-
dictionaryPath,
|
|
97
|
-
keyPath,
|
|
98
|
-
locale
|
|
99
|
-
);
|
|
100
|
-
};
|
|
101
|
-
const createReactElement = (element) => {
|
|
102
|
-
if (typeof element === "string") {
|
|
103
|
-
return element;
|
|
104
|
-
}
|
|
105
|
-
const convertChildrenAsArray = (element2) => {
|
|
106
|
-
if (element2?.props && typeof element2.props.children === "object") {
|
|
107
|
-
const childrenResult = [];
|
|
108
|
-
const { children } = element2.props;
|
|
109
|
-
Object.keys(children ?? {}).forEach((key) => {
|
|
110
|
-
childrenResult.push(
|
|
111
|
-
createReactElement((children ?? {})[key])
|
|
112
|
-
);
|
|
113
|
-
});
|
|
114
|
-
return {
|
|
115
|
-
...element2,
|
|
116
|
-
props: { ...element2.props, children: childrenResult }
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
return {
|
|
120
|
-
...element2,
|
|
121
|
-
props: { ...element2.props, children: element2.props.children }
|
|
122
|
-
};
|
|
123
|
-
};
|
|
124
|
-
const fixedElement = convertChildrenAsArray(
|
|
125
|
-
element
|
|
126
|
-
);
|
|
127
|
-
const { type, props } = fixedElement;
|
|
128
|
-
return (0, import_react.createElement)(
|
|
129
|
-
type ?? "div",
|
|
130
|
-
props,
|
|
131
|
-
...props.children
|
|
132
|
-
);
|
|
133
|
-
};
|
|
134
|
-
const traceKeys = ["filePath", "nodeType"];
|
|
135
|
-
const processDictionary = (content, dictionaryKey, dictionaryPath, keyPath = [], locale = defaultLocale) => {
|
|
136
|
-
if (isReactNode(content)) {
|
|
137
|
-
return createReactElement(
|
|
138
|
-
content
|
|
139
|
-
);
|
|
140
|
-
}
|
|
141
|
-
if (content && typeof content === "object") {
|
|
142
|
-
const isArray = Array.isArray(content);
|
|
143
|
-
let result = {};
|
|
144
|
-
if (typeof content.nodeType !== "undefined") {
|
|
145
|
-
return processNode(
|
|
146
|
-
content,
|
|
147
|
-
locale,
|
|
148
|
-
dictionaryKey,
|
|
149
|
-
dictionaryPath,
|
|
150
|
-
keyPath
|
|
151
|
-
);
|
|
152
|
-
} else if (isArray) {
|
|
153
|
-
result = content.map((field, key) => {
|
|
154
|
-
const resultKeyPath = [
|
|
155
|
-
...keyPath,
|
|
156
|
-
{ type: import_core.NodeType.Array, key }
|
|
157
|
-
];
|
|
158
|
-
return processNode(
|
|
159
|
-
field,
|
|
160
|
-
locale,
|
|
161
|
-
dictionaryKey,
|
|
162
|
-
dictionaryPath,
|
|
163
|
-
resultKeyPath
|
|
164
|
-
);
|
|
165
|
-
});
|
|
166
|
-
} else {
|
|
167
|
-
for (const key of Object.keys(content)) {
|
|
168
|
-
const field = content[key];
|
|
169
|
-
if (traceKeys.includes(key)) {
|
|
170
|
-
result[key] = field;
|
|
171
|
-
continue;
|
|
172
|
-
}
|
|
173
|
-
const resultKeyPath = [
|
|
174
|
-
...keyPath,
|
|
175
|
-
{ type: import_core.NodeType.Object, key }
|
|
176
|
-
];
|
|
177
|
-
const nodeResult = processNode(
|
|
178
|
-
field,
|
|
179
|
-
locale,
|
|
180
|
-
dictionaryKey,
|
|
181
|
-
dictionaryPath,
|
|
182
|
-
resultKeyPath
|
|
183
|
-
);
|
|
184
|
-
result[key] = nodeResult;
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
return result;
|
|
188
|
-
}
|
|
189
|
-
return {
|
|
190
|
-
content,
|
|
191
|
-
keyPath,
|
|
192
|
-
dictionaryKey,
|
|
193
|
-
dictionaryPath
|
|
194
|
-
};
|
|
195
|
-
};
|
|
196
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
197
|
-
0 && (module.exports = {
|
|
198
|
-
processDictionary,
|
|
199
|
-
processNode
|
|
200
|
-
});
|
|
201
|
-
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/processDictionary/index.ts"],"sourcesContent":["import { type Locales, getConfiguration } from '@intlayer/config/client';\nimport {\n NodeType,\n type QuantityContent,\n type LanguageContent,\n findMatchingCondition,\n type KeyPath,\n type DictionaryValue,\n type TranslationContent,\n type EnumerationContent,\n type TypedNode,\n} from '@intlayer/core';\nimport { type ReactElement, createElement, type ReactNode, JSX } from 'react';\nimport { getEnumeration } from '../getEnumeration';\nimport { getTranslation } from '../getTranslation';\nimport type {\n TransformedContent,\n TransformedContentValue,\n} from './contentDictionary';\n\nconst {\n internationalization: { defaultLocale },\n} = getConfiguration();\n\nconst processTranslation = (\n languageContent: LanguageContent<DictionaryValue>,\n locale: Locales,\n dictionaryKey: string,\n dictionaryPath?: string,\n keyPath: KeyPath[] = []\n): TransformedContent => {\n const translationResult: DictionaryValue = getTranslation<DictionaryValue>(\n languageContent,\n locale\n );\n\n const resultKeyPath: KeyPath[] = [\n ...keyPath,\n { type: NodeType.Translation, key: locale },\n ];\n\n return processDictionary(\n translationResult,\n dictionaryKey,\n dictionaryPath,\n resultKeyPath,\n locale\n );\n};\n\nconst processEnumeration =\n (\n enumerationContent: QuantityContent<DictionaryValue>,\n locale: Locales,\n dictionaryKey: string,\n dictionaryPath?: string,\n keyPath: KeyPath[] = []\n ): TransformedContentValue =>\n (quantity: number): TransformedContentValue => {\n const enumerationResult: DictionaryValue = getEnumeration<DictionaryValue>(\n enumerationContent,\n quantity\n );\n\n const matchingCondition = findMatchingCondition(\n enumerationContent,\n quantity\n );\n\n const resultKeyPath: KeyPath[] = [\n ...keyPath,\n { type: NodeType.Enumeration, key: matchingCondition.toString() },\n ];\n\n return processDictionary(\n enumerationResult,\n dictionaryKey,\n dictionaryPath,\n resultKeyPath,\n locale\n ) as TransformedContentValue;\n };\n\nconst isReactNode = (node: Record<string, unknown>): boolean =>\n typeof node?.key !== 'undefined' && typeof node?.props !== 'undefined';\n\nexport const processNode = (\n field: DictionaryValue | undefined,\n locale: Locales,\n dictionaryKey: string,\n dictionaryPath?: string,\n keyPath: KeyPath[] = []\n): TransformedContentValue => {\n if (typeof field === 'object') {\n if (\n (field as TranslationContent<DictionaryValue>).nodeType ===\n NodeType.Translation\n ) {\n return processTranslation(\n field[\n NodeType.Translation as keyof typeof field\n ] as LanguageContent<DictionaryValue>,\n locale,\n dictionaryKey,\n dictionaryPath,\n keyPath\n ) as TransformedContentValue;\n }\n\n if (\n (field as EnumerationContent<DictionaryValue>).nodeType ===\n NodeType.Enumeration\n ) {\n return processEnumeration(\n field[\n NodeType.Enumeration as keyof typeof field\n ] as QuantityContent<DictionaryValue>,\n locale,\n dictionaryKey,\n dictionaryPath,\n keyPath\n );\n }\n }\n\n return processDictionary(\n field!,\n dictionaryKey,\n dictionaryPath,\n keyPath,\n locale\n ) as TransformedContentValue;\n};\n\n// This function recursively creates React elements from a given JSON-like structure\nconst createReactElement = (element: ReactElement) => {\n if (typeof element === 'string') {\n // If it's a string, simply return it (used for text content)\n return element;\n }\n\n const convertChildrenAsArray = (\n element: ReactElement<{ children?: ReactNode }>\n ): ReactElement<{ children?: ReactNode }> => {\n if (element?.props && typeof element.props.children === 'object') {\n const childrenResult: ReactNode[] = [];\n const { children } = element.props;\n\n // Create the children elements recursively, if any\n Object.keys(children ?? {}).forEach((key) => {\n childrenResult.push(\n createReactElement((children ?? {})[key as keyof typeof children])\n );\n });\n\n return {\n ...element,\n props: { ...element.props, children: childrenResult },\n };\n }\n\n return {\n ...element,\n props: { ...element.props, children: element.props.children },\n };\n };\n\n const fixedElement = convertChildrenAsArray(\n element as ReactElement<{ children?: ReactNode }>\n );\n\n const { type, props } = fixedElement;\n\n // Create and return the React element\n return createElement(\n type ?? 'div',\n props,\n ...(props.children as ReactNode[])\n );\n};\n\nconst traceKeys: string[] = ['filePath', 'nodeType'];\n\n/**\n * Function that process a dictionary and return the result to be used in the application.\n */\nexport const processDictionary = (\n content: DictionaryValue,\n dictionaryKey: string,\n dictionaryPath?: string,\n keyPath: KeyPath[] = [],\n locale: Locales = defaultLocale\n): TransformedContent => {\n // If it's a React element, render it\n if (isReactNode(content as Record<string, unknown>)) {\n return createReactElement(\n content as unknown as ReactElement\n ) as unknown as TransformedContent;\n }\n\n if (content && typeof content === 'object') {\n const isArray = Array.isArray(content);\n\n let result: TransformedContent = {};\n\n if (typeof (content as TypedNode).nodeType !== 'undefined') {\n return processNode(\n content as DictionaryValue,\n locale,\n dictionaryKey,\n dictionaryPath,\n keyPath\n ) as TransformedContent;\n } else if (isArray) {\n // Eslint fix because promises are awaited during build stage\n\n result = (content as DictionaryValue[]).map((field, key) => {\n const resultKeyPath: KeyPath[] = [\n ...keyPath,\n { type: NodeType.Array, key },\n ];\n\n return processNode(\n field,\n locale,\n dictionaryKey,\n dictionaryPath,\n resultKeyPath\n );\n }) as TransformedContent;\n } else {\n // List each key in the content and process it\n for (const key of Object.keys(content)) {\n const field = content[key as keyof typeof content];\n\n if (traceKeys.includes(key)) {\n result[key] = field as TransformedContentValue;\n continue;\n }\n\n const resultKeyPath: KeyPath[] = [\n ...keyPath,\n { type: NodeType.Object, key },\n ];\n\n const nodeResult = processNode(\n field,\n locale,\n dictionaryKey,\n dictionaryPath,\n resultKeyPath\n );\n\n result[key] = nodeResult;\n }\n }\n\n return result;\n }\n\n return {\n content: content as TransformedContentValue,\n keyPath,\n dictionaryKey,\n dictionaryPath,\n };\n};\n"],"mappings":"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","names":["element"]}
|