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.
Files changed (142) hide show
  1. package/dist/cjs/IntlayerProvider.cjs +1 -1
  2. package/dist/cjs/IntlayerProvider.cjs.map +1 -1
  3. package/dist/cjs/cli/react-intlayer.cjs +68 -0
  4. package/dist/cjs/cli/react-intlayer.cjs.map +1 -0
  5. package/dist/cjs/cli/react-intlayer.d.ts +1 -0
  6. package/dist/cjs/client/IntlayerClientProvider.cjs +26 -2
  7. package/dist/cjs/client/IntlayerClientProvider.cjs.map +1 -1
  8. package/dist/cjs/client/IntlayerClientProvider.d.ts +2 -1
  9. package/dist/cjs/client/getBrowserLocale.cjs +170 -0
  10. package/dist/cjs/client/getBrowserLocale.cjs.map +1 -0
  11. package/dist/cjs/client/getBrowserLocale.d.ts +26 -0
  12. package/dist/cjs/client/index.cjs +6 -0
  13. package/dist/cjs/client/index.cjs.map +1 -1
  14. package/dist/cjs/client/index.d.ts +2 -0
  15. package/dist/cjs/client/useContent.cjs +2 -2
  16. package/dist/cjs/client/useContent.cjs.map +1 -1
  17. package/dist/cjs/client/useLocale.cjs +5 -3
  18. package/dist/cjs/client/useLocale.cjs.map +1 -1
  19. package/dist/cjs/client/useLocale.d.ts +1 -0
  20. package/dist/cjs/client/useLocaleBase.cjs +49 -0
  21. package/dist/cjs/client/useLocaleBase.cjs.map +1 -0
  22. package/dist/cjs/client/useLocaleBase.d.ts +14 -0
  23. package/dist/cjs/client/useLocaleCookie.cjs +1 -1
  24. package/dist/cjs/client/useLocaleCookie.cjs.map +1 -1
  25. package/dist/cjs/client/useTraduction.cjs.map +1 -1
  26. package/dist/cjs/client/useTraduction.d.ts +6 -5
  27. package/dist/cjs/craco/craco.config.cjs +32 -0
  28. package/dist/cjs/craco/craco.config.cjs.map +1 -0
  29. package/dist/cjs/craco/craco.config.d.ts +2 -0
  30. package/dist/cjs/craco/intlayerCracoPlugin.cjs +89 -0
  31. package/dist/cjs/craco/intlayerCracoPlugin.cjs.map +1 -0
  32. package/dist/cjs/craco/intlayerCracoPlugin.d.ts +26 -0
  33. package/dist/cjs/getEnumeration.cjs.map +1 -1
  34. package/dist/cjs/getEnumeration.d.ts +8 -5
  35. package/dist/cjs/getTranslation.cjs +1 -1
  36. package/dist/cjs/getTranslation.cjs.map +1 -1
  37. package/dist/cjs/getTranslation.d.ts +3 -2
  38. package/dist/cjs/index.cjs +4 -0
  39. package/dist/cjs/index.cjs.map +1 -1
  40. package/dist/cjs/index.d.ts +2 -0
  41. package/dist/cjs/processDictionary/index.cjs +33 -1
  42. package/dist/cjs/processDictionary/index.cjs.map +1 -1
  43. package/dist/cjs/server/IntlayerServerProvider.cjs +1 -1
  44. package/dist/cjs/server/IntlayerServerProvider.cjs.map +1 -1
  45. package/dist/cjs/server/getLocaleTranslation.cjs +1 -1
  46. package/dist/cjs/server/getLocaleTranslation.cjs.map +1 -1
  47. package/dist/cjs/server/useTraduction.cjs.map +1 -1
  48. package/dist/cjs/server/useTraduction.d.ts +4 -3
  49. package/dist/cjs/vite/intlayerPlugin.cjs +60 -0
  50. package/dist/cjs/vite/intlayerPlugin.cjs.map +1 -0
  51. package/dist/cjs/vite/intlayerPlugin.d.ts +17 -0
  52. package/dist/esm/ContentEditor/ContentEditor.mjs +1 -0
  53. package/dist/esm/ContentEditor/ContentEditor.mjs.map +1 -1
  54. package/dist/esm/ContentEditor/contentRender.mjs +1 -0
  55. package/dist/esm/ContentEditor/contentRender.mjs.map +1 -1
  56. package/dist/esm/IntlayerProvider.mjs +3 -2
  57. package/dist/esm/IntlayerProvider.mjs.map +1 -1
  58. package/dist/esm/chunk-ZNCO4QRF.mjs +9 -0
  59. package/dist/esm/chunk-ZNCO4QRF.mjs.map +1 -0
  60. package/dist/esm/cli/react-intlayer.d.mts +1 -0
  61. package/dist/esm/cli/react-intlayer.mjs +45 -0
  62. package/dist/esm/cli/react-intlayer.mjs.map +1 -0
  63. package/dist/esm/client/IntlayerClientProvider.d.mts +2 -1
  64. package/dist/esm/client/IntlayerClientProvider.mjs +33 -7
  65. package/dist/esm/client/IntlayerClientProvider.mjs.map +1 -1
  66. package/dist/esm/client/getBrowserLocale.d.mts +26 -0
  67. package/dist/esm/client/getBrowserLocale.mjs +146 -0
  68. package/dist/esm/client/getBrowserLocale.mjs.map +1 -0
  69. package/dist/esm/client/index.d.mts +2 -0
  70. package/dist/esm/client/index.mjs +5 -0
  71. package/dist/esm/client/index.mjs.map +1 -1
  72. package/dist/esm/client/useContent.mjs +3 -2
  73. package/dist/esm/client/useContent.mjs.map +1 -1
  74. package/dist/esm/client/useIntlayer.mjs +1 -0
  75. package/dist/esm/client/useIntlayer.mjs.map +1 -1
  76. package/dist/esm/client/useLocale.d.mts +1 -0
  77. package/dist/esm/client/useLocale.mjs +7 -4
  78. package/dist/esm/client/useLocale.mjs.map +1 -1
  79. package/dist/esm/client/useLocaleBase.d.mts +14 -0
  80. package/dist/esm/client/useLocaleBase.mjs +26 -0
  81. package/dist/esm/client/useLocaleBase.mjs.map +1 -0
  82. package/dist/esm/client/useLocaleCookie.mjs +3 -4
  83. package/dist/esm/client/useLocaleCookie.mjs.map +1 -1
  84. package/dist/esm/client/useTraduction.d.mts +6 -5
  85. package/dist/esm/client/useTraduction.mjs +1 -0
  86. package/dist/esm/client/useTraduction.mjs.map +1 -1
  87. package/dist/esm/craco/craco.config.d.mts +2 -0
  88. package/dist/esm/craco/craco.config.mjs +17 -0
  89. package/dist/esm/craco/craco.config.mjs.map +1 -0
  90. package/dist/esm/craco/intlayerCracoPlugin.d.mts +26 -0
  91. package/dist/esm/craco/intlayerCracoPlugin.mjs +54 -0
  92. package/dist/esm/craco/intlayerCracoPlugin.mjs.map +1 -0
  93. package/dist/esm/getEnumeration.d.mts +8 -5
  94. package/dist/esm/getEnumeration.mjs +1 -0
  95. package/dist/esm/getEnumeration.mjs.map +1 -1
  96. package/dist/esm/getTranslation.d.mts +3 -2
  97. package/dist/esm/getTranslation.mjs +3 -4
  98. package/dist/esm/getTranslation.mjs.map +1 -1
  99. package/dist/esm/index.d.mts +2 -0
  100. package/dist/esm/index.mjs +6 -1
  101. package/dist/esm/index.mjs.map +1 -1
  102. package/dist/esm/processDictionary/index.mjs +35 -4
  103. package/dist/esm/processDictionary/index.mjs.map +1 -1
  104. package/dist/esm/server/IntlayerServerProvider.mjs +3 -4
  105. package/dist/esm/server/IntlayerServerProvider.mjs.map +1 -1
  106. package/dist/esm/server/getLocaleTranslation.mjs +3 -2
  107. package/dist/esm/server/getLocaleTranslation.mjs.map +1 -1
  108. package/dist/esm/server/index.mjs +1 -0
  109. package/dist/esm/server/index.mjs.map +1 -1
  110. package/dist/esm/server/serverContext.mjs +1 -0
  111. package/dist/esm/server/serverContext.mjs.map +1 -1
  112. package/dist/esm/server/useIntlayer.mjs +1 -0
  113. package/dist/esm/server/useIntlayer.mjs.map +1 -1
  114. package/dist/esm/server/useTraduction.d.mts +4 -3
  115. package/dist/esm/server/useTraduction.mjs +1 -0
  116. package/dist/esm/server/useTraduction.mjs.map +1 -1
  117. package/dist/esm/useIntlayerBase.mjs +1 -0
  118. package/dist/esm/useIntlayerBase.mjs.map +1 -1
  119. package/dist/esm/vite/intlayerPlugin.d.mts +17 -0
  120. package/dist/esm/vite/intlayerPlugin.mjs +36 -0
  121. package/dist/esm/vite/intlayerPlugin.mjs.map +1 -0
  122. package/package.json +30 -5
  123. package/src/IntlayerProvider.tsx +2 -2
  124. package/src/cli/react-intlayer.ts +60 -0
  125. package/src/client/IntlayerClientProvider.tsx +43 -12
  126. package/src/client/getBrowserLocale.tsx +192 -0
  127. package/src/client/index.ts +2 -0
  128. package/src/client/useContent.ts +2 -2
  129. package/src/client/useLocale.ts +5 -4
  130. package/src/client/useLocaleBase.ts +24 -0
  131. package/src/client/useLocaleCookie.ts +2 -5
  132. package/src/client/useTraduction.ts +6 -5
  133. package/src/craco/craco.config.ts +11 -0
  134. package/src/craco/intlayerCracoPlugin.ts +89 -0
  135. package/src/getEnumeration.ts +8 -5
  136. package/src/getTranslation.ts +5 -7
  137. package/src/index.ts +2 -1
  138. package/src/processDictionary/index.ts +52 -5
  139. package/src/server/IntlayerServerProvider.tsx +2 -5
  140. package/src/server/getLocaleTranslation.ts +2 -2
  141. package/src/server/useTraduction.ts +4 -3
  142. package/src/vite/intlayerPlugin.ts +59 -0
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env node
2
+ import spawn from "cross-spawn";
3
+ const args = process.argv.slice(2);
4
+ const scriptIndex = args.findIndex(
5
+ (x) => x === "build" || x === "start" || x === "test"
6
+ );
7
+ const script = scriptIndex === -1 ? args[0] : args[scriptIndex];
8
+ switch (script) {
9
+ case "build":
10
+ case "start":
11
+ case "test": {
12
+ const nodeArgs = scriptIndex > 0 ? args.slice(0, scriptIndex) : [];
13
+ const scriptPath = require.resolve(`@craco/craco/dist/scripts/${script}`);
14
+ const scriptArgs = args.slice(scriptIndex + 1);
15
+ const processArgs = nodeArgs.concat(scriptPath).concat([
16
+ ...scriptArgs,
17
+ "--config",
18
+ "./node_modules/react-intlayer/dist/cjs/craco/craco.config.cjs"
19
+ ]);
20
+ const child = spawn.sync("node", processArgs, { stdio: "inherit" });
21
+ if (child.signal) {
22
+ if (child.signal === "SIGKILL") {
23
+ console.info(`
24
+ The build failed because the process exited too early.
25
+ This probably means the system ran out of memory or someone called
26
+ \`kill -9\` on the process.
27
+ `);
28
+ } else if (child.signal === "SIGTERM") {
29
+ console.info(`
30
+ The build failed because the process exited too early.
31
+ Someone might have called \`kill\` or \`killall\`, or the system could
32
+ be shutting down.
33
+ `);
34
+ }
35
+ process.exit(1);
36
+ }
37
+ process.exit(child.status ?? void 0);
38
+ break;
39
+ }
40
+ default:
41
+ console.info(`Unknown script "${script}".`);
42
+ console.info("Perhaps you need to update craco?");
43
+ break;
44
+ }
45
+ //# sourceMappingURL=react-intlayer.mjs.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,OAAO,WAAW;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,MAAM,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":[]}
@@ -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: Locales;
18
+ locale?: Locales;
18
19
  };
