react-intlayer 1.2.1 → 2.0.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/{ContentEditor/contentRender.cjs → client/ContentEditionLayout.cjs} +13 -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 → IntlayerProvider.cjs} +21 -10
- package/dist/cjs/client/IntlayerProvider.cjs.map +1 -0
- package/dist/{esm/client/IntlayerClientProvider.d.mts → cjs/client/IntlayerProvider.d.ts} +4 -3
- package/dist/cjs/client/index.cjs +6 -6
- package/dist/cjs/client/index.cjs.map +1 -1
- package/dist/cjs/client/index.d.ts +2 -1
- package/dist/cjs/client/useContent.d.ts +1 -2
- package/dist/cjs/client/useIntlayer.cjs +2 -2
- package/dist/cjs/client/useIntlayer.cjs.map +1 -1
- package/dist/cjs/client/useIntlayer.d.ts +2 -1
- package/dist/cjs/client/useLocale.cjs +2 -2
- package/dist/cjs/client/useLocale.cjs.map +1 -1
- package/dist/cjs/client/useLocaleBase.cjs +2 -2
- package/dist/cjs/client/useLocaleBase.cjs.map +1 -1
- package/dist/cjs/client/useTraduction.cjs +2 -2
- package/dist/cjs/client/useTraduction.cjs.map +1 -1
- package/dist/cjs/getEnumeration.cjs +0 -4
- package/dist/cjs/getEnumeration.cjs.map +1 -1
- package/dist/cjs/getTranslation.cjs +0 -4
- package/dist/cjs/getTranslation.cjs.map +1 -1
- package/dist/cjs/index.cjs +7 -4
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.ts +3 -2
- 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 +114 -33
- package/dist/cjs/processDictionary/index.cjs.map +1 -1
- package/dist/cjs/processDictionary/index.d.ts +5 -4
- package/dist/cjs/server/IntlayerServerProvider.cjs +3 -4
- package/dist/cjs/server/IntlayerServerProvider.cjs.map +1 -1
- package/dist/cjs/server/IntlayerServerProvider.d.ts +1 -1
- package/dist/cjs/server/index.d.ts +1 -0
- package/dist/cjs/server/useIntlayer.d.ts +2 -1
- package/dist/cjs/useIntlayerBase.cjs +48 -1
- package/dist/cjs/useIntlayerBase.cjs.map +1 -1
- package/dist/cjs/useIntlayerBase.d.ts +51 -4
- package/dist/cjs/vite/intlayerPlugin.cjs +1 -1
- package/dist/cjs/vite/intlayerPlugin.cjs.map +1 -1
- package/dist/esm/client/ContentEditionLayout.d.mts +6 -0
- package/dist/esm/client/ContentEditionLayout.mjs +15 -0
- package/dist/esm/client/ContentEditionLayout.mjs.map +1 -0
- package/dist/{cjs/client/IntlayerClientProvider.d.ts → esm/client/IntlayerProvider.d.mts} +4 -3
- package/dist/esm/client/{IntlayerClientProvider.mjs → IntlayerProvider.mjs} +17 -6
- package/dist/esm/client/IntlayerProvider.mjs.map +1 -0
- package/dist/esm/client/index.d.mts +2 -1
- package/dist/esm/client/index.mjs +4 -4
- package/dist/esm/client/index.mjs.map +1 -1
- package/dist/esm/client/useContent.d.mts +1 -2
- package/dist/esm/client/useIntlayer.d.mts +2 -1
- package/dist/esm/client/useIntlayer.mjs +1 -1
- package/dist/esm/client/useIntlayer.mjs.map +1 -1
- package/dist/esm/client/useLocale.mjs +1 -1
- package/dist/esm/client/useLocale.mjs.map +1 -1
- package/dist/esm/client/useLocaleBase.mjs +1 -1
- package/dist/esm/client/useLocaleBase.mjs.map +1 -1
- package/dist/esm/client/useTraduction.mjs +1 -1
- package/dist/esm/client/useTraduction.mjs.map +1 -1
- package/dist/esm/getEnumeration.mjs +0 -4
- package/dist/esm/getEnumeration.mjs.map +1 -1
- package/dist/esm/getTranslation.mjs +0 -4
- package/dist/esm/getTranslation.mjs.map +1 -1
- package/dist/esm/index.d.mts +3 -2
- package/dist/esm/index.mjs +6 -4
- 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/index.d.mts +5 -4
- package/dist/esm/processDictionary/index.mjs +116 -34
- package/dist/esm/processDictionary/index.mjs.map +1 -1
- package/dist/esm/server/IntlayerServerProvider.d.mts +1 -1
- package/dist/esm/server/IntlayerServerProvider.mjs +3 -4
- package/dist/esm/server/IntlayerServerProvider.mjs.map +1 -1
- package/dist/esm/server/index.d.mts +1 -0
- package/dist/esm/server/useIntlayer.d.mts +2 -1
- package/dist/esm/useIntlayerBase.d.mts +51 -4
- package/dist/esm/useIntlayerBase.mjs +46 -1
- package/dist/esm/useIntlayerBase.mjs.map +1 -1
- package/dist/esm/vite/intlayerPlugin.mjs +1 -1
- package/dist/esm/vite/intlayerPlugin.mjs.map +1 -1
- package/package.json +14 -9
- package/src/index.ts +4 -3
- 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/IntlayerProvider.cjs +0 -37
- package/dist/cjs/IntlayerProvider.cjs.map +0 -1
- package/dist/cjs/IntlayerProvider.d.ts +0 -9
- package/dist/cjs/client/IntlayerClientProvider.cjs.map +0 -1
- 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 -92
- 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 -14
- 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/IntlayerProvider.d.mts +0 -9
- package/dist/esm/IntlayerProvider.mjs +0 -18
- package/dist/esm/IntlayerProvider.mjs.map +0 -1
- package/dist/esm/client/IntlayerClientProvider.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/src/IntlayerProvider.tsx +0 -24
- package/src/cli/react-intlayer.ts +0 -60
- package/src/client/IntlayerClientProvider.tsx +0 -76
- package/src/client/getBrowserLocale.tsx +0 -192
- package/src/client/index.ts +0 -16
- package/src/client/useContent.ts +0 -20
- package/src/client/useIntlayer.ts +0 -25
- package/src/client/useLocale.ts +0 -23
- package/src/client/useLocaleBase.ts +0 -24
- package/src/client/useLocaleCookie.ts +0 -32
- package/src/client/useTraduction.ts +0 -33
- package/src/craco/craco.config.ts +0 -11
- package/src/craco/intlayerCracoPlugin.ts +0 -89
- package/src/getEnumeration.ts +0 -46
- package/src/getTranslation.ts +0 -42
- package/src/processDictionary/contentDictionary.d.ts +0 -27
- package/src/processDictionary/index.ts +0 -144
- package/src/server/IntlayerServerProvider.tsx +0 -36
- package/src/server/getLocaleTranslation.ts +0 -22
- package/src/server/index.ts +0 -8
- package/src/server/serverContext.ts +0 -85
- package/src/server/useIntlayer.ts +0 -23
- package/src/server/useTraduction.ts +0 -34
- package/src/useIntlayerBase.ts +0 -35
- package/src/vite/intlayerPlugin.ts +0 -59
- /package/dist/esm/processDictionary/{contentDictionary.d.mjs.map → contentDictionary.mjs.map} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/index.ts"],"sourcesContent":["export
|
|
1
|
+
{"version":3,"sources":["../../../src/client/index.ts"],"sourcesContent":["export {\n type IntlayerProviderProps,\n IntlayerClientContext,\n useIntlayerContext,\n IntlayerProvider,\n} from './IntlayerProvider';\nexport { useIntlayer } from './useIntlayer';\nexport { useLocaleBase } from './useLocaleBase';\nexport { useLocale } from './useLocale';\nexport { useTraduction } from './useTraduction';\nexport {\n useLocaleCookie,\n localeCookie,\n setLocaleCookie,\n} from './useLocaleCookie';\nexport { getBrowserLocale } from './getBrowserLocale';\n"],"mappings":";AAAA;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,mBAAmB;AAC5B,SAAS,qBAAqB;AAC9B,SAAS,iBAAiB;AAC1B,SAAS,qBAAqB;AAC9B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,wBAAwB;","names":[]}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as _intlayer_config_client from '@intlayer/config/client';
|
|
2
1
|
import * as intlayer from 'intlayer';
|
|
3
2
|
import { LanguageContent } from '@intlayer/core';
|
|
4
3
|
|
|
@@ -8,7 +7,7 @@ import { LanguageContent } from '@intlayer/core';
|
|
|
8
7
|
declare const useContent: <Content>(languageContent: LanguageContent<Content>) => {
|
|
9
8
|
locale: intlayer.Locales;
|
|
10
9
|
content: Content;
|
|
11
|
-
t: <Content_1 = string>(languageContent: Partial<Record<
|
|
10
|
+
t: <Content_1 = string>(languageContent: Partial<Record<intlayer.LocalesValues, Content_1>>) => Content_1;
|
|
12
11
|
};
|
|
13
12
|
|
|
14
13
|
export { useContent };
|
|
@@ -4,7 +4,7 @@ import { useContext } from "react";
|
|
|
4
4
|
import {
|
|
5
5
|
useIntlayerBase
|
|
6
6
|
} from '../useIntlayerBase.mjs';
|
|
7
|
-
import { IntlayerClientContext } from './
|
|
7
|
+
import { IntlayerClientContext } from './IntlayerProvider.mjs';
|
|
8
8
|
const useIntlayer = (id, locale) => {
|
|
9
9
|
const { locale: currentLocale } = useContext(IntlayerClientContext);
|
|
10
10
|
const localeTarget = locale ?? currentLocale;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["'use client';\n\nimport type { Locales } from '@intlayer/config/client';\nimport { useContext } from 'react';\nimport {\n type DictionaryKeys,\n useIntlayerBase,\n type UseIntlayer,\n} from '../useIntlayerBase';\nimport { IntlayerClientContext } from './
|
|
1
|
+
{"version":3,"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["'use client';\n\nimport type { Locales } from '@intlayer/config/client';\nimport { useContext } from 'react';\nimport {\n type DictionaryKeys,\n useIntlayerBase,\n type UseIntlayer,\n} from '../useIntlayerBase';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * On the client side, Hook that picking one dictionary by its id and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useIntlayer: UseIntlayer = <T extends DictionaryKeys>(\n id: T,\n locale?: Locales\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const localeTarget = locale ?? currentLocale;\n\n return useIntlayerBase(id, localeTarget);\n};\n"],"mappings":";;AAGA,SAAS,kBAAkB;AAC3B;AAAA,EAEE;AAAA,OAEK;AACP,SAAS,6BAA6B;AAO/B,MAAM,cAA2B,CACtC,IACA,WACG;AACH,QAAM,EAAE,QAAQ,cAAc,IAAI,WAAW,qBAAqB;AAClE,QAAM,eAAe,UAAU;AAE/B,SAAO,gBAAgB,IAAI,YAAY;AACzC;","names":[]}
|
|
@@ -3,7 +3,7 @@ import "../chunk-ZNCO4QRF.mjs";
|
|
|
3
3
|
import { getConfiguration } from "@intlayer/config/client";
|
|
4
4
|
import { localeList } from "@intlayer/core";
|
|
5
5
|
import { useContext } from "react";
|
|
6
|
-
import { IntlayerClientContext } from './
|
|
6
|
+
import { IntlayerClientContext } from './IntlayerProvider.mjs';
|
|
7
7
|
const useLocale = () => {
|
|
8
8
|
const { defaultLocale, locales: availableLocales } = getConfiguration().internationalization;
|
|
9
9
|
const { locale, setLocale } = useContext(IntlayerClientContext);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["'use client';\n\nimport { getConfiguration } from '@intlayer/config/client';\nimport { localeList } from '@intlayer/core';\nimport { useContext } from 'react';\nimport { IntlayerClientContext } from './
|
|
1
|
+
{"version":3,"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["'use client';\n\nimport { getConfiguration } from '@intlayer/config/client';\nimport { localeList } from '@intlayer/core';\nimport { useContext } from 'react';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * On the client side, hook to get the current locale and all related fields\n */\nexport const useLocale = () => {\n const { defaultLocale, locales: availableLocales } =\n getConfiguration().internationalization;\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":";;AAEA,SAAS,wBAAwB;AACjC,SAAS,kBAAkB;AAC3B,SAAS,kBAAkB;AAC3B,SAAS,6BAA6B;AAK/B,MAAM,YAAY,MAAM;AAC7B,QAAM,EAAE,eAAe,SAAS,iBAAiB,IAC/C,iBAAiB,EAAE;AACrB,QAAM,EAAE,QAAQ,UAAU,IAAI,WAAW,qBAAqB;AAE9D,SAAO;AAAA,IACL;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,EACF;AACF;","names":[]}
|
|
@@ -3,7 +3,7 @@ import "../chunk-ZNCO4QRF.mjs";
|
|
|
3
3
|
import { getConfiguration } from "@intlayer/config/client";
|
|
4
4
|
import { localeList } from "@intlayer/core";
|
|
5
5
|
import { useContext } from "react";
|
|
6
|
-
import { IntlayerClientContext } from './
|
|
6
|
+
import { IntlayerClientContext } from './IntlayerProvider.mjs';
|
|
7
7
|
const { defaultLocale, locales: availableLocales } = getConfiguration().internationalization;
|
|
8
8
|
const useLocaleBase = () => {
|
|
9
9
|
const { locale, setLocale } = useContext(IntlayerClientContext);
|
|
@@ -1 +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 './
|
|
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 './IntlayerProvider';\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":";;AAEA,SAAS,wBAAwB;AACjC,SAAS,kBAAkB;AAC3B,SAAS,kBAAkB;AAC3B,SAAS,6BAA6B;AAEtC,MAAM,EAAE,eAAe,SAAS,iBAAiB,IAC/C,iBAAiB,EAAE;AAKd,MAAM,gBAAgB,MAAM;AACjC,QAAM,EAAE,QAAQ,UAAU,IAAI,WAAW,qBAAqB;AAE9D,SAAO;AAAA,IACL;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import "../chunk-ZNCO4QRF.mjs";
|
|
2
2
|
import { useContext } from "react";
|
|
3
3
|
import { getTranslation } from '../getTranslation.mjs';
|
|
4
|
-
import { IntlayerClientContext } from './
|
|
4
|
+
import { IntlayerClientContext } from './IntlayerProvider.mjs';
|
|
5
5
|
const useTraduction = (languageContent) => {
|
|
6
6
|
const { locale } = useContext(IntlayerClientContext);
|
|
7
7
|
return getTranslation(languageContent, locale);
|
|
@@ -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 './
|
|
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 './IntlayerProvider';\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":";AACA,SAAS,kBAAkB;AAC3B,SAAS,sBAAsB;AAC/B,SAAS,6BAA6B;AAuB/B,MAAM,gBAAgB,CAC3B,oBACY;AACZ,QAAM,EAAE,OAAO,IAAI,WAAW,qBAAqB;AAEnD,SAAO,eAAe,iBAAiB,MAAM;AAC/C;","names":[]}
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
import "./chunk-ZNCO4QRF.mjs";
|
|
2
2
|
import { getEnumerationContent } from "@intlayer/core";
|
|
3
|
-
import { contentRender } from './ContentEditor/contentRender.mjs';
|
|
4
3
|
const getEnumeration = (enumerationContent, quantity) => {
|
|
5
4
|
const result = getEnumerationContent(
|
|
6
5
|
enumerationContent,
|
|
7
6
|
quantity
|
|
8
7
|
);
|
|
9
|
-
if (typeof result === "string") {
|
|
10
|
-
return contentRender(result);
|
|
11
|
-
}
|
|
12
8
|
return result;
|
|
13
9
|
};
|
|
14
10
|
export {
|
|
@@ -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,SAA+B,6BAA6B;AA8BrD,MAAM,iBAAiB,CAC5B,oBACA,aACY;AACZ,QAAM,SAAkB;AAAA,IACtB;AAAA,IACA;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
import "./chunk-ZNCO4QRF.mjs";
|
|
2
2
|
import { getConfiguration } from "@intlayer/config/client";
|
|
3
3
|
import { getTranslationContent } from "@intlayer/core";
|
|
4
|
-
import { contentRender } from './ContentEditor/contentRender.mjs';
|
|
5
4
|
const getTranslation = (languageContent, locale) => {
|
|
6
5
|
const { defaultLocale } = getConfiguration().internationalization;
|
|
7
6
|
const result = getTranslationContent(
|
|
8
7
|
languageContent,
|
|
9
8
|
locale ?? defaultLocale
|
|
10
9
|
);
|
|
11
|
-
if (typeof result === "string") {
|
|
12
|
-
return contentRender(result);
|
|
13
|
-
}
|
|
14
10
|
return result;
|
|
15
11
|
};
|
|
16
12
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/getTranslation.ts"],"sourcesContent":["import { type Locales, getConfiguration } from '@intlayer/config/client';\nimport { type LanguageContent, getTranslationContent } from '@intlayer/core';\
|
|
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,SAAuB,wBAAwB;AAC/C,SAA+B,6BAA6B;AAuBrD,MAAM,iBAAiB,CAC5B,iBACA,WACY;AACZ,QAAM,EAAE,cAAc,IAAI,iBAAiB,EAAE;AAE7C,QAAM,SAAkB;AAAA,IACtB;AAAA,IACA,UAAU;AAAA,EACZ;AAEA,SAAO;AACT;","names":[]}
|
package/dist/esm/index.d.mts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
export { getTranslation } from './getTranslation.mjs';
|
|
2
|
-
export { IntlayerClientContext
|
|
2
|
+
export { IntlayerClientContext, IntlayerProvider, IntlayerProviderProps } from './client/IntlayerProvider.mjs';
|
|
3
3
|
export { useIntlayer } from './client/useIntlayer.mjs';
|
|
4
4
|
export { useLocaleBase } from './client/useLocaleBase.mjs';
|
|
5
5
|
export { useLocale } from './client/useLocale.mjs';
|
|
6
6
|
export { useTraduction } from './client/useTraduction.mjs';
|
|
7
7
|
export { localeCookie, setLocaleCookie, useLocaleCookie } from './client/useLocaleCookie.mjs';
|
|
8
8
|
export { getBrowserLocale } from './client/getBrowserLocale.mjs';
|
|
9
|
+
export { recursiveStringifyContent } from './useIntlayerBase.mjs';
|
|
9
10
|
import '@intlayer/config/client';
|
|
10
11
|
import '@intlayer/core';
|
|
11
12
|
import 'react';
|
|
12
|
-
import '
|
|
13
|
+
import '@intlayer/config';
|
|
13
14
|
import 'intlayer';
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import "./chunk-ZNCO4QRF.mjs";
|
|
2
2
|
import { getTranslation } from './getTranslation.mjs';
|
|
3
3
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
IntlayerProvider,
|
|
5
|
+
IntlayerClientContext,
|
|
6
6
|
useIntlayer,
|
|
7
7
|
useLocale,
|
|
8
8
|
useTraduction,
|
|
@@ -12,12 +12,14 @@ import {
|
|
|
12
12
|
getBrowserLocale,
|
|
13
13
|
useLocaleBase
|
|
14
14
|
} from './client/index.mjs';
|
|
15
|
+
import { recursiveStringifyContent } from './useIntlayerBase.mjs';
|
|
15
16
|
export {
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
IntlayerClientContext,
|
|
18
|
+
IntlayerProvider,
|
|
18
19
|
getBrowserLocale,
|
|
19
20
|
getTranslation,
|
|
20
21
|
localeCookie,
|
|
22
|
+
recursiveStringifyContent,
|
|
21
23
|
setLocaleCookie,
|
|
22
24
|
useIntlayer,
|
|
23
25
|
useLocale,
|
package/dist/esm/index.mjs.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 IntlayerProvider,\n type IntlayerProviderProps,\n IntlayerClientContext,\n useIntlayer,\n useLocale,\n useTraduction,\n useLocaleCookie,\n localeCookie,\n setLocaleCookie,\n getBrowserLocale,\n useLocaleBase,\n} from './client/index';\nexport { recursiveStringifyContent } from './useIntlayerBase';\n"],"mappings":";AAAA,SAAS,sBAAsB;AAC/B;AAAA,EACE;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,iCAAiC;","names":[]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { KeyPath, Locales } from '@intlayer/core';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
|
|
4
|
+
type TransformedContentValue = string | ReactNode | {
|
|
5
|
+
[key: string]: TransformedContentValue;
|
|
6
|
+
} | undefined | ((quantity: number) => TransformedContentValue);
|
|
7
|
+
type TransformedContentObject = {
|
|
8
|
+
dictionaryId: string;
|
|
9
|
+
dictionaryPath: string;
|
|
10
|
+
keyPath: KeyPath[];
|
|
11
|
+
locale: Locales;
|
|
12
|
+
content: TransformedContentValue | TransformedContentValue[] | undefined;
|
|
13
|
+
};
|
|
14
|
+
type TransformedContent = Record<string, TransformedContentValue | TransformedContentValue[] | TransformedContentObject | undefined> | ReactNode;
|
|
15
|
+
|
|
16
|
+
export type { TransformedContent, TransformedContentObject, TransformedContentValue };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=contentDictionary.mjs.map
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { Locales } from '@intlayer/config/client';
|
|
2
|
-
import {
|
|
3
|
-
import '
|
|
2
|
+
import { DictionaryValue, KeyPath, Dictionary } from '@intlayer/core';
|
|
3
|
+
import { TransformedContentValue, TransformedContent } from './contentDictionary.mjs';
|
|
4
|
+
import 'react';
|
|
4
5
|
|
|
5
|
-
declare const processNode: (field:
|
|
6
|
+
declare const processNode: (field: DictionaryValue | undefined, locale: Locales, dictionaryId: string, dictionaryPath: string, keyPath?: KeyPath[]) => TransformedContentValue;
|
|
6
7
|
/**
|
|
7
8
|
* Function that process a dictionary and return the result to be used in the application.
|
|
8
9
|
*/
|
|
9
|
-
declare const processDictionary: (content:
|
|
10
|
+
declare const processDictionary: (content: Dictionary | DictionaryValue, dictionaryId: string, dictionaryPath: string, keyPath?: KeyPath[], locale?: Locales) => TransformedContent;
|
|
10
11
|
|
|
11
12
|
export { processDictionary, processNode };
|
|
@@ -1,46 +1,82 @@
|
|
|
1
1
|
import "../chunk-ZNCO4QRF.mjs";
|
|
2
2
|
import { getConfiguration } from "@intlayer/config/client";
|
|
3
3
|
import {
|
|
4
|
-
NodeType
|
|
4
|
+
NodeType,
|
|
5
|
+
findMatchingCondition
|
|
5
6
|
} from "@intlayer/core";
|
|
6
7
|
import { createElement } from "react";
|
|
7
8
|
import { getEnumeration } from '../getEnumeration.mjs';
|
|
8
9
|
import { getTranslation } from '../getTranslation.mjs';
|
|
9
|
-
const {
|
|
10
|
-
|
|
10
|
+
const {
|
|
11
|
+
internationalization: { defaultLocale }
|
|
12
|
+
} = getConfiguration();
|
|
13
|
+
const processTranslation = (languageContent, locale, dictionaryId, dictionaryPath, keyPath = []) => {
|
|
11
14
|
const translationResult = getTranslation(
|
|
12
15
|
languageContent,
|
|
13
16
|
locale
|
|
14
17
|
);
|
|
15
|
-
|
|
18
|
+
const resultKeyPath = [
|
|
19
|
+
...keyPath,
|
|
20
|
+
{ type: NodeType.Translation, key: locale }
|
|
21
|
+
];
|
|
22
|
+
return processDictionary(
|
|
23
|
+
translationResult,
|
|
24
|
+
dictionaryId,
|
|
25
|
+
dictionaryPath,
|
|
26
|
+
resultKeyPath,
|
|
27
|
+
locale
|
|
28
|
+
);
|
|
16
29
|
};
|
|
17
|
-
const processEnumeration = (enumerationContent, locale) => {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
30
|
+
const processEnumeration = (enumerationContent, locale, dictionaryId, dictionaryPath, keyPath = []) => (quantity) => {
|
|
31
|
+
const enumerationResult = getEnumeration(
|
|
32
|
+
enumerationContent,
|
|
33
|
+
quantity
|
|
34
|
+
);
|
|
35
|
+
const matchingCondition = findMatchingCondition(
|
|
36
|
+
enumerationContent,
|
|
37
|
+
quantity
|
|
38
|
+
);
|
|
39
|
+
const resultKeyPath = [
|
|
40
|
+
...keyPath,
|
|
41
|
+
{ type: NodeType.Enumeration, key: matchingCondition.toString() }
|
|
42
|
+
];
|
|
43
|
+
return processDictionary(
|
|
44
|
+
enumerationResult,
|
|
45
|
+
dictionaryId,
|
|
46
|
+
dictionaryPath,
|
|
47
|
+
resultKeyPath,
|
|
48
|
+
locale
|
|
49
|
+
);
|
|
25
50
|
};
|
|
26
51
|
const isReactNode = (node) => typeof node?.key !== "undefined" && typeof node?.props !== "undefined";
|
|
27
|
-
const processNode = (field, locale) => {
|
|
28
|
-
if (typeof field
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
)
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
52
|
+
const processNode = (field, locale, dictionaryId, dictionaryPath, keyPath = []) => {
|
|
53
|
+
if (typeof field === "object") {
|
|
54
|
+
if (field.nodeType === NodeType.Translation) {
|
|
55
|
+
return processTranslation(
|
|
56
|
+
field,
|
|
57
|
+
locale,
|
|
58
|
+
dictionaryId,
|
|
59
|
+
dictionaryPath,
|
|
60
|
+
keyPath
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
if (field.nodeType === NodeType.Enumeration) {
|
|
64
|
+
return processEnumeration(
|
|
65
|
+
field,
|
|
66
|
+
locale,
|
|
67
|
+
dictionaryId,
|
|
68
|
+
dictionaryPath,
|
|
69
|
+
keyPath
|
|
70
|
+
);
|
|
71
|
+
}
|
|
42
72
|
}
|
|
43
|
-
return
|
|
73
|
+
return processDictionary(
|
|
74
|
+
field,
|
|
75
|
+
dictionaryId,
|
|
76
|
+
dictionaryPath,
|
|
77
|
+
keyPath,
|
|
78
|
+
locale
|
|
79
|
+
);
|
|
44
80
|
};
|
|
45
81
|
const createReactElement = (element) => {
|
|
46
82
|
if (typeof element === "string") {
|
|
@@ -67,21 +103,67 @@ const createReactElement = (element) => {
|
|
|
67
103
|
const { type, props } = fixedElement;
|
|
68
104
|
return createElement(type ?? "div", props, ...props.children);
|
|
69
105
|
};
|
|
70
|
-
const
|
|
106
|
+
const traceKeys = ["filePath", "nodeType"];
|
|
107
|
+
const processDictionary = (content, dictionaryId, dictionaryPath, keyPath = [], locale = defaultLocale) => {
|
|
71
108
|
if (isReactNode(content)) {
|
|
72
109
|
return createReactElement(
|
|
73
110
|
content
|
|
74
111
|
);
|
|
75
112
|
}
|
|
76
113
|
if (content && typeof content === "object") {
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
114
|
+
const isArray = Array.isArray(content);
|
|
115
|
+
let result = {};
|
|
116
|
+
if (typeof content.nodeType !== "undefined") {
|
|
117
|
+
return processNode(
|
|
118
|
+
content,
|
|
119
|
+
locale,
|
|
120
|
+
dictionaryId,
|
|
121
|
+
dictionaryPath,
|
|
122
|
+
keyPath
|
|
123
|
+
);
|
|
124
|
+
} else if (isArray) {
|
|
125
|
+
result = content.map((field, key) => {
|
|
126
|
+
const resultKeyPath = [
|
|
127
|
+
...keyPath,
|
|
128
|
+
{ type: "ArrayExpression", key }
|
|
129
|
+
];
|
|
130
|
+
return processNode(
|
|
131
|
+
field,
|
|
132
|
+
locale,
|
|
133
|
+
dictionaryId,
|
|
134
|
+
dictionaryPath,
|
|
135
|
+
resultKeyPath
|
|
136
|
+
);
|
|
137
|
+
});
|
|
138
|
+
} else {
|
|
139
|
+
for (const key of Object.keys(content)) {
|
|
140
|
+
const field = content[key];
|
|
141
|
+
if (traceKeys.includes(key)) {
|
|
142
|
+
result[key] = field;
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
const resultKeyPath = [
|
|
146
|
+
...keyPath,
|
|
147
|
+
{ type: "ObjectExpression", key }
|
|
148
|
+
];
|
|
149
|
+
const nodeResult = processNode(
|
|
150
|
+
field,
|
|
151
|
+
locale,
|
|
152
|
+
dictionaryId,
|
|
153
|
+
dictionaryPath,
|
|
154
|
+
resultKeyPath
|
|
155
|
+
);
|
|
156
|
+
result[key] = nodeResult;
|
|
157
|
+
}
|
|
81
158
|
}
|
|
82
159
|
return result;
|
|
83
160
|
}
|
|
84
|
-
return
|
|
161
|
+
return {
|
|
162
|
+
content,
|
|
163
|
+
keyPath,
|
|
164
|
+
dictionaryId,
|
|
165
|
+
dictionaryPath
|
|
166
|
+
};
|
|
85
167
|
};
|
|
86
168
|
export {
|
|
87
169
|
processDictionary,
|
|
@@ -1 +1 @@
|
|
|
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
|
|
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 type Dictionary,\n type DictionaryValue,\n type TranslationContent,\n type EnumerationContent,\n type TypedNode,\n} from '@intlayer/core';\nimport { type ReactElement, createElement, type ReactNode } from 'react';\nimport { getEnumeration } from '../getEnumeration';\nimport { getTranslation } from '../getTranslation';\nimport type {\n TransformedContent,\n TransformedContentValue,\n} from './contentDictionary';\n\nconst {\n internationalization: { defaultLocale },\n} = getConfiguration();\n\nconst processTranslation = (\n languageContent: LanguageContent<DictionaryValue>,\n locale: Locales,\n dictionaryId: string,\n dictionaryPath: string,\n keyPath: KeyPath[] = []\n): TransformedContent => {\n const translationResult: DictionaryValue = getTranslation<DictionaryValue>(\n languageContent,\n locale\n );\n\n const resultKeyPath: KeyPath[] = [\n ...keyPath,\n { type: NodeType.Translation, key: locale },\n ];\n\n return processDictionary(\n translationResult,\n dictionaryId,\n dictionaryPath,\n resultKeyPath,\n locale\n );\n};\n\nconst processEnumeration =\n (\n enumerationContent: QuantityContent<DictionaryValue>,\n locale: Locales,\n dictionaryId: string,\n dictionaryPath: string,\n keyPath: KeyPath[] = []\n ): TransformedContentValue =>\n (quantity: number): TransformedContentValue => {\n const enumerationResult: DictionaryValue = getEnumeration<DictionaryValue>(\n enumerationContent,\n quantity\n );\n\n const matchingCondition = findMatchingCondition(\n enumerationContent,\n quantity\n );\n\n const resultKeyPath: KeyPath[] = [\n ...keyPath,\n { type: NodeType.Enumeration, key: matchingCondition.toString() },\n ];\n\n return processDictionary(\n enumerationResult,\n dictionaryId,\n dictionaryPath,\n resultKeyPath,\n locale\n ) as TransformedContentValue;\n };\n\nconst isReactNode = (node: Record<string, unknown>): boolean =>\n typeof node?.key !== 'undefined' && typeof node?.props !== 'undefined';\n\nexport const processNode = (\n field: DictionaryValue | undefined,\n locale: Locales,\n dictionaryId: string,\n dictionaryPath: string,\n keyPath: KeyPath[] = []\n): TransformedContentValue => {\n if (typeof field === 'object') {\n if (\n (field as TranslationContent<DictionaryValue>).nodeType ===\n NodeType.Translation\n ) {\n return processTranslation(\n field as LanguageContent<DictionaryValue>,\n locale,\n dictionaryId,\n dictionaryPath,\n keyPath\n ) as TransformedContentValue;\n }\n\n if (\n (field as EnumerationContent<DictionaryValue>).nodeType ===\n NodeType.Enumeration\n ) {\n return processEnumeration(\n field as QuantityContent<DictionaryValue>,\n locale,\n dictionaryId,\n dictionaryPath,\n keyPath\n );\n }\n }\n\n return processDictionary(\n field!,\n dictionaryId,\n dictionaryPath,\n keyPath,\n locale\n ) as TransformedContentValue;\n};\n\n// This function recursively creates React elements from a given JSON-like structure\nconst createReactElement = (element: ReactElement) => {\n if (typeof element === 'string') {\n // If it's a string, simply return it (used for text content)\n return element;\n }\n\n // 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', '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: Dictionary | DictionaryValue,\n dictionaryId: string,\n dictionaryPath: string,\n keyPath: KeyPath[] = [],\n locale: Locales = defaultLocale\n // eslint-disable-next-line sonarjs/cognitive-complexity\n): TransformedContent => {\n // If it's a React element, render it\n if (isReactNode(content as Record<string, unknown>)) {\n return createReactElement(\n content as unknown as ReactElement\n ) as unknown as TransformedContent;\n }\n\n if (content && typeof content === 'object') {\n const isArray = Array.isArray(content);\n\n let result: TransformedContent = {};\n\n if (typeof (content as TypedNode).nodeType !== 'undefined') {\n return processNode(\n content as DictionaryValue,\n locale,\n dictionaryId,\n dictionaryPath,\n keyPath\n ) as TransformedContent;\n } else if (isArray) {\n // Eslint fix because promises are awaited during build stage\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n result = (content as DictionaryValue[]).map((field, key) => {\n const resultKeyPath: KeyPath[] = [\n ...keyPath,\n { type: 'ArrayExpression', key },\n ];\n\n return processNode(\n field,\n locale,\n dictionaryId,\n dictionaryPath,\n resultKeyPath\n );\n }) as TransformedContent;\n } else {\n // List each key in the content and process it\n for (const key of Object.keys(content)) {\n const field = content[key as keyof typeof content];\n\n if (traceKeys.includes(key)) {\n result[key] = field as TransformedContentValue;\n continue;\n }\n\n const resultKeyPath: KeyPath[] = [\n ...keyPath,\n { type: 'ObjectExpression', key },\n ];\n\n const nodeResult = processNode(\n field,\n locale,\n dictionaryId,\n dictionaryPath,\n resultKeyPath\n );\n\n result[key] = nodeResult;\n }\n }\n\n return result;\n }\n\n return {\n content,\n keyPath,\n dictionaryId,\n dictionaryPath,\n };\n};\n"],"mappings":"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","names":["element"]}
|
|
@@ -27,7 +27,7 @@ declare const useIntlayer: () => Locales | undefined;
|
|
|
27
27
|
*/
|
|
28
28
|
declare const locale: Locales | undefined;
|
|
29
29
|
type IntlayerServerProviderProps = PropsWithChildren & {
|
|
30
|
-
locale
|
|
30
|
+
locale?: Locales;
|
|
31
31
|
};
|
|
32
32
|
/**
|
|
33
33
|
* Provider that store the current locale on the server side
|
|
@@ -2,14 +2,13 @@ import "../chunk-ZNCO4QRF.mjs";
|
|
|
2
2
|
import { jsx } from "react/jsx-runtime";
|
|
3
3
|
import { getConfiguration } from "@intlayer/config/client";
|
|
4
4
|
import { createServerContext, getServerContext } from './serverContext.mjs';
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
);
|
|
5
|
+
const { defaultLocale } = getConfiguration().internationalization;
|
|
6
|
+
const IntlayerServerContext = createServerContext(defaultLocale);
|
|
8
7
|
const useIntlayer = () => getServerContext(IntlayerServerContext);
|
|
9
8
|
const locale = getServerContext(IntlayerServerContext);
|
|
10
9
|
const IntlayerServerProvider = ({
|
|
11
10
|
children,
|
|
12
|
-
locale: locale2
|
|
11
|
+
locale: locale2 = defaultLocale
|
|
13
12
|
}) => /* @__PURE__ */ jsx(IntlayerServerContext.Provider, { value: locale2, children });
|
|
14
13
|
export {
|
|
15
14
|
IntlayerServerContext,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/server/IntlayerServerProvider.tsx"],"sourcesContent":["import { type Locales, getConfiguration } from '@intlayer/config/client';\nimport type { FC, PropsWithChildren } from 'react';\nimport { createServerContext, getServerContext } from './serverContext';\n\n/**\n * Context that store the current locale on the server side\n */\nexport const IntlayerServerContext
|
|
1
|
+
{"version":3,"sources":["../../../src/server/IntlayerServerProvider.tsx"],"sourcesContent":["import { type Locales, getConfiguration } from '@intlayer/config/client';\nimport type { FC, PropsWithChildren } from 'react';\nimport { createServerContext, getServerContext } from './serverContext';\n\nconst { defaultLocale } = getConfiguration().internationalization;\n\n/**\n * Context that store the current locale on the server side\n */\nexport const IntlayerServerContext =\n createServerContext<Locales>(defaultLocale);\n\n/**\n * Hook that provides the current locale\n */\nexport const useIntlayer = () => getServerContext(IntlayerServerContext);\n\n/**\n * Get the current locale\n */\nexport const locale = getServerContext(IntlayerServerContext);\n\nexport type IntlayerServerProviderProps = PropsWithChildren & {\n locale?: Locales;\n};\n\n/**\n * Provider that store the current locale on the server side\n */\nexport const IntlayerServerProvider: FC<IntlayerServerProviderProps> = ({\n children,\n locale = defaultLocale,\n}) => (\n <IntlayerServerContext.Provider value={locale}>\n {children}\n </IntlayerServerContext.Provider>\n);\n"],"mappings":";AAiCE;AAjCF,SAAuB,wBAAwB;AAE/C,SAAS,qBAAqB,wBAAwB;AAEtD,MAAM,EAAE,cAAc,IAAI,iBAAiB,EAAE;AAKtC,MAAM,wBACX,oBAA6B,aAAa;AAKrC,MAAM,cAAc,MAAM,iBAAiB,qBAAqB;AAKhE,MAAM,SAAS,iBAAiB,qBAAqB;AASrD,MAAM,yBAA0D,CAAC;AAAA,EACtE;AAAA,EACA,QAAAA,UAAS;AACX,MACE,oBAAC,sBAAsB,UAAtB,EAA+B,OAAOA,SACpC,UACH;","names":["locale"]}
|
|
@@ -1,12 +1,59 @@
|
|
|
1
|
-
import { Locales } from '@intlayer/config
|
|
1
|
+
import { Locales } from '@intlayer/config';
|
|
2
2
|
import { IntlayerDictionaryTypesConnector } from 'intlayer';
|
|
3
|
+
import { ReactNode } from 'react';
|
|
3
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Provides a fallback to string type if the generic type T is never,
|
|
7
|
+
* otherwise returns T. This is useful for handling cases where no keys are found.
|
|
8
|
+
* Example: StringFallback<never> -> string; StringFallback<'key'> -> 'key'
|
|
9
|
+
*/
|
|
4
10
|
type StringFallback<T> = T extends never ? string : T;
|
|
11
|
+
/**
|
|
12
|
+
* Represents the keys of the IntlayerDictionaryTypesConnector,
|
|
13
|
+
* ensuring they are valid dictionary keys or fallback to string if none exist.
|
|
14
|
+
*
|
|
15
|
+
* Example:
|
|
16
|
+
* ```ts
|
|
17
|
+
* DictionaryKeys -> 'key1' | 'key2'
|
|
18
|
+
* // or if IntlayerDictionaryTypesConnector is not defined,
|
|
19
|
+
* DictionaryKeys -> string
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
5
22
|
type DictionaryKeys = StringFallback<keyof IntlayerDictionaryTypesConnector>;
|
|
6
|
-
type
|
|
23
|
+
type IntlayerNode = ReactNode & {
|
|
24
|
+
value: string;
|
|
25
|
+
};
|
|
26
|
+
type DeepTransformContent<T> = T extends object ? {
|
|
27
|
+
[K in keyof T]: DeepTransformContent<T[K]>;
|
|
28
|
+
} : IntlayerNode;
|
|
29
|
+
/**
|
|
30
|
+
* Excludes the 'id' and 'filePath' keys from the dictionary content,
|
|
31
|
+
* as they are not part of the IntlayerDictionaryTypesConnector type.
|
|
32
|
+
*/
|
|
33
|
+
type ExcludeIntlayerUtilsKeys<T> = Omit<T, 'id' | 'filePath'>;
|
|
34
|
+
/**
|
|
35
|
+
* Represents the data type returned by the useIntlayer hook,
|
|
36
|
+
* excluding the 'id' and 'filePath' keys from the dictionary content.
|
|
37
|
+
*/
|
|
38
|
+
type Data<T extends DictionaryKeys> = ExcludeIntlayerUtilsKeys<DeepTransformContent<IntlayerDictionaryTypesConnector[T]>>;
|
|
39
|
+
/**
|
|
40
|
+
* Parcourt the object. If a object has a keyPath, render the intlayer editor if editor enabled.
|
|
41
|
+
*/
|
|
42
|
+
declare const recursiveTransformContent: (obj: object) => object;
|
|
43
|
+
type DeepStrinfifyContent<T> = T extends React.ComponentType<unknown> ? string : T extends object ? {
|
|
44
|
+
[K in keyof T]: DeepStrinfifyContent<T[K]>;
|
|
45
|
+
} : T;
|
|
46
|
+
declare const recursiveStringifyContent: <T extends object>(obj: T) => DeepStrinfifyContent<T>;
|
|
47
|
+
/**
|
|
48
|
+
* Type definition for the useIntlayer hook, which takes a dictionary ID and an optional locale,
|
|
49
|
+
* and returns the deeply transformed dictionary content.
|
|
50
|
+
*
|
|
51
|
+
*/
|
|
52
|
+
type UseIntlayer = <T extends DictionaryKeys>(id: T, locale?: Locales) => Data<T>;
|
|
7
53
|
/**
|
|
8
|
-
* Hook that
|
|
54
|
+
* Hook that picks one dictionary by its ID and returns the content,
|
|
55
|
+
* deeply transformed according to the dictionary structure and metadata.
|
|
9
56
|
*/
|
|
10
57
|
declare const useIntlayerBase: UseIntlayer;
|
|
11
58
|
|
|
12
|
-
export { type DictionaryKeys, type StringFallback, type UseIntlayer, useIntlayerBase };
|
|
59
|
+
export { type DictionaryKeys, type IntlayerNode, type StringFallback, type UseIntlayer, recursiveStringifyContent, recursiveTransformContent, useIntlayerBase };
|