react-intlayer 2.0.0 → 2.0.2

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 (125) hide show
  1. package/dist/cjs/client/ContentEditionLayout.cjs.map +1 -1
  2. package/dist/cjs/client/{IntlayerClientProvider.cjs → IntlayerProvider.cjs} +14 -11
  3. package/dist/cjs/client/IntlayerProvider.cjs.map +1 -0
  4. package/dist/cjs/client/{IntlayerClientProvider.d.ts → IntlayerProvider.d.ts} +5 -3
  5. package/dist/cjs/client/getBrowserLocale.cjs +7 -14
  6. package/dist/cjs/client/getBrowserLocale.cjs.map +1 -1
  7. package/dist/cjs/client/index.cjs +6 -6
  8. package/dist/cjs/client/index.cjs.map +1 -1
  9. package/dist/cjs/client/index.d.ts +3 -2
  10. package/dist/cjs/client/useContent.d.ts +1 -1
  11. package/dist/cjs/client/useIntlayer.cjs +2 -2
  12. package/dist/cjs/client/useIntlayer.cjs.map +1 -1
  13. package/dist/cjs/client/useIntlayer.d.ts +3 -1
  14. package/dist/cjs/client/useLocale.cjs +2 -2
  15. package/dist/cjs/client/useLocale.cjs.map +1 -1
  16. package/dist/cjs/client/useLocaleBase.cjs +2 -2
  17. package/dist/cjs/client/useLocaleBase.cjs.map +1 -1
  18. package/dist/cjs/client/useLocaleCookie.cjs.map +1 -1
  19. package/dist/cjs/client/useTraduction.cjs +2 -2
  20. package/dist/cjs/client/useTraduction.cjs.map +1 -1
  21. package/dist/cjs/index.cjs +4 -4
  22. package/dist/cjs/index.cjs.map +1 -1
  23. package/dist/cjs/index.d.ts +3 -2
  24. package/dist/cjs/processDictionary/contentDictionary.cjs.map +1 -1
  25. package/dist/cjs/processDictionary/contentDictionary.d.ts +9 -9
  26. package/dist/cjs/processDictionary/index.cjs +69 -53
  27. package/dist/cjs/processDictionary/index.cjs.map +1 -1
  28. package/dist/cjs/processDictionary/index.d.ts +4 -4
  29. package/dist/cjs/server/IntlayerServerProvider.cjs +3 -4
  30. package/dist/cjs/server/IntlayerServerProvider.cjs.map +1 -1
  31. package/dist/cjs/server/IntlayerServerProvider.d.ts +6 -7
  32. package/dist/cjs/server/index.d.ts +1 -0
  33. package/dist/cjs/server/serverContext.cjs +1 -2
  34. package/dist/cjs/server/serverContext.cjs.map +1 -1
  35. package/dist/cjs/server/useIntlayer.d.ts +3 -1
  36. package/dist/cjs/useIntlayerBase.cjs +26 -1
  37. package/dist/cjs/useIntlayerBase.cjs.map +1 -1
  38. package/dist/cjs/useIntlayerBase.d.ts +62 -4
  39. package/dist/esm/{chunk-ZNCO4QRF.mjs → chunk-ZD7AOCMD.mjs} +1 -1
  40. package/dist/esm/client/ContentEditionLayout.mjs +1 -1
  41. package/dist/esm/client/ContentEditionLayout.mjs.map +1 -1
  42. package/dist/esm/client/{IntlayerClientProvider.d.mts → IntlayerProvider.d.mts} +5 -3
  43. package/dist/esm/client/{IntlayerClientProvider.mjs → IntlayerProvider.mjs} +11 -8
  44. package/dist/esm/client/IntlayerProvider.mjs.map +1 -0
  45. package/dist/esm/client/getBrowserLocale.mjs +8 -15
  46. package/dist/esm/client/getBrowserLocale.mjs.map +1 -1
  47. package/dist/esm/client/index.d.mts +3 -2
  48. package/dist/esm/client/index.mjs +5 -5
  49. package/dist/esm/client/index.mjs.map +1 -1
  50. package/dist/esm/client/useContent.d.mts +1 -1
  51. package/dist/esm/client/useContent.mjs +1 -1
  52. package/dist/esm/client/useIntlayer.d.mts +3 -1
  53. package/dist/esm/client/useIntlayer.mjs +2 -2
  54. package/dist/esm/client/useIntlayer.mjs.map +1 -1
  55. package/dist/esm/client/useLocale.mjs +2 -2
  56. package/dist/esm/client/useLocale.mjs.map +1 -1
  57. package/dist/esm/client/useLocaleBase.mjs +2 -2
  58. package/dist/esm/client/useLocaleBase.mjs.map +1 -1
  59. package/dist/esm/client/useLocaleCookie.mjs +1 -1
  60. package/dist/esm/client/useLocaleCookie.mjs.map +1 -1
  61. package/dist/esm/client/useTraduction.mjs +2 -2
  62. package/dist/esm/client/useTraduction.mjs.map +1 -1
  63. package/dist/esm/craco/craco.config.mjs +1 -1
  64. package/dist/esm/craco/intlayerCracoPlugin.mjs +1 -1
  65. package/dist/esm/getEnumeration.mjs +1 -1
  66. package/dist/esm/getTranslation.mjs +1 -1
  67. package/dist/esm/index.d.mts +3 -2
  68. package/dist/esm/index.mjs +5 -5
  69. package/dist/esm/index.mjs.map +1 -1
  70. package/dist/esm/processDictionary/contentDictionary.d.mts +9 -9
  71. package/dist/esm/processDictionary/index.d.mts +4 -4
  72. package/dist/esm/processDictionary/index.mjs +70 -54
  73. package/dist/esm/processDictionary/index.mjs.map +1 -1
  74. package/dist/esm/server/IntlayerServerProvider.d.mts +6 -7
  75. package/dist/esm/server/IntlayerServerProvider.mjs +4 -5
  76. package/dist/esm/server/IntlayerServerProvider.mjs.map +1 -1
  77. package/dist/esm/server/getLocaleTranslation.mjs +1 -1
  78. package/dist/esm/server/index.d.mts +1 -0
  79. package/dist/esm/server/index.mjs +1 -1
  80. package/dist/esm/server/serverContext.mjs +2 -3
  81. package/dist/esm/server/serverContext.mjs.map +1 -1
  82. package/dist/esm/server/useIntlayer.d.mts +3 -1
  83. package/dist/esm/server/useIntlayer.mjs +1 -1
  84. package/dist/esm/server/useTraduction.mjs +1 -1
  85. package/dist/esm/useIntlayerBase.d.mts +62 -4
  86. package/dist/esm/useIntlayerBase.mjs +26 -2
  87. package/dist/esm/useIntlayerBase.mjs.map +1 -1
  88. package/dist/esm/vite/intlayerPlugin.mjs +1 -1
  89. package/package.json +18 -19
  90. package/src/index.ts +4 -3
  91. package/dist/cjs/IntlayerProvider.cjs +0 -37
  92. package/dist/cjs/IntlayerProvider.cjs.map +0 -1
  93. package/dist/cjs/IntlayerProvider.d.ts +0 -9
  94. package/dist/cjs/client/IntlayerClientProvider.cjs.map +0 -1
  95. package/dist/esm/IntlayerProvider.d.mts +0 -9
  96. package/dist/esm/IntlayerProvider.mjs +0 -18
  97. package/dist/esm/IntlayerProvider.mjs.map +0 -1
  98. package/dist/esm/client/IntlayerClientProvider.mjs.map +0 -1
  99. package/src/IntlayerProvider.tsx +0 -24
  100. package/src/cli/react-intlayer.ts +0 -60
  101. package/src/client/ContentEditionLayout.tsx +0 -15
  102. package/src/client/IntlayerClientProvider.tsx +0 -83
  103. package/src/client/getBrowserLocale.tsx +0 -192
  104. package/src/client/index.ts +0 -16
  105. package/src/client/useContent.ts +0 -20
  106. package/src/client/useIntlayer.ts +0 -25
  107. package/src/client/useLocale.ts +0 -23
  108. package/src/client/useLocaleBase.ts +0 -24
  109. package/src/client/useLocaleCookie.ts +0 -32
  110. package/src/client/useTraduction.ts +0 -33
  111. package/src/craco/craco.config.ts +0 -11
  112. package/src/craco/intlayerCracoPlugin.ts +0 -89
  113. package/src/getEnumeration.ts +0 -41
  114. package/src/getTranslation.ts +0 -37
  115. package/src/processDictionary/contentDictionary.ts +0 -28
  116. package/src/processDictionary/index.ts +0 -231
  117. package/src/server/IntlayerServerProvider.tsx +0 -36
  118. package/src/server/getLocaleTranslation.ts +0 -22
  119. package/src/server/index.ts +0 -8
  120. package/src/server/serverContext.ts +0 -85
  121. package/src/server/useIntlayer.ts +0 -23
  122. package/src/server/useTraduction.ts +0 -34
  123. package/src/useIntlayerBase.ts +0 -38
  124. package/src/vite/intlayerPlugin.ts +0 -59
  125. /package/dist/esm/{chunk-ZNCO4QRF.mjs.map → chunk-ZD7AOCMD.mjs.map} +0 -0
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/client/ContentEditionLayout.tsx"],"sourcesContent":["import {\n ContentEditionLayout as ContentEditionLayoutBase,\n type ContentEditionLayoutProps,\n} from 'intlayer-editor/client';\nimport type { FC } from 'react';\n\nconst BlankLayout: FC<ContentEditionLayoutProps> = ({ children }) => (\n <>{children}</>\n);\n\n// intlayer-editor is an optional dependency. If it's not installed, return the blank layout\nexport const ContentEditionLayout: FC<ContentEditionLayoutProps> =\n typeof ContentEditionLayoutBase === 'undefined'\n ? BlankLayout\n : (ContentEditionLayoutBase as typeof ContentEditionLayout);\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAOE;AAPF,oBAGO;AAGP,MAAM,cAA6C,CAAC,EAAE,SAAS,MAC7D,2EAAG,UAAS;AAIP,MAAM,uBACX,OAAO,cAAAA,yBAA6B,cAChC,cACC,cAAAA;","names":["ContentEditionLayoutBase"]}
1
+ {"version":3,"sources":["../../../src/client/ContentEditionLayout.tsx"],"sourcesContent":["import {\n ContentEditionLayout as ContentEditionLayoutBase,\n type ContentEditionLayoutProps,\n} from 'intlayer-editor/client';\nimport type { FC } from 'react';\n\nconst BlankLayout: FC<ContentEditionLayoutProps> = ({ children }) => (\n <>{children}</>\n);\n\n// intlayer-editor is an optional dependency. If it's not installed, return the blank layout\nexport const ContentEditionLayout: FC<ContentEditionLayoutProps> =\n typeof ContentEditionLayoutBase === 'undefined'\n ? BlankLayout\n : ContentEditionLayoutBase;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAOE;AAPF,oBAGO;AAGP,MAAM,cAA6C,CAAC,EAAE,SAAS,MAC7D,2EAAG,UAAS;AAIP,MAAM,uBACX,OAAO,cAAAA,yBAA6B,cAChC,cACA,cAAAA;","names":["ContentEditionLayoutBase"]}
@@ -17,13 +17,13 @@ var __copyProps = (to, from, except, desc) => {
17
17
  return to;
18
18
  };
19
19
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
- var IntlayerClientProvider_exports = {};
21
- __export(IntlayerClientProvider_exports, {
20
+ var IntlayerProvider_exports = {};
21
+ __export(IntlayerProvider_exports, {
22
22
  IntlayerClientContext: () => IntlayerClientContext,
23
- IntlayerClientProvider: () => IntlayerClientProvider,
23
+ IntlayerProvider: () => IntlayerProvider,
24
24
  useIntlayerContext: () => useIntlayerContext
25
25
  });
26
- module.exports = __toCommonJS(IntlayerClientProvider_exports);
26
+ module.exports = __toCommonJS(IntlayerProvider_exports);
27
27
  var import_jsx_runtime = require("react/jsx-runtime");
28
28
  var import_client = require("@intlayer/config/client");
29
29
  var import_react = require("react");
@@ -34,18 +34,19 @@ const IntlayerClientContext = (0, import_react.createContext)({
34
34
  setLocale: () => null
35
35
  });
36
36
  const useIntlayerContext = () => (0, import_react.useContext)(IntlayerClientContext);
37
- const IntlayerClientProvider = ({
37
+ const IntlayerProvider = ({
38
38
  locale,
39
- children
39
+ children,
40
+ setLocale: setLocaleProp,
41
+ editorEnabled
40
42
  }) => {
41
43
  const { defaultLocale, locales: availableLocales } = (0, import_client.getConfiguration)().internationalization;
42
44
  const [currentLocale, setCurrentLocale] = (0, import_react.useState)(
43
45
  locale ?? import_useLocaleCookie.localeCookie ?? defaultLocale
44
46
  );
45
- const setLocale = (0, import_react.useCallback)(
47
+ const setLocaleBase = (0, import_react.useCallback)(
46
48
  (newLocale) => {
47
- if (currentLocale.toString() === newLocale.toString())
48
- return;
49
+ if (currentLocale.toString() === newLocale.toString()) return;
49
50
  if (!availableLocales.includes(newLocale)) {
50
51
  console.error(`Locale ${locale} is not available`);
51
52
  return;
@@ -55,6 +56,7 @@ const IntlayerClientProvider = ({
55
56
  },
56
57
  [availableLocales, currentLocale, locale]
57
58
  );
59
+ const setLocale = setLocaleProp ?? setLocaleBase;
58
60
  const value = (0, import_react.useMemo)(
59
61
  () => ({ locale: currentLocale, setLocale }),
60
62
  [currentLocale, setLocale]
@@ -65,6 +67,7 @@ const IntlayerClientProvider = ({
65
67
  locale: currentLocale,
66
68
  setLocale,
67
69
  localeList: availableLocales,
70
+ editorEnabled,
68
71
  children
69
72
  }
70
73
  ) });
@@ -72,7 +75,7 @@ const IntlayerClientProvider = ({
72
75
  // Annotate the CommonJS export names for ESM import in node:
73
76
  0 && (module.exports = {
74
77
  IntlayerClientContext,
75
- IntlayerClientProvider,
78
+ IntlayerProvider,
76
79
  useIntlayerContext
77
80
  });
78
- //# sourceMappingURL=IntlayerClientProvider.cjs.map
81
+ //# sourceMappingURL=IntlayerProvider.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/client/IntlayerProvider.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 { ContentEditionLayout } from './ContentEditionLayout';\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 IntlayerProviderProps = PropsWithChildren & {\n locale?: Locales;\n setLocale?: (locale: Locales) => void;\n editorEnabled?: boolean;\n};\n\n/**\n * Provider that store the current locale on the client side\n */\nexport const IntlayerProvider: FC<IntlayerProviderProps> = ({\n locale,\n children,\n setLocale: setLocaleProp,\n editorEnabled,\n}) => {\n const { defaultLocale, locales: availableLocales } =\n getConfiguration().internationalization;\n\n const [currentLocale, setCurrentLocale] = useState(\n locale ?? localeCookie ?? defaultLocale\n );\n\n const setLocaleBase = 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 setLocale = setLocaleProp ?? setLocaleBase;\n\n const value: IntlayerValue = useMemo<IntlayerValue>(\n () => ({ locale: currentLocale, setLocale: setLocale }),\n [currentLocale, setLocale]\n );\n\n return (\n <IntlayerClientContext.Provider value={value}>\n <ContentEditionLayout\n locale={currentLocale}\n setLocale={setLocale}\n localeList={availableLocales}\n editorEnabled={editorEnabled}\n >\n {children}\n </ContentEditionLayout>\n </IntlayerClientContext.Provider>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA+EM;AA7EN,oBAA+C;AAC/C,mBAQO;AACP,kCAAqC;AACrC,6BAA8C;AAUvC,MAAM,4BAAwB,4BAA6B;AAAA,EAChE,QAAQ,2CAAgB,gCAAiB,EAAE,qBAAqB;AAAA,EAChE,WAAW,MAAM;AACnB,CAAC;AAKM,MAAM,qBAAqB,UAAM,yBAAW,qBAAqB;AAWjE,MAAM,mBAA8C,CAAC;AAAA,EAC1D;AAAA,EACA;AAAA,EACA,WAAW;AAAA,EACX;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,oBAAgB;AAAA,IACpB,CAAC,cAAuB;AACtB,UAAI,cAAc,SAAS,MAAM,UAAU,SAAS,EAAG;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,YAAY,iBAAiB;AAEnC,QAAM,YAAuB;AAAA,IAC3B,OAAO,EAAE,QAAQ,eAAe,UAAqB;AAAA,IACrD,CAAC,eAAe,SAAS;AAAA,EAC3B;AAEA,SACE,4CAAC,sBAAsB,UAAtB,EAA+B,OAC9B;AAAA,IAAC;AAAA;AAAA,MACC,QAAQ;AAAA,MACR;AAAA,MACA,YAAY;AAAA,MACZ;AAAA,MAEC;AAAA;AAAA,EACH,GACF;AAEJ;","names":[]}
@@ -14,12 +14,14 @@ declare const IntlayerClientContext: react.Context<IntlayerValue>;
14
14
  * Hook that provides the current locale
15
15
  */
16
16
  declare const useIntlayerContext: () => IntlayerValue;
17
- type IntlayerClientProviderProps = PropsWithChildren & {
17
+ type IntlayerProviderProps = PropsWithChildren & {
18
18
  locale?: Locales;
19
+ setLocale?: (locale: Locales) => void;
20
+ editorEnabled?: boolean;
19
21
  };
20
22
  /**
21
23
  * Provider that store the current locale on the client side
22
24
  */
23
- declare const IntlayerClientProvider: FC<IntlayerClientProviderProps>;
25
+ declare const IntlayerProvider: FC<IntlayerProviderProps>;
24
26
 
25
- export { IntlayerClientContext, IntlayerClientProvider, type IntlayerClientProviderProps, useIntlayerContext };
27
+ export { IntlayerClientContext, IntlayerProvider, type IntlayerProviderProps, useIntlayerContext };
@@ -49,8 +49,7 @@ const getDefaultsOptions = () => {
49
49
  };
50
50
  const isLocalStorageAvailable = () => {
51
51
  try {
52
- if (typeof window === "undefined")
53
- return false;
52
+ if (typeof window === "undefined") return false;
54
53
  const testKey = "intlayer.translate.boo";
55
54
  window.localStorage.setItem(testKey, "foo");
56
55
  window.localStorage.removeItem(testKey);
@@ -61,8 +60,7 @@ const isLocalStorageAvailable = () => {
61
60
  };
62
61
  const isSessionStorageAvailable = () => {
63
62
  try {
64
- if (typeof window === "undefined")
65
- return false;
63
+ if (typeof window === "undefined") return false;
66
64
  const testKey = "intlayer.translate.boo";
67
65
  window.sessionStorage.setItem(testKey, "foo");
68
66
  window.sessionStorage.removeItem(testKey);
@@ -74,8 +72,7 @@ const isSessionStorageAvailable = () => {
74
72
  const detectLanguage = (order, options) => {
75
73
  const detected = {};
76
74
  const queryStringDetector = () => {
77
- if (typeof window === "undefined")
78
- return;
75
+ if (typeof window === "undefined") return;
79
76
  const search = window.location.search || "";
80
77
  const params = new URLSearchParams(search);
81
78
  const value = params.get(options.lookupQuerystring ?? "");
@@ -84,8 +81,7 @@ const detectLanguage = (order, options) => {
84
81
  }
85
82
  };
86
83
  const cookieDetector = () => {
87
- if (typeof document === "undefined")
88
- return;
84
+ if (typeof document === "undefined") return;
89
85
  const cookies = document.cookie.split(";");
90
86
  const cookieName = `${options.lookupCookie ?? ""}=`;
91
87
  const cookie = cookies.find((c) => c.trim().startsWith(cookieName));
@@ -95,16 +91,14 @@ const detectLanguage = (order, options) => {
95
91
  }
96
92
  };
97
93
  const localStorageDetector = () => {
98
- if (!isLocalStorageAvailable())
99
- return;
94
+ if (!isLocalStorageAvailable()) return;
100
95
  const value = window.localStorage.getItem(options.lookupLocalStorage ?? "");
101
96
  if (value) {
102
97
  detected["localStorage" /* LocalStorage */] = value;
103
98
  }
104
99
  };
105
100
  const sessionStorageDetector = () => {
106
- if (!isSessionStorageAvailable())
107
- return;
101
+ if (!isSessionStorageAvailable()) return;
108
102
  const value = window.sessionStorage.getItem(
109
103
  options.lookupSessionStorage ?? ""
110
104
  );
@@ -113,8 +107,7 @@ const detectLanguage = (order, options) => {
113
107
  }
114
108
  };
115
109
  const navigatorDetector = () => {
116
- if (typeof navigator === "undefined")
117
- return;
110
+ if (typeof navigator === "undefined") return;
118
111
  if (navigator.language) {
119
112
  detected["navigator" /* Navigator */] = navigator.language;
120
113
  }
@@ -1 +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
+ {"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"]}
@@ -18,20 +18,20 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var client_exports = {};
20
20
  __export(client_exports, {
21
- IntlayerClient: () => import_IntlayerClientProvider.IntlayerClientContext,
22
- IntlayerClientProvider: () => import_IntlayerClientProvider.IntlayerClientProvider,
21
+ IntlayerClientContext: () => import_IntlayerProvider.IntlayerClientContext,
22
+ IntlayerProvider: () => import_IntlayerProvider.IntlayerProvider,
23
23
  getBrowserLocale: () => import_getBrowserLocale.getBrowserLocale,
24
24
  localeCookie: () => import_useLocaleCookie.localeCookie,
25
25
  setLocaleCookie: () => import_useLocaleCookie.setLocaleCookie,
26
26
  useIntlayer: () => import_useIntlayer.useIntlayer,
27
- useIntlayerContext: () => import_IntlayerClientProvider.useIntlayerContext,
27
+ useIntlayerContext: () => import_IntlayerProvider.useIntlayerContext,
28
28
  useLocale: () => import_useLocale.useLocale,
29
29
  useLocaleBase: () => import_useLocaleBase.useLocaleBase,
30
30
  useLocaleCookie: () => import_useLocaleCookie.useLocaleCookie,
31
31
  useTraduction: () => import_useTraduction.useTraduction
32
32
  });
33
33
  module.exports = __toCommonJS(client_exports);
34
- var import_IntlayerClientProvider = require('./IntlayerClientProvider.cjs');
34
+ var import_IntlayerProvider = require('./IntlayerProvider.cjs');
35
35
  var import_useIntlayer = require('./useIntlayer.cjs');
36
36
  var import_useLocaleBase = require('./useLocaleBase.cjs');
37
37
  var import_useLocale = require('./useLocale.cjs');
@@ -40,8 +40,8 @@ var import_useLocaleCookie = require('./useLocaleCookie.cjs');
40
40
  var import_getBrowserLocale = require('./getBrowserLocale.cjs');
41
41
  // Annotate the CommonJS export names for ESM import in node:
42
42
  0 && (module.exports = {
43
- IntlayerClient,
44
- IntlayerClientProvider,
43
+ IntlayerClientContext,
44
+ IntlayerProvider,
45
45
  getBrowserLocale,
46
46
  localeCookie,
47
47
  setLocaleCookie,
@@ -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 { 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
+ {"version":3,"sources":["../../../src/client/index.ts"],"sourcesContent":["export {\n type IntlayerProviderProps,\n IntlayerClientContext,\n useIntlayerContext,\n IntlayerProvider,\n} from './IntlayerProvider';\nexport { useIntlayer } from './useIntlayer';\nexport { useLocaleBase } from './useLocaleBase';\nexport { useLocale } from './useLocale';\nexport { useTraduction } from './useTraduction';\nexport {\n useLocaleCookie,\n localeCookie,\n setLocaleCookie,\n} from './useLocaleCookie';\nexport { getBrowserLocale } from './getBrowserLocale';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,8BAKO;AACP,yBAA4B;AAC5B,2BAA8B;AAC9B,uBAA0B;AAC1B,2BAA8B;AAC9B,6BAIO;AACP,8BAAiC;","names":[]}
@@ -1,4 +1,4 @@
1
- export { IntlayerClientContext as IntlayerClient, IntlayerClientProvider, IntlayerClientProviderProps, useIntlayerContext } from './IntlayerClientProvider.js';
1
+ export { IntlayerClientContext, IntlayerProvider, IntlayerProviderProps, useIntlayerContext } from './IntlayerProvider.js';
2
2
  export { useIntlayer } from './useIntlayer.js';
3
3
  export { useLocaleBase } from './useLocaleBase.js';
4
4
  export { useLocale } from './useLocale.js';
@@ -8,5 +8,6 @@ export { getBrowserLocale } from './getBrowserLocale.js';
8
8
  import 'react';
9
9
  import '@intlayer/config/client';
10
10
  import '../useIntlayerBase.js';
11
- import 'intlayer';
11
+ import '@intlayer/config';
12
12
  import '@intlayer/core';
13
+ import 'intlayer';
@@ -7,7 +7,7 @@ import { LanguageContent } from '@intlayer/core';
7
7
  declare const useContent: <Content>(languageContent: LanguageContent<Content>) => {
8
8
  locale: intlayer.Locales;
9
9
  content: Content;
10
- t: <Content_1 = string>(languageContent: Partial<Record<intlayer.LocalesValues, Content_1>>) => Content_1;
10
+ t: <Content_1 = string>(languageContent: LanguageContent<Content_1>) => Content_1;
11
11
  };
12
12
 
13
13
  export { useContent };
@@ -24,9 +24,9 @@ __export(useIntlayer_exports, {
24
24
  module.exports = __toCommonJS(useIntlayer_exports);
25
25
  var import_react = require("react");
26
26
  var import_useIntlayerBase = require('../useIntlayerBase.cjs');
27
- var import_IntlayerClientProvider = require('./IntlayerClientProvider.cjs');
27
+ var import_IntlayerProvider = require('./IntlayerProvider.cjs');
28
28
  const useIntlayer = (id, locale) => {
29
- const { locale: currentLocale } = (0, import_react.useContext)(import_IntlayerClientProvider.IntlayerClientContext);
29
+ const { locale: currentLocale } = (0, import_react.useContext)(import_IntlayerProvider.IntlayerClientContext);
30
30
  const localeTarget = locale ?? currentLocale;
31
31
  return (0, import_useIntlayerBase.useIntlayerBase)(id, localeTarget);
32
32
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["'use client';\n\nimport type { Locales } from '@intlayer/config/client';\nimport { useContext } from 'react';\nimport {\n type DictionaryKeys,\n useIntlayerBase,\n type UseIntlayer,\n} from '../useIntlayerBase';\nimport { IntlayerClientContext } from './IntlayerClientProvider';\n\n/**\n * On the client side, Hook that picking one dictionary by its id and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useIntlayer: UseIntlayer = <T extends DictionaryKeys>(\n id: T,\n locale?: Locales\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const localeTarget = locale ?? currentLocale;\n\n return useIntlayerBase(id, localeTarget);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,mBAA2B;AAC3B,6BAIO;AACP,oCAAsC;AAO/B,MAAM,cAA2B,CACtC,IACA,WACG;AACH,QAAM,EAAE,QAAQ,cAAc,QAAI,yBAAW,mDAAqB;AAClE,QAAM,eAAe,UAAU;AAE/B,aAAO,wCAAgB,IAAI,YAAY;AACzC;","names":[]}
1
+ {"version":3,"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["'use client';\n\nimport type { Locales } from '@intlayer/config/client';\nimport { useContext } from 'react';\nimport {\n type DictionaryKeys,\n useIntlayerBase,\n type UseIntlayer,\n} from '../useIntlayerBase';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * On the client side, Hook that picking one dictionary by its id and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useIntlayer: UseIntlayer = <T extends DictionaryKeys>(\n id: T,\n locale?: Locales\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const localeTarget = locale ?? currentLocale;\n\n return useIntlayerBase(id, localeTarget);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,mBAA2B;AAC3B,6BAIO;AACP,8BAAsC;AAO/B,MAAM,cAA2B,CACtC,IACA,WACG;AACH,QAAM,EAAE,QAAQ,cAAc,QAAI,yBAAW,6CAAqB;AAClE,QAAM,eAAe,UAAU;AAE/B,aAAO,wCAAgB,IAAI,YAAY;AACzC;","names":[]}
@@ -1,6 +1,8 @@
1
1
  import { UseIntlayer } from '../useIntlayerBase.js';
2
- import '@intlayer/config/client';
2
+ import '@intlayer/config';
3
+ import '@intlayer/core';
3
4
  import 'intlayer';
5
+ import 'react';
4
6
 
5
7
  /**
6
8
  * On the client side, Hook that picking one dictionary by its id and return the content
@@ -25,10 +25,10 @@ module.exports = __toCommonJS(useLocale_exports);
25
25
  var import_client = require("@intlayer/config/client");
26
26
  var import_core = require("@intlayer/core");
27
27
  var import_react = require("react");
28
- var import_IntlayerClientProvider = require('./IntlayerClientProvider.cjs');
28
+ var import_IntlayerProvider = require('./IntlayerProvider.cjs');
29
29
  const useLocale = () => {
30
30
  const { defaultLocale, locales: availableLocales } = (0, import_client.getConfiguration)().internationalization;
31
- const { locale, setLocale } = (0, import_react.useContext)(import_IntlayerClientProvider.IntlayerClientContext);
31
+ const { locale, setLocale } = (0, import_react.useContext)(import_IntlayerProvider.IntlayerClientContext);
32
32
  return {
33
33
  locale,
34
34
  // Current locale
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["'use client';\n\nimport { 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":[]}
1
+ {"version":3,"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["'use client';\n\nimport { getConfiguration } from '@intlayer/config/client';\nimport { localeList } from '@intlayer/core';\nimport { useContext } from 'react';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * On the client side, hook to get the current locale and all related fields\n */\nexport const useLocale = () => {\n const { defaultLocale, locales: availableLocales } =\n getConfiguration().internationalization;\n const { locale, setLocale } = useContext(IntlayerClientContext);\n\n return {\n locale, // Current locale\n defaultLocale, // Principal locale defined in config\n availableLocales, // List of the available locales defined in config\n localeList, // List of all available locales\n setLocale, // Function to set the locale\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,oBAAiC;AACjC,kBAA2B;AAC3B,mBAA2B;AAC3B,8BAAsC;AAK/B,MAAM,YAAY,MAAM;AAC7B,QAAM,EAAE,eAAe,SAAS,iBAAiB,QAC/C,gCAAiB,EAAE;AACrB,QAAM,EAAE,QAAQ,UAAU,QAAI,yBAAW,6CAAqB;AAE9D,SAAO;AAAA,IACL;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,EACF;AACF;","names":[]}
@@ -25,10 +25,10 @@ module.exports = __toCommonJS(useLocaleBase_exports);
25
25
  var import_client = require("@intlayer/config/client");
26
26
  var import_core = require("@intlayer/core");
27
27
  var import_react = require("react");
28
- var import_IntlayerClientProvider = require('./IntlayerClientProvider.cjs');
28
+ var import_IntlayerProvider = require('./IntlayerProvider.cjs');
29
29
  const { defaultLocale, locales: availableLocales } = (0, import_client.getConfiguration)().internationalization;
30
30
  const useLocaleBase = () => {
31
- const { locale, setLocale } = (0, import_react.useContext)(import_IntlayerClientProvider.IntlayerClientContext);
31
+ const { locale, setLocale } = (0, import_react.useContext)(import_IntlayerProvider.IntlayerClientContext);
32
32
  return {
33
33
  locale,
34
34
  // Current locale
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/client/useLocaleBase.ts"],"sourcesContent":["'use client';\n\nimport { getConfiguration } from '@intlayer/config/client';\nimport { localeList } from '@intlayer/core';\nimport { useContext } from 'react';\nimport { IntlayerClientContext } from './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":[]}
1
+ {"version":3,"sources":["../../../src/client/useLocaleBase.ts"],"sourcesContent":["'use client';\n\nimport { getConfiguration } from '@intlayer/config/client';\nimport { localeList } from '@intlayer/core';\nimport { useContext } from 'react';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\nconst { defaultLocale, locales: availableLocales } =\n getConfiguration().internationalization;\n\n/**\n * On the client side, hook to get the current locale and all related fields\n */\nexport const useLocaleBase = () => {\n const { locale, setLocale } = useContext(IntlayerClientContext);\n\n return {\n locale, // Current locale\n defaultLocale, // Principal locale defined in config\n availableLocales, // List of the available locales defined in config\n localeList, // List of all available locales\n setLocale, // Function to set the locale\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,oBAAiC;AACjC,kBAA2B;AAC3B,mBAA2B;AAC3B,8BAAsC;AAEtC,MAAM,EAAE,eAAe,SAAS,iBAAiB,QAC/C,gCAAiB,EAAE;AAKd,MAAM,gBAAgB,MAAM;AACjC,QAAM,EAAE,QAAQ,UAAU,QAAI,yBAAW,6CAAqB;AAE9D,SAAO;AAAA,IACL;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,EACF;AACF;","names":[]}
@@ -1 +1 @@
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
+ {"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 unknown as\n | Locales\n | 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;AAO3C,MAAM,kBAAkB,CAAC,WAAoB;AAClD,mBAAAA,QAAQ,IAAI,YAAY,QAAQ,gBAAgB;AAClD;AAKO,MAAM,kBAAkB,OAAO;AAAA,EACpC;AAAA,EACA;AACF;","names":["Cookies"]}
@@ -23,9 +23,9 @@ __export(useTraduction_exports, {
23
23
  module.exports = __toCommonJS(useTraduction_exports);
24
24
  var import_react = require("react");
25
25
  var import_getTranslation = require('../getTranslation.cjs');
26
- var import_IntlayerClientProvider = require('./IntlayerClientProvider.cjs');
26
+ var import_IntlayerProvider = require('./IntlayerProvider.cjs');
27
27
  const useTraduction = (languageContent) => {
28
- const { locale } = (0, import_react.useContext)(import_IntlayerClientProvider.IntlayerClientContext);
28
+ const { locale } = (0, import_react.useContext)(import_IntlayerProvider.IntlayerClientContext);
29
29
  return (0, import_getTranslation.getTranslation)(languageContent, locale);
30
30
  };
31
31
  // Annotate the CommonJS export names for ESM import in node:
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/client/useTraduction.ts"],"sourcesContent":["import type { LanguageContent } from '@intlayer/core';\nimport { useContext } from 'react';\nimport { getTranslation } from '../getTranslation';\nimport { IntlayerClientContext } from './IntlayerClientProvider';\n\n/**\n * On the client side, Hook that picking one dictionary by its id and return the content.\n *\n * If not locale found, it will return the content related to the default locale.\n *\n * Return either the content editor, or the content itself depending on the configuration.\n *\n * Usage:\n *\n * ```tsx\n * const content = useTraduction<string>({\n * en: 'Hello',\n * fr: 'Bonjour',\n * }, 'fr');\n * // 'Bonjour'\n * ```\n *\n * Using TypeScript:\n * - this function will require each locale to be defined if defined in the project configuration.\n * - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.\n */\nexport const useTraduction = <Content = string>(\n languageContent: LanguageContent<Content>\n): Content => {\n const { locale } = useContext(IntlayerClientContext);\n\n return getTranslation(languageContent, locale);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAA2B;AAC3B,4BAA+B;AAC/B,oCAAsC;AAuB/B,MAAM,gBAAgB,CAC3B,oBACY;AACZ,QAAM,EAAE,OAAO,QAAI,yBAAW,mDAAqB;AAEnD,aAAO,sCAAe,iBAAiB,MAAM;AAC/C;","names":[]}
1
+ {"version":3,"sources":["../../../src/client/useTraduction.ts"],"sourcesContent":["import type { LanguageContent } from '@intlayer/core';\nimport { useContext } from 'react';\nimport { getTranslation } from '../getTranslation';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * On the client side, Hook that picking one dictionary by its id and return the content.\n *\n * If not locale found, it will return the content related to the default locale.\n *\n * Return either the content editor, or the content itself depending on the configuration.\n *\n * Usage:\n *\n * ```tsx\n * const content = useTraduction<string>({\n * en: 'Hello',\n * fr: 'Bonjour',\n * }, 'fr');\n * // 'Bonjour'\n * ```\n *\n * Using TypeScript:\n * - this function will require each locale to be defined if defined in the project configuration.\n * - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.\n */\nexport const useTraduction = <Content = string>(\n languageContent: LanguageContent<Content>\n): Content => {\n const { locale } = useContext(IntlayerClientContext);\n\n return getTranslation(languageContent, locale);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAA2B;AAC3B,4BAA+B;AAC/B,8BAAsC;AAuB/B,MAAM,gBAAgB,CAC3B,oBACY;AACZ,QAAM,EAAE,OAAO,QAAI,yBAAW,6CAAqB;AAEnD,aAAO,sCAAe,iBAAiB,MAAM;AAC/C;","names":[]}
@@ -18,8 +18,8 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var src_exports = {};
20
20
  __export(src_exports, {
21
- IntlayerClient: () => import_client.IntlayerClient,
22
- IntlayerClientProvider: () => import_client.IntlayerClientProvider,
21
+ IntlayerClientContext: () => import_client.IntlayerClientContext,
22
+ IntlayerProvider: () => import_client.IntlayerProvider,
23
23
  getBrowserLocale: () => import_client.getBrowserLocale,
24
24
  getTranslation: () => import_getTranslation.getTranslation,
25
25
  localeCookie: () => import_client.localeCookie,
@@ -35,8 +35,8 @@ var import_getTranslation = require('./getTranslation.cjs');
35
35
  var import_client = require('./client/index.cjs');
36
36
  // Annotate the CommonJS export names for ESM import in node:
37
37
  0 && (module.exports = {
38
- IntlayerClient,
39
- IntlayerClientProvider,
38
+ IntlayerClientContext,
39
+ IntlayerProvider,
40
40
  getBrowserLocale,
41
41
  getTranslation,
42
42
  localeCookie,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export { getTranslation } from './getTranslation';\nexport {\n IntlayerClientProvider,\n type IntlayerClientProviderProps,\n IntlayerClient,\n useIntlayer,\n useLocale,\n useTraduction,\n useLocaleCookie,\n localeCookie,\n setLocaleCookie,\n getBrowserLocale,\n useLocaleBase,\n} from './client/index';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAA+B;AAC/B,oBAYO;","names":[]}
1
+ {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export { getTranslation } from './getTranslation';\nexport {\n IntlayerProvider,\n type IntlayerProviderProps,\n IntlayerClientContext,\n useIntlayer,\n useLocale,\n useTraduction,\n useLocaleCookie,\n localeCookie,\n setLocaleCookie,\n getBrowserLocale,\n useLocaleBase,\n} from './client/index';\nexport type { IntlayerNode } from './useIntlayerBase';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAA+B;AAC/B,oBAYO;","names":[]}
@@ -1,13 +1,14 @@
1
1
  export { getTranslation } from './getTranslation.js';
2
- export { IntlayerClientContext as IntlayerClient, IntlayerClientProvider, IntlayerClientProviderProps } from './client/IntlayerClientProvider.js';
2
+ export { IntlayerClientContext, IntlayerProvider, IntlayerProviderProps } from './client/IntlayerProvider.js';
3
3
  export { useIntlayer } from './client/useIntlayer.js';
4
4
  export { useLocaleBase } from './client/useLocaleBase.js';
5
5
  export { useLocale } from './client/useLocale.js';
6
6
  export { useTraduction } from './client/useTraduction.js';
7
7
  export { localeCookie, setLocaleCookie, useLocaleCookie } from './client/useLocaleCookie.js';
8
8
  export { getBrowserLocale } from './client/getBrowserLocale.js';
9
+ export { IntlayerNode } from './useIntlayerBase.js';
9
10
  import '@intlayer/config/client';
10
11
  import '@intlayer/core';
11
12
  import 'react';
12
- import './useIntlayerBase.js';
13
+ import '@intlayer/config';
13
14
  import 'intlayer';
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/processDictionary/contentDictionary.ts"],"sourcesContent":["import type { TranslationContent } from '@intlayer/core';\nimport type { ReactNode } from 'react';\n\nexport type ContentValue =\n | string\n | {\n [key: string]: ContentValue;\n }\n | TranslationContent<unknown>;\n\nexport type Content = Record<string, ContentValue | undefined>;\n\nexport type TransformedContentValue =\n | string\n | ReactNode\n | {\n [key: string]: TransformedContentValue;\n }\n | undefined\n | ((quantity: number) => TransformedContentValue);\n\nexport type TransformedContent =\n | Record<string, TransformedContentValue | undefined>\n | ReactNode;\n\nexport type ContentDictionary = Content & {\n id: string;\n};\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
1
+ {"version":3,"sources":["../../../src/processDictionary/contentDictionary.ts"],"sourcesContent":["import type { KeyPath, Locales } from '@intlayer/core';\nimport type { ReactNode } from 'react';\n\nexport type TransformedContentValue =\n | string\n | ReactNode\n | {\n [key: string]: TransformedContentValue;\n }\n | undefined\n | ((quantity: number) => TransformedContentValue);\n\nexport type TransformedContentObject = {\n dictionaryId: string;\n dictionaryPath: string;\n keyPath: KeyPath[];\n locale: Locales;\n content: TransformedContentValue | TransformedContentValue[] | undefined;\n};\n\nexport type TransformedContent =\n | Record<\n string,\n | TransformedContentValue\n | TransformedContentValue[]\n | TransformedContentObject\n | undefined\n >\n | ReactNode;\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -1,16 +1,16 @@
1
- import { TranslationContent } from '@intlayer/core';
1
+ import { KeyPath, Locales } from '@intlayer/core';
2
2
  import { ReactNode } from 'react';
3
3
 
4
- type ContentValue = string | {
5
- [key: string]: ContentValue;
6
- } | TranslationContent<unknown>;
7
- type Content = Record<string, ContentValue | undefined>;
8
4
  type TransformedContentValue = string | ReactNode | {
9
5
  [key: string]: TransformedContentValue;
10
6
  } | undefined | ((quantity: number) => TransformedContentValue);
11
- type TransformedContent = Record<string, TransformedContentValue | undefined> | ReactNode;
12
- type ContentDictionary = Content & {
13
- id: string;
7
+ type TransformedContentObject = {
8
+ dictionaryId: string;
9
+ dictionaryPath: string;
10
+ keyPath: KeyPath[];
11
+ locale: Locales;
12
+ content: TransformedContentValue | TransformedContentValue[] | undefined;
14
13
  };
14
+ type TransformedContent = Record<string, TransformedContentValue | TransformedContentValue[] | TransformedContentObject | undefined> | ReactNode;
15
15
 
16
- export type { Content, ContentDictionary, ContentValue, TransformedContent, TransformedContentValue };
16
+ export type { TransformedContent, TransformedContentObject, TransformedContentValue };