19
20
  /**
20
21
  * Provider that store the current locale on the client side
@@ -1,21 +1,47 @@
1
1
  "use client";
2
+ import "../chunk-ZNCO4QRF.mjs";
2
3
  import { jsx } from "react/jsx-runtime";
3
- import {
4
- intlayerIntlConfiguration
5
- } from "@intlayer/config/client";
4
+ import { getConfiguration } from "@intlayer/config/client";
6
5
  import {
7
6
  createContext,
8
- useContext
7
+ useContext,
8
+ useMemo,
9
+ useState,
10
+ useCallback
9
11
  } from "react";
10
- import { localeCookie } from './useLocaleCookie.mjs';
12
+ import { localeCookie, setLocaleCookie } from './useLocaleCookie.mjs';
11
13
  const IntlayerClientContext = createContext({
12
- locale: localeCookie ?? intlayerIntlConfiguration.defaultLocale
14
+ locale: localeCookie ?? getConfiguration().internationalization.defaultLocale,
15
+ setLocale: () => null
13
16
  });
14
17
  const useIntlayerContext = () => useContext(IntlayerClientContext);
15
18
  const IntlayerClientProvider = ({
16
19
  locale,
17
20
  children
18
- }) => /* @__PURE__ */ jsx(IntlayerClientContext.Provider, { value: { locale }, children });
21
+ }) => {
22
+ const { defaultLocale, locales: availableLocales } = getConfiguration().internationalization;
23
+ const [currentLocale, setCurrentLocale] = useState(
24
+ locale ?? localeCookie ?? defaultLocale
25
+ );
26
+ const setLocale = useCallback(
27
+ (newLocale) => {
28
+ if (currentLocale.toString() === newLocale.toString())
29
+ return;
30
+ if (!availableLocales.includes(newLocale)) {
31
+ console.error(`Locale ${locale} is not available`);
32
+ return;
33
+ }
34
+ setCurrentLocale(newLocale);
35
+ setLocaleCookie(newLocale);
36
+ },
37
+ [availableLocales, currentLocale, locale]
38
+ );
39
+ const value = useMemo(
40
+ () => ({ locale: currentLocale, setLocale }),
41
+ [currentLocale, setLocale]
42
+ );
43
+ return /* @__PURE__ */ jsx(IntlayerClientContext.Provider, { value, children });
44
+ };
19
45
  export {
20
46
  IntlayerClientContext,
21
47
  IntlayerClientProvider,
@@ -1 +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":";AAyCE;AAvCF;AAAA,EACE;AAAA,OAEK;AACP;AAAA,EAEE;AAAA,EACA;AAAA,OAEK;AACP,SAAS,oBAAoB;AAStB,MAAM,wBAAwB,cAA6B;AAAA,EAChE,QAAQ,gBAAgB,0BAA0B;AACpD,CAAC;AAKM,MAAM,qBAAqB,MAAM,WAAW,qBAAqB;AASjE,MAAM,yBAA0D,CAAC;AAAA,EACtE;AAAA,EACA;AACF,MACE,oBAAC,sBAAsB,UAAtB,EAA+B,OAAO,EAAE,OAAO,GAC7C,UACH;","names":[]}
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":";;AAuEI;AArEJ,SAAS,wBAAsC;AAC/C;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,OACK;AACP,SAAS,cAAc,uBAAuB;AAUvC,MAAM,wBAAwB,cAA6B;AAAA,EAChE,QAAQ,gBAAgB,iBAAiB,EAAE,qBAAqB;AAAA,EAChE,WAAW,MAAM;AACnB,CAAC;AAKM,MAAM,qBAAqB,MAAM,WAAW,qBAAqB;AASjE,MAAM,yBAA0D,CAAC;AAAA,EACtE;AAAA,EACA;AACF,MAAM;AACJ,QAAM,EAAE,eAAe,SAAS,iBAAiB,IAC/C,iBAAiB,EAAE;AAErB,QAAM,CAAC,eAAe,gBAAgB,IAAI;AAAA,IACxC,UAAU,gBAAgB;AAAA,EAC5B;AAEA,QAAM,YAAY;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,sBAAgB,SAAS;AAAA,IAC3B;AAAA,IACA,CAAC,kBAAkB,eAAe,MAAM;AAAA,EAC1C;AAEA,QAAM,QAAuB;AAAA,IAC3B,OAAO,EAAE,QAAQ,eAAe,UAAU;AAAA,IAC1C,CAAC,eAAe,SAAS;AAAA,EAC3B;AAEA,SACE,oBAAC,sBAAsB,UAAtB,EAA+B,OAC7B,UACH;AAEJ;","names":[]}
@@ -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 };
@@ -0,0 +1,146 @@
1
+ import "../chunk-ZNCO4QRF.mjs";
2
+ import { getConfiguration } from "@intlayer/config/client";
3
+ import { localeList } from "@intlayer/core";
4
+ var LanguageDetector = /* @__PURE__ */ ((LanguageDetector2) => {
5
+ LanguageDetector2["Querystring"] = "querystring";
6
+ LanguageDetector2["Cookie"] = "cookie";
7
+ LanguageDetector2["LocalStorage"] = "localStorage";
8
+ LanguageDetector2["SessionStorage"] = "sessionStorage";
9
+ LanguageDetector2["Navigator"] = "navigator";
10
+ LanguageDetector2["HtmlTag"] = "htmlTag";
11
+ return LanguageDetector2;
12
+ })(LanguageDetector || {});
13
+ const getDefaultsOptions = () => {
14
+ const { middleware } = getConfiguration();
15
+ return {
16
+ order: [
17
+ "querystring" /* Querystring */,
18
+ "cookie" /* Cookie */,
19
+ "navigator" /* Navigator */,
20
+ "htmlTag" /* HtmlTag */
21
+ ],
22
+ lookupQuerystring: "locale",
23
+ lookupCookie: middleware.cookieName,
24
+ htmlTag: document.documentElement
25
+ };
26
+ };
27
+ const isLocalStorageAvailable = () => {
28
+ try {
29
+ if (typeof window === "undefined")
30
+ return false;
31
+ const testKey = "intlayer.translate.boo";
32
+ window.localStorage.setItem(testKey, "foo");
33
+ window.localStorage.removeItem(testKey);
34
+ return true;
35
+ } catch {
36
+ return false;
37
+ }
38
+ };
39
+ const isSessionStorageAvailable = () => {
40
+ try {
41
+ if (typeof window === "undefined")
42
+ return false;
43
+ const testKey = "intlayer.translate.boo";
44
+ window.sessionStorage.setItem(testKey, "foo");
45
+ window.sessionStorage.removeItem(testKey);
46
+ return true;
47
+ } catch {
48
+ return false;
49
+ }
50
+ };
51
+ const detectLanguage = (order, options) => {
52
+ const detected = {};
53
+ const queryStringDetector = () => {
54
+ if (typeof window === "undefined")
55
+ return;
56
+ const search = window.location.search || "";
57
+ const params = new URLSearchParams(search);
58
+ const value = params.get(options.lookupQuerystring ?? "");
59
+ if (value) {
60
+ detected["querystring" /* Querystring */] = value;
61
+ }
62
+ };
63
+ const cookieDetector = () => {
64
+ if (typeof document === "undefined")
65
+ return;
66
+ const cookies = document.cookie.split(";");
67
+ const cookieName = `${options.lookupCookie ?? ""}=`;
68
+ const cookie = cookies.find((c) => c.trim().startsWith(cookieName));
69
+ if (cookie) {
70
+ const value = cookie.split("=")[1].trim();
71
+ detected["cookie" /* Cookie */] = value;
72
+ }
73
+ };
74
+ const localStorageDetector = () => {
75
+ if (!isLocalStorageAvailable())
76
+ return;
77
+ const value = window.localStorage.getItem(options.lookupLocalStorage ?? "");
78
+ if (value) {
79
+ detected["localStorage" /* LocalStorage */] = value;
80
+ }
81
+ };
82
+ const sessionStorageDetector = () => {
83
+ if (!isSessionStorageAvailable())
84
+ return;
85
+ const value = window.sessionStorage.getItem(
86
+ options.lookupSessionStorage ?? ""
87
+ );
88
+ if (value) {
89
+ detected["sessionStorage" /* SessionStorage */] = value;
90
+ }
91
+ };
92
+ const navigatorDetector = () => {
93
+ if (typeof navigator === "undefined")
94
+ return;
95
+ if (navigator.language) {
96
+ detected["navigator" /* Navigator */] = navigator.language;
97
+ }
98
+ };
99
+ const htmlTagDetector = () => {
100
+ const htmlTag = options.htmlTag;
101
+ if (htmlTag && typeof htmlTag.getAttribute === "function") {
102
+ const lang = htmlTag.getAttribute("lang");
103
+ if (lang) {
104
+ detected["htmlTag" /* HtmlTag */] = lang;
105
+ }
106
+ }
107
+ };
108
+ const detectors = {
109
+ ["querystring" /* Querystring */]: queryStringDetector,
110
+ ["cookie" /* Cookie */]: cookieDetector,
111
+ ["localStorage" /* LocalStorage */]: localStorageDetector,
112
+ ["sessionStorage" /* SessionStorage */]: sessionStorageDetector,
113
+ ["navigator" /* Navigator */]: navigatorDetector,
114
+ ["htmlTag" /* HtmlTag */]: htmlTagDetector
115
+ };
116
+ order.forEach((detectorName) => {
117
+ detectors[detectorName]?.();
118
+ });
119
+ return detected;
120
+ };
121
+ const getFirstAvailableLocale = (locales, order) => {
122
+ const { internationalization } = getConfiguration();
123
+ for (const detector of order) {
124
+ const localesArray = [locales[detector]].flat();
125
+ for (const locale of localesArray) {
126
+ if (locale && (internationalization.locales ?? localeList).includes(locale)) {
127
+ return locale;
128
+ } else if (locale?.includes("-") && (internationalization.locales ?? localeList).includes(
129
+ locale.split("-")[0]
130
+ )) {
131
+ return locale.split("-")[0];
132
+ }
133
+ }
134
+ }
135
+ return internationalization.defaultLocale;
136
+ };
137
+ const getBrowserLocale = (userOptions = {}) => {
138
+ const options = { ...getDefaultsOptions(), ...userOptions };
139
+ const locales = detectLanguage(options.order ?? [], options);
140
+ return getFirstAvailableLocale(locales, options.order ?? []);
141
+ };
142
+ export {
143
+ LanguageDetector,
144
+ getBrowserLocale
145
+ };
146
+ //# sourceMappingURL=getBrowserLocale.mjs.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":"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","names":["LanguageDetector"]}
@@ -1,8 +1,10 @@
1
1
  export { IntlayerClientContext as IntlayerClient, IntlayerClientProvider, IntlayerClientProviderProps, useIntlayerContext } from './IntlayerClientProvider.mjs';
