react-intlayer 1.0.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/{LocaleContextProvider.cjs → IntlayerProvider.cjs} +10 -10
- package/dist/cjs/IntlayerProvider.cjs.map +1 -0
- package/dist/cjs/IntlayerProvider.d.ts +9 -0
- package/dist/cjs/client/{LocaleClientContextProvider.cjs → IntlayerClientProvider.cjs} +16 -13
- package/dist/cjs/client/IntlayerClientProvider.cjs.map +1 -0
- package/dist/cjs/client/IntlayerClientProvider.d.ts +24 -0
- package/dist/cjs/client/index.cjs +7 -7
- package/dist/cjs/client/index.cjs.map +1 -1
- package/dist/cjs/client/index.d.ts +1 -1
- 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 +2 -2
- package/dist/cjs/client/useLocale.cjs.map +1 -1
- package/dist/cjs/client/useLocale.d.ts +3 -0
- 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 +21 -1
- package/dist/cjs/getEnumeration.cjs.map +1 -1
- package/dist/cjs/getEnumeration.d.ts +25 -0
- package/dist/cjs/getTranslation.cjs.map +1 -1
- package/dist/cjs/getTranslation.d.ts +21 -1
- package/dist/cjs/index.cjs +4 -6
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.ts +1 -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} +19 -13
- 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 +2 -2
- 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 +21 -1
- package/dist/cjs/useIntlayerBase.cjs.map +1 -1
- package/dist/cjs/useIntlayerBase.d.ts +3 -6
- package/dist/esm/IntlayerProvider.d.mts +9 -0
- package/dist/esm/IntlayerProvider.mjs +17 -0
- package/dist/esm/IntlayerProvider.mjs.map +1 -0
- package/dist/esm/client/IntlayerClientProvider.d.mts +24 -0
- package/dist/esm/client/IntlayerClientProvider.mjs +24 -0
- package/dist/esm/client/IntlayerClientProvider.mjs.map +1 -0
- package/dist/esm/client/index.d.mts +1 -1
- package/dist/esm/client/index.mjs +7 -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.map +1 -1
- package/dist/esm/client/useIntlayer.d.mts +5 -0
- package/dist/esm/client/useIntlayer.mjs +2 -2
- package/dist/esm/client/useIntlayer.mjs.map +1 -1
- package/dist/esm/client/useLocale.d.mts +3 -0
- package/dist/esm/client/useLocale.mjs +2 -2
- package/dist/esm/client/useLocale.mjs.map +1 -1
- package/dist/esm/client/useLocaleCookie.d.mts +9 -0
- package/dist/esm/client/useLocaleCookie.mjs.map +1 -1
- package/dist/esm/client/useTraduction.d.mts +21 -1
- package/dist/esm/client/useTraduction.mjs +2 -2
- package/dist/esm/client/useTraduction.mjs.map +1 -1
- package/dist/esm/getEnumeration.d.mts +25 -0
- package/dist/esm/getEnumeration.mjs.map +1 -1
- package/dist/esm/getTranslation.d.mts +21 -1
- package/dist/esm/getTranslation.mjs.map +1 -1
- package/dist/esm/index.d.mts +1 -1
- package/dist/esm/index.mjs +4 -6
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/processDictionary/index.d.mts +1 -1
- 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 +21 -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 +2 -2
- package/dist/esm/server/getLocaleTranslation.mjs.map +1 -1
- package/dist/esm/server/index.d.mts +1 -1
- package/dist/esm/server/index.mjs +5 -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.map +1 -1
- package/dist/esm/server/useIntlayer.d.mts +5 -0
- package/dist/esm/server/useIntlayer.mjs +2 -2
- package/dist/esm/server/useIntlayer.mjs.map +1 -1
- package/dist/esm/server/useTraduction.d.mts +21 -1
- package/dist/esm/server/useTraduction.mjs +2 -2
- package/dist/esm/server/useTraduction.mjs.map +1 -1
- package/dist/esm/useIntlayerBase.d.mts +3 -6
- package/dist/esm/useIntlayerBase.mjs.map +1 -1
- package/package.json +7 -7
- package/src/IntlayerProvider.tsx +24 -0
- package/src/client/IntlayerClientProvider.tsx +45 -0
- package/src/client/index.ts +5 -5
- package/src/client/useContent.ts +3 -0
- package/src/client/useIntlayer.ts +7 -2
- package/src/client/useLocale.ts +5 -2
- package/src/client/useLocaleCookie.ts +9 -1
- package/src/client/useTraduction.ts +23 -3
- package/src/getEnumeration.ts +25 -0
- package/src/getTranslation.ts +21 -1
- package/src/index.ts +3 -4
- package/src/processDictionary/index.ts +1 -1
- package/src/server/IntlayerServerProvider.tsx +39 -0
- package/src/server/getLocaleTranslation.ts +5 -2
- 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 +23 -3
- package/src/useIntlayerBase.ts +4 -1
- 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
|
@@ -16,22 +16,22 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var
|
|
20
|
-
__export(
|
|
21
|
-
|
|
19
|
+
var IntlayerProvider_exports = {};
|
|
20
|
+
__export(IntlayerProvider_exports, {
|
|
21
|
+
IntlayerProvider: () => IntlayerProvider
|
|
22
22
|
});
|
|
23
|
-
module.exports = __toCommonJS(
|
|
23
|
+
module.exports = __toCommonJS(IntlayerProvider_exports);
|
|
24
24
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
25
25
|
var import_client = require("@intlayer/config/client");
|
|
26
|
-
var
|
|
27
|
-
var
|
|
26
|
+
var import_IntlayerClientProvider = require('./client/IntlayerClientProvider.cjs');
|
|
27
|
+
var import_IntlayerServerProvider = require('./server/IntlayerServerProvider.cjs');
|
|
28
28
|
const defaultLocale = import_client.intlayerIntlConfiguration.defaultLocale;
|
|
29
|
-
const
|
|
29
|
+
const IntlayerProvider = ({
|
|
30
30
|
children,
|
|
31
31
|
locale = defaultLocale
|
|
32
|
-
}) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
32
|
+
}) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_IntlayerServerProvider.IntlayerServerProvider, { locale, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_IntlayerClientProvider.IntlayerClientProvider, { locale, children }) });
|
|
33
33
|
// Annotate the CommonJS export names for ESM import in node:
|
|
34
34
|
0 && (module.exports = {
|
|
35
|
-
|
|
35
|
+
IntlayerProvider
|
|
36
36
|
});
|
|
37
|
-
//# sourceMappingURL=
|
|
37
|
+
//# sourceMappingURL=IntlayerProvider.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/IntlayerProvider.tsx"],"sourcesContent":["import { intlayerIntlConfiguration } from '@intlayer/config/client';\nimport type { FC } from 'react';\nimport {\n IntlayerClientProvider,\n type IntlayerClientProviderProps,\n} from './client/IntlayerClientProvider';\nimport {\n IntlayerServerProvider,\n type IntlayerServerProviderProps,\n} from './server/IntlayerServerProvider';\n\nconst defaultLocale = intlayerIntlConfiguration.defaultLocale;\n\ntype IntlayerProviderProps = IntlayerClientProviderProps &\n IntlayerServerProviderProps;\n\nexport const IntlayerProvider: FC<IntlayerProviderProps> = ({\n children,\n locale = defaultLocale,\n}) => (\n <IntlayerServerProvider locale={locale}>\n <IntlayerClientProvider locale={locale}>{children}</IntlayerClientProvider>\n </IntlayerServerProvider>\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAqBI;AArBJ,oBAA0C;AAE1C,oCAGO;AACP,oCAGO;AAEP,MAAM,gBAAgB,wCAA0B;AAKzC,MAAM,mBAA8C,CAAC;AAAA,EAC1D;AAAA,EACA,SAAS;AACX,MACE,4CAAC,wDAAuB,QACtB,sDAAC,wDAAuB,QAAiB,UAAS,GACpD;","names":[]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
import { IntlayerClientProviderProps } from './client/IntlayerClientProvider.js';
|
|
3
|
+
import { IntlayerServerProviderProps } from './server/IntlayerServerProvider.js';
|
|
4
|
+
import '@intlayer/config/client';
|
|
5
|
+
|
|
6
|
+
type IntlayerProviderProps = IntlayerClientProviderProps & IntlayerServerProviderProps;
|
|
7
|
+
declare const IntlayerProvider: FC<IntlayerProviderProps>;
|
|
8
|
+
|
|
9
|
+
export { IntlayerProvider };
|
|
@@ -17,26 +17,29 @@ 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
|
-
|
|
24
|
-
|
|
20
|
+
var IntlayerClientProvider_exports = {};
|
|
21
|
+
__export(IntlayerClientProvider_exports, {
|
|
22
|
+
IntlayerClientContext: () => IntlayerClientContext,
|
|
23
|
+
IntlayerClientProvider: () => IntlayerClientProvider,
|
|
24
|
+
useIntlayerContext: () => useIntlayerContext
|
|
25
25
|
});
|
|
26
|
-
module.exports = __toCommonJS(
|
|
26
|
+
module.exports = __toCommonJS(IntlayerClientProvider_exports);
|
|
27
27
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
28
28
|
var import_client = require("@intlayer/config/client");
|
|
29
29
|
var import_react = require("react");
|
|
30
30
|
var import_useLocaleCookie = require('./useLocaleCookie.cjs');
|
|
31
|
-
const
|
|
31
|
+
const IntlayerClientContext = (0, import_react.createContext)({
|
|
32
32
|
locale: import_useLocaleCookie.localeCookie ?? import_client.intlayerIntlConfiguration.defaultLocale
|
|
33
33
|
});
|
|
34
|
-
const
|
|
35
|
-
const
|
|
34
|
+
const useIntlayerContext = () => (0, import_react.useContext)(IntlayerClientContext);
|
|
35
|
+
const IntlayerClientProvider = ({
|
|
36
|
+
locale,
|
|
37
|
+
children
|
|
38
|
+
}) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(IntlayerClientContext.Provider, { value: { locale }, children });
|
|
36
39
|
// Annotate the CommonJS export names for ESM import in node:
|
|
37
40
|
0 && (module.exports = {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
+
IntlayerClientContext,
|
|
42
|
+
IntlayerClientProvider,
|
|
43
|
+
useIntlayerContext
|
|
41
44
|
});
|
|
42
|
-
//# sourceMappingURL=
|
|
45
|
+
//# sourceMappingURL=IntlayerClientProvider.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/client/IntlayerClientProvider.tsx"],"sourcesContent":["'use client';\n\nimport {\n intlayerIntlConfiguration,\n type Locales,\n} from '@intlayer/config/client';\nimport {\n type PropsWithChildren,\n createContext,\n useContext,\n type FC,\n} from 'react';\nimport { localeCookie } from './useLocaleCookie';\n\ntype IntlayerValue = {\n locale: Locales;\n};\n\n/**\n * Context that store the current locale on the client side\n */\nexport const IntlayerClientContext = createContext<IntlayerValue>({\n locale: localeCookie ?? intlayerIntlConfiguration.defaultLocale,\n});\n\n/**\n * Hook that provides the current locale\n */\nexport const useIntlayerContext = () => useContext(IntlayerClientContext);\n\nexport type IntlayerClientProviderProps = PropsWithChildren & {\n locale: Locales;\n};\n\n/**\n * Provider that store the current locale on the client side\n */\nexport const IntlayerClientProvider: FC<IntlayerClientProviderProps> = ({\n locale,\n children,\n}) => (\n <IntlayerClientContext.Provider value={{ locale }}>\n {children}\n </IntlayerClientContext.Provider>\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAyCE;AAvCF,oBAGO;AACP,mBAKO;AACP,6BAA6B;AAStB,MAAM,4BAAwB,4BAA6B;AAAA,EAChE,QAAQ,uCAAgB,wCAA0B;AACpD,CAAC;AAKM,MAAM,qBAAqB,UAAM,yBAAW,qBAAqB;AASjE,MAAM,yBAA0D,CAAC;AAAA,EACtE;AAAA,EACA;AACF,MACE,4CAAC,sBAAsB,UAAtB,EAA+B,OAAO,EAAE,OAAO,GAC7C,UACH;","names":[]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { PropsWithChildren, FC } from 'react';
|
|
3
|
+
import { Locales } from '@intlayer/config/client';
|
|
4
|
+
|
|
5
|
+
type IntlayerValue = {
|
|
6
|
+
locale: Locales;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Context that store the current locale on the client side
|
|
10
|
+
*/
|
|
11
|
+
declare const IntlayerClientContext: react.Context<IntlayerValue>;
|
|
12
|
+
/**
|
|
13
|
+
* Hook that provides the current locale
|
|
14
|
+
*/
|
|
15
|
+
declare const useIntlayerContext: () => IntlayerValue;
|
|
16
|
+
type IntlayerClientProviderProps = PropsWithChildren & {
|
|
17
|
+
locale: Locales;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Provider that store the current locale on the client side
|
|
21
|
+
*/
|
|
22
|
+
declare const IntlayerClientProvider: FC<IntlayerClientProviderProps>;
|
|
23
|
+
|
|
24
|
+
export { IntlayerClientContext, IntlayerClientProvider, type IntlayerClientProviderProps, useIntlayerContext };
|
|
@@ -18,31 +18,31 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var client_exports = {};
|
|
20
20
|
__export(client_exports, {
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
IntlayerClient: () => import_IntlayerClientProvider.IntlayerClientContext,
|
|
22
|
+
IntlayerClientProvider: () => import_IntlayerClientProvider.IntlayerClientProvider,
|
|
23
23
|
localeCookie: () => import_useLocaleCookie.localeCookie,
|
|
24
24
|
setLocaleCookie: () => import_useLocaleCookie.setLocaleCookie,
|
|
25
25
|
useIntlayer: () => import_useIntlayer.useIntlayer,
|
|
26
|
+
useIntlayerContext: () => import_IntlayerClientProvider.useIntlayerContext,
|
|
26
27
|
useLocale: () => import_useLocale.useLocale,
|
|
27
|
-
useLocaleContext: () => import_LocaleClientContextProvider.useLocaleContext,
|
|
28
28
|
useLocaleCookie: () => import_useLocaleCookie.useLocaleCookie,
|
|
29
29
|
useTraduction: () => import_useTraduction.useTraduction
|
|
30
30
|
});
|
|
31
31
|
module.exports = __toCommonJS(client_exports);
|
|
32
|
-
var
|
|
32
|
+
var import_IntlayerClientProvider = require('./IntlayerClientProvider.cjs');
|
|
33
33
|
var import_useIntlayer = require('./useIntlayer.cjs');
|
|
34
34
|
var import_useLocale = require('./useLocale.cjs');
|
|
35
35
|
var import_useTraduction = require('./useTraduction.cjs');
|
|
36
36
|
var import_useLocaleCookie = require('./useLocaleCookie.cjs');
|
|
37
37
|
// Annotate the CommonJS export names for ESM import in node:
|
|
38
38
|
0 && (module.exports = {
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
IntlayerClient,
|
|
40
|
+
IntlayerClientProvider,
|
|
41
41
|
localeCookie,
|
|
42
42
|
setLocaleCookie,
|
|
43
43
|
useIntlayer,
|
|
44
|
+
useIntlayerContext,
|
|
44
45
|
useLocale,
|
|
45
|
-
useLocaleContext,
|
|
46
46
|
useLocaleCookie,
|
|
47
47
|
useTraduction
|
|
48
48
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/index.ts"],"sourcesContent":["export type {
|
|
1
|
+
{"version":3,"sources":["../../../src/client/index.ts"],"sourcesContent":["export type { IntlayerClientProviderProps } from './IntlayerClientProvider';\nexport {\n IntlayerClientContext as IntlayerClient,\n useIntlayerContext,\n IntlayerClientProvider,\n} from './IntlayerClientProvider';\nexport { useIntlayer } from './useIntlayer';\nexport { useLocale } from './useLocale';\nexport { useTraduction } from './useTraduction';\nexport {\n useLocaleCookie,\n localeCookie,\n setLocaleCookie,\n} from './useLocaleCookie';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oCAIO;AACP,yBAA4B;AAC5B,uBAA0B;AAC1B,2BAA8B;AAC9B,6BAIO;","names":[]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { IntlayerClientContext as IntlayerClient, IntlayerClientProvider, IntlayerClientProviderProps, useIntlayerContext } from './IntlayerClientProvider.js';
|
|
2
2
|
export { useIntlayer } from './useIntlayer.js';
|
|
3
3
|
export { useLocale } from './useLocale.js';
|
|
4
4
|
export { useTraduction } from './useTraduction.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/useContent.ts"],"sourcesContent":["import type { LanguageContent } from '@intlayer/core';\nimport { useLocale } from './useLocale';\nimport { useTraduction } from './useTraduction';\n\nexport const useContent = <Content>(\n languageContent: LanguageContent<Content>\n) => {\n const { locale } = useLocale();\n\n const content = useTraduction(languageContent);\n\n return {\n locale,\n content,\n t: useTraduction,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,uBAA0B;AAC1B,2BAA8B;
|
|
1
|
+
{"version":3,"sources":["../../../src/client/useContent.ts"],"sourcesContent":["import type { LanguageContent } from '@intlayer/core';\nimport { useLocale } from './useLocale';\nimport { useTraduction } from './useTraduction';\n\n/**\n * On the client side, hook to get the translation content based on the locale\n */\nexport const useContent = <Content>(\n languageContent: LanguageContent<Content>\n) => {\n const { locale } = useLocale();\n\n const content = useTraduction(languageContent);\n\n return {\n locale,\n content,\n t: useTraduction,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,uBAA0B;AAC1B,2BAA8B;AAKvB,MAAM,aAAa,CACxB,oBACG;AACH,QAAM,EAAE,OAAO,QAAI,4BAAU;AAE7B,QAAM,cAAU,oCAAc,eAAe;AAE7C,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EACL;AACF;","names":[]}
|
|
@@ -2,10 +2,13 @@ import * as _intlayer_config_client from '@intlayer/config/client';
|
|
|
2
2
|
import * as intlayer from 'intlayer';
|
|
3
3
|
import { LanguageContent } from '@intlayer/core';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* On the client side, hook to get the translation content based on the locale
|
|
7
|
+
*/
|
|
5
8
|
declare const useContent: <Content>(languageContent: LanguageContent<Content>) => {
|
|
6
9
|
locale: intlayer.Locales;
|
|
7
10
|
content: Content;
|
|
8
|
-
t: <Content_1>(languageContent: Partial<Record<_intlayer_config_client.LocalesValues, Content_1>>) => Content_1;
|
|
11
|
+
t: <Content_1 = string>(languageContent: Partial<Record<_intlayer_config_client.LocalesValues, Content_1>>) => Content_1;
|
|
9
12
|
};
|
|
10
13
|
|
|
11
14
|
export { useContent };
|
|
@@ -24,9 +24,9 @@ __export(useIntlayer_exports, {
|
|
|
24
24
|
module.exports = __toCommonJS(useIntlayer_exports);
|
|
25
25
|
var import_react = require("react");
|
|
26
26
|
var import_useIntlayerBase = require('../useIntlayerBase.cjs');
|
|
27
|
-
var
|
|
27
|
+
var import_IntlayerClientProvider = require('./IntlayerClientProvider.cjs');
|
|
28
28
|
const useIntlayer = (id, locale) => {
|
|
29
|
-
const { locale: currentLocale } = (0, import_react.useContext)(
|
|
29
|
+
const { locale: currentLocale } = (0, import_react.useContext)(import_IntlayerClientProvider.IntlayerClientContext);
|
|
30
30
|
const localeTarget = locale ?? currentLocale;
|
|
31
31
|
return (0, import_useIntlayerBase.useIntlayerBase)(id, localeTarget);
|
|
32
32
|
};
|
|
@@ -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 {
|
|
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 './IntlayerClientProvider';\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":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,mBAA2B;AAC3B,6BAIO;AACP,oCAAsC;AAO/B,MAAM,cAA2B,CACtC,IACA,WACG;AACH,QAAM,EAAE,QAAQ,cAAc,QAAI,yBAAW,mDAAqB;AAClE,QAAM,eAAe,UAAU;AAE/B,aAAO,wCAAgB,IAAI,YAAY;AACzC;","names":[]}
|
|
@@ -2,6 +2,11 @@ import { UseIntlayer } from '../useIntlayerBase.js';
|
|
|
2
2
|
import '@intlayer/config/client';
|
|
3
3
|
import 'intlayer';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* On the client side, Hook that picking one dictionary by its id and return the content
|
|
7
|
+
*
|
|
8
|
+
* If the locale is not provided, it will use the locale from the client context
|
|
9
|
+
*/
|
|
5
10
|
declare const useIntlayer: UseIntlayer;
|
|
6
11
|
|
|
7
12
|
export { useIntlayer };
|
|
@@ -25,10 +25,10 @@ module.exports = __toCommonJS(useLocale_exports);
|
|
|
25
25
|
var import_client = require("@intlayer/config/client");
|
|
26
26
|
var import_core = require("@intlayer/core");
|
|
27
27
|
var import_react = require("react");
|
|
28
|
-
var
|
|
28
|
+
var import_IntlayerClientProvider = require('./IntlayerClientProvider.cjs');
|
|
29
29
|
const { defaultLocale, locales: availableLocales } = import_client.intlayerIntlConfiguration;
|
|
30
30
|
const useLocale = () => {
|
|
31
|
-
const { locale } = (0, import_react.useContext)(
|
|
31
|
+
const { locale } = (0, import_react.useContext)(import_IntlayerClientProvider.IntlayerClientContext);
|
|
32
32
|
return {
|
|
33
33
|
locale,
|
|
34
34
|
// Current locale
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["'use client';\n\nimport { intlayerIntlConfiguration } from '@intlayer/config/client';\nimport { localeList } from '@intlayer/core';\nimport { useContext } from 'react';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["'use client';\n\nimport { intlayerIntlConfiguration } from '@intlayer/config/client';\nimport { localeList } from '@intlayer/core';\nimport { useContext } from 'react';\nimport { IntlayerClientContext } from './IntlayerClientProvider';\n\nconst { defaultLocale, locales: availableLocales } = intlayerIntlConfiguration;\n\n/**\n * On the client side, hook to get the current locale and all related fields\n */\nexport const useLocale = () => {\n const { locale } = 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 };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,oBAA0C;AAC1C,kBAA2B;AAC3B,mBAA2B;AAC3B,oCAAsC;AAEtC,MAAM,EAAE,eAAe,SAAS,iBAAiB,IAAI;AAK9C,MAAM,YAAY,MAAM;AAC7B,QAAM,EAAE,OAAO,QAAI,yBAAW,mDAAqB;AAEnD,SAAO;AAAA,IACL;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1,5 +1,8 @@
|
|
|
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;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/useLocaleCookie.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../../src/client/useLocaleCookie.ts"],"sourcesContent":["import {\n type Locales,\n intlayerMiddlewareConfiguration,\n} from '@intlayer/config/client';\nimport Cookies from 'js-cookie';\n\nconst { cookieName } = intlayerMiddlewareConfiguration;\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,oBAGO;AACP,uBAAoB;AAEpB,MAAM,EAAE,WAAW,IAAI;AAEvB,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 * const content = getTranslation<string>({\n * en: 'Hello',\n * fr: 'Bonjour',\n * },\n * 'fr');\n * // 'Bonjour'\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;AAsB/B,MAAM,gBAAgB,CAC3B,oBACY;AACZ,QAAM,EAAE,OAAO,QAAI,yBAAW,mDAAqB;AAEnD,aAAO,sCAAe,iBAAiB,MAAM;AAC/C;","names":[]}
|
|
@@ -1,5 +1,25 @@
|
|
|
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
|
+
* const content = getTranslation<string>({
|
|
13
|
+
* en: 'Hello',
|
|
14
|
+
* fr: 'Bonjour',
|
|
15
|
+
* },
|
|
16
|
+
* 'fr');
|
|
17
|
+
* // 'Bonjour'
|
|
18
|
+
*
|
|
19
|
+
* Using TypeScript:
|
|
20
|
+
* - this function will require each locale to be defined if defined in the project configuration.
|
|
21
|
+
* - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.
|
|
22
|
+
*/
|
|
23
|
+
declare const useTraduction: <Content = string>(languageContent: LanguageContent<Content>) => Content;
|
|
4
24
|
|
|
5
25
|
export { useTraduction };
|
|
@@ -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 * 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 * },\n * 2);\n * // 'You have two'\n *\n * The order of the keys will define the priority of the content.\n *\n * const content = getEnumeration({\n * '<4': 'You have less than four',\n * '2': 'You have two',\n * });\n * // 'You have less than four'\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;AA2BvB,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,30 @@
|
|
|
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
|
+
* const content = getEnumeration({
|
|
11
|
+
* '<=-2.3': 'You have less than -2.3',
|
|
12
|
+
* '<1': 'You have less than one',
|
|
13
|
+
* '2': 'You have two',
|
|
14
|
+
* '>=3': 'You have three or more',
|
|
15
|
+
* },
|
|
16
|
+
* 2);
|
|
17
|
+
* // 'You have two'
|
|
18
|
+
*
|
|
19
|
+
* The order of the keys will define the priority of the content.
|
|
20
|
+
*
|
|
21
|
+
* const content = getEnumeration({
|
|
22
|
+
* '<4': 'You have less than four',
|
|
23
|
+
* '2': 'You have two',
|
|
24
|
+
* });
|
|
25
|
+
* // 'You have less than four'
|
|
26
|
+
*
|
|
27
|
+
*/
|
|
3
28
|
declare const getEnumeration: <Content>(enumerationContent: QuantityContent<Content>, quantity: number) => Content;
|
|
4
29
|
|
|
5
30
|
export { getEnumeration };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/getTranslation.ts"],"sourcesContent":["import {\n type Locales,\n intlayerIntlConfiguration,\n} from '@intlayer/config/client';\nimport { type LanguageContent, getTranslationContent } from '@intlayer/core';\nimport { contentRender } from './ContentEditor/contentRender';\n\nexport const getTranslation = <Content>(\n languageContent: LanguageContent<Content>,\n locale?: Locales\n): Content => {\n const { defaultLocale } = intlayerIntlConfiguration;\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,oBAGO;AACP,kBAA4D;AAC5D,2BAA8B;
|
|
1
|
+
{"version":3,"sources":["../../src/getTranslation.ts"],"sourcesContent":["import {\n type Locales,\n intlayerIntlConfiguration,\n} 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 * const content = getTranslation<string>({\n * en: 'Hello',\n * fr: 'Bonjour',\n * },\n * 'fr');\n * // 'Bonjour'\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 } = intlayerIntlConfiguration;\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,oBAGO;AACP,kBAA4D;AAC5D,2BAA8B;AAsBvB,MAAM,iBAAiB,CAC5B,iBACA,WACY;AACZ,QAAM,EAAE,cAAc,IAAI;AAE1B,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,26 @@
|
|
|
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
|
+
* const content = getTranslation<string>({
|
|
14
|
+
* en: 'Hello',
|
|
15
|
+
* fr: 'Bonjour',
|
|
16
|
+
* },
|
|
17
|
+
* 'fr');
|
|
18
|
+
* // 'Bonjour'
|
|
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 getTranslation: <Content = string>(languageContent: LanguageContent<Content>, locale?: Locales) => Content;
|
|
5
25
|
|
|
6
26
|
export { getTranslation };
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -18,14 +18,13 @@ 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
23
|
getTranslation: () => import_getTranslation.getTranslation,
|
|
24
24
|
localeCookie: () => import_client.localeCookie,
|
|
25
25
|
setLocaleCookie: () => import_client.setLocaleCookie,
|
|
26
26
|
useIntlayer: () => import_client.useIntlayer,
|
|
27
27
|
useLocale: () => import_client.useLocale,
|
|
28
|
-
useLocaleContext: () => import_client.useLocaleContext,
|
|
29
28
|
useLocaleCookie: () => import_client.useLocaleCookie,
|
|
30
29
|
useTraduction: () => import_client.useTraduction
|
|
31
30
|
});
|
|
@@ -34,14 +33,13 @@ var import_getTranslation = require('./getTranslation.cjs');
|
|
|
34
33
|
var import_client = require('./client/index.cjs');
|
|
35
34
|
// Annotate the CommonJS export names for ESM import in node:
|
|
36
35
|
0 && (module.exports = {
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
IntlayerClient,
|
|
37
|
+
IntlayerClientProvider,
|
|
39
38
|
getTranslation,
|
|
40
39
|
localeCookie,
|
|
41
40
|
setLocaleCookie,
|
|
42
41
|
useIntlayer,
|
|
43
42
|
useLocale,
|
|
44
|
-
useLocaleContext,
|
|
45
43
|
useLocaleCookie,
|
|
46
44
|
useTraduction
|
|
47
45
|
});
|
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} from './client/index';\nexport {} from './client/useLocaleCookie';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAA+B;AAC/B,oBAUO;","names":[]}
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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
4
|
export { useLocale } from './client/useLocale.js';
|
|
5
5
|
export { useTraduction } from './client/useTraduction.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/processDictionary/index.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport {\n type Locales,\n intlayerIntlConfiguration,\n} from '@intlayer/config/client';\nimport {\n NodeType,\n type QuantityContent,\n type LanguageContent,\n} from '@intlayer/core';\nimport { getEnumeration } from '../getEnumeration';\nimport { getTranslation } from '../getTranslation';\nimport type {\n Content,\n ContentValue,\n TransformedContent,\n TransformedContentValue,\n} from './contentDictionary';\n\nconst defaultLocale = intlayerIntlConfiguration.defaultLocale;\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\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/**\n * Function
|
|
1
|
+
{"version":3,"sources":["../../../src/processDictionary/index.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport {\n type Locales,\n intlayerIntlConfiguration,\n} from '@intlayer/config/client';\nimport {\n NodeType,\n type QuantityContent,\n type LanguageContent,\n} from '@intlayer/core';\nimport { getEnumeration } from '../getEnumeration';\nimport { getTranslation } from '../getTranslation';\nimport type {\n Content,\n ContentValue,\n TransformedContent,\n TransformedContentValue,\n} from './contentDictionary';\n\nconst defaultLocale = intlayerIntlConfiguration.defaultLocale;\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\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/**\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 (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,oBAGO;AACP,kBAIO;AACP,4BAA+B;AAC/B,4BAA+B;AAQ/B,MAAM,gBAAgB,wCAA0B;AAEhD,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;AAEO,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;AAKO,MAAM,oBAAoB,CAC/B,SACA,SAAkB,kBACK;AACvB,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":[]}
|
|
@@ -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
|
|
|
@@ -16,25 +16,31 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var
|
|
20
|
-
__export(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
locale: () => locale
|
|
19
|
+
var IntlayerServerProvider_exports = {};
|
|
20
|
+
__export(IntlayerServerProvider_exports, {
|
|
21
|
+
IntlayerServerContext: () => IntlayerServerContext,
|
|
22
|
+
IntlayerServerProvider: () => IntlayerServerProvider,
|
|
23
|
+
locale: () => locale,
|
|
24
|
+
useIntlayer: () => useIntlayer
|
|
24
25
|
});
|
|
25
|
-
module.exports = __toCommonJS(
|
|
26
|
+
module.exports = __toCommonJS(IntlayerServerProvider_exports);
|
|
26
27
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
27
28
|
var import_client = require("@intlayer/config/client");
|
|
28
29
|
var import_serverContext = require('./serverContext.cjs');
|
|
29
|
-
const
|
|
30
|
+
const IntlayerServerContext = (0, import_serverContext.createServerContext)(
|
|
30
31
|
import_client.intlayerIntlConfiguration.defaultLocale
|
|
31
32
|
);
|
|
32
|
-
const
|
|
33
|
-
const
|
|
33
|
+
const useIntlayer = () => (0, import_serverContext.getServerContext)(IntlayerServerContext);
|
|
34
|
+
const locale = (0, import_serverContext.getServerContext)(IntlayerServerContext);
|
|
35
|
+
const IntlayerServerProvider = ({
|
|
36
|
+
children,
|
|
37
|
+
locale: locale2
|
|
38
|
+
}) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(IntlayerServerContext.Provider, { value: locale2, children });
|
|
34
39
|
// Annotate the CommonJS export names for ESM import in node:
|
|
35
40
|
0 && (module.exports = {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
locale
|
|
41
|
+
IntlayerServerContext,
|
|
42
|
+
IntlayerServerProvider,
|
|
43
|
+
locale,
|
|
44
|
+
useIntlayer
|
|
39
45
|
});
|
|
40
|
-
//# sourceMappingURL=
|
|
46
|
+
//# sourceMappingURL=IntlayerServerProvider.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/server/IntlayerServerProvider.tsx"],"sourcesContent":["import {\n type Locales,\n intlayerIntlConfiguration,\n} 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 = createServerContext<Locales>(\n intlayerIntlConfiguration.defaultLocale\n);\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,\n}) => (\n <IntlayerServerContext.Provider value={locale}>\n {children}\n </IntlayerServerContext.Provider>\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAmCE;AAnCF,oBAGO;AAEP,2BAAsD;AAK/C,MAAM,4BAAwB;AAAA,EACnC,wCAA0B;AAC5B;AAKO,MAAM,cAAc,UAAM,uCAAiB,qBAAqB;AAKhE,MAAM,aAAS,uCAAiB,qBAAqB;AASrD,MAAM,yBAA0D,CAAC;AAAA,EACtE;AAAA,EACA,QAAAA;AACF,MACE,4CAAC,sBAAsB,UAAtB,EAA+B,OAAOA,SACpC,UACH;","names":["locale"]}
|
package/dist/{esm/server/LocaleServerContextProvider.d.mts → cjs/server/IntlayerServerProvider.d.ts}
RENAMED
|
@@ -2,7 +2,10 @@ import * as react from 'react';
|
|
|
2
2
|
import { PropsWithChildren, FC } from 'react';
|
|
3
3
|
import { Locales } from '@intlayer/config/client';
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Context that store the current locale on the server side
|
|
7
|
+
*/
|
|
8
|
+
declare const IntlayerServerContext: {
|
|
6
9
|
Provider: ({ children, value, }: {
|
|
7
10
|
children: react.ReactNode;
|
|
8
11
|
value: Locales;
|
|
@@ -15,10 +18,20 @@ declare const LocaleServerContext: {
|
|
|
15
18
|
};
|
|
16
19
|
_defaultValue: Locales | undefined;
|
|
17
20
|
};
|
|
21
|
+
/**
|
|
22
|
+
* Hook that provides the current locale
|
|
23
|
+
*/
|
|
24
|
+
declare const useIntlayer: () => Locales | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Get the current locale
|
|
27
|
+
*/
|
|
18
28
|
declare const locale: Locales | undefined;
|
|
19
|
-
type
|
|
29
|
+
type IntlayerServerProviderProps = PropsWithChildren & {
|
|
20
30
|
locale: Locales;
|
|
21
31
|
};
|
|
22
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Provider that store the current locale on the server side
|
|
34
|
+
*/
|
|
35
|
+
declare const IntlayerServerProvider: FC<IntlayerServerProviderProps>;
|
|
23
36
|
|
|
24
|
-
export {
|
|
37
|
+
export { IntlayerServerContext, IntlayerServerProvider, type IntlayerServerProviderProps, locale, useIntlayer };
|
|
@@ -23,10 +23,10 @@ __export(getLocaleTranslation_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(getLocaleTranslation_exports);
|
|
24
24
|
var import_client = require("@intlayer/config/client");
|
|
25
25
|
var import_core = require("@intlayer/core");
|
|
26
|
-
var
|
|
26
|
+
var import_IntlayerServerProvider = require('./IntlayerServerProvider.cjs');
|
|
27
27
|
var import_serverContext = require('./serverContext.cjs');
|
|
28
28
|
const getLocaleTranslation = (languageContent) => {
|
|
29
|
-
const locale = (0, import_serverContext.getServerContext)(
|
|
29
|
+
const locale = (0, import_serverContext.getServerContext)(import_IntlayerServerProvider.IntlayerServerContext);
|
|
30
30
|
const content = (0, import_core.getTranslationContent)(
|
|
31
31
|
languageContent,
|
|
32
32
|
locale ?? import_client.intlayerIntlConfiguration.defaultLocale
|