react-intlayer 1.0.1 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/{LocaleContextProvider.cjs → IntlayerProvider.cjs} +11 -11
- package/dist/cjs/IntlayerProvider.cjs.map +1 -0
- package/dist/cjs/IntlayerProvider.d.ts +9 -0
- 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/client/IntlayerClientProvider.cjs +69 -0
- package/dist/cjs/client/IntlayerClientProvider.cjs.map +1 -0
- package/dist/cjs/client/IntlayerClientProvider.d.ts +25 -0
- 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 +13 -7
- package/dist/cjs/client/index.cjs.map +1 -1
- package/dist/cjs/client/index.d.ts +3 -1
- package/dist/cjs/client/useContent.cjs +2 -2
- package/dist/cjs/client/useContent.cjs.map +1 -1
- package/dist/cjs/client/useContent.d.ts +4 -1
- package/dist/cjs/client/useIntlayer.cjs +2 -2
- package/dist/cjs/client/useIntlayer.cjs.map +1 -1
- package/dist/cjs/client/useIntlayer.d.ts +5 -0
- package/dist/cjs/client/useLocale.cjs +6 -4
- package/dist/cjs/client/useLocale.cjs.map +1 -1
- package/dist/cjs/client/useLocale.d.ts +4 -0
- package/dist/cjs/client/{LocaleClientContextProvider.cjs → useLocaleBase.cjs} +24 -17
- 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/useLocaleCookie.d.ts +9 -0
- package/dist/cjs/client/useTraduction.cjs +2 -2
- package/dist/cjs/client/useTraduction.cjs.map +1 -1
- package/dist/cjs/client/useTraduction.d.ts +22 -1
- 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.map +1 -1
- package/dist/cjs/getEnumeration.d.ts +28 -0
- package/dist/cjs/getTranslation.cjs +1 -1
- package/dist/cjs/getTranslation.cjs.map +1 -1
- package/dist/cjs/getTranslation.d.ts +22 -1
- package/dist/cjs/index.cjs +8 -6
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.ts +3 -1
- package/dist/cjs/processDictionary/index.cjs +33 -1
- package/dist/cjs/processDictionary/index.cjs.map +1 -1
- package/dist/cjs/processDictionary/index.d.ts +1 -1
- package/dist/cjs/server/{LocaleServerContextProvider.cjs → IntlayerServerProvider.cjs} +20 -14
- package/dist/cjs/server/IntlayerServerProvider.cjs.map +1 -0
- package/dist/{esm/server/LocaleServerContextProvider.d.mts → cjs/server/IntlayerServerProvider.d.ts} +17 -4
- package/dist/cjs/server/getLocaleTranslation.cjs +3 -3
- package/dist/cjs/server/getLocaleTranslation.cjs.map +1 -1
- package/dist/cjs/server/getLocaleTranslation.d.ts +3 -0
- package/dist/cjs/server/index.cjs +6 -6
- package/dist/cjs/server/index.cjs.map +1 -1
- package/dist/cjs/server/index.d.ts +1 -1
- package/dist/cjs/server/serverContext.cjs.map +1 -1
- package/dist/cjs/server/serverContext.d.ts +4 -4
- package/dist/cjs/server/useIntlayer.cjs +2 -2
- package/dist/cjs/server/useIntlayer.cjs.map +1 -1
- package/dist/cjs/server/useIntlayer.d.ts +5 -0
- package/dist/cjs/server/useTraduction.cjs +2 -2
- package/dist/cjs/server/useTraduction.cjs.map +1 -1
- package/dist/cjs/server/useTraduction.d.ts +22 -1
- package/dist/cjs/useIntlayerBase.cjs.map +1 -1
- package/dist/cjs/useIntlayerBase.d.ts +3 -6
- 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/ContentEditor/ContentEditor.mjs +1 -0
- package/dist/esm/ContentEditor/ContentEditor.mjs.map +1 -1
- package/dist/esm/ContentEditor/contentRender.mjs +1 -0
- package/dist/esm/ContentEditor/contentRender.mjs.map +1 -1
- package/dist/esm/IntlayerProvider.d.mts +9 -0
- package/dist/esm/IntlayerProvider.mjs +18 -0
- package/dist/esm/IntlayerProvider.mjs.map +1 -0
- package/dist/esm/chunk-ZNCO4QRF.mjs +9 -0
- package/dist/esm/chunk-ZNCO4QRF.mjs.map +1 -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/IntlayerClientProvider.d.mts +25 -0
- package/dist/esm/client/IntlayerClientProvider.mjs +50 -0
- package/dist/esm/client/IntlayerClientProvider.mjs.map +1 -0
- 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 +3 -1
- package/dist/esm/client/index.mjs +12 -7
- package/dist/esm/client/index.mjs.map +1 -1
- package/dist/esm/client/useContent.d.mts +4 -1
- package/dist/esm/client/useContent.mjs +3 -2
- package/dist/esm/client/useContent.mjs.map +1 -1
- package/dist/esm/client/useIntlayer.d.mts +5 -0
- package/dist/esm/client/useIntlayer.mjs +3 -2
- package/dist/esm/client/useIntlayer.mjs.map +1 -1
- package/dist/esm/client/useLocale.d.mts +4 -0
- package/dist/esm/client/useLocale.mjs +8 -5
- 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.d.mts +9 -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 +22 -1
- package/dist/esm/client/useTraduction.mjs +3 -2
- 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 +28 -0
- package/dist/esm/getEnumeration.mjs +1 -0
- package/dist/esm/getEnumeration.mjs.map +1 -1
- package/dist/esm/getTranslation.d.mts +22 -1
- package/dist/esm/getTranslation.mjs +3 -4
- package/dist/esm/getTranslation.mjs.map +1 -1
- package/dist/esm/index.d.mts +3 -1
- package/dist/esm/index.mjs +10 -7
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/processDictionary/index.d.mts +1 -1
- package/dist/esm/processDictionary/index.mjs +35 -4
- package/dist/esm/processDictionary/index.mjs.map +1 -1
- package/dist/{cjs/server/LocaleServerContextProvider.d.ts → esm/server/IntlayerServerProvider.d.mts} +17 -4
- package/dist/esm/server/IntlayerServerProvider.mjs +20 -0
- package/dist/esm/server/IntlayerServerProvider.mjs.map +1 -0
- package/dist/esm/server/getLocaleTranslation.d.mts +3 -0
- package/dist/esm/server/getLocaleTranslation.mjs +5 -4
- package/dist/esm/server/getLocaleTranslation.mjs.map +1 -1
- package/dist/esm/server/index.d.mts +1 -1
- package/dist/esm/server/index.mjs +6 -5
- package/dist/esm/server/index.mjs.map +1 -1
- package/dist/esm/server/serverContext.d.mts +4 -4
- package/dist/esm/server/serverContext.mjs +1 -0
- package/dist/esm/server/serverContext.mjs.map +1 -1
- package/dist/esm/server/useIntlayer.d.mts +5 -0
- package/dist/esm/server/useIntlayer.mjs +3 -2
- package/dist/esm/server/useIntlayer.mjs.map +1 -1
- package/dist/esm/server/useTraduction.d.mts +22 -1
- package/dist/esm/server/useTraduction.mjs +3 -2
- package/dist/esm/server/useTraduction.mjs.map +1 -1
- package/dist/esm/useIntlayerBase.d.mts +3 -6
- package/dist/esm/useIntlayerBase.mjs +1 -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 +32 -7
- package/src/IntlayerProvider.tsx +24 -0
- package/src/cli/react-intlayer.ts +60 -0
- package/src/client/IntlayerClientProvider.tsx +76 -0
- package/src/client/getBrowserLocale.tsx +192 -0
- package/src/client/index.ts +7 -5
- package/src/client/useContent.ts +5 -2
- package/src/client/useIntlayer.ts +7 -2
- package/src/client/useLocale.ts +9 -5
- package/src/client/useLocaleBase.ts +24 -0
- package/src/client/useLocaleCookie.ts +11 -6
- package/src/client/useTraduction.ts +24 -3
- package/src/craco/craco.config.ts +11 -0
- package/src/craco/intlayerCracoPlugin.ts +89 -0
- package/src/getEnumeration.ts +28 -0
- package/src/getTranslation.ts +24 -6
- package/src/index.ts +5 -5
- package/src/processDictionary/index.ts +53 -6
- package/src/server/IntlayerServerProvider.tsx +36 -0
- package/src/server/getLocaleTranslation.ts +7 -4
- package/src/server/index.ts +3 -3
- package/src/server/serverContext.ts +4 -4
- package/src/server/useIntlayer.ts +8 -2
- package/src/server/useTraduction.ts +24 -3
- package/src/useIntlayerBase.ts +4 -1
- package/src/vite/intlayerPlugin.ts +59 -0
- package/dist/cjs/LocaleContextProvider.cjs.map +0 -1
- package/dist/cjs/LocaleContextProvider.d.ts +0 -9
- package/dist/cjs/client/LocaleClientContextProvider.cjs.map +0 -1
- package/dist/cjs/client/LocaleClientContextProvider.d.ts +0 -15
- package/dist/cjs/server/LocaleServerContextProvider.cjs.map +0 -1
- package/dist/esm/LocaleContextProvider.d.mts +0 -9
- package/dist/esm/LocaleContextProvider.mjs +0 -17
- package/dist/esm/LocaleContextProvider.mjs.map +0 -1
- package/dist/esm/client/LocaleClientContextProvider.d.mts +0 -15
- package/dist/esm/client/LocaleClientContextProvider.mjs +0 -21
- package/dist/esm/client/LocaleClientContextProvider.mjs.map +0 -1
- package/dist/esm/server/LocaleServerContextProvider.mjs +0 -16
- package/dist/esm/server/LocaleServerContextProvider.mjs.map +0 -1
- package/src/LocaleContextProvider.tsx +0 -26
- package/src/client/LocaleClientContextProvider.tsx +0 -35
- package/src/server/LocaleServerContextProvider.tsx +0 -24
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import * as _intlayer_config_client from '@intlayer/config/client';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* On the client side, hook to get the current locale and all related fields
|
|
5
|
+
*/
|
|
3
6
|
declare const useLocale: () => {
|
|
4
7
|
locale: _intlayer_config_client.Locales;
|
|
5
8
|
defaultLocale: _intlayer_config_client.Locales;
|
|
6
9
|
availableLocales: _intlayer_config_client.Locales[];
|
|
7
10
|
localeList: _intlayer_config_client.Locales[];
|
|
11
|
+
setLocale: (newLocale: _intlayer_config_client.Locales) => void;
|
|
8
12
|
};
|
|
9
13
|
|
|
10
14
|
export { useLocale };
|
|
@@ -17,26 +17,33 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
return to;
|
|
18
18
|
};
|
|
19
19
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
-
var
|
|
21
|
-
__export(
|
|
22
|
-
|
|
23
|
-
LocaleClientContextProvider: () => LocaleClientContextProvider,
|
|
24
|
-
useLocaleContext: () => useLocaleContext
|
|
20
|
+
var useLocaleBase_exports = {};
|
|
21
|
+
__export(useLocaleBase_exports, {
|
|
22
|
+
useLocaleBase: () => useLocaleBase
|
|
25
23
|
});
|
|
26
|
-
module.exports = __toCommonJS(
|
|
27
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
24
|
+
module.exports = __toCommonJS(useLocaleBase_exports);
|
|
28
25
|
var import_client = require("@intlayer/config/client");
|
|
26
|
+
var import_core = require("@intlayer/core");
|
|
29
27
|
var import_react = require("react");
|
|
30
|
-
var
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
|
|
28
|
+
var import_IntlayerClientProvider = require('./IntlayerClientProvider.cjs');
|
|
29
|
+
const { defaultLocale, locales: availableLocales } = (0, import_client.getConfiguration)().internationalization;
|
|
30
|
+
const useLocaleBase = () => {
|
|
31
|
+
const { locale, setLocale } = (0, import_react.useContext)(import_IntlayerClientProvider.IntlayerClientContext);
|
|
32
|
+
return {
|
|
33
|
+
locale,
|
|
34
|
+
// Current locale
|
|
35
|
+
defaultLocale,
|
|
36
|
+
// Principal locale defined in config
|
|
37
|
+
availableLocales,
|
|
38
|
+
// List of the available locales defined in config
|
|
39
|
+
localeList: import_core.localeList,
|
|
40
|
+
// List of all available locales
|
|
41
|
+
setLocale
|
|
42
|
+
// Function to set the locale
|
|
43
|
+
};
|
|
44
|
+
};
|
|
36
45
|
// Annotate the CommonJS export names for ESM import in node:
|
|
37
46
|
0 && (module.exports = {
|
|
38
|
-
|
|
39
|
-
LocaleClientContextProvider,
|
|
40
|
-
useLocaleContext
|
|
47
|
+
useLocaleBase
|
|
41
48
|
});
|
|
42
|
-
//# sourceMappingURL=
|
|
49
|
+
//# sourceMappingURL=useLocaleBase.cjs.map
|
|
@@ -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":["
|
|
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,7 +1,16 @@
|
|
|
1
1
|
import { Locales } from '@intlayer/config/client';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Get the locale cookie
|
|
5
|
+
*/
|
|
3
6
|
declare const localeCookie: Locales | undefined;
|
|
7
|
+
/**
|
|
8
|
+
* Set the locale cookie
|
|
9
|
+
*/
|
|
4
10
|
declare const setLocaleCookie: (locale: Locales) => void;
|
|
11
|
+
/**
|
|
12
|
+
* Hook that provides the locale cookie and a function to set it
|
|
13
|
+
*/
|
|
5
14
|
declare const useLocaleCookie: () => {
|
|
6
15
|
localeCookie: Locales | undefined;
|
|
7
16
|
setLocaleCookie: (locale: Locales) => void;
|
|
@@ -23,9 +23,9 @@ __export(useTraduction_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(useTraduction_exports);
|
|
24
24
|
var import_react = require("react");
|
|
25
25
|
var import_getTranslation = require('../getTranslation.cjs');
|
|
26
|
-
var
|
|
26
|
+
var import_IntlayerClientProvider = require('./IntlayerClientProvider.cjs');
|
|
27
27
|
const useTraduction = (languageContent) => {
|
|
28
|
-
const { locale } = (0, import_react.useContext)(
|
|
28
|
+
const { locale } = (0, import_react.useContext)(import_IntlayerClientProvider.IntlayerClientContext);
|
|
29
29
|
return (0, import_getTranslation.getTranslation)(languageContent, locale);
|
|
30
30
|
};
|
|
31
31
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -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 {
|
|
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":[]}
|
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
import { LanguageContent } from '@intlayer/core';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* On the client side, Hook that picking one dictionary by its id and return the content.
|
|
5
|
+
*
|
|
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
|
+
* ```tsx
|
|
13
|
+
* const content = useTraduction<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.
|
|
23
|
+
*/
|
|
24
|
+
declare const useTraduction: <Content = string>(languageContent: LanguageContent<Content>) => Content;
|
|
4
25
|
|
|
5
26
|
export { useTraduction };
|
|
@@ -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 };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/getEnumeration.ts"],"sourcesContent":["import { type QuantityContent, getEnumerationContent } from '@intlayer/core';\nimport { contentRender } from './ContentEditor/contentRender';\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 if (typeof result === 'string') {\n return contentRender(result) as Content;\n }\n\n return result;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA4D;AAC5D,2BAA8B;
|
|
1
|
+
{"version":3,"sources":["../../src/getEnumeration.ts"],"sourcesContent":["import { type QuantityContent, getEnumerationContent } from '@intlayer/core';\nimport { contentRender } from './ContentEditor/contentRender';\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 if (typeof result === 'string') {\n return contentRender(result) as Content;\n }\n\n return result;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA4D;AAC5D,2BAA8B;AA8BvB,MAAM,iBAAiB,CAC5B,oBACA,aACY;AACZ,QAAM,aAAkB;AAAA,IACtB;AAAA,IACA;AAAA,EACF;AAEA,MAAI,OAAO,WAAW,UAAU;AAC9B,eAAO,oCAAc,MAAM;AAAA,EAC7B;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
import { QuantityContent } from '@intlayer/core';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Allow to pick a content based on a quantity.
|
|
5
|
+
*
|
|
6
|
+
* Return either the content editor, or the content itself depending on the configuration.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* const content = getEnumeration({
|
|
12
|
+
* '<=-2.3': 'You have less than -2.3',
|
|
13
|
+
* '<1': 'You have less than one',
|
|
14
|
+
* '2': 'You have two',
|
|
15
|
+
* '>=3': 'You have three or more',
|
|
16
|
+
* }, 2);
|
|
17
|
+
* // 'You have two'
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* The order of the keys will define the priority of the content.
|
|
21
|
+
*
|
|
22
|
+
* ```ts
|
|
23
|
+
* const content = getEnumeration({
|
|
24
|
+
* '<4': 'You have less than four',
|
|
25
|
+
* '2': 'You have two',
|
|
26
|
+
* }, 2);
|
|
27
|
+
* // 'You have less than four'
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
*/
|
|
3
31
|
declare const getEnumeration: <Content>(enumerationContent: QuantityContent<Content>, quantity: number) => Content;
|
|
4
32
|
|
|
5
33
|
export { getEnumeration };
|
|
@@ -25,7 +25,7 @@ var import_client = require("@intlayer/config/client");
|
|
|
25
25
|
var import_core = require("@intlayer/core");
|
|
26
26
|
var import_contentRender = require('./ContentEditor/contentRender.cjs');
|
|
27
27
|
const getTranslation = (languageContent, locale) => {
|
|
28
|
-
const { defaultLocale } = import_client.
|
|
28
|
+
const { defaultLocale } = (0, import_client.getConfiguration)().internationalization;
|
|
29
29
|
const result = (0, import_core.getTranslationContent)(
|
|
30
30
|
languageContent,
|
|
31
31
|
locale ?? defaultLocale
|
|
@@ -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';\nimport { contentRender } from './ContentEditor/contentRender';\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 if (typeof result === 'string') {\n return contentRender(result) as Content;\n }\n\n return result;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA+C;AAC/C,kBAA4D;AAC5D,2BAA8B;AAuBvB,MAAM,iBAAiB,CAC5B,iBACA,WACY;AACZ,QAAM,EAAE,cAAc,QAAI,gCAAiB,EAAE;AAE7C,QAAM,aAAkB;AAAA,IACtB;AAAA,IACA,UAAU;AAAA,EACZ;AAEA,MAAI,OAAO,WAAW,UAAU;AAC9B,eAAO,oCAAc,MAAM;AAAA,EAC7B;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -1,6 +1,27 @@
|
|
|
1
1
|
import { Locales } from '@intlayer/config/client';
|
|
2
2
|
import { LanguageContent } from '@intlayer/core';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* Allow to pick a content based on a locale.
|
|
7
|
+
* If not locale found, it will return the content related to the default locale.
|
|
8
|
+
*
|
|
9
|
+
* Return either the content editor, or the content itself depending on the configuration.
|
|
10
|
+
*
|
|
11
|
+
* Usage:
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* const content = getTranslation<string>({
|
|
15
|
+
* en: 'Hello',
|
|
16
|
+
* fr: 'Bonjour',
|
|
17
|
+
* }, 'fr');
|
|
18
|
+
* // 'Bonjour'
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* Using TypeScript:
|
|
22
|
+
* - this function will require each locale to be defined if defined in the project configuration.
|
|
23
|
+
* - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.
|
|
24
|
+
*/
|
|
25
|
+
declare const getTranslation: <Content = string>(languageContent: LanguageContent<Content>, locale?: Locales) => Content;
|
|
5
26
|
|
|
6
27
|
export { getTranslation };
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -18,14 +18,15 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var src_exports = {};
|
|
20
20
|
__export(src_exports, {
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
IntlayerClient: () => import_client.IntlayerClient,
|
|
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,
|
|
28
|
-
|
|
29
|
+
useLocaleBase: () => import_client.useLocaleBase,
|
|
29
30
|
useLocaleCookie: () => import_client.useLocaleCookie,
|
|
30
31
|
useTraduction: () => import_client.useTraduction
|
|
31
32
|
});
|
|
@@ -34,14 +35,15 @@ var import_getTranslation = require('./getTranslation.cjs');
|
|
|
34
35
|
var import_client = require('./client/index.cjs');
|
|
35
36
|
// Annotate the CommonJS export names for ESM import in node:
|
|
36
37
|
0 && (module.exports = {
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
IntlayerClient,
|
|
39
|
+
IntlayerClientProvider,
|
|
40
|
+
getBrowserLocale,
|
|
39
41
|
getTranslation,
|
|
40
42
|
localeCookie,
|
|
41
43
|
setLocaleCookie,
|
|
42
44
|
useIntlayer,
|
|
43
45
|
useLocale,
|
|
44
|
-
|
|
46
|
+
useLocaleBase,
|
|
45
47
|
useLocaleCookie,
|
|
46
48
|
useTraduction
|
|
47
49
|
});
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export { getTranslation } from './getTranslation';\nexport {\n
|
|
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
|
-
export {
|
|
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';
|
|
@@ -24,9 +24,10 @@ __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_react = require("react");
|
|
27
28
|
var import_getEnumeration = require('../getEnumeration.cjs');
|
|
28
29
|
var import_getTranslation = require('../getTranslation.cjs');
|
|
29
|
-
const defaultLocale = import_client.
|
|
30
|
+
const { defaultLocale } = (0, import_client.getConfiguration)().internationalization;
|
|
30
31
|
const processTranslation = (languageContent, locale) => {
|
|
31
32
|
const translationResult = (0, import_getTranslation.getTranslation)(
|
|
32
33
|
languageContent,
|
|
@@ -43,6 +44,7 @@ const processEnumeration = (enumerationContent, locale) => {
|
|
|
43
44
|
return processDictionary(enumerationResult, locale);
|
|
44
45
|
};
|
|
45
46
|
};
|
|
47
|
+
const isReactNode = (node) => typeof node?.key !== "undefined" && typeof node?.props !== "undefined";
|
|
46
48
|
const processNode = (field, locale) => {
|
|
47
49
|
if (typeof field !== "object" || field === null) {
|
|
48
50
|
return field;
|
|
@@ -61,7 +63,37 @@ const processNode = (field, locale) => {
|
|
|
61
63
|
}
|
|
62
64
|
return field;
|
|
63
65
|
};
|
|
66
|
+
const createReactElement = (element) => {
|
|
67
|
+
if (typeof element === "string") {
|
|
68
|
+
return element;
|
|
69
|
+
}
|
|
70
|
+
const convertChildrenAsArray = (element2) => {
|
|
71
|
+
if (element2?.props && typeof element2.props.children === "object") {
|
|
72
|
+
const childrenResult = [];
|
|
73
|
+
const { children } = element2.props;
|
|
74
|
+
Object.keys(children).forEach((key) => {
|
|
75
|
+
childrenResult.push(createReactElement(children[key]));
|
|
76
|
+
});
|
|
77
|
+
return {
|
|
78
|
+
...element2,
|
|
79
|
+
props: { ...element2.props, children: childrenResult }
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
...element2,
|
|
84
|
+
props: { ...element2.props, children: element2.props.children }
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
const fixedElement = convertChildrenAsArray(element);
|
|
88
|
+
const { type, props } = fixedElement;
|
|
89
|
+
return (0, import_react.createElement)(type ?? "div", props, ...props.children);
|
|
90
|
+
};
|
|
64
91
|
const processDictionary = (content, locale = defaultLocale) => {
|
|
92
|
+
if (isReactNode(content)) {
|
|
93
|
+
return createReactElement(
|
|
94
|
+
content
|
|
95
|
+
);
|
|
96
|
+
}
|
|
65
97
|
if (content && typeof content === "object") {
|
|
66
98
|
const result = {};
|
|
67
99
|
for (const key of Object.keys(content)) {
|
|
@@ -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} from '@intlayer/core';\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 { defaultLocale } = getConfiguration().internationalization;\n\nconst processTranslation = (\n languageContent: LanguageContent<ContentValue>,\n locale: Locales\n): TransformedContent => {\n const translationResult: ContentValue = getTranslation<ContentValue>(\n languageContent,\n locale\n );\n\n return processDictionary(translationResult as Content, locale);\n};\n\nconst processEnumeration = (\n enumerationContent: QuantityContent<ContentValue>,\n locale: Locales\n): TransformedContentValue => {\n return (quantity: number): TransformedContentValue => {\n const enumerationResult: ContentValue = getEnumeration<ContentValue>(\n enumerationContent,\n quantity\n );\n\n //\n return processDictionary(enumerationResult as Content, locale);\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): TransformedContentValue => {\n if (typeof field !== 'object' || field === null) {\n return field;\n }\n\n if (field.nodeType === NodeType.Translation) {\n return processTranslation(field as LanguageContent<ContentValue>, locale);\n }\n\n if (field.nodeType === NodeType.Enumeration) {\n return processEnumeration(\n field satisfies QuantityContent<ContentValue>,\n locale\n );\n }\n\n if (typeof (field as any).type === 'undefined') {\n return processDictionary(field as Content, locale);\n }\n\n return field 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 // 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\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 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 result[key] = processNode(field, locale);\n }\n\n return result;\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,kBAIO;AACP,mBAAiE;AACjE,4BAA+B;AAC/B,4BAA+B;AAQ/B,MAAM,EAAE,cAAc,QAAI,gCAAiB,EAAE;AAE7C,MAAM,qBAAqB,CACzB,iBACA,WACuB;AACvB,QAAM,wBAAkC;AAAA,IACtC;AAAA,IACA;AAAA,EACF;AAEA,SAAO,kBAAkB,mBAA8B,MAAM;AAC/D;AAEA,MAAM,qBAAqB,CACzB,oBACA,WAC4B;AAC5B,SAAO,CAAC,aAA8C;AACpD,UAAM,wBAAkC;AAAA,MACtC;AAAA,MACA;AAAA,IACF;AAGA,WAAO,kBAAkB,mBAA8B,MAAM;AAAA,EAC/D;AACF;AAEA,MAAM,cAAc,CAAC,SACnB,OAAO,MAAM,QAAQ,eAAe,OAAO,MAAM,UAAU;AAEtD,MAAM,cAAc,CACzB,OACA,WAC4B;AAC5B,MAAI,OAAO,UAAU,YAAY,UAAU,MAAM;AAC/C,WAAO;AAAA,EACT;AAEA,MAAI,MAAM,aAAa,qBAAS,aAAa;AAC3C,WAAO,mBAAmB,OAAwC,MAAM;AAAA,EAC1E;AAEA,MAAI,MAAM,aAAa,qBAAS,aAAa;AAC3C,WAAO;AAAA,MACL;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,MAAI,OAAQ,MAAc,SAAS,aAAa;AAC9C,WAAO,kBAAkB,OAAkB,MAAM;AAAA,EACnD;AAEA,SAAO;AACT;AAGA,MAAM,qBAAqB,CAAC,YAA0B;AACpD,MAAI,OAAO,YAAY,UAAU;AAE/B,WAAO;AAAA,EACT;AAIA,QAAM,yBAAyB,CAACA,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;AAKO,MAAM,oBAAoB,CAC/B,SACA,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,aAAO,GAAG,IAAI,YAAY,OAAO,MAAM;AAAA,IACzC;AAEA,WAAO;AAAA,EACT;AAGA,SAAO;AACT;","names":["element"]}
|
|
@@ -4,7 +4,7 @@ import '@intlayer/core';
|
|
|
4
4
|
|
|
5
5
|
declare const processNode: (field: ContentValue | undefined, locale: Locales) => TransformedContentValue;
|
|
6
6
|
/**
|
|
7
|
-
* Function
|
|
7
|
+
* Function that process a dictionary and return the result to be used in the application.
|
|
8
8
|
*/
|
|
9
9
|
declare const processDictionary: (content: Content, locale?: Locales) => TransformedContent;
|
|
10
10
|
|