react-intlayer 1.2.0 → 2.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/dist/cjs/IntlayerProvider.cjs +1 -1
- package/dist/cjs/IntlayerProvider.cjs.map +1 -1
- package/dist/cjs/cli/react-intlayer.cjs +68 -0
- package/dist/cjs/cli/react-intlayer.cjs.map +1 -0
- package/dist/cjs/cli/react-intlayer.d.ts +1 -0
- package/dist/cjs/{ContentEditor/contentRender.cjs → client/ContentEditionLayout.cjs} +9 -14
- package/dist/cjs/client/ContentEditionLayout.cjs.map +1 -0
- package/dist/cjs/client/ContentEditionLayout.d.ts +6 -0
- package/dist/cjs/client/IntlayerClientProvider.cjs +35 -2
- package/dist/cjs/client/IntlayerClientProvider.cjs.map +1 -1
- package/dist/cjs/client/IntlayerClientProvider.d.ts +2 -1
- package/dist/cjs/client/getBrowserLocale.cjs +170 -0
- package/dist/cjs/client/getBrowserLocale.cjs.map +1 -0
- package/dist/cjs/client/getBrowserLocale.d.ts +26 -0
- package/dist/cjs/client/index.cjs +6 -0
- package/dist/cjs/client/index.cjs.map +1 -1
- package/dist/cjs/client/index.d.ts +2 -0
- package/dist/cjs/client/useContent.cjs +2 -2
- package/dist/cjs/client/useContent.cjs.map +1 -1
- package/dist/cjs/client/useContent.d.ts +1 -2
- package/dist/cjs/client/useLocale.cjs +5 -3
- package/dist/cjs/client/useLocale.cjs.map +1 -1
- package/dist/cjs/client/useLocale.d.ts +1 -0
- package/dist/cjs/client/useLocaleBase.cjs +49 -0
- package/dist/cjs/client/useLocaleBase.cjs.map +1 -0
- package/dist/cjs/client/useLocaleBase.d.ts +14 -0
- package/dist/cjs/client/useLocaleCookie.cjs +1 -1
- package/dist/cjs/client/useLocaleCookie.cjs.map +1 -1
- package/dist/cjs/client/useTraduction.cjs.map +1 -1
- package/dist/cjs/client/useTraduction.d.ts +6 -5
- package/dist/cjs/craco/craco.config.cjs +32 -0
- package/dist/cjs/craco/craco.config.cjs.map +1 -0
- package/dist/cjs/craco/craco.config.d.ts +2 -0
- package/dist/cjs/craco/intlayerCracoPlugin.cjs +89 -0
- package/dist/cjs/craco/intlayerCracoPlugin.cjs.map +1 -0
- package/dist/cjs/craco/intlayerCracoPlugin.d.ts +26 -0
- package/dist/cjs/getEnumeration.cjs +0 -4
- package/dist/cjs/getEnumeration.cjs.map +1 -1
- package/dist/cjs/getEnumeration.d.ts +8 -5
- package/dist/cjs/getTranslation.cjs +1 -5
- package/dist/cjs/getTranslation.cjs.map +1 -1
- package/dist/cjs/getTranslation.d.ts +3 -2
- package/dist/cjs/index.cjs +4 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/processDictionary/{contentDictionary.d.cjs → contentDictionary.cjs} +3 -3
- package/dist/cjs/processDictionary/contentDictionary.cjs.map +1 -0
- package/dist/cjs/processDictionary/contentDictionary.d.ts +16 -0
- package/dist/cjs/processDictionary/index.cjs +118 -21
- package/dist/cjs/processDictionary/index.cjs.map +1 -1
- package/dist/cjs/processDictionary/index.d.ts +5 -4
- package/dist/cjs/server/IntlayerServerProvider.cjs +1 -1
- package/dist/cjs/server/IntlayerServerProvider.cjs.map +1 -1
- package/dist/cjs/server/getLocaleTranslation.cjs +1 -1
- package/dist/cjs/server/getLocaleTranslation.cjs.map +1 -1
- package/dist/cjs/server/useTraduction.cjs.map +1 -1
- package/dist/cjs/server/useTraduction.d.ts +4 -3
- package/dist/cjs/useIntlayerBase.cjs +3 -0
- package/dist/cjs/useIntlayerBase.cjs.map +1 -1
- package/dist/cjs/vite/intlayerPlugin.cjs +60 -0
- package/dist/cjs/vite/intlayerPlugin.cjs.map +1 -0
- package/dist/cjs/vite/intlayerPlugin.d.ts +17 -0
- package/dist/esm/IntlayerProvider.mjs +3 -2
- package/dist/esm/IntlayerProvider.mjs.map +1 -1
- package/dist/esm/chunk-ZNCO4QRF.mjs +9 -0
- package/dist/esm/cli/react-intlayer.d.mts +1 -0
- package/dist/esm/cli/react-intlayer.mjs +45 -0
- package/dist/esm/cli/react-intlayer.mjs.map +1 -0
- package/dist/esm/client/ContentEditionLayout.d.mts +6 -0
- package/dist/esm/client/ContentEditionLayout.mjs +11 -0
- package/dist/esm/client/ContentEditionLayout.mjs.map +1 -0
- package/dist/esm/client/IntlayerClientProvider.d.mts +2 -1
- package/dist/esm/client/IntlayerClientProvider.mjs +42 -7
- package/dist/esm/client/IntlayerClientProvider.mjs.map +1 -1
- package/dist/esm/client/getBrowserLocale.d.mts +26 -0
- package/dist/esm/client/getBrowserLocale.mjs +146 -0
- package/dist/esm/client/getBrowserLocale.mjs.map +1 -0
- package/dist/esm/client/index.d.mts +2 -0
- package/dist/esm/client/index.mjs +5 -0
- package/dist/esm/client/index.mjs.map +1 -1
- package/dist/esm/client/useContent.d.mts +1 -2
- package/dist/esm/client/useContent.mjs +3 -2
- package/dist/esm/client/useContent.mjs.map +1 -1
- package/dist/esm/client/useIntlayer.mjs +1 -0
- package/dist/esm/client/useIntlayer.mjs.map +1 -1
- package/dist/esm/client/useLocale.d.mts +1 -0
- package/dist/esm/client/useLocale.mjs +7 -4
- package/dist/esm/client/useLocale.mjs.map +1 -1
- package/dist/esm/client/useLocaleBase.d.mts +14 -0
- package/dist/esm/client/useLocaleBase.mjs +26 -0
- package/dist/esm/client/useLocaleBase.mjs.map +1 -0
- package/dist/esm/client/useLocaleCookie.mjs +3 -4
- package/dist/esm/client/useLocaleCookie.mjs.map +1 -1
- package/dist/esm/client/useTraduction.d.mts +6 -5
- package/dist/esm/client/useTraduction.mjs +1 -0
- package/dist/esm/client/useTraduction.mjs.map +1 -1
- package/dist/esm/craco/craco.config.d.mts +2 -0
- package/dist/esm/craco/craco.config.mjs +17 -0
- package/dist/esm/craco/craco.config.mjs.map +1 -0
- package/dist/esm/craco/intlayerCracoPlugin.d.mts +26 -0
- package/dist/esm/craco/intlayerCracoPlugin.mjs +54 -0
- package/dist/esm/craco/intlayerCracoPlugin.mjs.map +1 -0
- package/dist/esm/getEnumeration.d.mts +8 -5
- package/dist/esm/getEnumeration.mjs +1 -4
- package/dist/esm/getEnumeration.mjs.map +1 -1
- package/dist/esm/getTranslation.d.mts +3 -2
- package/dist/esm/getTranslation.mjs +3 -8
- package/dist/esm/getTranslation.mjs.map +1 -1
- package/dist/esm/index.d.mts +2 -0
- package/dist/esm/index.mjs +6 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/processDictionary/contentDictionary.d.mts +16 -0
- package/dist/esm/processDictionary/contentDictionary.mjs +1 -0
- package/dist/esm/processDictionary/contentDictionary.mjs.map +1 -0
- package/dist/esm/processDictionary/index.d.mts +5 -4
- package/dist/esm/processDictionary/index.mjs +122 -25
- package/dist/esm/processDictionary/index.mjs.map +1 -1
- package/dist/esm/server/IntlayerServerProvider.mjs +3 -4
- package/dist/esm/server/IntlayerServerProvider.mjs.map +1 -1
- package/dist/esm/server/getLocaleTranslation.mjs +3 -2
- package/dist/esm/server/getLocaleTranslation.mjs.map +1 -1
- package/dist/esm/server/index.mjs +1 -0
- package/dist/esm/server/index.mjs.map +1 -1
- package/dist/esm/server/serverContext.mjs +1 -0
- package/dist/esm/server/serverContext.mjs.map +1 -1
- package/dist/esm/server/useIntlayer.mjs +1 -0
- package/dist/esm/server/useIntlayer.mjs.map +1 -1
- package/dist/esm/server/useTraduction.d.mts +4 -3
- package/dist/esm/server/useTraduction.mjs +1 -0
- package/dist/esm/server/useTraduction.mjs.map +1 -1
- package/dist/esm/useIntlayerBase.mjs +4 -0
- package/dist/esm/useIntlayerBase.mjs.map +1 -1
- package/dist/esm/vite/intlayerPlugin.d.mts +17 -0
- package/dist/esm/vite/intlayerPlugin.mjs +36 -0
- package/dist/esm/vite/intlayerPlugin.mjs.map +1 -0
- package/package.json +37 -6
- package/src/IntlayerProvider.tsx +2 -2
- package/src/cli/react-intlayer.ts +60 -0
- package/src/client/ContentEditionLayout.tsx +15 -0
- package/src/client/IntlayerClientProvider.tsx +50 -12
- package/src/client/getBrowserLocale.tsx +192 -0
- package/src/client/index.ts +2 -0
- package/src/client/useContent.ts +2 -2
- package/src/client/useLocale.ts +5 -4
- package/src/client/useLocaleBase.ts +24 -0
- package/src/client/useLocaleCookie.ts +2 -5
- package/src/client/useTraduction.ts +6 -5
- package/src/craco/craco.config.ts +11 -0
- package/src/craco/intlayerCracoPlugin.ts +89 -0
- package/src/getEnumeration.ts +8 -10
- package/src/getTranslation.ts +5 -12
- package/src/index.ts +2 -1
- package/src/processDictionary/{contentDictionary.d.ts → contentDictionary.ts} +6 -5
- package/src/processDictionary/index.ts +159 -25
- package/src/server/IntlayerServerProvider.tsx +2 -5
- package/src/server/getLocaleTranslation.ts +2 -2
- package/src/server/useTraduction.ts +4 -3
- package/src/useIntlayerBase.ts +3 -0
- package/src/vite/intlayerPlugin.ts +59 -0
- package/dist/cjs/ContentEditor/ContentEditor.cjs +0 -110
- package/dist/cjs/ContentEditor/ContentEditor.cjs.map +0 -1
- package/dist/cjs/ContentEditor/ContentEditor.d.ts +0 -8
- package/dist/cjs/ContentEditor/contentRender.cjs.map +0 -1
- package/dist/cjs/ContentEditor/contentRender.d.ts +0 -3
- package/dist/cjs/ContentEditor/index.cjs +0 -25
- package/dist/cjs/ContentEditor/index.cjs.map +0 -1
- package/dist/cjs/ContentEditor/index.d.ts +0 -3
- package/dist/cjs/processDictionary/contentDictionary.d.cjs.map +0 -1
- package/dist/cjs/processDictionary/contentDictionary.d.d.ts +0 -29
- package/dist/esm/ContentEditor/ContentEditor.d.mts +0 -8
- package/dist/esm/ContentEditor/ContentEditor.mjs +0 -91
- package/dist/esm/ContentEditor/ContentEditor.mjs.map +0 -1
- package/dist/esm/ContentEditor/contentRender.d.mts +0 -3
- package/dist/esm/ContentEditor/contentRender.mjs +0 -13
- package/dist/esm/ContentEditor/contentRender.mjs.map +0 -1
- package/dist/esm/ContentEditor/index.d.mts +0 -3
- package/dist/esm/ContentEditor/index.mjs +0 -3
- package/dist/esm/ContentEditor/index.mjs.map +0 -1
- package/dist/esm/processDictionary/contentDictionary.d.d.mts +0 -29
- package/dist/esm/processDictionary/contentDictionary.d.mjs +0 -1
- package/src/ContentEditor/ContentEditor.tsx +0 -116
- package/src/ContentEditor/contentRender.tsx +0 -11
- package/src/ContentEditor/index.tsx +0 -2
- /package/dist/esm/{processDictionary/contentDictionary.d.mjs.map → chunk-ZNCO4QRF.mjs.map} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/client/useLocaleBase.ts"],"sourcesContent":["'use client';\n\nimport { getConfiguration } from '@intlayer/config/client';\nimport { localeList } from '@intlayer/core';\nimport { useContext } from 'react';\nimport { IntlayerClientContext } from './IntlayerClientProvider';\n\nconst { defaultLocale, locales: availableLocales } =\n getConfiguration().internationalization;\n\n/**\n * On the client side, hook to get the current locale and all related fields\n */\nexport const useLocaleBase = () => {\n const { locale, setLocale } = useContext(IntlayerClientContext);\n\n return {\n locale, // Current locale\n defaultLocale, // Principal locale defined in config\n availableLocales, // List of the available locales defined in config\n localeList, // List of all available locales\n setLocale, // Function to set the locale\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,oBAAiC;AACjC,kBAA2B;AAC3B,mBAA2B;AAC3B,oCAAsC;AAEtC,MAAM,EAAE,eAAe,SAAS,iBAAiB,QAC/C,gCAAiB,EAAE;AAKd,MAAM,gBAAgB,MAAM;AACjC,QAAM,EAAE,QAAQ,UAAU,QAAI,yBAAW,mDAAqB;AAE9D,SAAO;AAAA,IACL;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as _intlayer_config_client from '@intlayer/config/client';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* On the client side, hook to get the current locale and all related fields
|
|
5
|
+
*/
|
|
6
|
+
declare const useLocaleBase: () => {
|
|
7
|
+
locale: _intlayer_config_client.Locales;
|
|
8
|
+
defaultLocale: _intlayer_config_client.Locales;
|
|
9
|
+
availableLocales: _intlayer_config_client.Locales[];
|
|
10
|
+
localeList: _intlayer_config_client.Locales[];
|
|
11
|
+
setLocale: (newLocale: _intlayer_config_client.Locales) => void;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export { useLocaleBase };
|
|
@@ -35,7 +35,7 @@ __export(useLocaleCookie_exports, {
|
|
|
35
35
|
module.exports = __toCommonJS(useLocaleCookie_exports);
|
|
36
36
|
var import_client = require("@intlayer/config/client");
|
|
37
37
|
var import_js_cookie = __toESM(require("js-cookie"));
|
|
38
|
-
const { cookieName } = import_client.
|
|
38
|
+
const { cookieName } = (0, import_client.getConfiguration)().middleware;
|
|
39
39
|
const cookieAttributes = {
|
|
40
40
|
path: "/",
|
|
41
41
|
expires: void 0,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/useLocaleCookie.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../../src/client/useLocaleCookie.ts"],"sourcesContent":["import { type Locales, getConfiguration } from '@intlayer/config/client';\nimport Cookies from 'js-cookie';\n\nconst { cookieName } = getConfiguration().middleware;\n\nconst cookieAttributes: Cookies.CookieAttributes = {\n path: '/',\n expires: undefined,\n domain: undefined,\n secure: false,\n sameSite: 'strict',\n};\n\n/**\n * Get the locale cookie\n */\nexport const localeCookie = Cookies.get(cookieName) as Locales | undefined;\n\n/**\n * Set the locale cookie\n */\nexport const setLocaleCookie = (locale: Locales) => {\n Cookies.set(cookieName, locale, cookieAttributes);\n};\n\n/**\n * Hook that provides the locale cookie and a function to set it\n */\nexport const useLocaleCookie = () => ({\n localeCookie,\n setLocaleCookie,\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA+C;AAC/C,uBAAoB;AAEpB,MAAM,EAAE,WAAW,QAAI,gCAAiB,EAAE;AAE1C,MAAM,mBAA6C;AAAA,EACjD,MAAM;AAAA,EACN,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,UAAU;AACZ;AAKO,MAAM,eAAe,iBAAAA,QAAQ,IAAI,UAAU;AAK3C,MAAM,kBAAkB,CAAC,WAAoB;AAClD,mBAAAA,QAAQ,IAAI,YAAY,QAAQ,gBAAgB;AAClD;AAKO,MAAM,kBAAkB,OAAO;AAAA,EACpC;AAAA,EACA;AACF;","names":["Cookies"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/useTraduction.ts"],"sourcesContent":["import type { LanguageContent } from '@intlayer/core';\nimport { useContext } from 'react';\nimport { getTranslation } from '../getTranslation';\nimport { IntlayerClientContext } from './IntlayerClientProvider';\n\n/**\n * On the client side, Hook that picking one dictionary by its id and return the content.\n *\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 * const content =
|
|
1
|
+
{"version":3,"sources":["../../../src/client/useTraduction.ts"],"sourcesContent":["import type { LanguageContent } from '@intlayer/core';\nimport { useContext } from 'react';\nimport { getTranslation } from '../getTranslation';\nimport { IntlayerClientContext } from './IntlayerClientProvider';\n\n/**\n * On the client side, Hook that picking one dictionary by its id and return the content.\n *\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 * ```tsx\n * const content = useTraduction<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 useTraduction = <Content = string>(\n languageContent: LanguageContent<Content>\n): Content => {\n const { locale } = useContext(IntlayerClientContext);\n\n return getTranslation(languageContent, locale);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAA2B;AAC3B,4BAA+B;AAC/B,oCAAsC;AAuB/B,MAAM,gBAAgB,CAC3B,oBACY;AACZ,QAAM,EAAE,OAAO,QAAI,yBAAW,mDAAqB;AAEnD,aAAO,sCAAe,iBAAiB,MAAM;AAC/C;","names":[]}
|
|
@@ -9,12 +9,13 @@ import { LanguageContent } from '@intlayer/core';
|
|
|
9
9
|
*
|
|
10
10
|
* Usage:
|
|
11
11
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* 'fr');
|
|
12
|
+
* ```tsx
|
|
13
|
+
* const content = useTraduction<string>({
|
|
14
|
+
* en: 'Hello',
|
|
15
|
+
* fr: 'Bonjour',
|
|
16
|
+
* }, 'fr');
|
|
17
17
|
* // 'Bonjour'
|
|
18
|
+
* ```
|
|
18
19
|
*
|
|
19
20
|
* Using TypeScript:
|
|
20
21
|
* - this function will require each locale to be defined if defined in the project configuration.
|
|
@@ -0,0 +1,32 @@
|
|
|
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 __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
var intlayerPlugin = __toESM(require('./intlayerCracoPlugin.cjs'));
|
|
25
|
+
module.exports = {
|
|
26
|
+
plugins: [
|
|
27
|
+
{
|
|
28
|
+
plugin: intlayerPlugin
|
|
29
|
+
}
|
|
30
|
+
]
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=craco.config.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/craco/craco.config.ts"],"sourcesContent":["import type { CracoConfig } from '@craco/types';\nimport * as intlayerPlugin from './intlayerCracoPlugin';\n\n// Usage Example\nmodule.exports = {\n plugins: [\n {\n plugin: intlayerPlugin,\n },\n ],\n} satisfies CracoConfig;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AACA,qBAAgC;AAGhC,OAAO,UAAU;AAAA,EACf,SAAS;AAAA,IACP;AAAA,MACE,QAAQ;AAAA,IACV;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,89 @@
|
|
|
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 intlayerCracoPlugin_exports = {};
|
|
30
|
+
__export(intlayerCracoPlugin_exports, {
|
|
31
|
+
overrideCracoConfig: () => overrideCracoConfig,
|
|
32
|
+
overrideWebpackConfig: () => overrideWebpackConfig,
|
|
33
|
+
plugin: () => plugin
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(intlayerCracoPlugin_exports);
|
|
36
|
+
var import_path = require("path");
|
|
37
|
+
var import_config = require("@intlayer/config");
|
|
38
|
+
var import_webpack = require("@intlayer/webpack");
|
|
39
|
+
var import_webpack2 = __toESM(require("webpack"));
|
|
40
|
+
const intlayerConfig = (0, import_config.getConfiguration)();
|
|
41
|
+
const env = (0, import_config.formatEnvVariable)("react_app");
|
|
42
|
+
const overrideWebpackConfig = ({
|
|
43
|
+
webpackConfig
|
|
44
|
+
}) => {
|
|
45
|
+
webpackConfig.externals = {
|
|
46
|
+
...typeof webpackConfig.externals === "object" ? webpackConfig.externals : {},
|
|
47
|
+
esbuild: "esbuild",
|
|
48
|
+
module: "module",
|
|
49
|
+
fs: "fs",
|
|
50
|
+
vm: "vm"
|
|
51
|
+
};
|
|
52
|
+
(webpackConfig.module?.rules ?? []).push({
|
|
53
|
+
test: /\.node$/,
|
|
54
|
+
use: "node-loader"
|
|
55
|
+
});
|
|
56
|
+
return webpackConfig;
|
|
57
|
+
};
|
|
58
|
+
const overrideCracoConfig = ({
|
|
59
|
+
cracoConfig
|
|
60
|
+
}) => {
|
|
61
|
+
const { mainDir, baseDir } = intlayerConfig.content;
|
|
62
|
+
const dictionariesPath = (0, import_path.join)(mainDir, "dictionaries.mjs");
|
|
63
|
+
const relativeDictionariesPath = (0, import_path.relative)(baseDir, dictionariesPath);
|
|
64
|
+
return {
|
|
65
|
+
...cracoConfig,
|
|
66
|
+
webpack: {
|
|
67
|
+
...cracoConfig.webpack,
|
|
68
|
+
plugins: {
|
|
69
|
+
...cracoConfig.webpack?.plugins,
|
|
70
|
+
add: [new import_webpack2.default.EnvironmentPlugin(env), new import_webpack.IntLayerPlugin()]
|
|
71
|
+
},
|
|
72
|
+
alias: {
|
|
73
|
+
...cracoConfig.webpack?.alias,
|
|
74
|
+
"@intlayer/dictionaries-entry": (0, import_path.resolve)("./", relativeDictionariesPath)
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
const plugin = {
|
|
80
|
+
overrideCracoConfig,
|
|
81
|
+
overrideWebpackConfig
|
|
82
|
+
};
|
|
83
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
84
|
+
0 && (module.exports = {
|
|
85
|
+
overrideCracoConfig,
|
|
86
|
+
overrideWebpackConfig,
|
|
87
|
+
plugin
|
|
88
|
+
});
|
|
89
|
+
//# sourceMappingURL=intlayerCracoPlugin.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/craco/intlayerCracoPlugin.ts"],"sourcesContent":["import { resolve, relative, join } from 'path';\nimport type {\n CracoConfig,\n CracoConfigOverride,\n CracoPlugin,\n WebpackConfigOverride,\n} from '@craco/types';\nimport { getConfiguration, formatEnvVariable } from '@intlayer/config';\nimport { IntLayerPlugin as IntLayerWebpackPlugin } from '@intlayer/webpack';\nimport webpack, { type Configuration as WebpackConfig } from 'webpack';\n\n// Get IntLayer configuration\nconst intlayerConfig = getConfiguration();\n\n// Format environment variables\nconst env: Record<string, string> = formatEnvVariable('react_app');\n\n// Custom CRACO plugin function to override webpack configuration\nexport const overrideWebpackConfig = ({\n webpackConfig,\n}: WebpackConfigOverride): WebpackConfig => {\n webpackConfig.externals = {\n ...(typeof webpackConfig.externals === 'object'\n ? webpackConfig.externals\n : {}),\n esbuild: 'esbuild',\n module: 'module',\n fs: 'fs',\n vm: 'vm',\n };\n\n (webpackConfig.module?.rules ?? []).push({\n test: /\\.node$/,\n use: 'node-loader',\n });\n\n // You can add any custom CRACO plugins here if needed\n // config.plugins.push(new CustomCracoPlugin());\n\n return webpackConfig;\n};\n\n// Return a CRACO configuration object\nexport const overrideCracoConfig = ({\n cracoConfig,\n}: CracoConfigOverride): CracoConfig => {\n const { mainDir, baseDir } = intlayerConfig.content;\n\n const dictionariesPath = join(mainDir, 'dictionaries.mjs');\n const relativeDictionariesPath = relative(baseDir, dictionariesPath);\n\n return {\n ...cracoConfig,\n webpack: {\n ...cracoConfig.webpack,\n plugins: {\n ...cracoConfig.webpack?.plugins,\n add: [new webpack.EnvironmentPlugin(env), new IntLayerWebpackPlugin()],\n },\n alias: {\n ...cracoConfig.webpack?.alias,\n '@intlayer/dictionaries-entry': resolve('./', relativeDictionariesPath),\n },\n },\n };\n};\n\n/**\n * A CRACO plugin that adds the IntLayer configuration to the webpack configuration and sets the environment variables.\n *\n * Usage:\n *\n * ```ts\n * const cracoConfig: CracoConfig = {\n * plugins: [\n * {\n * plugin: intlayerCracoPlugin(),\n * },\n * ],\n * };\n *\n * export default cracoConfig;\n * ```\n *\n */\nexport const plugin: CracoPlugin = {\n overrideCracoConfig,\n overrideWebpackConfig,\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAwC;AAOxC,oBAAoD;AACpD,qBAAwD;AACxD,IAAAA,kBAA6D;AAG7D,MAAM,qBAAiB,gCAAiB;AAGxC,MAAM,UAA8B,iCAAkB,WAAW;AAG1D,MAAM,wBAAwB,CAAC;AAAA,EACpC;AACF,MAA4C;AAC1C,gBAAc,YAAY;AAAA,IACxB,GAAI,OAAO,cAAc,cAAc,WACnC,cAAc,YACd,CAAC;AAAA,IACL,SAAS;AAAA,IACT,QAAQ;AAAA,IACR,IAAI;AAAA,IACJ,IAAI;AAAA,EACN;AAEA,GAAC,cAAc,QAAQ,SAAS,CAAC,GAAG,KAAK;AAAA,IACvC,MAAM;AAAA,IACN,KAAK;AAAA,EACP,CAAC;AAKD,SAAO;AACT;AAGO,MAAM,sBAAsB,CAAC;AAAA,EAClC;AACF,MAAwC;AACtC,QAAM,EAAE,SAAS,QAAQ,IAAI,eAAe;AAE5C,QAAM,uBAAmB,kBAAK,SAAS,kBAAkB;AACzD,QAAM,+BAA2B,sBAAS,SAAS,gBAAgB;AAEnE,SAAO;AAAA,IACL,GAAG;AAAA,IACH,SAAS;AAAA,MACP,GAAG,YAAY;AAAA,MACf,SAAS;AAAA,QACP,GAAG,YAAY,SAAS;AAAA,QACxB,KAAK,CAAC,IAAI,gBAAAC,QAAQ,kBAAkB,GAAG,GAAG,IAAI,eAAAC,eAAsB,CAAC;AAAA,MACvE;AAAA,MACA,OAAO;AAAA,QACL,GAAG,YAAY,SAAS;AAAA,QACxB,oCAAgC,qBAAQ,MAAM,wBAAwB;AAAA,MACxE;AAAA,IACF;AAAA,EACF;AACF;AAoBO,MAAM,SAAsB;AAAA,EACjC;AAAA,EACA;AACF;","names":["import_webpack","webpack","IntLayerWebpackPlugin"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { WebpackConfigOverride, CracoConfigOverride, CracoConfig, CracoPlugin } from '@craco/types';
|
|
2
|
+
import { Configuration } from 'webpack';
|
|
3
|
+
|
|
4
|
+
declare const overrideWebpackConfig: ({ webpackConfig, }: WebpackConfigOverride) => Configuration;
|
|
5
|
+
declare const overrideCracoConfig: ({ cracoConfig, }: CracoConfigOverride) => CracoConfig;
|
|
6
|
+
/**
|
|
7
|
+
* A CRACO plugin that adds the IntLayer configuration to the webpack configuration and sets the environment variables.
|
|
8
|
+
*
|
|
9
|
+
* Usage:
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* const cracoConfig: CracoConfig = {
|
|
13
|
+
* plugins: [
|
|
14
|
+
* {
|
|
15
|
+
* plugin: intlayerCracoPlugin(),
|
|
16
|
+
* },
|
|
17
|
+
* ],
|
|
18
|
+
* };
|
|
19
|
+
*
|
|
20
|
+
* export default cracoConfig;
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
*/
|
|
24
|
+
declare const plugin: CracoPlugin;
|
|
25
|
+
|
|
26
|
+
export { overrideCracoConfig, overrideWebpackConfig, plugin };
|
|
@@ -22,15 +22,11 @@ __export(getEnumeration_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(getEnumeration_exports);
|
|
24
24
|
var import_core = require("@intlayer/core");
|
|
25
|
-
var import_contentRender = require('./ContentEditor/contentRender.cjs');
|
|
26
25
|
const getEnumeration = (enumerationContent, quantity) => {
|
|
27
26
|
const result = (0, import_core.getEnumerationContent)(
|
|
28
27
|
enumerationContent,
|
|
29
28
|
quantity
|
|
30
29
|
);
|
|
31
|
-
if (typeof result === "string") {
|
|
32
|
-
return (0, import_contentRender.contentRender)(result);
|
|
33
|
-
}
|
|
34
30
|
return result;
|
|
35
31
|
};
|
|
36
32
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/getEnumeration.ts"],"sourcesContent":["import { type QuantityContent, getEnumerationContent } from '@intlayer/core';\
|
|
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":[]}
|
|
@@ -7,22 +7,25 @@ import { QuantityContent } from '@intlayer/core';
|
|
|
7
7
|
*
|
|
8
8
|
* Usage:
|
|
9
9
|
*
|
|
10
|
+
* ```ts
|
|
10
11
|
* const content = getEnumeration({
|
|
11
12
|
* '<=-2.3': 'You have less than -2.3',
|
|
12
13
|
* '<1': 'You have less than one',
|
|
13
14
|
* '2': 'You have two',
|
|
14
15
|
* '>=3': 'You have three or more',
|
|
15
|
-
* },
|
|
16
|
-
* 2);
|
|
16
|
+
* }, 2);
|
|
17
17
|
* // 'You have two'
|
|
18
|
+
* ```
|
|
18
19
|
*
|
|
19
20
|
* The order of the keys will define the priority of the content.
|
|
20
21
|
*
|
|
22
|
+
* ```ts
|
|
21
23
|
* const content = getEnumeration({
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* });
|
|
24
|
+
* '<4': 'You have less than four',
|
|
25
|
+
* '2': 'You have two',
|
|
26
|
+
* }, 2);
|
|
25
27
|
* // 'You have less than four'
|
|
28
|
+
* ```
|
|
26
29
|
*
|
|
27
30
|
*/
|
|
28
31
|
declare const getEnumeration: <Content>(enumerationContent: QuantityContent<Content>, quantity: number) => Content;
|
|
@@ -23,16 +23,12 @@ __export(getTranslation_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(getTranslation_exports);
|
|
24
24
|
var import_client = require("@intlayer/config/client");
|
|
25
25
|
var import_core = require("@intlayer/core");
|
|
26
|
-
var import_contentRender = require('./ContentEditor/contentRender.cjs');
|
|
27
26
|
const getTranslation = (languageContent, locale) => {
|
|
28
|
-
const { defaultLocale } = import_client.
|
|
27
|
+
const { defaultLocale } = (0, import_client.getConfiguration)().internationalization;
|
|
29
28
|
const result = (0, import_core.getTranslationContent)(
|
|
30
29
|
languageContent,
|
|
31
30
|
locale ?? defaultLocale
|
|
32
31
|
);
|
|
33
|
-
if (typeof result === "string") {
|
|
34
|
-
return (0, import_contentRender.contentRender)(result);
|
|
35
|
-
}
|
|
36
32
|
return result;
|
|
37
33
|
};
|
|
38
34
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/getTranslation.ts"],"sourcesContent":["import {
|
|
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":[]}
|
|
@@ -10,12 +10,13 @@ import { LanguageContent } from '@intlayer/core';
|
|
|
10
10
|
*
|
|
11
11
|
* Usage:
|
|
12
12
|
*
|
|
13
|
+
* ```ts
|
|
13
14
|
* const content = getTranslation<string>({
|
|
14
15
|
* en: 'Hello',
|
|
15
16
|
* fr: 'Bonjour',
|
|
16
|
-
* },
|
|
17
|
-
* 'fr');
|
|
17
|
+
* }, 'fr');
|
|
18
18
|
* // 'Bonjour'
|
|
19
|
+
* ```
|
|
19
20
|
*
|
|
20
21
|
* Using TypeScript:
|
|
21
22
|
* - this function will require each locale to be defined if defined in the project configuration.
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -20,11 +20,13 @@ var src_exports = {};
|
|
|
20
20
|
__export(src_exports, {
|
|
21
21
|
IntlayerClient: () => import_client.IntlayerClient,
|
|
22
22
|
IntlayerClientProvider: () => import_client.IntlayerClientProvider,
|
|
23
|
+
getBrowserLocale: () => import_client.getBrowserLocale,
|
|
23
24
|
getTranslation: () => import_getTranslation.getTranslation,
|
|
24
25
|
localeCookie: () => import_client.localeCookie,
|
|
25
26
|
setLocaleCookie: () => import_client.setLocaleCookie,
|
|
26
27
|
useIntlayer: () => import_client.useIntlayer,
|
|
27
28
|
useLocale: () => import_client.useLocale,
|
|
29
|
+
useLocaleBase: () => import_client.useLocaleBase,
|
|
28
30
|
useLocaleCookie: () => import_client.useLocaleCookie,
|
|
29
31
|
useTraduction: () => import_client.useTraduction
|
|
30
32
|
});
|
|
@@ -35,11 +37,13 @@ var import_client = require('./client/index.cjs');
|
|
|
35
37
|
0 && (module.exports = {
|
|
36
38
|
IntlayerClient,
|
|
37
39
|
IntlayerClientProvider,
|
|
40
|
+
getBrowserLocale,
|
|
38
41
|
getTranslation,
|
|
39
42
|
localeCookie,
|
|
40
43
|
setLocaleCookie,
|
|
41
44
|
useIntlayer,
|
|
42
45
|
useLocale,
|
|
46
|
+
useLocaleBase,
|
|
43
47
|
useLocaleCookie,
|
|
44
48
|
useTraduction
|
|
45
49
|
});
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export { getTranslation } from './getTranslation';\nexport {\n IntlayerClientProvider,\n type IntlayerClientProviderProps,\n IntlayerClient,\n useIntlayer,\n useLocale,\n useTraduction,\n useLocaleCookie,\n localeCookie,\n setLocaleCookie,\n} from './client/index';\
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export { getTranslation } from './getTranslation';\nexport {\n IntlayerClientProvider,\n type IntlayerClientProviderProps,\n IntlayerClient,\n useIntlayer,\n useLocale,\n useTraduction,\n useLocaleCookie,\n localeCookie,\n setLocaleCookie,\n getBrowserLocale,\n useLocaleBase,\n} from './client/index';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAA+B;AAC/B,oBAYO;","names":[]}
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
export { getTranslation } from './getTranslation.js';
|
|
2
2
|
export { IntlayerClientContext as IntlayerClient, IntlayerClientProvider, IntlayerClientProviderProps } from './client/IntlayerClientProvider.js';
|
|
3
3
|
export { useIntlayer } from './client/useIntlayer.js';
|
|
4
|
+
export { useLocaleBase } from './client/useLocaleBase.js';
|
|
4
5
|
export { useLocale } from './client/useLocale.js';
|
|
5
6
|
export { useTraduction } from './client/useTraduction.js';
|
|
6
7
|
export { localeCookie, setLocaleCookie, useLocaleCookie } from './client/useLocaleCookie.js';
|
|
8
|
+
export { getBrowserLocale } from './client/getBrowserLocale.js';
|
|
7
9
|
import '@intlayer/config/client';
|
|
8
10
|
import '@intlayer/core';
|
|
9
11
|
import 'react';
|
|
@@ -12,6 +12,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
12
12
|
return to;
|
|
13
13
|
};
|
|
14
14
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
-
var
|
|
16
|
-
module.exports = __toCommonJS(
|
|
17
|
-
//# sourceMappingURL=contentDictionary.
|
|
15
|
+
var contentDictionary_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(contentDictionary_exports);
|
|
17
|
+
//# sourceMappingURL=contentDictionary.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/processDictionary/contentDictionary.ts"],"sourcesContent":["import type { TranslationContent } from '@intlayer/core';\nimport type { ReactNode } from 'react';\n\nexport type ContentValue =\n | string\n | {\n [key: string]: ContentValue;\n }\n | TranslationContent<unknown>;\n\nexport type Content = Record<string, ContentValue | undefined>;\n\nexport type TransformedContentValue =\n | string\n | ReactNode\n | {\n [key: string]: TransformedContentValue;\n }\n | undefined\n | ((quantity: number) => TransformedContentValue);\n\nexport type TransformedContent =\n | Record<string, TransformedContentValue | undefined>\n | ReactNode;\n\nexport type ContentDictionary = Content & {\n id: string;\n};\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { TranslationContent } from '@intlayer/core';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
|
|
4
|
+
type ContentValue = string | {
|
|
5
|
+
[key: string]: ContentValue;
|
|
6
|
+
} | TranslationContent<unknown>;
|
|
7
|
+
type Content = Record<string, ContentValue | undefined>;
|
|
8
|
+
type TransformedContentValue = string | ReactNode | {
|
|
9
|
+
[key: string]: TransformedContentValue;
|
|
10
|
+
} | undefined | ((quantity: number) => TransformedContentValue);
|
|
11
|
+
type TransformedContent = Record<string, TransformedContentValue | undefined> | ReactNode;
|
|
12
|
+
type ContentDictionary = Content & {
|
|
13
|
+
id: string;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export type { Content, ContentDictionary, ContentValue, TransformedContent, TransformedContentValue };
|
|
@@ -24,52 +24,149 @@ __export(processDictionary_exports, {
|
|
|
24
24
|
module.exports = __toCommonJS(processDictionary_exports);
|
|
25
25
|
var import_client = require("@intlayer/config/client");
|
|
26
26
|
var import_core = require("@intlayer/core");
|
|
27
|
+
var import_client2 = require("intlayer-editor/client");
|
|
28
|
+
var import_react = require("react");
|
|
27
29
|
var import_getEnumeration = require('../getEnumeration.cjs');
|
|
28
30
|
var import_getTranslation = require('../getTranslation.cjs');
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
+
const {
|
|
32
|
+
internationalization: { defaultLocale }
|
|
33
|
+
} = (0, import_client.getConfiguration)();
|
|
34
|
+
const processTranslation = (languageContent, locale, dictionaryId, dictionaryPath, keyPath = []) => {
|
|
31
35
|
const translationResult = (0, import_getTranslation.getTranslation)(
|
|
32
36
|
languageContent,
|
|
33
37
|
locale
|
|
34
38
|
);
|
|
35
|
-
|
|
39
|
+
const resultKeyPath = [
|
|
40
|
+
...keyPath,
|
|
41
|
+
{ type: import_core.NodeType.Translation, key: locale }
|
|
42
|
+
];
|
|
43
|
+
return processDictionary(
|
|
44
|
+
translationResult,
|
|
45
|
+
dictionaryId,
|
|
46
|
+
dictionaryPath,
|
|
47
|
+
resultKeyPath,
|
|
48
|
+
locale
|
|
49
|
+
);
|
|
36
50
|
};
|
|
37
|
-
const processEnumeration = (enumerationContent, locale) => {
|
|
51
|
+
const processEnumeration = (enumerationContent, locale, dictionaryId, dictionaryPath, keyPath = []) => {
|
|
38
52
|
return (quantity) => {
|
|
39
53
|
const enumerationResult = (0, import_getEnumeration.getEnumeration)(
|
|
40
54
|
enumerationContent,
|
|
41
55
|
quantity
|
|
42
56
|
);
|
|
43
|
-
|
|
57
|
+
const matchingCondition = (0, import_core.findMatchingCondition)(
|
|
58
|
+
enumerationContent,
|
|
59
|
+
quantity
|
|
60
|
+
);
|
|
61
|
+
const resultKeyPath = [
|
|
62
|
+
...keyPath,
|
|
63
|
+
{ type: import_core.NodeType.Enumeration, key: matchingCondition.toString() }
|
|
64
|
+
];
|
|
65
|
+
return processDictionary(
|
|
66
|
+
enumerationResult,
|
|
67
|
+
dictionaryId,
|
|
68
|
+
dictionaryPath,
|
|
69
|
+
resultKeyPath,
|
|
70
|
+
locale
|
|
71
|
+
);
|
|
44
72
|
};
|
|
45
73
|
};
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
74
|
+
const isReactNode = (node) => typeof node?.key !== "undefined" && typeof node?.props !== "undefined";
|
|
75
|
+
const processNode = (field, locale, dictionaryId, dictionaryPath, keyPath = []) => {
|
|
76
|
+
if (typeof field === "object") {
|
|
77
|
+
if (field.nodeType === import_core.NodeType.Translation) {
|
|
78
|
+
return processTranslation(
|
|
79
|
+
field,
|
|
80
|
+
locale,
|
|
81
|
+
dictionaryId,
|
|
82
|
+
dictionaryPath,
|
|
83
|
+
keyPath
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
if (field.nodeType === import_core.NodeType.Enumeration) {
|
|
87
|
+
return processEnumeration(
|
|
88
|
+
field,
|
|
89
|
+
locale,
|
|
90
|
+
dictionaryId,
|
|
91
|
+
dictionaryPath,
|
|
92
|
+
keyPath
|
|
93
|
+
);
|
|
94
|
+
}
|
|
49
95
|
}
|
|
50
|
-
|
|
51
|
-
|
|
96
|
+
return processDictionary(
|
|
97
|
+
field,
|
|
98
|
+
dictionaryId,
|
|
99
|
+
dictionaryPath,
|
|
100
|
+
keyPath,
|
|
101
|
+
locale
|
|
102
|
+
);
|
|
103
|
+
};
|
|
104
|
+
const createReactElement = (element) => {
|
|
105
|
+
if (typeof element === "string") {
|
|
106
|
+
return element;
|
|
52
107
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
108
|
+
const convertChildrenAsArray = (element2) => {
|
|
109
|
+
if (element2?.props && typeof element2.props.children === "object") {
|
|
110
|
+
const childrenResult = [];
|
|
111
|
+
const { children } = element2.props;
|
|
112
|
+
Object.keys(children).forEach((key) => {
|
|
113
|
+
childrenResult.push(createReactElement(children[key]));
|
|
114
|
+
});
|
|
115
|
+
return {
|
|
116
|
+
...element2,
|
|
117
|
+
props: { ...element2.props, children: childrenResult }
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
return {
|
|
121
|
+
...element2,
|
|
122
|
+
props: { ...element2.props, children: element2.props.children }
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
const fixedElement = convertChildrenAsArray(element);
|
|
126
|
+
const { type, props } = fixedElement;
|
|
127
|
+
return (0, import_react.createElement)(type ?? "div", props, ...props.children);
|
|
128
|
+
};
|
|
129
|
+
const traceKeys = ["filePath", "id", "nodeType"];
|
|
130
|
+
const processDictionary = (content, dictionaryId, dictionaryPath, keyPath = [], locale = defaultLocale) => {
|
|
131
|
+
if (isReactNode(content)) {
|
|
132
|
+
return createReactElement(
|
|
133
|
+
content
|
|
57
134
|
);
|
|
58
135
|
}
|
|
59
|
-
if (typeof field.type === "undefined") {
|
|
60
|
-
return processDictionary(field, locale);
|
|
61
|
-
}
|
|
62
|
-
return field;
|
|
63
|
-
};
|
|
64
|
-
const processDictionary = (content, locale = defaultLocale) => {
|
|
65
136
|
if (content && typeof content === "object") {
|
|
66
137
|
const result = {};
|
|
67
138
|
for (const key of Object.keys(content)) {
|
|
68
139
|
const field = content[key];
|
|
69
|
-
|
|
140
|
+
if (traceKeys.includes(key)) {
|
|
141
|
+
result[key] = field;
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
const resultKeyPath = [
|
|
145
|
+
...keyPath,
|
|
146
|
+
{ type: "ObjectExpression", key }
|
|
147
|
+
];
|
|
148
|
+
result[key] = processNode(
|
|
149
|
+
field,
|
|
150
|
+
locale,
|
|
151
|
+
dictionaryId,
|
|
152
|
+
dictionaryPath,
|
|
153
|
+
resultKeyPath
|
|
154
|
+
);
|
|
70
155
|
}
|
|
71
156
|
return result;
|
|
72
157
|
}
|
|
158
|
+
if (typeof content === "string") {
|
|
159
|
+
try {
|
|
160
|
+
return (0, import_client2.renderContentEditor)(
|
|
161
|
+
content,
|
|
162
|
+
dictionaryId,
|
|
163
|
+
dictionaryPath,
|
|
164
|
+
keyPath
|
|
165
|
+
);
|
|
166
|
+
} catch (e) {
|
|
167
|
+
return content;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
73
170
|
return content;
|
|
74
171
|
};
|
|
75
172
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/processDictionary/index.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/processDictionary/index.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { type Locales, getConfiguration } from '@intlayer/config/client';\nimport {\n NodeType,\n type QuantityContent,\n type LanguageContent,\n findMatchingCondition,\n type KeyPath,\n} from '@intlayer/core';\nimport { renderContentEditor } from 'intlayer-editor/client';\nimport { type ReactElement, createElement, type ReactNode } from 'react';\nimport { getEnumeration } from '../getEnumeration';\nimport { getTranslation } from '../getTranslation';\nimport type {\n Content,\n ContentValue,\n TransformedContent,\n TransformedContentValue,\n} from './contentDictionary';\n\nconst {\n internationalization: { defaultLocale },\n} = getConfiguration();\n\nconst processTranslation = (\n languageContent: LanguageContent<ContentValue>,\n locale: Locales,\n dictionaryId: string,\n dictionaryPath: string,\n keyPath: KeyPath[] = []\n): TransformedContent => {\n const translationResult: ContentValue = getTranslation<ContentValue>(\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 as Content,\n dictionaryId,\n dictionaryPath,\n resultKeyPath,\n locale\n );\n};\n\nconst processEnumeration = (\n enumerationContent: QuantityContent<ContentValue>,\n locale: Locales,\n dictionaryId: string,\n dictionaryPath: string,\n keyPath: KeyPath[] = []\n): TransformedContentValue => {\n return (quantity: number): TransformedContentValue => {\n const enumerationResult: ContentValue = getEnumeration<ContentValue>(\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 //\n return processDictionary(\n enumerationResult as Content,\n dictionaryId,\n dictionaryPath,\n resultKeyPath,\n locale\n );\n };\n};\n\nconst isReactNode = (node: Record<string, unknown>): boolean =>\n typeof node?.key !== 'undefined' && typeof node?.props !== 'undefined';\n\nexport const processNode = (\n field: ContentValue | undefined,\n locale: Locales,\n dictionaryId: string,\n dictionaryPath: string,\n keyPath: KeyPath[] = []\n): TransformedContentValue => {\n if (typeof field === 'object') {\n if (field.nodeType === NodeType.Translation) {\n return processTranslation(\n field as LanguageContent<ContentValue>,\n locale,\n dictionaryId,\n dictionaryPath,\n keyPath\n );\n }\n\n if (field.nodeType === NodeType.Enumeration) {\n return processEnumeration(\n field satisfies QuantityContent<ContentValue>,\n locale,\n dictionaryId,\n dictionaryPath,\n keyPath\n );\n }\n }\n\n return processDictionary(\n field as Content,\n dictionaryId,\n dictionaryPath,\n keyPath,\n locale\n );\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 // Destructure the component properties\n\n const convertChildrenAsArray = (element: ReactElement): ReactElement => {\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(createReactElement(children[key]));\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(element);\n\n const { type, props } = fixedElement;\n\n // Create and return the React element\n return createElement(type ?? 'div', props, ...props.children);\n};\n\nconst traceKeys: string[] = ['filePath', 'id', '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: Content,\n dictionaryId: 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)) {\n return createReactElement(\n content as unknown as ReactElement\n ) as unknown as TransformedContent;\n }\n\n if (content && typeof content === 'object') {\n const result: TransformedContent = {};\n\n // List each key in the content and process it\n for (const key of Object.keys(content)) {\n const field = content[key];\n\n if (traceKeys.includes(key)) {\n result[key] = field as TransformedContentValue;\n continue;\n }\n\n const resultKeyPath: KeyPath[] = [\n ...keyPath,\n { type: 'ObjectExpression', key },\n ];\n\n result[key] = processNode(\n field,\n locale,\n dictionaryId,\n dictionaryPath,\n resultKeyPath\n );\n }\n\n return result;\n }\n\n if (typeof content === 'string') {\n try {\n // renderContentEditor come from intlayer-editor, which is an optional dependency.\n // intlayer-editor should be installed in the project to use the content editor.\n return renderContentEditor(\n content,\n dictionaryId,\n dictionaryPath,\n keyPath\n );\n } catch (e) {\n // If renderContentEditor not available, it will return the content as is.\n return content;\n }\n }\n\n // If it's a string, number, or function, return it\n return content;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAA+C;AAC/C,kBAMO;AACP,IAAAA,iBAAoC;AACpC,mBAAiE;AACjE,4BAA+B;AAC/B,4BAA+B;AAQ/B,MAAM;AAAA,EACJ,sBAAsB,EAAE,cAAc;AACxC,QAAI,gCAAiB;AAErB,MAAM,qBAAqB,CACzB,iBACA,QACA,cACA,gBACA,UAAqB,CAAC,MACC;AACvB,QAAM,wBAAkC;AAAA,IACtC;AAAA,IACA;AAAA,EACF;AAEA,QAAM,gBAA2B;AAAA,IAC/B,GAAG;AAAA,IACH,EAAE,MAAM,qBAAS,aAAa,KAAK,OAAO;AAAA,EAC5C;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAEA,MAAM,qBAAqB,CACzB,oBACA,QACA,cACA,gBACA,UAAqB,CAAC,MACM;AAC5B,SAAO,CAAC,aAA8C;AACpD,UAAM,wBAAkC;AAAA,MACtC;AAAA,MACA;AAAA,IACF;AAEA,UAAM,wBAAoB;AAAA,MACxB;AAAA,MACA;AAAA,IACF;AAEA,UAAM,gBAA2B;AAAA,MAC/B,GAAG;AAAA,MACH,EAAE,MAAM,qBAAS,aAAa,KAAK,kBAAkB,SAAS,EAAE;AAAA,IAClE;AAGA,WAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;AAEA,MAAM,cAAc,CAAC,SACnB,OAAO,MAAM,QAAQ,eAAe,OAAO,MAAM,UAAU;AAEtD,MAAM,cAAc,CACzB,OACA,QACA,cACA,gBACA,UAAqB,CAAC,MACM;AAC5B,MAAI,OAAO,UAAU,UAAU;AAC7B,QAAI,MAAM,aAAa,qBAAS,aAAa;AAC3C,aAAO;AAAA,QACL;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAEA,QAAI,MAAM,aAAa,qBAAS,aAAa;AAC3C,aAAO;AAAA,QACL;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAGA,MAAM,qBAAqB,CAAC,YAA0B;AACpD,MAAI,OAAO,YAAY,UAAU;AAE/B,WAAO;AAAA,EACT;AAIA,QAAM,yBAAyB,CAACC,aAAwC;AACtE,QAAIA,UAAS,SAAS,OAAOA,SAAQ,MAAM,aAAa,UAAU;AAChE,YAAM,iBAA8B,CAAC;AACrC,YAAM,EAAE,SAAS,IAAIA,SAAQ;AAG7B,aAAO,KAAK,QAAQ,EAAE,QAAQ,CAAC,QAAQ;AACrC,uBAAe,KAAK,mBAAmB,SAAS,GAAG,CAAC,CAAC;AAAA,MACvD,CAAC;AAED,aAAO;AAAA,QACL,GAAGA;AAAA,QACH,OAAO,EAAE,GAAGA,SAAQ,OAAO,UAAU,eAAe;AAAA,MACtD;AAAA,IACF;AAEA,WAAO;AAAA,MACL,GAAGA;AAAA,MACH,OAAO,EAAE,GAAGA,SAAQ,OAAO,UAAUA,SAAQ,MAAM,SAAS;AAAA,IAC9D;AAAA,EACF;AAEA,QAAM,eAAe,uBAAuB,OAAO;AAEnD,QAAM,EAAE,MAAM,MAAM,IAAI;AAGxB,aAAO,4BAAc,QAAQ,OAAO,OAAO,GAAG,MAAM,QAAQ;AAC9D;AAEA,MAAM,YAAsB,CAAC,YAAY,MAAM,UAAU;AAKlD,MAAM,oBAAoB,CAC/B,SACA,cACA,gBACA,UAAqB,CAAC,GACtB,SAAkB,kBACK;AAEvB,MAAI,YAAY,OAAO,GAAG;AACxB,WAAO;AAAA,MACL;AAAA,IACF;AAAA,EACF;AAEA,MAAI,WAAW,OAAO,YAAY,UAAU;AAC1C,UAAM,SAA6B,CAAC;AAGpC,eAAW,OAAO,OAAO,KAAK,OAAO,GAAG;AACtC,YAAM,QAAQ,QAAQ,GAAG;AAEzB,UAAI,UAAU,SAAS,GAAG,GAAG;AAC3B,eAAO,GAAG,IAAI;AACd;AAAA,MACF;AAEA,YAAM,gBAA2B;AAAA,QAC/B,GAAG;AAAA,QACH,EAAE,MAAM,oBAAoB,IAAI;AAAA,MAClC;AAEA,aAAO,GAAG,IAAI;AAAA,QACZ;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AAEA,MAAI,OAAO,YAAY,UAAU;AAC/B,QAAI;AAGF,iBAAO;AAAA,QACL;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,IACF,SAAS,GAAG;AAEV,aAAO;AAAA,IACT;AAAA,EACF;AAGA,SAAO;AACT;","names":["import_client","element"]}
|