2
2
  export { useIntlayer } from './useIntlayer.mjs';
3
+ export { useLocaleBase } from './useLocaleBase.mjs';
3
4
  export { useLocale } from './useLocale.mjs';
4
5
  export { useTraduction } from './useTraduction.mjs';
5
6
  export { localeCookie, setLocaleCookie, useLocaleCookie } from './useLocaleCookie.mjs';
7
+ export { getBrowserLocale } from './getBrowserLocale.mjs';
6
8
  import 'react';
7
9
  import '@intlayer/config/client';
8
10
  import '../useIntlayerBase.mjs';
@@ -1,9 +1,11 @@
1
+ import "../chunk-ZNCO4QRF.mjs";
1
2
  import {
2
3
  IntlayerClientContext,
3
4
  useIntlayerContext,
4
5
  IntlayerClientProvider
5
6
  } from './IntlayerClientProvider.mjs';
6
7
  import { useIntlayer } from './useIntlayer.mjs';
8
+ import { useLocaleBase } from './useLocaleBase.mjs';
7
9
  import { useLocale } from './useLocale.mjs';
8
10
  import { useTraduction } from './useTraduction.mjs';
9
11
  import {
@@ -11,14 +13,17 @@ import {
11
13
  localeCookie,
12
14
  setLocaleCookie
13
15
  } from './useLocaleCookie.mjs';
16
+ import { getBrowserLocale } from './getBrowserLocale.mjs';
14
17
  export {
15
18
  IntlayerClientContext as IntlayerClient,
16
19
  IntlayerClientProvider,
20
+ getBrowserLocale,
17
21
  localeCookie,
18
22
  setLocaleCookie,
19
23
  useIntlayer,
20
24
  useIntlayerContext,
21
25
  useLocale,
26
+ useLocaleBase,
22
27
  useLocaleCookie,
23
28
  useTraduction
24
29
  };
@@ -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":"AACA;AAAA,EAC2B;AAAA,EACzB;AAAA,EACA;AAAA,OACK;AACP,SAAS,mBAAmB;AAC5B,SAAS,iBAAiB;AAC1B,SAAS,qBAAqB;AAC9B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;","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":";AACA;AAAA,EAC2B;AAAA,EACzB;AAAA,EACA;AAAA,OACK;AACP,SAAS,mBAAmB;AAC5B,SAAS,qBAAqB;AAC9B,SAAS,iBAAiB;AAC1B,SAAS,qBAAqB;AAC9B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,wBAAwB;","names":[]}
@@ -1,7 +1,8 @@
1
- import { useLocale } from './useLocale.mjs';
1
+ import "../chunk-ZNCO4QRF.mjs";
2
+ import { useLocaleBase } from './useLocaleBase.mjs';
2
3
  import { useTraduction } from './useTraduction.mjs';
3
4
  const useContent = (languageContent) => {
4
- const { locale } = useLocale();
5
+ const { locale } = useLocaleBase();
5
6
  const content = useTraduction(languageContent);
6
7
  return {
7
8
  locale,
@@ -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\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":"AACA,SAAS,iBAAiB;AAC1B,SAAS,qBAAqB;AAKvB,MAAM,aAAa,CACxB,oBACG;AACH,QAAM,EAAE,OAAO,IAAI,UAAU;AAE7B,QAAM,UAAU,cAAc,eAAe;AAE7C,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EACL;AACF;","names":[]}
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":";AACA,SAAS,qBAAqB;AAC9B,SAAS,qBAAqB;AAKvB,MAAM,aAAa,CACxB,oBACG;AACH,QAAM,EAAE,OAAO,IAAI,cAAc;AAEjC,QAAM,UAAU,cAAc,eAAe;AAE7C,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EACL;AACF;","names":[]}
@@ -1,4 +1,5 @@
1
1
  "use client";
2
+ import "../chunk-ZNCO4QRF.mjs";
2
3
  import { useContext } from "react";
3
4
  import {
4
5
  useIntlayerBase
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["'use client';\n\nimport type { Locales } from '@intlayer/config/client';\nimport { useContext } from 'react';\nimport {\n type DictionaryKeys,\n useIntlayerBase,\n type UseIntlayer,\n} from '../useIntlayerBase';\nimport { IntlayerClientContext } from './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":";AAGA,SAAS,kBAAkB;AAC3B;AAAA,EAEE;AAAA,OAEK;AACP,SAAS,6BAA6B;AAO/B,MAAM,cAA2B,CACtC,IACA,WACG;AACH,QAAM,EAAE,QAAQ,cAAc,IAAI,WAAW,qBAAqB;AAClE,QAAM,eAAe,UAAU;AAE/B,SAAO,gBAAgB,IAAI,YAAY;AACzC;","names":[]}
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":";;AAGA,SAAS,kBAAkB;AAC3B;AAAA,EAEE;AAAA,OAEK;AACP,SAAS,6BAA6B;AAO/B,MAAM,cAA2B,CACtC,IACA,WACG;AACH,QAAM,EAAE,QAAQ,cAAc,IAAI,WAAW,qBAAqB;AAClE,QAAM,eAAe,UAAU;AAE/B,SAAO,gBAAgB,IAAI,YAAY;AACzC;","names":[]}
@@ -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 };
@@ -1,11 +1,12 @@
1
1
  "use client";
2
- import { intlayerIntlConfiguration } from "@intlayer/config/client";
2
+ import "../chunk-ZNCO4QRF.mjs";
3
+ import { getConfiguration } from "@intlayer/config/client";
3
4
  import { localeList } from "@intlayer/core";
4
5
  import { useContext } from "react";
5
6
  import { IntlayerClientContext } from './IntlayerClientProvider.mjs';
6
- const { defaultLocale, locales: availableLocales } = intlayerIntlConfiguration;
7
7
  const useLocale = () => {
8
- const { locale } = useContext(IntlayerClientContext);
8
+ const { defaultLocale, locales: availableLocales } = getConfiguration().internationalization;
9
+ const { locale, setLocale } = useContext(IntlayerClientContext);
9
10
  return {
10
11
  locale,
11
12
  // Current locale
@@ -13,8 +14,10 @@ const useLocale = () => {
13
14
  // Principal locale defined in config
14
15
  availableLocales,
15
16
  // List of the available locales defined in config
16
- localeList
17
+ localeList,
17
18
  // List of all available locales
19
+ setLocale
20
+ // Function to set the locale
18
21
  };
19
22
  };
20
23
  export {
@@ -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 { 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":";AAEA,SAAS,iCAAiC;AAC1C,SAAS,kBAAkB;AAC3B,SAAS,kBAAkB;AAC3B,SAAS,6BAA6B;AAEtC,MAAM,EAAE,eAAe,SAAS,iBAAiB,IAAI;AAK9C,MAAM,YAAY,MAAM;AAC7B,QAAM,EAAE,OAAO,IAAI,WAAW,qBAAqB;AAEnD,SAAO;AAAA,IACL;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,EACF;AACF;","names":[]}
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":";;AAEA,SAAS,wBAAwB;AACjC,SAAS,kBAAkB;AAC3B,SAAS,kBAAkB;AAC3B,SAAS,6BAA6B;AAK/B,MAAM,YAAY,MAAM;AAC7B,QAAM,EAAE,eAAe,SAAS,iBAAiB,IAC/C,iBAAiB,EAAE;AACrB,QAAM,EAAE,QAAQ,UAAU,IAAI,WAAW,qBAAqB;AAE9D,SAAO;AAAA,IACL;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,EACF;AACF;","names":[]}
@@ -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 };
@@ -0,0 +1,26 @@
1
+ "use client";
2
+ import "../chunk-ZNCO4QRF.mjs";
3
+ import { getConfiguration } from "@intlayer/config/client";
4
+ import { localeList } from "@intlayer/core";
5
+ import { useContext } from "react";
6
+ import { IntlayerClientContext } from './IntlayerClientProvider.mjs';
7
+ const { defaultLocale, locales: availableLocales } = getConfiguration().internationalization;
8
+ const useLocaleBase = () => {
9
+ const { locale, setLocale } = useContext(IntlayerClientContext);
10
+ return {
11
+ locale,
12
+ // Current locale
13
+ defaultLocale,
14
+ // Principal locale defined in config
15
+ availableLocales,
16
+ // List of the available locales defined in config
17
+ localeList,
18
+ // List of all available locales
19
+ setLocale
20
+ // Function to set the locale
21
+ };
22
+ };
23
+ export {
24
+ useLocaleBase
25
+ };
26
+ //# sourceMappingURL=useLocaleBase.mjs.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":";;AAEA,SAAS,wBAAwB;AACjC,SAAS,kBAAkB;AAC3B,SAAS,kBAAkB;AAC3B,SAAS,6BAA6B;AAEtC,MAAM,EAAE,eAAe,SAAS,iBAAiB,IAC/C,iBAAiB,EAAE;AAKd,MAAM,gBAAgB,MAAM;AACjC,QAAM,EAAE,QAAQ,UAAU,IAAI,WAAW,qBAAqB;AAE9D,SAAO;AAAA,IACL;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,EACF;AACF;","names":[]}
@@ -1,8 +1,7 @@
1
- import {
2
- intlayerMiddlewareConfiguration
3
- } from "@intlayer/config/client";
1
+ import "../chunk-ZNCO4QRF.mjs";
2
+ import { getConfiguration } from "@intlayer/config/client";
4
3
  import Cookies from "js-cookie";
5
- const { cookieName } = intlayerMiddlewareConfiguration;
4
+ const { cookieName } = getConfiguration().middleware;
6
5
  const cookieAttributes = {
7
6
  path: "/",
8
7
  expires: void 0,
@@ -1 +1 @@
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,EAEE;AAAA,OACK;AACP,OAAO,aAAa;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,QAAQ,IAAI,UAAU;AAK3C,MAAM,kBAAkB,CAAC,WAAoB;AAClD,UAAQ,IAAI,YAAY,QAAQ,gBAAgB;AAClD;AAKO,MAAM,kBAAkB,OAAO;AAAA,EACpC;AAAA,EACA;AACF;","names":[]}
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,SAAuB,wBAAwB;AAC/C,OAAO,aAAa;AAEpB,MAAM,EAAE,WAAW,IAAI,iBAAiB,EAAE;AAE1C,MAAM,mBAA6C;AAAA,EACjD,MAAM;AAAA,EACN,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,UAAU;AACZ;AAKO,MAAM,eAAe,QAAQ,IAAI,UAAU;AAK3C,MAAM,kBAAkB,CAAC,WAAoB;AAClD,UAAQ,IAAI,YAAY,QAAQ,gBAAgB;AAClD;AAKO,MAAM,kBAAkB,OAAO;AAAA,EACpC;AAAA,EACA;AACF;","names":[]}
@@ -9,12 +9,13 @@ import { LanguageContent } from '@intlayer/core';
9
9
  *
10
10
  * Usage:
11
11
  *
12
- * const content = getTranslation<string>({
13
- * en: 'Hello',
14
- * fr: 'Bonjour',
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.
@@ -1,3 +1,4 @@
1
+ import "../chunk-ZNCO4QRF.mjs";
1
2
  import { useContext } from "react";
2
3
  import { getTranslation } from '../getTranslation.mjs';
3
4
  import { IntlayerClientContext } from './IntlayerClientProvider.mjs';
@@ -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 = 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":"AACA,SAAS,kBAAkB;AAC3B,SAAS,sBAAsB;AAC/B,SAAS,6BAA6B;AAsB/B,MAAM,gBAAgB,CAC3B,oBACY;AACZ,QAAM,EAAE,OAAO,IAAI,WAAW,qBAAqB;AAEnD,SAAO,eAAe,iBAAiB,MAAM;AAC/C;","names":[]}
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":";AACA,SAAS,kBAAkB;AAC3B,SAAS,sBAAsB;AAC/B,SAAS,6BAA6B;AAuB/B,MAAM,gBAAgB,CAC3B,oBACY;AACZ,QAAM,EAAE,OAAO,IAAI,WAAW,qBAAqB;AAEnD,SAAO,eAAe,iBAAiB,MAAM;AAC/C;","names":[]}
@@ -0,0 +1,2 @@
1
+
2
+ export { }
@@ -0,0 +1,17 @@
1
+ import {
2
+ __commonJS
3
+ } from '../chunk-ZNCO4QRF.mjs';
4
+ import * as intlayerPlugin from './intlayerCracoPlugin.mjs';
5
+ var require_craco_config = __commonJS({
6
+ "src/craco/craco.config.ts"(exports, module) {
7
+ module.exports = {
8
+ plugins: [
9
+ {
10
+ plugin: intlayerPlugin
11
+ }
12
+ ]
13
+ };
14
+ }
15
+ });
16
+ export default require_craco_config();
17
+ //# sourceMappingURL=craco.config.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/craco/craco.config.ts"],"sourcesContent":["import type { CracoConfig } from '@craco/types';\nimport * as intlayerPlugin from './intlayerCracoPlugin';\n\n// Usage Example\nmodule.exports = {\n plugins: [\n {\n plugin: intlayerPlugin,\n },\n ],\n} satisfies CracoConfig;\n"],"mappings":";;;AACA,YAAY,oBAAoB;AADhC;AAAA;AAIA,WAAO,UAAU;AAAA,MACf,SAAS;AAAA,QACP;AAAA,UACE,QAAQ;AAAA,QACV;AAAA,MACF;AAAA,IACF;AAAA;AAAA;","names":[]}
@@ -0,0 +1,26 @@
1
+ import { WebpackConfigOverride, CracoConfigOverride, CracoConfig, CracoPlugin } from '@craco/types';
2
+ import { Configuration } from 'webpack';
3
+
4
+ declare const overrideWebpackConfig: ({ webpackConfig, }: WebpackConfigOverride) => Configuration;
5
+ declare const overrideCracoConfig: ({ cracoConfig, }: CracoConfigOverride) => CracoConfig;
6
+ /**
7
+ * A CRACO plugin that adds the IntLayer configuration to the webpack configuration and sets the environment variables.
8
+ *
9
+ * Usage:
10
+ *
11
+ * ```ts
12
+ * const cracoConfig: CracoConfig = {
13
+ * plugins: [
14
+ * {
15
+ * plugin: intlayerCracoPlugin(),
16
+ * },
17
+ * ],
18
+ * };
19
+ *
20
+ * export default cracoConfig;
21
+ * ```
22
+ *
23
+ */
24
+ declare const plugin: CracoPlugin;
25
+
26
+ export { overrideCracoConfig, overrideWebpackConfig, plugin };