react-intlayer 1.2.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/IntlayerProvider.cjs +1 -1
- package/dist/cjs/IntlayerProvider.cjs.map +1 -1
- package/dist/cjs/cli/react-intlayer.cjs +68 -0
- package/dist/cjs/cli/react-intlayer.cjs.map +1 -0
- package/dist/cjs/cli/react-intlayer.d.ts +1 -0
- package/dist/cjs/client/IntlayerClientProvider.cjs +26 -2
- package/dist/cjs/client/IntlayerClientProvider.cjs.map +1 -1
- package/dist/cjs/client/IntlayerClientProvider.d.ts +2 -1
- package/dist/cjs/client/getBrowserLocale.cjs +170 -0
- package/dist/cjs/client/getBrowserLocale.cjs.map +1 -0
- package/dist/cjs/client/getBrowserLocale.d.ts +26 -0
- package/dist/cjs/client/index.cjs +6 -0
- package/dist/cjs/client/index.cjs.map +1 -1
- package/dist/cjs/client/index.d.ts +2 -0
- package/dist/cjs/client/useContent.cjs +2 -2
- package/dist/cjs/client/useContent.cjs.map +1 -1
- package/dist/cjs/client/useLocale.cjs +5 -3
- package/dist/cjs/client/useLocale.cjs.map +1 -1
- package/dist/cjs/client/useLocale.d.ts +1 -0
- package/dist/cjs/client/useLocaleBase.cjs +49 -0
- package/dist/cjs/client/useLocaleBase.cjs.map +1 -0
- package/dist/cjs/client/useLocaleBase.d.ts +14 -0
- package/dist/cjs/client/useLocaleCookie.cjs +1 -1
- package/dist/cjs/client/useLocaleCookie.cjs.map +1 -1
- package/dist/cjs/client/useTraduction.cjs.map +1 -1
- package/dist/cjs/client/useTraduction.d.ts +6 -5
- package/dist/cjs/craco/craco.config.cjs +32 -0
- package/dist/cjs/craco/craco.config.cjs.map +1 -0
- package/dist/cjs/craco/craco.config.d.ts +2 -0
- package/dist/cjs/craco/intlayerCracoPlugin.cjs +89 -0
- package/dist/cjs/craco/intlayerCracoPlugin.cjs.map +1 -0
- package/dist/cjs/craco/intlayerCracoPlugin.d.ts +26 -0
- package/dist/cjs/getEnumeration.cjs.map +1 -1
- package/dist/cjs/getEnumeration.d.ts +8 -5
- package/dist/cjs/getTranslation.cjs +1 -1
- package/dist/cjs/getTranslation.cjs.map +1 -1
- package/dist/cjs/getTranslation.d.ts +3 -2
- package/dist/cjs/index.cjs +4 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/processDictionary/index.cjs +33 -1
- package/dist/cjs/processDictionary/index.cjs.map +1 -1
- package/dist/cjs/server/IntlayerServerProvider.cjs +1 -1
- package/dist/cjs/server/IntlayerServerProvider.cjs.map +1 -1
- package/dist/cjs/server/getLocaleTranslation.cjs +1 -1
- package/dist/cjs/server/getLocaleTranslation.cjs.map +1 -1
- package/dist/cjs/server/useTraduction.cjs.map +1 -1
- package/dist/cjs/server/useTraduction.d.ts +4 -3
- package/dist/cjs/vite/intlayerPlugin.cjs +60 -0
- package/dist/cjs/vite/intlayerPlugin.cjs.map +1 -0
- package/dist/cjs/vite/intlayerPlugin.d.ts +17 -0
- package/dist/esm/ContentEditor/ContentEditor.mjs +1 -0
- package/dist/esm/ContentEditor/ContentEditor.mjs.map +1 -1
- package/dist/esm/ContentEditor/contentRender.mjs +1 -0
- package/dist/esm/ContentEditor/contentRender.mjs.map +1 -1
- package/dist/esm/IntlayerProvider.mjs +3 -2
- package/dist/esm/IntlayerProvider.mjs.map +1 -1
- package/dist/esm/chunk-ZNCO4QRF.mjs +9 -0
- package/dist/esm/chunk-ZNCO4QRF.mjs.map +1 -0
- package/dist/esm/cli/react-intlayer.d.mts +1 -0
- package/dist/esm/cli/react-intlayer.mjs +45 -0
- package/dist/esm/cli/react-intlayer.mjs.map +1 -0
- package/dist/esm/client/IntlayerClientProvider.d.mts +2 -1
- package/dist/esm/client/IntlayerClientProvider.mjs +33 -7
- package/dist/esm/client/IntlayerClientProvider.mjs.map +1 -1
- package/dist/esm/client/getBrowserLocale.d.mts +26 -0
- package/dist/esm/client/getBrowserLocale.mjs +146 -0
- package/dist/esm/client/getBrowserLocale.mjs.map +1 -0
- package/dist/esm/client/index.d.mts +2 -0
- package/dist/esm/client/index.mjs +5 -0
- package/dist/esm/client/index.mjs.map +1 -1
- package/dist/esm/client/useContent.mjs +3 -2
- package/dist/esm/client/useContent.mjs.map +1 -1
- package/dist/esm/client/useIntlayer.mjs +1 -0
- package/dist/esm/client/useIntlayer.mjs.map +1 -1
- package/dist/esm/client/useLocale.d.mts +1 -0
- package/dist/esm/client/useLocale.mjs +7 -4
- package/dist/esm/client/useLocale.mjs.map +1 -1
- package/dist/esm/client/useLocaleBase.d.mts +14 -0
- package/dist/esm/client/useLocaleBase.mjs +26 -0
- package/dist/esm/client/useLocaleBase.mjs.map +1 -0
- package/dist/esm/client/useLocaleCookie.mjs +3 -4
- package/dist/esm/client/useLocaleCookie.mjs.map +1 -1
- package/dist/esm/client/useTraduction.d.mts +6 -5
- package/dist/esm/client/useTraduction.mjs +1 -0
- package/dist/esm/client/useTraduction.mjs.map +1 -1
- package/dist/esm/craco/craco.config.d.mts +2 -0
- package/dist/esm/craco/craco.config.mjs +17 -0
- package/dist/esm/craco/craco.config.mjs.map +1 -0
- package/dist/esm/craco/intlayerCracoPlugin.d.mts +26 -0
- package/dist/esm/craco/intlayerCracoPlugin.mjs +54 -0
- package/dist/esm/craco/intlayerCracoPlugin.mjs.map +1 -0
- package/dist/esm/getEnumeration.d.mts +8 -5
- package/dist/esm/getEnumeration.mjs +1 -0
- package/dist/esm/getEnumeration.mjs.map +1 -1
- package/dist/esm/getTranslation.d.mts +3 -2
- package/dist/esm/getTranslation.mjs +3 -4
- package/dist/esm/getTranslation.mjs.map +1 -1
- package/dist/esm/index.d.mts +2 -0
- package/dist/esm/index.mjs +6 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/processDictionary/index.mjs +35 -4
- package/dist/esm/processDictionary/index.mjs.map +1 -1
- package/dist/esm/server/IntlayerServerProvider.mjs +3 -4
- package/dist/esm/server/IntlayerServerProvider.mjs.map +1 -1
- package/dist/esm/server/getLocaleTranslation.mjs +3 -2
- package/dist/esm/server/getLocaleTranslation.mjs.map +1 -1
- package/dist/esm/server/index.mjs +1 -0
- package/dist/esm/server/index.mjs.map +1 -1
- package/dist/esm/server/serverContext.mjs +1 -0
- package/dist/esm/server/serverContext.mjs.map +1 -1
- package/dist/esm/server/useIntlayer.mjs +1 -0
- package/dist/esm/server/useIntlayer.mjs.map +1 -1
- package/dist/esm/server/useTraduction.d.mts +4 -3
- package/dist/esm/server/useTraduction.mjs +1 -0
- package/dist/esm/server/useTraduction.mjs.map +1 -1
- package/dist/esm/useIntlayerBase.mjs +1 -0
- package/dist/esm/useIntlayerBase.mjs.map +1 -1
- package/dist/esm/vite/intlayerPlugin.d.mts +17 -0
- package/dist/esm/vite/intlayerPlugin.mjs +36 -0
- package/dist/esm/vite/intlayerPlugin.mjs.map +1 -0
- package/package.json +30 -5
- package/src/IntlayerProvider.tsx +2 -2
- package/src/cli/react-intlayer.ts +60 -0
- package/src/client/IntlayerClientProvider.tsx +43 -12
- package/src/client/getBrowserLocale.tsx +192 -0
- package/src/client/index.ts +2 -0
- package/src/client/useContent.ts +2 -2
- package/src/client/useLocale.ts +5 -4
- package/src/client/useLocaleBase.ts +24 -0
- package/src/client/useLocaleCookie.ts +2 -5
- package/src/client/useTraduction.ts +6 -5
- package/src/craco/craco.config.ts +11 -0
- package/src/craco/intlayerCracoPlugin.ts +89 -0
- package/src/getEnumeration.ts +8 -5
- package/src/getTranslation.ts +5 -7
- package/src/index.ts +2 -1
- package/src/processDictionary/index.ts +52 -5
- package/src/server/IntlayerServerProvider.tsx +2 -5
- package/src/server/getLocaleTranslation.ts +2 -2
- package/src/server/useTraduction.ts +4 -3
- package/src/vite/intlayerPlugin.ts +59 -0
|
@@ -25,7 +25,7 @@ var import_jsx_runtime = require("react/jsx-runtime");
|
|
|
25
25
|
var import_client = require("@intlayer/config/client");
|
|
26
26
|
var import_IntlayerClientProvider = require('./client/IntlayerClientProvider.cjs');
|
|
27
27
|
var import_IntlayerServerProvider = require('./server/IntlayerServerProvider.cjs');
|
|
28
|
-
const defaultLocale = import_client.
|
|
28
|
+
const { defaultLocale } = (0, import_client.getConfiguration)().internationalization;
|
|
29
29
|
const IntlayerProvider = ({
|
|
30
30
|
children,
|
|
31
31
|
locale = defaultLocale
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/IntlayerProvider.tsx"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../src/IntlayerProvider.tsx"],"sourcesContent":["import { getConfiguration } 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 } = getConfiguration().internationalization;\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,oBAAiC;AAEjC,oCAGO;AACP,oCAGO;AAEP,MAAM,EAAE,cAAc,QAAI,gCAAiB,EAAE;AAKtC,MAAM,mBAA8C,CAAC;AAAA,EAC1D;AAAA,EACA,SAAS;AACX,MACE,4CAAC,wDAAuB,QACtB,sDAAC,wDAAuB,QAAiB,UAAS,GACpD;","names":[]}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
18
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
19
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
20
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
21
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
22
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
23
|
+
mod
|
|
24
|
+
));
|
|
25
|
+
var import_cross_spawn = __toESM(require("cross-spawn"));
|
|
26
|
+
const args = process.argv.slice(2);
|
|
27
|
+
const scriptIndex = args.findIndex(
|
|
28
|
+
(x) => x === "build" || x === "start" || x === "test"
|
|
29
|
+
);
|
|
30
|
+
const script = scriptIndex === -1 ? args[0] : args[scriptIndex];
|
|
31
|
+
switch (script) {
|
|
32
|
+
case "build":
|
|
33
|
+
case "start":
|
|
34
|
+
case "test": {
|
|
35
|
+
const nodeArgs = scriptIndex > 0 ? args.slice(0, scriptIndex) : [];
|
|
36
|
+
const scriptPath = require.resolve(`@craco/craco/dist/scripts/${script}`);
|
|
37
|
+
const scriptArgs = args.slice(scriptIndex + 1);
|
|
38
|
+
const processArgs = nodeArgs.concat(scriptPath).concat([
|
|
39
|
+
...scriptArgs,
|
|
40
|
+
"--config",
|
|
41
|
+
"./node_modules/react-intlayer/dist/cjs/craco/craco.config.cjs"
|
|
42
|
+
]);
|
|
43
|
+
const child = import_cross_spawn.default.sync("node", processArgs, { stdio: "inherit" });
|
|
44
|
+
if (child.signal) {
|
|
45
|
+
if (child.signal === "SIGKILL") {
|
|
46
|
+
console.info(`
|
|
47
|
+
The build failed because the process exited too early.
|
|
48
|
+
This probably means the system ran out of memory or someone called
|
|
49
|
+
\`kill -9\` on the process.
|
|
50
|
+
`);
|
|
51
|
+
} else if (child.signal === "SIGTERM") {
|
|
52
|
+
console.info(`
|
|
53
|
+
The build failed because the process exited too early.
|
|
54
|
+
Someone might have called \`kill\` or \`killall\`, or the system could
|
|
55
|
+
be shutting down.
|
|
56
|
+
`);
|
|
57
|
+
}
|
|
58
|
+
process.exit(1);
|
|
59
|
+
}
|
|
60
|
+
process.exit(child.status ?? void 0);
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
default:
|
|
64
|
+
console.info(`Unknown script "${script}".`);
|
|
65
|
+
console.info("Perhaps you need to update craco?");
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=react-intlayer.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/cli/react-intlayer.ts"],"sourcesContent":["#!/usr/bin/env node\n\n/**\n * To make the setup easier, we are using craco to override the webpack configuration.\n * This script is used to run the craco scripts with the custom configuration.\n *\n * The script is based on the original craco script from create-react-app.\n */\n\nimport spawn from 'cross-spawn';\n\nconst args = process.argv.slice(2);\nconst scriptIndex = args.findIndex(\n (x) => x === 'build' || x === 'start' || x === 'test'\n);\nconst script = scriptIndex === -1 ? args[0] : args[scriptIndex];\n\nswitch (script) {\n case 'build':\n case 'start':\n case 'test': {\n const nodeArgs = scriptIndex > 0 ? args.slice(0, scriptIndex) : [];\n const scriptPath = require.resolve(`@craco/craco/dist/scripts/${script}`);\n const scriptArgs = args.slice(scriptIndex + 1);\n const processArgs = nodeArgs\n .concat(scriptPath)\n .concat([\n ...scriptArgs,\n '--config',\n './node_modules/react-intlayer/dist/cjs/craco/craco.config.cjs',\n ]);\n\n const child = spawn.sync('node', processArgs, { stdio: 'inherit' });\n\n if (child.signal) {\n if (child.signal === 'SIGKILL') {\n console.info(`\n The build failed because the process exited too early.\n This probably means the system ran out of memory or someone called\n \\`kill -9\\` on the process.\n `);\n } else if (child.signal === 'SIGTERM') {\n console.info(`\n The build failed because the process exited too early.\n Someone might have called \\`kill\\` or \\`killall\\`, or the system could\n be shutting down.\n `);\n }\n\n process.exit(1);\n }\n\n process.exit(child.status ?? undefined);\n break;\n }\n default:\n console.info(`Unknown script \"${script}\".`);\n console.info('Perhaps you need to update craco?');\n break;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AASA,yBAAkB;AAElB,MAAM,OAAO,QAAQ,KAAK,MAAM,CAAC;AACjC,MAAM,cAAc,KAAK;AAAA,EACvB,CAAC,MAAM,MAAM,WAAW,MAAM,WAAW,MAAM;AACjD;AACA,MAAM,SAAS,gBAAgB,KAAK,KAAK,CAAC,IAAI,KAAK,WAAW;AAE9D,QAAQ,QAAQ;AAAA,EACd,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK,QAAQ;AACX,UAAM,WAAW,cAAc,IAAI,KAAK,MAAM,GAAG,WAAW,IAAI,CAAC;AACjE,UAAM,aAAa,QAAQ,QAAQ,6BAA6B,MAAM,EAAE;AACxE,UAAM,aAAa,KAAK,MAAM,cAAc,CAAC;AAC7C,UAAM,cAAc,SACjB,OAAO,UAAU,EACjB,OAAO;AAAA,MACN,GAAG;AAAA,MACH;AAAA,MACA;AAAA,IACF,CAAC;AAEH,UAAM,QAAQ,mBAAAA,QAAM,KAAK,QAAQ,aAAa,EAAE,OAAO,UAAU,CAAC;AAElE,QAAI,MAAM,QAAQ;AAChB,UAAI,MAAM,WAAW,WAAW;AAC9B,gBAAQ,KAAK;AAAA;AAAA;AAAA;AAAA,aAIR;AAAA,MACP,WAAW,MAAM,WAAW,WAAW;AACrC,gBAAQ,KAAK;AAAA;AAAA;AAAA;AAAA,aAIR;AAAA,MACP;AAEA,cAAQ,KAAK,CAAC;AAAA,IAChB;AAEA,YAAQ,KAAK,MAAM,UAAU,MAAS;AACtC;AAAA,EACF;AAAA,EACA;AACE,YAAQ,KAAK,mBAAmB,MAAM,IAAI;AAC1C,YAAQ,KAAK,mCAAmC;AAChD;AACJ;","names":["spawn"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
@@ -29,13 +29,37 @@ var import_client = require("@intlayer/config/client");
|
|
|
29
29
|
var import_react = require("react");
|
|
30
30
|
var import_useLocaleCookie = require('./useLocaleCookie.cjs');
|
|
31
31
|
const IntlayerClientContext = (0, import_react.createContext)({
|
|
32
|
-
locale: import_useLocaleCookie.localeCookie ?? import_client.
|
|
32
|
+
locale: import_useLocaleCookie.localeCookie ?? (0, import_client.getConfiguration)().internationalization.defaultLocale,
|
|
33
|
+
setLocale: () => null
|
|
33
34
|
});
|
|
34
35
|
const useIntlayerContext = () => (0, import_react.useContext)(IntlayerClientContext);
|
|
35
36
|
const IntlayerClientProvider = ({
|
|
36
37
|
locale,
|
|
37
38
|
children
|
|
38
|
-
}) =>
|
|
39
|
+
}) => {
|
|
40
|
+
const { defaultLocale, locales: availableLocales } = (0, import_client.getConfiguration)().internationalization;
|
|
41
|
+
const [currentLocale, setCurrentLocale] = (0, import_react.useState)(
|
|
42
|
+
locale ?? import_useLocaleCookie.localeCookie ?? defaultLocale
|
|
43
|
+
);
|
|
44
|
+
const setLocale = (0, import_react.useCallback)(
|
|
45
|
+
(newLocale) => {
|
|
46
|
+
if (currentLocale.toString() === newLocale.toString())
|
|
47
|
+
return;
|
|
48
|
+
if (!availableLocales.includes(newLocale)) {
|
|
49
|
+
console.error(`Locale ${locale} is not available`);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
setCurrentLocale(newLocale);
|
|
53
|
+
(0, import_useLocaleCookie.setLocaleCookie)(newLocale);
|
|
54
|
+
},
|
|
55
|
+
[availableLocales, currentLocale, locale]
|
|
56
|
+
);
|
|
57
|
+
const value = (0, import_react.useMemo)(
|
|
58
|
+
() => ({ locale: currentLocale, setLocale }),
|
|
59
|
+
[currentLocale, setLocale]
|
|
60
|
+
);
|
|
61
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(IntlayerClientContext.Provider, { value, children });
|
|
62
|
+
};
|
|
39
63
|
// Annotate the CommonJS export names for ESM import in node:
|
|
40
64
|
0 && (module.exports = {
|
|
41
65
|
IntlayerClientContext,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/IntlayerClientProvider.tsx"],"sourcesContent":["'use client';\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/client/IntlayerClientProvider.tsx"],"sourcesContent":["'use client';\n\nimport { getConfiguration, type Locales } from '@intlayer/config/client';\nimport {\n type PropsWithChildren,\n createContext,\n useContext,\n useMemo,\n type FC,\n useState,\n useCallback,\n} from 'react';\nimport { localeCookie, setLocaleCookie } from './useLocaleCookie';\n\ntype IntlayerValue = {\n locale: Locales;\n setLocale: (newLocale: Locales) => void;\n};\n\n/**\n * Context that store the current locale on the client side\n */\nexport const IntlayerClientContext = createContext<IntlayerValue>({\n locale: localeCookie ?? getConfiguration().internationalization.defaultLocale,\n setLocale: () => null,\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 const { defaultLocale, locales: availableLocales } =\n getConfiguration().internationalization;\n\n const [currentLocale, setCurrentLocale] = useState(\n locale ?? localeCookie ?? defaultLocale\n );\n\n const setLocale = useCallback(\n (newLocale: Locales) => {\n if (currentLocale.toString() === newLocale.toString()) return;\n\n if (!availableLocales.includes(newLocale)) {\n console.error(`Locale ${locale} is not available`);\n return;\n }\n\n setCurrentLocale(newLocale); // Update state\n setLocaleCookie(newLocale); // Optionally set cookie for persistence\n },\n [availableLocales, currentLocale, locale]\n );\n\n const value: IntlayerValue = useMemo<IntlayerValue>(\n () => ({ locale: currentLocale, setLocale }),\n [currentLocale, setLocale]\n );\n\n return (\n <IntlayerClientContext.Provider value={value}>\n {children}\n </IntlayerClientContext.Provider>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAuEI;AArEJ,oBAA+C;AAC/C,mBAQO;AACP,6BAA8C;AAUvC,MAAM,4BAAwB,4BAA6B;AAAA,EAChE,QAAQ,2CAAgB,gCAAiB,EAAE,qBAAqB;AAAA,EAChE,WAAW,MAAM;AACnB,CAAC;AAKM,MAAM,qBAAqB,UAAM,yBAAW,qBAAqB;AASjE,MAAM,yBAA0D,CAAC;AAAA,EACtE;AAAA,EACA;AACF,MAAM;AACJ,QAAM,EAAE,eAAe,SAAS,iBAAiB,QAC/C,gCAAiB,EAAE;AAErB,QAAM,CAAC,eAAe,gBAAgB,QAAI;AAAA,IACxC,UAAU,uCAAgB;AAAA,EAC5B;AAEA,QAAM,gBAAY;AAAA,IAChB,CAAC,cAAuB;AACtB,UAAI,cAAc,SAAS,MAAM,UAAU,SAAS;AAAG;AAEvD,UAAI,CAAC,iBAAiB,SAAS,SAAS,GAAG;AACzC,gBAAQ,MAAM,UAAU,MAAM,mBAAmB;AACjD;AAAA,MACF;AAEA,uBAAiB,SAAS;AAC1B,kDAAgB,SAAS;AAAA,IAC3B;AAAA,IACA,CAAC,kBAAkB,eAAe,MAAM;AAAA,EAC1C;AAEA,QAAM,YAAuB;AAAA,IAC3B,OAAO,EAAE,QAAQ,eAAe,UAAU;AAAA,IAC1C,CAAC,eAAe,SAAS;AAAA,EAC3B;AAEA,SACE,4CAAC,sBAAsB,UAAtB,EAA+B,OAC7B,UACH;AAEJ;","names":[]}
|
|
@@ -4,6 +4,7 @@ import { Locales } from '@intlayer/config/client';
|
|
|
4
4
|
|
|
5
5
|
type IntlayerValue = {
|
|
6
6
|
locale: Locales;
|
|
7
|
+
setLocale: (newLocale: Locales) => void;
|
|
7
8
|
};
|
|
8
9
|
/**
|
|
9
10
|
* Context that store the current locale on the client side
|
|
@@ -14,7 +15,7 @@ declare const IntlayerClientContext: react.Context<IntlayerValue>;
|
|
|
14
15
|
*/
|
|
15
16
|
declare const useIntlayerContext: () => IntlayerValue;
|
|
16
17
|
type IntlayerClientProviderProps = PropsWithChildren & {
|
|
17
|
-
locale
|
|
18
|
+
locale?: Locales;
|
|
18
19
|
};
|
|
19
20
|
/**
|
|
20
21
|
* Provider that store the current locale on the client side
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var getBrowserLocale_exports = {};
|
|
20
|
+
__export(getBrowserLocale_exports, {
|
|
21
|
+
LanguageDetector: () => LanguageDetector,
|
|
22
|
+
getBrowserLocale: () => getBrowserLocale
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(getBrowserLocale_exports);
|
|
25
|
+
var import_client = require("@intlayer/config/client");
|
|
26
|
+
var import_core = require("@intlayer/core");
|
|
27
|
+
var LanguageDetector = /* @__PURE__ */ ((LanguageDetector2) => {
|
|
28
|
+
LanguageDetector2["Querystring"] = "querystring";
|
|
29
|
+
LanguageDetector2["Cookie"] = "cookie";
|
|
30
|
+
LanguageDetector2["LocalStorage"] = "localStorage";
|
|
31
|
+
LanguageDetector2["SessionStorage"] = "sessionStorage";
|
|
32
|
+
LanguageDetector2["Navigator"] = "navigator";
|
|
33
|
+
LanguageDetector2["HtmlTag"] = "htmlTag";
|
|
34
|
+
return LanguageDetector2;
|
|
35
|
+
})(LanguageDetector || {});
|
|
36
|
+
const getDefaultsOptions = () => {
|
|
37
|
+
const { middleware } = (0, import_client.getConfiguration)();
|
|
38
|
+
return {
|
|
39
|
+
order: [
|
|
40
|
+
"querystring" /* Querystring */,
|
|
41
|
+
"cookie" /* Cookie */,
|
|
42
|
+
"navigator" /* Navigator */,
|
|
43
|
+
"htmlTag" /* HtmlTag */
|
|
44
|
+
],
|
|
45
|
+
lookupQuerystring: "locale",
|
|
46
|
+
lookupCookie: middleware.cookieName,
|
|
47
|
+
htmlTag: document.documentElement
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
const isLocalStorageAvailable = () => {
|
|
51
|
+
try {
|
|
52
|
+
if (typeof window === "undefined")
|
|
53
|
+
return false;
|
|
54
|
+
const testKey = "intlayer.translate.boo";
|
|
55
|
+
window.localStorage.setItem(testKey, "foo");
|
|
56
|
+
window.localStorage.removeItem(testKey);
|
|
57
|
+
return true;
|
|
58
|
+
} catch {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
const isSessionStorageAvailable = () => {
|
|
63
|
+
try {
|
|
64
|
+
if (typeof window === "undefined")
|
|
65
|
+
return false;
|
|
66
|
+
const testKey = "intlayer.translate.boo";
|
|
67
|
+
window.sessionStorage.setItem(testKey, "foo");
|
|
68
|
+
window.sessionStorage.removeItem(testKey);
|
|
69
|
+
return true;
|
|
70
|
+
} catch {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
const detectLanguage = (order, options) => {
|
|
75
|
+
const detected = {};
|
|
76
|
+
const queryStringDetector = () => {
|
|
77
|
+
if (typeof window === "undefined")
|
|
78
|
+
return;
|
|
79
|
+
const search = window.location.search || "";
|
|
80
|
+
const params = new URLSearchParams(search);
|
|
81
|
+
const value = params.get(options.lookupQuerystring ?? "");
|
|
82
|
+
if (value) {
|
|
83
|
+
detected["querystring" /* Querystring */] = value;
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
const cookieDetector = () => {
|
|
87
|
+
if (typeof document === "undefined")
|
|
88
|
+
return;
|
|
89
|
+
const cookies = document.cookie.split(";");
|
|
90
|
+
const cookieName = `${options.lookupCookie ?? ""}=`;
|
|
91
|
+
const cookie = cookies.find((c) => c.trim().startsWith(cookieName));
|
|
92
|
+
if (cookie) {
|
|
93
|
+
const value = cookie.split("=")[1].trim();
|
|
94
|
+
detected["cookie" /* Cookie */] = value;
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
const localStorageDetector = () => {
|
|
98
|
+
if (!isLocalStorageAvailable())
|
|
99
|
+
return;
|
|
100
|
+
const value = window.localStorage.getItem(options.lookupLocalStorage ?? "");
|
|
101
|
+
if (value) {
|
|
102
|
+
detected["localStorage" /* LocalStorage */] = value;
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
const sessionStorageDetector = () => {
|
|
106
|
+
if (!isSessionStorageAvailable())
|
|
107
|
+
return;
|
|
108
|
+
const value = window.sessionStorage.getItem(
|
|
109
|
+
options.lookupSessionStorage ?? ""
|
|
110
|
+
);
|
|
111
|
+
if (value) {
|
|
112
|
+
detected["sessionStorage" /* SessionStorage */] = value;
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
const navigatorDetector = () => {
|
|
116
|
+
if (typeof navigator === "undefined")
|
|
117
|
+
return;
|
|
118
|
+
if (navigator.language) {
|
|
119
|
+
detected["navigator" /* Navigator */] = navigator.language;
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
const htmlTagDetector = () => {
|
|
123
|
+
const htmlTag = options.htmlTag;
|
|
124
|
+
if (htmlTag && typeof htmlTag.getAttribute === "function") {
|
|
125
|
+
const lang = htmlTag.getAttribute("lang");
|
|
126
|
+
if (lang) {
|
|
127
|
+
detected["htmlTag" /* HtmlTag */] = lang;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
const detectors = {
|
|
132
|
+
["querystring" /* Querystring */]: queryStringDetector,
|
|
133
|
+
["cookie" /* Cookie */]: cookieDetector,
|
|
134
|
+
["localStorage" /* LocalStorage */]: localStorageDetector,
|
|
135
|
+
["sessionStorage" /* SessionStorage */]: sessionStorageDetector,
|
|
136
|
+
["navigator" /* Navigator */]: navigatorDetector,
|
|
137
|
+
["htmlTag" /* HtmlTag */]: htmlTagDetector
|
|
138
|
+
};
|
|
139
|
+
order.forEach((detectorName) => {
|
|
140
|
+
detectors[detectorName]?.();
|
|
141
|
+
});
|
|
142
|
+
return detected;
|
|
143
|
+
};
|
|
144
|
+
const getFirstAvailableLocale = (locales, order) => {
|
|
145
|
+
const { internationalization } = (0, import_client.getConfiguration)();
|
|
146
|
+
for (const detector of order) {
|
|
147
|
+
const localesArray = [locales[detector]].flat();
|
|
148
|
+
for (const locale of localesArray) {
|
|
149
|
+
if (locale && (internationalization.locales ?? import_core.localeList).includes(locale)) {
|
|
150
|
+
return locale;
|
|
151
|
+
} else if (locale?.includes("-") && (internationalization.locales ?? import_core.localeList).includes(
|
|
152
|
+
locale.split("-")[0]
|
|
153
|
+
)) {
|
|
154
|
+
return locale.split("-")[0];
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return internationalization.defaultLocale;
|
|
159
|
+
};
|
|
160
|
+
const getBrowserLocale = (userOptions = {}) => {
|
|
161
|
+
const options = { ...getDefaultsOptions(), ...userOptions };
|
|
162
|
+
const locales = detectLanguage(options.order ?? [], options);
|
|
163
|
+
return getFirstAvailableLocale(locales, options.order ?? []);
|
|
164
|
+
};
|
|
165
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
166
|
+
0 && (module.exports = {
|
|
167
|
+
LanguageDetector,
|
|
168
|
+
getBrowserLocale
|
|
169
|
+
});
|
|
170
|
+
//# sourceMappingURL=getBrowserLocale.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/client/getBrowserLocale.tsx"],"sourcesContent":["import { getConfiguration, type Locales } from '@intlayer/config/client';\nimport { localeList } from '@intlayer/core';\n\nexport enum LanguageDetector {\n Querystring = 'querystring',\n Cookie = 'cookie',\n LocalStorage = 'localStorage',\n SessionStorage = 'sessionStorage',\n Navigator = 'navigator',\n HtmlTag = 'htmlTag',\n}\n\n// Default settings for the language detector\ntype LanguageDetectorOptions = {\n order?: LanguageDetector[];\n lookupQuerystring?: string;\n lookupCookie?: string;\n lookupLocalStorage?: string;\n lookupSessionStorage?: string;\n excludeCacheFor?: string[];\n htmlTag?: HTMLElement | null;\n};\n\nconst getDefaultsOptions = (): LanguageDetectorOptions => {\n const { middleware } = getConfiguration();\n\n return {\n order: [\n LanguageDetector.Querystring,\n LanguageDetector.Cookie,\n LanguageDetector.Navigator,\n LanguageDetector.HtmlTag,\n ],\n lookupQuerystring: 'locale',\n lookupCookie: middleware.cookieName,\n htmlTag: document.documentElement,\n };\n};\n\n// Helper functions for various checks and operations\nconst isLocalStorageAvailable = (): boolean => {\n try {\n if (typeof window === 'undefined') return false;\n const testKey = 'intlayer.translate.boo';\n window.localStorage.setItem(testKey, 'foo');\n window.localStorage.removeItem(testKey);\n return true;\n } catch {\n return false;\n }\n};\n\nconst isSessionStorageAvailable = (): boolean => {\n try {\n if (typeof window === 'undefined') return false;\n const testKey = 'intlayer.translate.boo';\n window.sessionStorage.setItem(testKey, 'foo');\n window.sessionStorage.removeItem(testKey);\n return true;\n } catch {\n return false;\n }\n};\n\n// Function to detect language using different detectors\nconst detectLanguage = (\n order: string[],\n options: LanguageDetectorOptions\n): Record<LanguageDetector, Locales | Locales[]> => {\n const detected: Record<LanguageDetector, Locales | Locales[]> = {} as Record<\n LanguageDetector,\n Locales | Locales[]\n >;\n\n const queryStringDetector = () => {\n if (typeof window === 'undefined') return;\n const search = window.location.search || '';\n const params = new URLSearchParams(search);\n const value = params.get(options.lookupQuerystring ?? '');\n if (value) {\n detected[LanguageDetector.Querystring] = value as Locales;\n }\n };\n\n const cookieDetector = () => {\n if (typeof document === 'undefined') return;\n const cookies = document.cookie.split(';');\n const cookieName = `${options.lookupCookie ?? ''}=`;\n const cookie = cookies.find((c) => c.trim().startsWith(cookieName));\n if (cookie) {\n const value = cookie.split('=')[1].trim();\n\n detected[LanguageDetector.Cookie] = value as Locales;\n }\n };\n\n const localStorageDetector = () => {\n if (!isLocalStorageAvailable()) return;\n const value = window.localStorage.getItem(options.lookupLocalStorage ?? '');\n if (value) {\n detected[LanguageDetector.LocalStorage] = value as Locales;\n }\n };\n\n const sessionStorageDetector = () => {\n if (!isSessionStorageAvailable()) return;\n const value = window.sessionStorage.getItem(\n options.lookupSessionStorage ?? ''\n );\n if (value) {\n detected[LanguageDetector.SessionStorage] = value as Locales;\n }\n };\n\n const navigatorDetector = () => {\n if (typeof navigator === 'undefined') return;\n\n if (navigator.language) {\n detected[LanguageDetector.Navigator] = navigator.language as Locales;\n }\n };\n\n const htmlTagDetector = () => {\n const htmlTag = options.htmlTag;\n if (htmlTag && typeof htmlTag.getAttribute === 'function') {\n const lang = htmlTag.getAttribute('lang');\n if (lang) {\n detected[LanguageDetector.HtmlTag] = lang as Locales;\n }\n }\n };\n\n // Map detector names to their corresponding functions\n const detectors: Record<string, () => void> = {\n [LanguageDetector.Querystring]: queryStringDetector,\n [LanguageDetector.Cookie]: cookieDetector,\n [LanguageDetector.LocalStorage]: localStorageDetector,\n [LanguageDetector.SessionStorage]: sessionStorageDetector,\n [LanguageDetector.Navigator]: navigatorDetector,\n [LanguageDetector.HtmlTag]: htmlTagDetector,\n };\n\n // Use the provided order to run each detector\n order.forEach((detectorName) => {\n detectors[detectorName]?.();\n });\n\n return detected;\n};\n\nconst getFirstAvailableLocale = (\n locales: Record<LanguageDetector, Locales | Locales[]>,\n order: LanguageDetector[]\n): Locales => {\n const { internationalization } = getConfiguration();\n\n for (const detector of order) {\n const localesArray = [locales[detector]].flat() as Locales[];\n\n for (const locale of localesArray) {\n if (\n locale &&\n (internationalization.locales ?? localeList).includes(locale)\n ) {\n return locale;\n } else if (\n locale?.includes('-') &&\n (internationalization.locales ?? localeList).includes(\n locale.split('-')[0] as Locales\n )\n ) {\n return locale.split('-')[0] as Locales;\n }\n }\n }\n\n return internationalization.defaultLocale;\n};\n\n/**\n * Core language detector function\n * const detectedLanguages = detectLanguage(['LanguageDetector.Cookie', 'LanguageDetector.LocalStorage'], { lookupCookie: 'myCookie' });\n */\nexport const getBrowserLocale = (\n userOptions: LanguageDetectorOptions | undefined = {}\n): Locales => {\n const options = { ...getDefaultsOptions(), ...userOptions };\n\n const locales = detectLanguage(options.order ?? [], options);\n\n return getFirstAvailableLocale(locales, options.order ?? []);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA+C;AAC/C,kBAA2B;AAEpB,IAAK,mBAAL,kBAAKA,sBAAL;AACL,EAAAA,kBAAA,iBAAc;AACd,EAAAA,kBAAA,YAAS;AACT,EAAAA,kBAAA,kBAAe;AACf,EAAAA,kBAAA,oBAAiB;AACjB,EAAAA,kBAAA,eAAY;AACZ,EAAAA,kBAAA,aAAU;AANA,SAAAA;AAAA,GAAA;AAoBZ,MAAM,qBAAqB,MAA+B;AACxD,QAAM,EAAE,WAAW,QAAI,gCAAiB;AAExC,SAAO;AAAA,IACL,OAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,IACA,mBAAmB;AAAA,IACnB,cAAc,WAAW;AAAA,IACzB,SAAS,SAAS;AAAA,EACpB;AACF;AAGA,MAAM,0BAA0B,MAAe;AAC7C,MAAI;AACF,QAAI,OAAO,WAAW;AAAa,aAAO;AAC1C,UAAM,UAAU;AAChB,WAAO,aAAa,QAAQ,SAAS,KAAK;AAC1C,WAAO,aAAa,WAAW,OAAO;AACtC,WAAO;AAAA,EACT,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEA,MAAM,4BAA4B,MAAe;AAC/C,MAAI;AACF,QAAI,OAAO,WAAW;AAAa,aAAO;AAC1C,UAAM,UAAU;AAChB,WAAO,eAAe,QAAQ,SAAS,KAAK;AAC5C,WAAO,eAAe,WAAW,OAAO;AACxC,WAAO;AAAA,EACT,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAGA,MAAM,iBAAiB,CACrB,OACA,YACkD;AAClD,QAAM,WAA0D,CAAC;AAKjE,QAAM,sBAAsB,MAAM;AAChC,QAAI,OAAO,WAAW;AAAa;AACnC,UAAM,SAAS,OAAO,SAAS,UAAU;AACzC,UAAM,SAAS,IAAI,gBAAgB,MAAM;AACzC,UAAM,QAAQ,OAAO,IAAI,QAAQ,qBAAqB,EAAE;AACxD,QAAI,OAAO;AACT,eAAS,+BAA4B,IAAI;AAAA,IAC3C;AAAA,EACF;AAEA,QAAM,iBAAiB,MAAM;AAC3B,QAAI,OAAO,aAAa;AAAa;AACrC,UAAM,UAAU,SAAS,OAAO,MAAM,GAAG;AACzC,UAAM,aAAa,GAAG,QAAQ,gBAAgB,EAAE;AAChD,UAAM,SAAS,QAAQ,KAAK,CAAC,MAAM,EAAE,KAAK,EAAE,WAAW,UAAU,CAAC;AAClE,QAAI,QAAQ;AACV,YAAM,QAAQ,OAAO,MAAM,GAAG,EAAE,CAAC,EAAE,KAAK;AAExC,eAAS,qBAAuB,IAAI;AAAA,IACtC;AAAA,EACF;AAEA,QAAM,uBAAuB,MAAM;AACjC,QAAI,CAAC,wBAAwB;AAAG;AAChC,UAAM,QAAQ,OAAO,aAAa,QAAQ,QAAQ,sBAAsB,EAAE;AAC1E,QAAI,OAAO;AACT,eAAS,iCAA6B,IAAI;AAAA,IAC5C;AAAA,EACF;AAEA,QAAM,yBAAyB,MAAM;AACnC,QAAI,CAAC,0BAA0B;AAAG;AAClC,UAAM,QAAQ,OAAO,eAAe;AAAA,MAClC,QAAQ,wBAAwB;AAAA,IAClC;AACA,QAAI,OAAO;AACT,eAAS,qCAA+B,IAAI;AAAA,IAC9C;AAAA,EACF;AAEA,QAAM,oBAAoB,MAAM;AAC9B,QAAI,OAAO,cAAc;AAAa;AAEtC,QAAI,UAAU,UAAU;AACtB,eAAS,2BAA0B,IAAI,UAAU;AAAA,IACnD;AAAA,EACF;AAEA,QAAM,kBAAkB,MAAM;AAC5B,UAAM,UAAU,QAAQ;AACxB,QAAI,WAAW,OAAO,QAAQ,iBAAiB,YAAY;AACzD,YAAM,OAAO,QAAQ,aAAa,MAAM;AACxC,UAAI,MAAM;AACR,iBAAS,uBAAwB,IAAI;AAAA,MACvC;AAAA,IACF;AAAA,EACF;AAGA,QAAM,YAAwC;AAAA,IAC5C,CAAC,+BAA4B,GAAG;AAAA,IAChC,CAAC,qBAAuB,GAAG;AAAA,IAC3B,CAAC,iCAA6B,GAAG;AAAA,IACjC,CAAC,qCAA+B,GAAG;AAAA,IACnC,CAAC,2BAA0B,GAAG;AAAA,IAC9B,CAAC,uBAAwB,GAAG;AAAA,EAC9B;AAGA,QAAM,QAAQ,CAAC,iBAAiB;AAC9B,cAAU,YAAY,IAAI;AAAA,EAC5B,CAAC;AAED,SAAO;AACT;AAEA,MAAM,0BAA0B,CAC9B,SACA,UACY;AACZ,QAAM,EAAE,qBAAqB,QAAI,gCAAiB;AAElD,aAAW,YAAY,OAAO;AAC5B,UAAM,eAAe,CAAC,QAAQ,QAAQ,CAAC,EAAE,KAAK;AAE9C,eAAW,UAAU,cAAc;AACjC,UACE,WACC,qBAAqB,WAAW,wBAAY,SAAS,MAAM,GAC5D;AACA,eAAO;AAAA,MACT,WACE,QAAQ,SAAS,GAAG,MACnB,qBAAqB,WAAW,wBAAY;AAAA,QAC3C,OAAO,MAAM,GAAG,EAAE,CAAC;AAAA,MACrB,GACA;AACA,eAAO,OAAO,MAAM,GAAG,EAAE,CAAC;AAAA,MAC5B;AAAA,IACF;AAAA,EACF;AAEA,SAAO,qBAAqB;AAC9B;AAMO,MAAM,mBAAmB,CAC9B,cAAmD,CAAC,MACxC;AACZ,QAAM,UAAU,EAAE,GAAG,mBAAmB,GAAG,GAAG,YAAY;AAE1D,QAAM,UAAU,eAAe,QAAQ,SAAS,CAAC,GAAG,OAAO;AAE3D,SAAO,wBAAwB,SAAS,QAAQ,SAAS,CAAC,CAAC;AAC7D;","names":["LanguageDetector"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Locales } from '@intlayer/config/client';
|
|
2
|
+
|
|
3
|
+
declare enum LanguageDetector {
|
|
4
|
+
Querystring = "querystring",
|
|
5
|
+
Cookie = "cookie",
|
|
6
|
+
LocalStorage = "localStorage",
|
|
7
|
+
SessionStorage = "sessionStorage",
|
|
8
|
+
Navigator = "navigator",
|
|
9
|
+
HtmlTag = "htmlTag"
|
|
10
|
+
}
|
|
11
|
+
type LanguageDetectorOptions = {
|
|
12
|
+
order?: LanguageDetector[];
|
|
13
|
+
lookupQuerystring?: string;
|
|
14
|
+
lookupCookie?: string;
|
|
15
|
+
lookupLocalStorage?: string;
|
|
16
|
+
lookupSessionStorage?: string;
|
|
17
|
+
excludeCacheFor?: string[];
|
|
18
|
+
htmlTag?: HTMLElement | null;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Core language detector function
|
|
22
|
+
* const detectedLanguages = detectLanguage(['LanguageDetector.Cookie', 'LanguageDetector.LocalStorage'], { lookupCookie: 'myCookie' });
|
|
23
|
+
*/
|
|
24
|
+
declare const getBrowserLocale: (userOptions?: LanguageDetectorOptions | undefined) => Locales;
|
|
25
|
+
|
|
26
|
+
export { LanguageDetector, getBrowserLocale };
|
|
@@ -20,29 +20,35 @@ var client_exports = {};
|
|
|
20
20
|
__export(client_exports, {
|
|
21
21
|
IntlayerClient: () => import_IntlayerClientProvider.IntlayerClientContext,
|
|
22
22
|
IntlayerClientProvider: () => import_IntlayerClientProvider.IntlayerClientProvider,
|
|
23
|
+
getBrowserLocale: () => import_getBrowserLocale.getBrowserLocale,
|
|
23
24
|
localeCookie: () => import_useLocaleCookie.localeCookie,
|
|
24
25
|
setLocaleCookie: () => import_useLocaleCookie.setLocaleCookie,
|
|
25
26
|
useIntlayer: () => import_useIntlayer.useIntlayer,
|
|
26
27
|
useIntlayerContext: () => import_IntlayerClientProvider.useIntlayerContext,
|
|
27
28
|
useLocale: () => import_useLocale.useLocale,
|
|
29
|
+
useLocaleBase: () => import_useLocaleBase.useLocaleBase,
|
|
28
30
|
useLocaleCookie: () => import_useLocaleCookie.useLocaleCookie,
|
|
29
31
|
useTraduction: () => import_useTraduction.useTraduction
|
|
30
32
|
});
|
|
31
33
|
module.exports = __toCommonJS(client_exports);
|
|
32
34
|
var import_IntlayerClientProvider = require('./IntlayerClientProvider.cjs');
|
|
33
35
|
var import_useIntlayer = require('./useIntlayer.cjs');
|
|
36
|
+
var import_useLocaleBase = require('./useLocaleBase.cjs');
|
|
34
37
|
var import_useLocale = require('./useLocale.cjs');
|
|
35
38
|
var import_useTraduction = require('./useTraduction.cjs');
|
|
36
39
|
var import_useLocaleCookie = require('./useLocaleCookie.cjs');
|
|
40
|
+
var import_getBrowserLocale = require('./getBrowserLocale.cjs');
|
|
37
41
|
// Annotate the CommonJS export names for ESM import in node:
|
|
38
42
|
0 && (module.exports = {
|
|
39
43
|
IntlayerClient,
|
|
40
44
|
IntlayerClientProvider,
|
|
45
|
+
getBrowserLocale,
|
|
41
46
|
localeCookie,
|
|
42
47
|
setLocaleCookie,
|
|
43
48
|
useIntlayer,
|
|
44
49
|
useIntlayerContext,
|
|
45
50
|
useLocale,
|
|
51
|
+
useLocaleBase,
|
|
46
52
|
useLocaleCookie,
|
|
47
53
|
useTraduction
|
|
48
54
|
});
|
|
@@ -1 +1 @@
|
|
|
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
|
+
{"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 { 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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oCAIO;AACP,yBAA4B;AAC5B,2BAA8B;AAC9B,uBAA0B;AAC1B,2BAA8B;AAC9B,6BAIO;AACP,8BAAiC;","names":[]}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
export { IntlayerClientContext as IntlayerClient, IntlayerClientProvider, IntlayerClientProviderProps, useIntlayerContext } from './IntlayerClientProvider.js';
|
|
2
2
|
export { useIntlayer } from './useIntlayer.js';
|
|
3
|
+
export { useLocaleBase } from './useLocaleBase.js';
|
|
3
4
|
export { useLocale } from './useLocale.js';
|
|
4
5
|
export { useTraduction } from './useTraduction.js';
|
|
5
6
|
export { localeCookie, setLocaleCookie, useLocaleCookie } from './useLocaleCookie.js';
|
|
7
|
+
export { getBrowserLocale } from './getBrowserLocale.js';
|
|
6
8
|
import 'react';
|
|
7
9
|
import '@intlayer/config/client';
|
|
8
10
|
import '../useIntlayerBase.js';
|
|
@@ -21,10 +21,10 @@ __export(useContent_exports, {
|
|
|
21
21
|
useContent: () => useContent
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(useContent_exports);
|
|
24
|
-
var
|
|
24
|
+
var import_useLocaleBase = require('./useLocaleBase.cjs');
|
|
25
25
|
var import_useTraduction = require('./useTraduction.cjs');
|
|
26
26
|
const useContent = (languageContent) => {
|
|
27
|
-
const { locale } = (0,
|
|
27
|
+
const { locale } = (0, import_useLocaleBase.useLocaleBase)();
|
|
28
28
|
const content = (0, import_useTraduction.useTraduction)(languageContent);
|
|
29
29
|
return {
|
|
30
30
|
locale,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/useContent.ts"],"sourcesContent":["import type { LanguageContent } from '@intlayer/core';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/client/useContent.ts"],"sourcesContent":["import type { LanguageContent } from '@intlayer/core';\nimport { useLocaleBase } from './useLocaleBase';\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 } = useLocaleBase();\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,2BAA8B;AAC9B,2BAA8B;AAKvB,MAAM,aAAa,CACxB,oBACG;AACH,QAAM,EAAE,OAAO,QAAI,oCAAc;AAEjC,QAAM,cAAU,oCAAc,eAAe;AAE7C,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EACL;AACF;","names":[]}
|
|
@@ -26,9 +26,9 @@ var import_client = require("@intlayer/config/client");
|
|
|
26
26
|
var import_core = require("@intlayer/core");
|
|
27
27
|
var import_react = require("react");
|
|
28
28
|
var import_IntlayerClientProvider = require('./IntlayerClientProvider.cjs');
|
|
29
|
-
const { defaultLocale, locales: availableLocales } = import_client.intlayerIntlConfiguration;
|
|
30
29
|
const useLocale = () => {
|
|
31
|
-
const {
|
|
30
|
+
const { defaultLocale, locales: availableLocales } = (0, import_client.getConfiguration)().internationalization;
|
|
31
|
+
const { locale, setLocale } = (0, import_react.useContext)(import_IntlayerClientProvider.IntlayerClientContext);
|
|
32
32
|
return {
|
|
33
33
|
locale,
|
|
34
34
|
// Current locale
|
|
@@ -36,8 +36,10 @@ const useLocale = () => {
|
|
|
36
36
|
// Principal locale defined in config
|
|
37
37
|
availableLocales,
|
|
38
38
|
// List of the available locales defined in config
|
|
39
|
-
localeList: import_core.localeList
|
|
39
|
+
localeList: import_core.localeList,
|
|
40
40
|
// List of all available locales
|
|
41
|
+
setLocale
|
|
42
|
+
// Function to set the locale
|
|
41
43
|
};
|
|
42
44
|
};
|
|
43
45
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["'use client';\n\nimport {
|
|
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 './IntlayerClientProvider';\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":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,oBAAiC;AACjC,kBAA2B;AAC3B,mBAA2B;AAC3B,oCAAsC;AAK/B,MAAM,YAAY,MAAM;AAC7B,QAAM,EAAE,eAAe,SAAS,iBAAiB,QAC/C,gCAAiB,EAAE;AACrB,QAAM,EAAE,QAAQ,UAAU,QAAI,yBAAW,mDAAqB;AAE9D,SAAO;AAAA,IACL;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,EACF;AACF;","names":[]}
|
|
@@ -8,6 +8,7 @@ declare const useLocale: () => {
|
|
|
8
8
|
defaultLocale: _intlayer_config_client.Locales;
|
|
9
9
|
availableLocales: _intlayer_config_client.Locales[];
|
|
10
10
|
localeList: _intlayer_config_client.Locales[];
|
|
11
|
+
setLocale: (newLocale: _intlayer_config_client.Locales) => void;
|
|
11
12
|
};
|
|
12
13
|
|
|
13
14
|
export { useLocale };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
var useLocaleBase_exports = {};
|
|
21
|
+
__export(useLocaleBase_exports, {
|
|
22
|
+
useLocaleBase: () => useLocaleBase
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(useLocaleBase_exports);
|
|
25
|
+
var import_client = require("@intlayer/config/client");
|
|
26
|
+
var import_core = require("@intlayer/core");
|
|
27
|
+
var import_react = require("react");
|
|
28
|
+
var import_IntlayerClientProvider = require('./IntlayerClientProvider.cjs');
|
|
29
|
+
const { defaultLocale, locales: availableLocales } = (0, import_client.getConfiguration)().internationalization;
|
|
30
|
+
const useLocaleBase = () => {
|
|
31
|
+
const { locale, setLocale } = (0, import_react.useContext)(import_IntlayerClientProvider.IntlayerClientContext);
|
|
32
|
+
return {
|
|
33
|
+
locale,
|
|
34
|
+
// Current locale
|
|
35
|
+
defaultLocale,
|
|
36
|
+
// Principal locale defined in config
|
|
37
|
+
availableLocales,
|
|
38
|
+
// List of the available locales defined in config
|
|
39
|
+
localeList: import_core.localeList,
|
|
40
|
+
// List of all available locales
|
|
41
|
+
setLocale
|
|
42
|
+
// Function to set the locale
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
46
|
+
0 && (module.exports = {
|
|
47
|
+
useLocaleBase
|
|
48
|
+
});
|
|
49
|
+
//# sourceMappingURL=useLocaleBase.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/client/useLocaleBase.ts"],"sourcesContent":["'use client';\n\nimport { getConfiguration } from '@intlayer/config/client';\nimport { localeList } from '@intlayer/core';\nimport { useContext } from 'react';\nimport { IntlayerClientContext } from './IntlayerClientProvider';\n\nconst { defaultLocale, locales: availableLocales } =\n getConfiguration().internationalization;\n\n/**\n * On the client side, hook to get the current locale and all related fields\n */\nexport const useLocaleBase = () => {\n const { locale, setLocale } = useContext(IntlayerClientContext);\n\n return {\n locale, // Current locale\n defaultLocale, // Principal locale defined in config\n availableLocales, // List of the available locales defined in config\n localeList, // List of all available locales\n setLocale, // Function to set the locale\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,oBAAiC;AACjC,kBAA2B;AAC3B,mBAA2B;AAC3B,oCAAsC;AAEtC,MAAM,EAAE,eAAe,SAAS,iBAAiB,QAC/C,gCAAiB,EAAE;AAKd,MAAM,gBAAgB,MAAM;AACjC,QAAM,EAAE,QAAQ,UAAU,QAAI,yBAAW,mDAAqB;AAE9D,SAAO;AAAA,IACL;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as _intlayer_config_client from '@intlayer/config/client';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* On the client side, hook to get the current locale and all related fields
|
|
5
|
+
*/
|
|
6
|
+
declare const useLocaleBase: () => {
|
|
7
|
+
locale: _intlayer_config_client.Locales;
|
|
8
|
+
defaultLocale: _intlayer_config_client.Locales;
|
|
9
|
+
availableLocales: _intlayer_config_client.Locales[];
|
|
10
|
+
localeList: _intlayer_config_client.Locales[];
|
|
11
|
+
setLocale: (newLocale: _intlayer_config_client.Locales) => void;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export { useLocaleBase };
|
|
@@ -35,7 +35,7 @@ __export(useLocaleCookie_exports, {
|
|
|
35
35
|
module.exports = __toCommonJS(useLocaleCookie_exports);
|
|
36
36
|
var import_client = require("@intlayer/config/client");
|
|
37
37
|
var import_js_cookie = __toESM(require("js-cookie"));
|
|
38
|
-
const { cookieName } = import_client.
|
|
38
|
+
const { cookieName } = (0, import_client.getConfiguration)().middleware;
|
|
39
39
|
const cookieAttributes = {
|
|
40
40
|
path: "/",
|
|
41
41
|
expires: void 0,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/useLocaleCookie.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../../src/client/useLocaleCookie.ts"],"sourcesContent":["import { type Locales, getConfiguration } from '@intlayer/config/client';\nimport Cookies from 'js-cookie';\n\nconst { cookieName } = getConfiguration().middleware;\n\nconst cookieAttributes: Cookies.CookieAttributes = {\n path: '/',\n expires: undefined,\n domain: undefined,\n secure: false,\n sameSite: 'strict',\n};\n\n/**\n * Get the locale cookie\n */\nexport const localeCookie = Cookies.get(cookieName) as Locales | undefined;\n\n/**\n * Set the locale cookie\n */\nexport const setLocaleCookie = (locale: Locales) => {\n Cookies.set(cookieName, locale, cookieAttributes);\n};\n\n/**\n * Hook that provides the locale cookie and a function to set it\n */\nexport const useLocaleCookie = () => ({\n localeCookie,\n setLocaleCookie,\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA+C;AAC/C,uBAAoB;AAEpB,MAAM,EAAE,WAAW,QAAI,gCAAiB,EAAE;AAE1C,MAAM,mBAA6C;AAAA,EACjD,MAAM;AAAA,EACN,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,UAAU;AACZ;AAKO,MAAM,eAAe,iBAAAA,QAAQ,IAAI,UAAU;AAK3C,MAAM,kBAAkB,CAAC,WAAoB;AAClD,mBAAAA,QAAQ,IAAI,YAAY,QAAQ,gBAAgB;AAClD;AAKO,MAAM,kBAAkB,OAAO;AAAA,EACpC;AAAA,EACA;AACF;","names":["Cookies"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/useTraduction.ts"],"sourcesContent":["import type { LanguageContent } from '@intlayer/core';\nimport { useContext } from 'react';\nimport { getTranslation } from '../getTranslation';\nimport { IntlayerClientContext } from './IntlayerClientProvider';\n\n/**\n * On the client side, Hook that picking one dictionary by its id and return the content.\n *\n * If not locale found, it will return the content related to the default locale.\n *\n * Return either the content editor, or the content itself depending on the configuration.\n *\n * Usage:\n *\n * const content =
|
|
1
|
+
{"version":3,"sources":["../../../src/client/useTraduction.ts"],"sourcesContent":["import type { LanguageContent } from '@intlayer/core';\nimport { useContext } from 'react';\nimport { getTranslation } from '../getTranslation';\nimport { IntlayerClientContext } from './IntlayerClientProvider';\n\n/**\n * On the client side, Hook that picking one dictionary by its id and return the content.\n *\n * If not locale found, it will return the content related to the default locale.\n *\n * Return either the content editor, or the content itself depending on the configuration.\n *\n * Usage:\n *\n * ```tsx\n * const content = useTraduction<string>({\n * en: 'Hello',\n * fr: 'Bonjour',\n * }, 'fr');\n * // 'Bonjour'\n * ```\n *\n * Using TypeScript:\n * - this function will require each locale to be defined if defined in the project configuration.\n * - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.\n */\nexport const useTraduction = <Content = string>(\n languageContent: LanguageContent<Content>\n): Content => {\n const { locale } = useContext(IntlayerClientContext);\n\n return getTranslation(languageContent, locale);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAA2B;AAC3B,4BAA+B;AAC/B,oCAAsC;AAuB/B,MAAM,gBAAgB,CAC3B,oBACY;AACZ,QAAM,EAAE,OAAO,QAAI,yBAAW,mDAAqB;AAEnD,aAAO,sCAAe,iBAAiB,MAAM;AAC/C;","names":[]}
|
|
@@ -9,12 +9,13 @@ import { LanguageContent } from '@intlayer/core';
|
|
|
9
9
|
*
|
|
10
10
|
* Usage:
|
|
11
11
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* 'fr');
|
|
12
|
+
* ```tsx
|
|
13
|
+
* const content = useTraduction<string>({
|
|
14
|
+
* en: 'Hello',
|
|
15
|
+
* fr: 'Bonjour',
|
|
16
|
+
* }, 'fr');
|
|
17
17
|
* // 'Bonjour'
|
|
18
|
+
* ```
|
|
18
19
|
*
|
|
19
20
|
* Using TypeScript:
|
|
20
21
|
* - this function will require each locale to be defined if defined in the project configuration.
|