react-intlayer 1.0.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (169) hide show
  1. package/dist/cjs/ContentEditor/ContentEditor.cjs +36 -39
  2. package/dist/cjs/ContentEditor/ContentEditor.d.ts +2 -2
  3. package/dist/cjs/ContentEditor/contentRender.cjs +10 -18
  4. package/dist/cjs/ContentEditor/index.cjs +11 -27
  5. package/dist/cjs/ContentEditor/index.d.ts +3 -3
  6. package/dist/cjs/IntlayerProvider.cjs +37 -0
  7. package/dist/cjs/IntlayerProvider.cjs.map +1 -0
  8. package/dist/cjs/IntlayerProvider.d.ts +9 -0
  9. package/dist/cjs/client/IntlayerClientProvider.cjs +45 -0
  10. package/dist/cjs/client/IntlayerClientProvider.cjs.map +1 -0
  11. package/dist/cjs/client/IntlayerClientProvider.d.ts +24 -0
  12. package/dist/cjs/client/index.cjs +24 -31
  13. package/dist/cjs/client/index.cjs.map +1 -1
  14. package/dist/cjs/client/index.d.ts +10 -19
  15. package/dist/cjs/client/useContent.cjs +11 -16
  16. package/dist/cjs/client/useContent.cjs.map +1 -1
  17. package/dist/cjs/client/useContent.d.ts +10 -8
  18. package/dist/cjs/client/useIntlayer.cjs +11 -18
  19. package/dist/cjs/client/useIntlayer.cjs.map +1 -1
  20. package/dist/cjs/client/useIntlayer.d.ts +8 -3
  21. package/dist/cjs/client/useLocale.cjs +12 -20
  22. package/dist/cjs/client/useLocale.cjs.map +1 -1
  23. package/dist/cjs/client/useLocale.d.ts +8 -5
  24. package/dist/cjs/client/useLocaleCookie.cjs +20 -30
  25. package/dist/cjs/client/useLocaleCookie.cjs.map +1 -1
  26. package/dist/cjs/client/useLocaleCookie.d.ts +12 -3
  27. package/dist/cjs/client/useTraduction.cjs +11 -18
  28. package/dist/cjs/client/useTraduction.cjs.map +1 -1
  29. package/dist/cjs/client/useTraduction.d.ts +22 -4
  30. package/dist/cjs/getEnumeration.cjs +9 -14
  31. package/dist/cjs/getEnumeration.cjs.map +1 -1
  32. package/dist/cjs/getEnumeration.d.ts +27 -5
  33. package/dist/cjs/getTranslation.cjs +9 -14
  34. package/dist/cjs/getTranslation.cjs.map +1 -1
  35. package/dist/cjs/getTranslation.d.ts +23 -6
  36. package/dist/cjs/index.cjs +20 -27
  37. package/dist/cjs/index.cjs.map +1 -1
  38. package/dist/cjs/index.d.ts +11 -20
  39. package/dist/cjs/processDictionary/contentDictionary.d.cjs +4 -8
  40. package/dist/cjs/processDictionary/contentDictionary.d.d.ts +6 -9
  41. package/dist/cjs/processDictionary/index.cjs +15 -17
  42. package/dist/cjs/processDictionary/index.cjs.map +1 -1
  43. package/dist/cjs/processDictionary/index.d.ts +6 -17
  44. package/dist/cjs/server/IntlayerServerProvider.cjs +46 -0
  45. package/dist/cjs/server/IntlayerServerProvider.cjs.map +1 -0
  46. package/dist/cjs/server/IntlayerServerProvider.d.ts +37 -0
  47. package/dist/cjs/server/getLocaleTranslation.cjs +12 -19
  48. package/dist/cjs/server/getLocaleTranslation.cjs.map +1 -1
  49. package/dist/cjs/server/getLocaleTranslation.d.ts +8 -7
  50. package/dist/cjs/server/index.cjs +20 -27
  51. package/dist/cjs/server/index.cjs.map +1 -1
  52. package/dist/cjs/server/index.d.ts +9 -13
  53. package/dist/cjs/server/serverContext.cjs +25 -31
  54. package/dist/cjs/server/serverContext.cjs.map +1 -1
  55. package/dist/cjs/server/serverContext.d.ts +16 -24
  56. package/dist/cjs/server/useIntlayer.cjs +12 -21
  57. package/dist/cjs/server/useIntlayer.cjs.map +1 -1
  58. package/dist/cjs/server/useIntlayer.d.ts +8 -3
  59. package/dist/cjs/server/useTraduction.cjs +12 -19
  60. package/dist/cjs/server/useTraduction.cjs.map +1 -1
  61. package/dist/cjs/server/useTraduction.d.ts +22 -4
  62. package/dist/cjs/useIntlayerBase.cjs +22 -31
  63. package/dist/cjs/useIntlayerBase.cjs.map +1 -1
  64. package/dist/cjs/useIntlayerBase.d.ts +7 -18
  65. package/dist/esm/ContentEditor/ContentEditor.d.mts +2 -2
  66. package/dist/esm/ContentEditor/ContentEditor.mjs +38 -29
  67. package/dist/esm/ContentEditor/contentRender.mjs +5 -3
  68. package/dist/esm/ContentEditor/index.d.mts +3 -3
  69. package/dist/esm/ContentEditor/index.mjs +3 -3
  70. package/dist/esm/IntlayerProvider.d.mts +9 -0
  71. package/dist/esm/IntlayerProvider.mjs +17 -0
  72. package/dist/esm/IntlayerProvider.mjs.map +1 -0
  73. package/dist/esm/client/IntlayerClientProvider.d.mts +24 -0
  74. package/dist/esm/client/IntlayerClientProvider.mjs +24 -0
  75. package/dist/esm/client/IntlayerClientProvider.mjs.map +1 -0
  76. package/dist/esm/client/index.d.mts +10 -19
  77. package/dist/esm/client/index.mjs +14 -14
  78. package/dist/esm/client/index.mjs.map +1 -1
  79. package/dist/esm/client/useContent.d.mts +10 -8
  80. package/dist/esm/client/useContent.mjs +7 -5
  81. package/dist/esm/client/useContent.mjs.map +1 -1
  82. package/dist/esm/client/useIntlayer.d.mts +8 -3
  83. package/dist/esm/client/useIntlayer.mjs +9 -5
  84. package/dist/esm/client/useIntlayer.mjs.map +1 -1
  85. package/dist/esm/client/useLocale.d.mts +8 -5
  86. package/dist/esm/client/useLocale.mjs +7 -5
  87. package/dist/esm/client/useLocale.mjs.map +1 -1
  88. package/dist/esm/client/useLocaleCookie.d.mts +12 -3
  89. package/dist/esm/client/useLocaleCookie.mjs +11 -5
  90. package/dist/esm/client/useLocaleCookie.mjs.map +1 -1
  91. package/dist/esm/client/useTraduction.d.mts +22 -4
  92. package/dist/esm/client/useTraduction.mjs +7 -5
  93. package/dist/esm/client/useTraduction.mjs.map +1 -1
  94. package/dist/esm/getEnumeration.d.mts +27 -5
  95. package/dist/esm/getEnumeration.mjs +9 -4
  96. package/dist/esm/getEnumeration.mjs.map +1 -1
  97. package/dist/esm/getTranslation.d.mts +23 -6
  98. package/dist/esm/getTranslation.mjs +8 -4
  99. package/dist/esm/getTranslation.mjs.map +1 -1
  100. package/dist/esm/index.d.mts +11 -20
  101. package/dist/esm/index.mjs +9 -11
  102. package/dist/esm/index.mjs.map +1 -1
  103. package/dist/esm/processDictionary/contentDictionary.d.d.mts +6 -9
  104. package/dist/esm/processDictionary/contentDictionary.d.mjs +1 -1
  105. package/dist/esm/processDictionary/index.d.mts +6 -17
  106. package/dist/esm/processDictionary/index.mjs +25 -9
  107. package/dist/esm/processDictionary/index.mjs.map +1 -1
  108. package/dist/esm/server/IntlayerServerProvider.d.mts +37 -0
  109. package/dist/esm/server/IntlayerServerProvider.mjs +21 -0
  110. package/dist/esm/server/IntlayerServerProvider.mjs.map +1 -0
  111. package/dist/esm/server/getLocaleTranslation.d.mts +8 -7
  112. package/dist/esm/server/getLocaleTranslation.mjs +8 -6
  113. package/dist/esm/server/getLocaleTranslation.mjs.map +1 -1
  114. package/dist/esm/server/index.d.mts +9 -13
  115. package/dist/esm/server/index.mjs +10 -10
  116. package/dist/esm/server/index.mjs.map +1 -1
  117. package/dist/esm/server/serverContext.d.mts +16 -24
  118. package/dist/esm/server/serverContext.mjs +13 -6
  119. package/dist/esm/server/serverContext.mjs.map +1 -1
  120. package/dist/esm/server/useIntlayer.d.mts +8 -3
  121. package/dist/esm/server/useIntlayer.mjs +10 -6
  122. package/dist/esm/server/useIntlayer.mjs.map +1 -1
  123. package/dist/esm/server/useTraduction.d.mts +22 -4
  124. package/dist/esm/server/useTraduction.mjs +8 -6
  125. package/dist/esm/server/useTraduction.mjs.map +1 -1
  126. package/dist/esm/useIntlayerBase.d.mts +7 -18
  127. package/dist/esm/useIntlayerBase.mjs +9 -4
  128. package/dist/esm/useIntlayerBase.mjs.map +1 -1
  129. package/package.json +10 -10
  130. package/src/IntlayerProvider.tsx +24 -0
  131. package/src/client/IntlayerClientProvider.tsx +45 -0
  132. package/src/client/index.ts +5 -5
  133. package/src/client/useContent.ts +3 -0
  134. package/src/client/useIntlayer.ts +7 -2
  135. package/src/client/useLocale.ts +5 -2
  136. package/src/client/useLocaleCookie.ts +9 -1
  137. package/src/client/useTraduction.ts +23 -3
  138. package/src/getEnumeration.ts +25 -0
  139. package/src/getTranslation.ts +21 -1
  140. package/src/index.ts +3 -4
  141. package/src/processDictionary/index.ts +1 -1
  142. package/src/server/IntlayerServerProvider.tsx +39 -0
  143. package/src/server/getLocaleTranslation.ts +5 -2
  144. package/src/server/index.ts +3 -3
  145. package/src/server/serverContext.ts +4 -4
  146. package/src/server/useIntlayer.ts +8 -2
  147. package/src/server/useTraduction.ts +23 -3
  148. package/src/useIntlayerBase.ts +4 -1
  149. package/dist/cjs/LocaleContextProvider.cjs +0 -49
  150. package/dist/cjs/LocaleContextProvider.cjs.map +0 -1
  151. package/dist/cjs/LocaleContextProvider.d.ts +0 -10
  152. package/dist/cjs/client/LocaleClientContextProvider.cjs +0 -54
  153. package/dist/cjs/client/LocaleClientContextProvider.cjs.map +0 -1
  154. package/dist/cjs/client/LocaleClientContextProvider.d.ts +0 -20
  155. package/dist/cjs/server/LocaleServerContextProvider.cjs +0 -49
  156. package/dist/cjs/server/LocaleServerContextProvider.cjs.map +0 -1
  157. package/dist/cjs/server/LocaleServerContextProvider.d.ts +0 -34
  158. package/dist/esm/LocaleContextProvider.d.mts +0 -10
  159. package/dist/esm/LocaleContextProvider.mjs +0 -15
  160. package/dist/esm/LocaleContextProvider.mjs.map +0 -1
  161. package/dist/esm/client/LocaleClientContextProvider.d.mts +0 -20
  162. package/dist/esm/client/LocaleClientContextProvider.mjs +0 -16
  163. package/dist/esm/client/LocaleClientContextProvider.mjs.map +0 -1
  164. package/dist/esm/server/LocaleServerContextProvider.d.mts +0 -34
  165. package/dist/esm/server/LocaleServerContextProvider.mjs +0 -14
  166. package/dist/esm/server/LocaleServerContextProvider.mjs.map +0 -1
  167. package/src/LocaleContextProvider.tsx +0 -26
  168. package/src/client/LocaleClientContextProvider.tsx +0 -35
  169. package/src/server/LocaleServerContextProvider.tsx +0 -24
@@ -2,10 +2,10 @@
2
2
  import { intlayerIntlConfiguration } from "@intlayer/config/client";
3
3
  import { localeList } from "@intlayer/core";
4
4
  import { useContext } from "react";
5
- import { LocaleClientContext } from "./LocaleClientContextProvider.mjs";
5
+ import { IntlayerClientContext } from './IntlayerClientProvider.mjs';
6
6
  const { defaultLocale, locales: availableLocales } = intlayerIntlConfiguration;
7
7
  const useLocale = () => {
8
- const { locale } = useContext(LocaleClientContext);
8
+ const { locale } = useContext(IntlayerClientContext);
9
9
  return {
10
10
  locale,
11
11
  // Current locale
@@ -13,9 +13,11 @@ const useLocale = () => {
13
13
  // Principal locale defined in config
14
14
  availableLocales,
15
15
  // List of the available locales defined in config
16
- localeList,
16
+ localeList
17
17
  // List of all available locales
18
18
  };
19
19
  };
20
- export { useLocale };
21
- //# sourceMappingURL=useLocale.mjs.map
20
+ export {
21
+ useLocale
22
+ };
23
+ //# sourceMappingURL=useLocale.mjs.map
@@ -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 { LocaleClientContext } from './LocaleClientContextProvider';\n\nconst { defaultLocale, locales: availableLocales } = intlayerIntlConfiguration;\n\nexport const useLocale = () => {\n const { locale } = useContext(LocaleClientContext);\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,2BAA2B;AAEpC,MAAM,EAAE,eAAe,SAAS,iBAAiB,IAAI;AAE9C,MAAM,YAAY,MAAM;AAC7B,QAAM,EAAE,OAAO,IAAI,WAAW,mBAAmB;AAEjD,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 { 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,10 +1,19 @@
1
- import { Locales } from "@intlayer/config/client";
1
+ import { Locales } from '@intlayer/config/client';
2
2
 
3
+ /**
4
+ * Get the locale cookie
5
+ */
3
6
  declare const localeCookie: Locales | undefined;
7
+ /**
8
+ * Set the locale cookie
9
+ */
4
10
  declare const setLocaleCookie: (locale: Locales) => void;
11
+ /**
12
+ * Hook that provides the locale cookie and a function to set it
13
+ */
5
14
  declare const useLocaleCookie: () => {
6
- localeCookie: Locales | undefined;
7
- setLocaleCookie: (locale: Locales) => void;
15
+ localeCookie: Locales | undefined;
16
+ setLocaleCookie: (locale: Locales) => void;
8
17
  };
9
18
 
10
19
  export { localeCookie, setLocaleCookie, useLocaleCookie };
@@ -1,4 +1,6 @@
1
- import { intlayerMiddlewareConfiguration } from "@intlayer/config/client";
1
+ import {
2
+ intlayerMiddlewareConfiguration
3
+ } from "@intlayer/config/client";
2
4
  import Cookies from "js-cookie";
3
5
  const { cookieName } = intlayerMiddlewareConfiguration;
4
6
  const cookieAttributes = {
@@ -6,7 +8,7 @@ const cookieAttributes = {
6
8
  expires: void 0,
7
9
  domain: void 0,
8
10
  secure: false,
9
- sameSite: "strict",
11
+ sameSite: "strict"
10
12
  };
11
13
  const localeCookie = Cookies.get(cookieName);
12
14
  const setLocaleCookie = (locale) => {
@@ -14,7 +16,11 @@ const setLocaleCookie = (locale) => {
14
16
  };
15
17
  const useLocaleCookie = () => ({
16
18
  localeCookie,
17
- setLocaleCookie,
19
+ setLocaleCookie
18
20
  });
19
- export { localeCookie, setLocaleCookie, useLocaleCookie };
20
- //# sourceMappingURL=useLocaleCookie.mjs.map
21
+ export {
22
+ localeCookie,
23
+ setLocaleCookie,
24
+ useLocaleCookie
25
+ };
26
+ //# sourceMappingURL=useLocaleCookie.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/client/useLocaleCookie.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-redundant-type-constituents */\nimport {\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\nexport const localeCookie = Cookies.get(cookieName) as Locales | undefined;\n\nexport const setLocaleCookie = (locale: Locales) => {\n Cookies.set(cookieName, locale, cookieAttributes);\n};\n\nexport const useLocaleCookie = () => ({\n localeCookie,\n setLocaleCookie,\n});\n"],"mappings":"AACA;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;AAEO,MAAM,eAAe,QAAQ,IAAI,UAAU;AAE3C,MAAM,kBAAkB,CAAC,WAAoB;AAClD,UAAQ,IAAI,YAAY,QAAQ,gBAAgB;AAClD;AAEO,MAAM,kBAAkB,OAAO;AAAA,EACpC;AAAA,EACA;AACF;","names":[]}
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,7 +1,25 @@
1
- import { LanguageContent } from "@intlayer/core";
1
+ import { LanguageContent } from '@intlayer/core';
2
2
 
3
- declare const useTraduction: <Content>(
4
- languageContent: LanguageContent<Content>
5
- ) => Content;
3
+ /**
4
+ * On the client side, Hook that picking one dictionary by its id and return the content.
5
+ *
6
+ * If not locale found, it will return the content related to the default locale.
7
+ *
8
+ * Return either the content editor, or the content itself depending on the configuration.
9
+ *
10
+ * Usage:
11
+ *
12
+ * const content = getTranslation<string>({
13
+ * en: 'Hello',
14
+ * fr: 'Bonjour',
15
+ * },
16
+ * 'fr');
17
+ * // 'Bonjour'
18
+ *
19
+ * Using TypeScript:
20
+ * - this function will require each locale to be defined if defined in the project configuration.
21
+ * - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.
22
+ */
23
+ declare const useTraduction: <Content = string>(languageContent: LanguageContent<Content>) => Content;
6
24
 
7
25
  export { useTraduction };
@@ -1,9 +1,11 @@
1
1
  import { useContext } from "react";
2
- import { getTranslation } from "../getTranslation.mjs";
3
- import { LocaleClientContext } from "./LocaleClientContextProvider.mjs";
2
+ import { getTranslation } from '../getTranslation.mjs';
3
+ import { IntlayerClientContext } from './IntlayerClientProvider.mjs';
4
4
  const useTraduction = (languageContent) => {
5
- const { locale } = useContext(LocaleClientContext);
5
+ const { locale } = useContext(IntlayerClientContext);
6
6
  return getTranslation(languageContent, locale);
7
7
  };
8
- export { useTraduction };
9
- //# sourceMappingURL=useTraduction.mjs.map
8
+ export {
9
+ useTraduction
10
+ };
11
+ //# sourceMappingURL=useTraduction.mjs.map
@@ -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 { LocaleClientContext } from './LocaleClientContextProvider';\n\nexport const useTraduction = <Content>(\n languageContent: LanguageContent<Content>\n): Content => {\n const { locale } = useContext(LocaleClientContext);\n\n return getTranslation(languageContent, locale);\n};\n"],"mappings":"AACA,SAAS,kBAAkB;AAC3B,SAAS,sBAAsB;AAC/B,SAAS,2BAA2B;AAE7B,MAAM,gBAAgB,CAC3B,oBACY;AACZ,QAAM,EAAE,OAAO,IAAI,WAAW,mBAAmB;AAEjD,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 * 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,8 +1,30 @@
1
- import { QuantityContent } from "@intlayer/core";
1
+ import { QuantityContent } from '@intlayer/core';
2
2
 
3
- declare const getEnumeration: <Content>(
4
- enumerationContent: QuantityContent<Content>,
5
- quantity: number
6
- ) => Content;
3
+ /**
4
+ * Allow to pick a content based on a quantity.
5
+ *
6
+ * Return either the content editor, or the content itself depending on the configuration.
7
+ *
8
+ * Usage:
9
+ *
10
+ * const content = getEnumeration({
11
+ * '<=-2.3': 'You have less than -2.3',
12
+ * '<1': 'You have less than one',
13
+ * '2': 'You have two',
14
+ * '>=3': 'You have three or more',
15
+ * },
16
+ * 2);
17
+ * // 'You have two'
18
+ *
19
+ * The order of the keys will define the priority of the content.
20
+ *
21
+ * const content = getEnumeration({
22
+ * '<4': 'You have less than four',
23
+ * '2': 'You have two',
24
+ * });
25
+ * // 'You have less than four'
26
+ *
27
+ */
28
+ declare const getEnumeration: <Content>(enumerationContent: QuantityContent<Content>, quantity: number) => Content;
7
29
 
8
30
  export { getEnumeration };
@@ -1,11 +1,16 @@
1
1
  import { getEnumerationContent } from "@intlayer/core";
2
- import { contentRender } from "./ContentEditor/contentRender.mjs";
2
+ import { contentRender } from './ContentEditor/contentRender.mjs';
3
3
  const getEnumeration = (enumerationContent, quantity) => {
4
- const result = getEnumerationContent(enumerationContent, quantity);
4
+ const result = getEnumerationContent(
5
+ enumerationContent,
6
+ quantity
7
+ );
5
8
  if (typeof result === "string") {
6
9
  return contentRender(result);
7
10
  }
8
11
  return result;
9
12
  };
10
- export { getEnumeration };
11
- //# sourceMappingURL=getEnumeration.mjs.map
13
+ export {
14
+ getEnumeration
15
+ };
16
+ //# sourceMappingURL=getEnumeration.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/getEnumeration.ts"],"sourcesContent":["import { type QuantityContent, getEnumerationContent } from '@intlayer/core';\nimport { contentRender } from './ContentEditor/contentRender';\n\nexport const getEnumeration = <Content>(\n enumerationContent: QuantityContent<Content>,\n quantity: number\n): Content => {\n const result: Content = getEnumerationContent<Content>(\n enumerationContent,\n quantity\n );\n\n if (typeof result === 'string') {\n return contentRender(result) as Content;\n }\n\n return result;\n};\n"],"mappings":"AAAA,SAA+B,6BAA6B;AAC5D,SAAS,qBAAqB;AAEvB,MAAM,iBAAiB,CAC5B,oBACA,aACY;AACZ,QAAM,SAAkB;AAAA,IACtB;AAAA,IACA;AAAA,EACF;AAEA,MAAI,OAAO,WAAW,UAAU;AAC9B,WAAO,cAAc,MAAM;AAAA,EAC7B;AAEA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../src/getEnumeration.ts"],"sourcesContent":["import { type QuantityContent, getEnumerationContent } from '@intlayer/core';\nimport { contentRender } from './ContentEditor/contentRender';\n\n/**\n * Allow to pick a content based on a quantity.\n *\n * Return either the content editor, or the content itself depending on the configuration.\n *\n * Usage:\n *\n * const content = getEnumeration({\n * '<=-2.3': 'You have less than -2.3',\n * '<1': 'You have less than one',\n * '2': 'You have two',\n * '>=3': 'You have three or more',\n * },\n * 2);\n * // 'You have two'\n *\n * The order of the keys will define the priority of the content.\n *\n * const content = getEnumeration({\n * '<4': 'You have less than four',\n * '2': 'You have two',\n * });\n * // 'You have less than four'\n *\n */\nexport const getEnumeration = <Content>(\n enumerationContent: QuantityContent<Content>,\n quantity: number\n): Content => {\n const result: Content = getEnumerationContent<Content>(\n enumerationContent,\n quantity\n );\n\n if (typeof result === 'string') {\n return contentRender(result) as Content;\n }\n\n return result;\n};\n"],"mappings":"AAAA,SAA+B,6BAA6B;AAC5D,SAAS,qBAAqB;AA2BvB,MAAM,iBAAiB,CAC5B,oBACA,aACY;AACZ,QAAM,SAAkB;AAAA,IACtB;AAAA,IACA;AAAA,EACF;AAEA,MAAI,OAAO,WAAW,UAAU;AAC9B,WAAO,cAAc,MAAM;AAAA,EAC7B;AAEA,SAAO;AACT;","names":[]}
@@ -1,9 +1,26 @@
1
- import { Locales } from "@intlayer/config/client";
2
- import { LanguageContent } from "@intlayer/core";
1
+ import { Locales } from '@intlayer/config/client';
2
+ import { LanguageContent } from '@intlayer/core';
3
3
 
4
- declare const getTranslation: <Content>(
5
- languageContent: LanguageContent<Content>,
6
- locale?: Locales
7
- ) => Content;
4
+ /**
5
+ *
6
+ * Allow to pick a content based on a locale.
7
+ * If not locale found, it will return the content related to the default locale.
8
+ *
9
+ * Return either the content editor, or the content itself depending on the configuration.
10
+ *
11
+ * Usage:
12
+ *
13
+ * const content = getTranslation<string>({
14
+ * en: 'Hello',
15
+ * fr: 'Bonjour',
16
+ * },
17
+ * 'fr');
18
+ * // 'Bonjour'
19
+ *
20
+ * Using TypeScript:
21
+ * - this function will require each locale to be defined if defined in the project configuration.
22
+ * - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.
23
+ */
24
+ declare const getTranslation: <Content = string>(languageContent: LanguageContent<Content>, locale?: Locales) => Content;
8
25
 
9
26
  export { getTranslation };
@@ -1,6 +1,8 @@
1
- import { intlayerIntlConfiguration } from "@intlayer/config/client";
1
+ import {
2
+ intlayerIntlConfiguration
3
+ } from "@intlayer/config/client";
2
4
  import { getTranslationContent } from "@intlayer/core";
3
- import { contentRender } from "./ContentEditor/contentRender.mjs";
5
+ import { contentRender } from './ContentEditor/contentRender.mjs';
4
6
  const getTranslation = (languageContent, locale) => {
5
7
  const { defaultLocale } = intlayerIntlConfiguration;
6
8
  const result = getTranslationContent(
@@ -12,5 +14,7 @@ const getTranslation = (languageContent, locale) => {
12
14
  }
13
15
  return result;
14
16
  };
15
- export { getTranslation };
16
- //# sourceMappingURL=getTranslation.mjs.map
17
+ export {
18
+ getTranslation
19
+ };
20
+ //# sourceMappingURL=getTranslation.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/getTranslation.ts"],"sourcesContent":["import {\n type Locales,\n intlayerIntlConfiguration,\n} from '@intlayer/config/client';\nimport { type LanguageContent, getTranslationContent } from '@intlayer/core';\nimport { contentRender } from './ContentEditor/contentRender';\n\nexport const getTranslation = <Content>(\n languageContent: LanguageContent<Content>,\n locale?: Locales\n): Content => {\n const { defaultLocale } = intlayerIntlConfiguration;\n\n const result: Content = getTranslationContent<Content>(\n languageContent,\n locale ?? defaultLocale\n );\n\n if (typeof result === 'string') {\n return contentRender(result) as Content;\n }\n\n return result;\n};\n"],"mappings":"AAAA;AAAA,EAEE;AAAA,OACK;AACP,SAA+B,6BAA6B;AAC5D,SAAS,qBAAqB;AAEvB,MAAM,iBAAiB,CAC5B,iBACA,WACY;AACZ,QAAM,EAAE,cAAc,IAAI;AAE1B,QAAM,SAAkB;AAAA,IACtB;AAAA,IACA,UAAU;AAAA,EACZ;AAEA,MAAI,OAAO,WAAW,UAAU;AAC9B,WAAO,cAAc,MAAM;AAAA,EAC7B;AAEA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../src/getTranslation.ts"],"sourcesContent":["import {\n type Locales,\n intlayerIntlConfiguration,\n} from '@intlayer/config/client';\nimport { type LanguageContent, getTranslationContent } from '@intlayer/core';\nimport { contentRender } from './ContentEditor/contentRender';\n\n/**\n *\n * Allow to pick a content based on a locale.\n * If not locale found, it will return the content related to the default locale.\n *\n * Return either the content editor, or the content itself depending on the configuration.\n *\n * Usage:\n *\n * const content = getTranslation<string>({\n * en: 'Hello',\n * fr: 'Bonjour',\n * },\n * 'fr');\n * // 'Bonjour'\n *\n * Using TypeScript:\n * - this function will require each locale to be defined if defined in the project configuration.\n * - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.\n */\nexport const getTranslation = <Content = string>(\n languageContent: LanguageContent<Content>,\n locale?: Locales\n): Content => {\n const { defaultLocale } = intlayerIntlConfiguration;\n\n const result: Content = getTranslationContent<Content>(\n languageContent,\n locale ?? defaultLocale\n );\n\n if (typeof result === 'string') {\n return contentRender(result) as Content;\n }\n\n return result;\n};\n"],"mappings":"AAAA;AAAA,EAEE;AAAA,OACK;AACP,SAA+B,6BAA6B;AAC5D,SAAS,qBAAqB;AAsBvB,MAAM,iBAAiB,CAC5B,iBACA,WACY;AACZ,QAAM,EAAE,cAAc,IAAI;AAE1B,QAAM,SAAkB;AAAA,IACtB;AAAA,IACA,UAAU;AAAA,EACZ;AAEA,MAAI,OAAO,WAAW,UAAU;AAC9B,WAAO,cAAc,MAAM;AAAA,EAC7B;AAEA,SAAO;AACT;","names":[]}
@@ -1,20 +1,11 @@
1
- export { getTranslation } from "./getTranslation.mjs";
2
- export {
3
- LocaleClientContext,
4
- LocaleClientContextProvider,
5
- LocaleClientContextProviderProps,
6
- useLocaleContext,
7
- } from "./client/LocaleClientContextProvider.mjs";
8
- export { useIntlayer } from "./client/useIntlayer.mjs";
9
- export { useLocale } from "./client/useLocale.mjs";
10
- export { useTraduction } from "./client/useTraduction.mjs";
11
- export {
12
- localeCookie,
13
- setLocaleCookie,
14
- useLocaleCookie,
15
- } from "./client/useLocaleCookie.mjs";
16
- import "@intlayer/config/client";
17
- import "@intlayer/core";
18
- import "react";
19
- import "./useIntlayerBase.mjs";
20
- import "intlayer";
1
+ export { getTranslation } from './getTranslation.mjs';
2
+ export { IntlayerClientContext as IntlayerClient, IntlayerClientProvider, IntlayerClientProviderProps } from './client/IntlayerClientProvider.mjs';
3
+ export { useIntlayer } from './client/useIntlayer.mjs';
4
+ export { useLocale } from './client/useLocale.mjs';
5
+ export { useTraduction } from './client/useTraduction.mjs';
6
+ export { localeCookie, setLocaleCookie, useLocaleCookie } from './client/useLocaleCookie.mjs';
7
+ import '@intlayer/config/client';
8
+ import '@intlayer/core';
9
+ import 'react';
10
+ import './useIntlayerBase.mjs';
11
+ import 'intlayer';
@@ -1,25 +1,23 @@
1
- import { getTranslation } from "./getTranslation.mjs";
1
+ import { getTranslation } from './getTranslation.mjs';
2
2
  import {
3
- LocaleClientContextProvider,
4
- LocaleClientContext,
5
- useLocaleContext,
3
+ IntlayerClientProvider,
4
+ IntlayerClient,
6
5
  useIntlayer,
7
6
  useLocale,
8
7
  useTraduction,
9
8
  useLocaleCookie,
10
9
  localeCookie,
11
- setLocaleCookie,
12
- } from "./client/index.mjs";
10
+ setLocaleCookie
11
+ } from './client/index.mjs';
13
12
  export {
14
- LocaleClientContext,
15
- LocaleClientContextProvider,
13
+ IntlayerClient,
14
+ IntlayerClientProvider,
16
15
  getTranslation,
17
16
  localeCookie,
18
17
  setLocaleCookie,
19
18
  useIntlayer,
20
19
  useLocale,
21
- useLocaleContext,
22
20
  useLocaleCookie,
23
- useTraduction,
21
+ useTraduction
24
22
  };
25
- //# sourceMappingURL=index.mjs.map
23
+ //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export { getTranslation } from './getTranslation';\nexport {\n LocaleClientContextProvider,\n type LocaleClientContextProviderProps,\n LocaleClientContext,\n useLocaleContext,\n useIntlayer,\n useLocale,\n useTraduction,\n useLocaleCookie,\n localeCookie,\n setLocaleCookie,\n} from './client/index';\nexport {} from './client/useLocaleCookie';\n"],"mappings":"AAAA,SAAS,sBAAsB;AAC/B;AAAA,EACE;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;","names":[]}
1
+ {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export { getTranslation } from './getTranslation';\nexport {\n IntlayerClientProvider,\n type IntlayerClientProviderProps,\n IntlayerClient,\n useIntlayer,\n useLocale,\n useTraduction,\n useLocaleCookie,\n localeCookie,\n setLocaleCookie,\n} from './client/index';\nexport {} from './client/useLocaleCookie';\n"],"mappings":"AAAA,SAAS,sBAAsB;AAC/B;AAAA,EACE;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;","names":[]}
@@ -1,4 +1,4 @@
1
- import { TranslationContent } from "@intlayer/core";
1
+ import { TranslationContent } from '@intlayer/core';
2
2
 
3
3
  type ContentValue =
4
4
  | string
@@ -17,16 +17,13 @@ type TransformedContentValue =
17
17
  | undefined
18
18
  | ((quantity: number) => TransformedContentValue);
19
19
 
20
- type TransformedContent = Record<string, TransformedContentValue | undefined>;
20
+ type TransformedContent = Record<
21
+ string,
22
+ TransformedContentValue | undefined
23
+ >;
21
24
 
22
25
  type ContentDictionary = Content & {
23
26
  id: string;
24
27
  };
25
28
 
26
- export type {
27
- Content,
28
- ContentDictionary,
29
- ContentValue,
30
- TransformedContent,
31
- TransformedContentValue,
32
- };
29
+ export type { Content, ContentDictionary, ContentValue, TransformedContent, TransformedContentValue };
@@ -1 +1 @@
1
- //# sourceMappingURL=contentDictionary.d.mjs.map
1
+ //# sourceMappingURL=contentDictionary.d.mjs.map
@@ -1,22 +1,11 @@
1
- import { Locales } from "@intlayer/config/client";
2
- import {
3
- ContentValue,
4
- TransformedContentValue,
5
- Content,
6
- TransformedContent,
7
- } from "./contentDictionary.d.mjs";
8
- import "@intlayer/core";
1
+ import { Locales } from '@intlayer/config/client';
2
+ import { ContentValue, TransformedContentValue, Content, TransformedContent } from './contentDictionary.d.mjs';
3
+ import '@intlayer/core';
9
4
 
10
- declare const processNode: (
11
- field: ContentValue | undefined,
12
- locale: Locales
13
- ) => TransformedContentValue;
5
+ declare const processNode: (field: ContentValue | undefined, locale: Locales) => TransformedContentValue;
14
6
  /**
15
- * Function to replace the multi lingual content with content in the current locale
7
+ * Function that process a dictionary and return the result to be used in the application.
16
8
  */
17
- declare const processDictionary: (
18
- content: Content,
19
- locale?: Locales
20
- ) => TransformedContent;
9
+ declare const processDictionary: (content: Content, locale?: Locales) => TransformedContent;
21
10
 
22
11
  export { processDictionary, processNode };
@@ -1,15 +1,25 @@
1
- import { intlayerIntlConfiguration } from "@intlayer/config/client";
2
- import { NodeType } from "@intlayer/core";
3
- import { getEnumeration } from "../getEnumeration.mjs";
4
- import { getTranslation } from "../getTranslation.mjs";
1
+ import {
2
+ intlayerIntlConfiguration
3
+ } from "@intlayer/config/client";
4
+ import {
5
+ NodeType
6
+ } from "@intlayer/core";
7
+ import { getEnumeration } from '../getEnumeration.mjs';
8
+ import { getTranslation } from '../getTranslation.mjs';
5
9
  const defaultLocale = intlayerIntlConfiguration.defaultLocale;
6
10
  const processTranslation = (languageContent, locale) => {
7
- const translationResult = getTranslation(languageContent, locale);
11
+ const translationResult = getTranslation(
12
+ languageContent,
13
+ locale
14
+ );
8
15
  return processDictionary(translationResult, locale);
9
16
  };
10
17
  const processEnumeration = (enumerationContent, locale) => {
11
18
  return (quantity) => {
12
- const enumerationResult = getEnumeration(enumerationContent, quantity);
19
+ const enumerationResult = getEnumeration(
20
+ enumerationContent,
21
+ quantity
22
+ );
13
23
  return processDictionary(enumerationResult, locale);
14
24
  };
15
25
  };
@@ -21,7 +31,10 @@ const processNode = (field, locale) => {
21
31
  return processTranslation(field, locale);
22
32
  }
23
33
  if (field.nodeType === NodeType.Enumeration) {
24
- return processEnumeration(field, locale);
34
+ return processEnumeration(
35
+ field,
36
+ locale
37
+ );
25
38
  }
26
39
  if (typeof field.type === "undefined") {
27
40
  return processDictionary(field, locale);
@@ -39,5 +52,8 @@ const processDictionary = (content, locale = defaultLocale) => {
39
52
  }
40
53
  return content;
41
54
  };
42
- export { processDictionary, processNode };
43
- //# sourceMappingURL=index.mjs.map
55
+ export {
56
+ processDictionary,
57
+ processNode
58
+ };
59
+ //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/processDictionary/index.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport {\n type Locales,\n intlayerIntlConfiguration,\n} from '@intlayer/config/client';\nimport {\n NodeType,\n type QuantityContent,\n type LanguageContent,\n} from '@intlayer/core';\nimport { getEnumeration } from '../getEnumeration';\nimport { getTranslation } from '../getTranslation';\nimport type {\n Content,\n ContentValue,\n TransformedContent,\n TransformedContentValue,\n} from './contentDictionary';\n\nconst defaultLocale = intlayerIntlConfiguration.defaultLocale;\n\nconst processTranslation = (\n languageContent: LanguageContent<ContentValue>,\n locale: Locales\n): TransformedContent => {\n const translationResult: ContentValue = getTranslation<ContentValue>(\n languageContent,\n locale\n );\n\n return processDictionary(translationResult as Content, locale);\n};\n\nconst processEnumeration = (\n enumerationContent: QuantityContent<ContentValue>,\n locale: Locales\n): TransformedContentValue => {\n return (quantity: number): TransformedContentValue => {\n const enumerationResult: ContentValue = getEnumeration<ContentValue>(\n enumerationContent,\n quantity\n );\n\n //\n return processDictionary(enumerationResult as Content, locale);\n };\n};\n\nexport const processNode = (\n field: ContentValue | undefined,\n locale: Locales\n): TransformedContentValue => {\n if (typeof field !== 'object' || field === null) {\n return field;\n }\n\n if (field.nodeType === NodeType.Translation) {\n return processTranslation(field as LanguageContent<ContentValue>, locale);\n }\n\n if (field.nodeType === NodeType.Enumeration) {\n return processEnumeration(\n field satisfies QuantityContent<ContentValue>,\n locale\n );\n }\n\n if (typeof (field as any).type === 'undefined') {\n return processDictionary(field as Content, locale);\n }\n\n return field as TransformedContentValue;\n};\n\n/**\n * Function to replace the multi lingual content with content in the current locale\n */\nexport const processDictionary = (\n content: Content,\n locale: Locales = defaultLocale\n): TransformedContent => {\n if (content && typeof content === 'object') {\n const result: TransformedContent = {};\n\n // List each key in the content and process it\n for (const key of Object.keys(content)) {\n const field = content[key];\n\n result[key] = processNode(field, locale);\n }\n\n return result;\n }\n\n // If it's a string, number, or function, return it\n return content;\n};\n"],"mappings":"AACA;AAAA,EAEE;AAAA,OACK;AACP;AAAA,EACE;AAAA,OAGK;AACP,SAAS,sBAAsB;AAC/B,SAAS,sBAAsB;AAQ/B,MAAM,gBAAgB,0BAA0B;AAEhD,MAAM,qBAAqB,CACzB,iBACA,WACuB;AACvB,QAAM,oBAAkC;AAAA,IACtC;AAAA,IACA;AAAA,EACF;AAEA,SAAO,kBAAkB,mBAA8B,MAAM;AAC/D;AAEA,MAAM,qBAAqB,CACzB,oBACA,WAC4B;AAC5B,SAAO,CAAC,aAA8C;AACpD,UAAM,oBAAkC;AAAA,MACtC;AAAA,MACA;AAAA,IACF;AAGA,WAAO,kBAAkB,mBAA8B,MAAM;AAAA,EAC/D;AACF;AAEO,MAAM,cAAc,CACzB,OACA,WAC4B;AAC5B,MAAI,OAAO,UAAU,YAAY,UAAU,MAAM;AAC/C,WAAO;AAAA,EACT;AAEA,MAAI,MAAM,aAAa,SAAS,aAAa;AAC3C,WAAO,mBAAmB,OAAwC,MAAM;AAAA,EAC1E;AAEA,MAAI,MAAM,aAAa,SAAS,aAAa;AAC3C,WAAO;AAAA,MACL;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,MAAI,OAAQ,MAAc,SAAS,aAAa;AAC9C,WAAO,kBAAkB,OAAkB,MAAM;AAAA,EACnD;AAEA,SAAO;AACT;AAKO,MAAM,oBAAoB,CAC/B,SACA,SAAkB,kBACK;AACvB,MAAI,WAAW,OAAO,YAAY,UAAU;AAC1C,UAAM,SAA6B,CAAC;AAGpC,eAAW,OAAO,OAAO,KAAK,OAAO,GAAG;AACtC,YAAM,QAAQ,QAAQ,GAAG;AAEzB,aAAO,GAAG,IAAI,YAAY,OAAO,MAAM;AAAA,IACzC;AAEA,WAAO;AAAA,EACT;AAGA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../../src/processDictionary/index.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport {\n type Locales,\n intlayerIntlConfiguration,\n} from '@intlayer/config/client';\nimport {\n NodeType,\n type QuantityContent,\n type LanguageContent,\n} from '@intlayer/core';\nimport { getEnumeration } from '../getEnumeration';\nimport { getTranslation } from '../getTranslation';\nimport type {\n Content,\n ContentValue,\n TransformedContent,\n TransformedContentValue,\n} from './contentDictionary';\n\nconst defaultLocale = intlayerIntlConfiguration.defaultLocale;\n\nconst processTranslation = (\n languageContent: LanguageContent<ContentValue>,\n locale: Locales\n): TransformedContent => {\n const translationResult: ContentValue = getTranslation<ContentValue>(\n languageContent,\n locale\n );\n\n return processDictionary(translationResult as Content, locale);\n};\n\nconst processEnumeration = (\n enumerationContent: QuantityContent<ContentValue>,\n locale: Locales\n): TransformedContentValue => {\n return (quantity: number): TransformedContentValue => {\n const enumerationResult: ContentValue = getEnumeration<ContentValue>(\n enumerationContent,\n quantity\n );\n\n //\n return processDictionary(enumerationResult as Content, locale);\n };\n};\n\nexport const processNode = (\n field: ContentValue | undefined,\n locale: Locales\n): TransformedContentValue => {\n if (typeof field !== 'object' || field === null) {\n return field;\n }\n\n if (field.nodeType === NodeType.Translation) {\n return processTranslation(field as LanguageContent<ContentValue>, locale);\n }\n\n if (field.nodeType === NodeType.Enumeration) {\n return processEnumeration(\n field satisfies QuantityContent<ContentValue>,\n locale\n );\n }\n\n if (typeof (field as any).type === 'undefined') {\n return processDictionary(field as Content, locale);\n }\n\n return field as TransformedContentValue;\n};\n\n/**\n * Function that process a dictionary and return the result to be used in the application.\n */\nexport const processDictionary = (\n content: Content,\n locale: Locales = defaultLocale\n): TransformedContent => {\n if (content && typeof content === 'object') {\n const result: TransformedContent = {};\n\n // List each key in the content and process it\n for (const key of Object.keys(content)) {\n const field = content[key];\n\n result[key] = processNode(field, locale);\n }\n\n return result;\n }\n\n // If it's a string, number, or function, return it\n return content;\n};\n"],"mappings":"AACA;AAAA,EAEE;AAAA,OACK;AACP;AAAA,EACE;AAAA,OAGK;AACP,SAAS,sBAAsB;AAC/B,SAAS,sBAAsB;AAQ/B,MAAM,gBAAgB,0BAA0B;AAEhD,MAAM,qBAAqB,CACzB,iBACA,WACuB;AACvB,QAAM,oBAAkC;AAAA,IACtC;AAAA,IACA;AAAA,EACF;AAEA,SAAO,kBAAkB,mBAA8B,MAAM;AAC/D;AAEA,MAAM,qBAAqB,CACzB,oBACA,WAC4B;AAC5B,SAAO,CAAC,aAA8C;AACpD,UAAM,oBAAkC;AAAA,MACtC;AAAA,MACA;AAAA,IACF;AAGA,WAAO,kBAAkB,mBAA8B,MAAM;AAAA,EAC/D;AACF;AAEO,MAAM,cAAc,CACzB,OACA,WAC4B;AAC5B,MAAI,OAAO,UAAU,YAAY,UAAU,MAAM;AAC/C,WAAO;AAAA,EACT;AAEA,MAAI,MAAM,aAAa,SAAS,aAAa;AAC3C,WAAO,mBAAmB,OAAwC,MAAM;AAAA,EAC1E;AAEA,MAAI,MAAM,aAAa,SAAS,aAAa;AAC3C,WAAO;AAAA,MACL;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,MAAI,OAAQ,MAAc,SAAS,aAAa;AAC9C,WAAO,kBAAkB,OAAkB,MAAM;AAAA,EACnD;AAEA,SAAO;AACT;AAKO,MAAM,oBAAoB,CAC/B,SACA,SAAkB,kBACK;AACvB,MAAI,WAAW,OAAO,YAAY,UAAU;AAC1C,UAAM,SAA6B,CAAC;AAGpC,eAAW,OAAO,OAAO,KAAK,OAAO,GAAG;AACtC,YAAM,QAAQ,QAAQ,GAAG;AAEzB,aAAO,GAAG,IAAI,YAAY,OAAO,MAAM;AAAA,IACzC;AAEA,WAAO;AAAA,EACT;AAGA,SAAO;AACT;","names":[]}
@@ -0,0 +1,37 @@
1
+ import * as react from 'react';
2
+ import { PropsWithChildren, FC } from 'react';
3
+ import { Locales } from '@intlayer/config/client';
4
+
5
+ /**
6
+ * Context that store the current locale on the server side
7
+ */
8
+ declare const IntlayerServerContext: {
9
+ Provider: ({ children, value, }: {
10
+ children: react.ReactNode;
11
+ value: Locales;
12
+ }) => react.ReactNode;
13
+ Consumer: ({ children, }: {
14
+ children: (context: Locales | undefined) => react.ReactNode;
15
+ }) => react.ReactNode;
16
+ _storage: () => {
17
+ value: Locales | undefined;
18
+ };
19
+ _defaultValue: Locales | undefined;
20
+ };
21
+ /**
22
+ * Hook that provides the current locale
23
+ */
24
+ declare const useIntlayer: () => Locales | undefined;
25
+ /**
26
+ * Get the current locale
27
+ */
28
+ declare const locale: Locales | undefined;
29
+ type IntlayerServerProviderProps = PropsWithChildren & {
30
+ locale: Locales;
31
+ };
32
+ /**
33
+ * Provider that store the current locale on the server side
34
+ */
35
+ declare const IntlayerServerProvider: FC<IntlayerServerProviderProps>;
36
+
37
+ export { IntlayerServerContext, IntlayerServerProvider, type IntlayerServerProviderProps, locale, useIntlayer };
@@ -0,0 +1,21 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import {
3
+ intlayerIntlConfiguration
4
+ } from "@intlayer/config/client";
5
+ import { createServerContext, getServerContext } from './serverContext.mjs';
6
+ const IntlayerServerContext = createServerContext(
7
+ intlayerIntlConfiguration.defaultLocale
8
+ );
9
+ const useIntlayer = () => getServerContext(IntlayerServerContext);
10
+ const locale = getServerContext(IntlayerServerContext);
11
+ const IntlayerServerProvider = ({
12
+ children,
13
+ locale: locale2
14
+ }) => /* @__PURE__ */ jsx(IntlayerServerContext.Provider, { value: locale2, children });
15
+ export {
16
+ IntlayerServerContext,
17
+ IntlayerServerProvider,
18
+ locale,
19
+ useIntlayer
20
+ };
21
+ //# sourceMappingURL=IntlayerServerProvider.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/server/IntlayerServerProvider.tsx"],"sourcesContent":["import {\n type Locales,\n intlayerIntlConfiguration,\n} from '@intlayer/config/client';\nimport type { FC, PropsWithChildren } from 'react';\nimport { createServerContext, getServerContext } from './serverContext';\n\n/**\n * Context that store the current locale on the server side\n */\nexport const IntlayerServerContext = createServerContext<Locales>(\n intlayerIntlConfiguration.defaultLocale\n);\n\n/**\n * Hook that provides the current locale\n */\nexport const useIntlayer = () => getServerContext(IntlayerServerContext);\n\n/**\n * Get the current locale\n */\nexport const locale = getServerContext(IntlayerServerContext);\n\nexport type IntlayerServerProviderProps = PropsWithChildren & {\n locale: Locales;\n};\n\n/**\n * Provider that store the current locale on the server side\n */\nexport const IntlayerServerProvider: FC<IntlayerServerProviderProps> = ({\n children,\n locale,\n}) => (\n <IntlayerServerContext.Provider value={locale}>\n {children}\n </IntlayerServerContext.Provider>\n);\n"],"mappings":"AAmCE;AAnCF;AAAA,EAEE;AAAA,OACK;AAEP,SAAS,qBAAqB,wBAAwB;AAK/C,MAAM,wBAAwB;AAAA,EACnC,0BAA0B;AAC5B;AAKO,MAAM,cAAc,MAAM,iBAAiB,qBAAqB;AAKhE,MAAM,SAAS,iBAAiB,qBAAqB;AASrD,MAAM,yBAA0D,CAAC;AAAA,EACtE;AAAA,EACA,QAAAA;AACF,MACE,oBAAC,sBAAsB,UAAtB,EAA+B,OAAOA,SACpC,UACH;","names":["locale"]}
@@ -1,11 +1,12 @@
1
- import * as _intlayer_config_client from "@intlayer/config/client";
2
- import { LanguageContent } from "@intlayer/core";
1
+ import * as _intlayer_config_client from '@intlayer/config/client';
2
+ import { LanguageContent } from '@intlayer/core';
3
3
 
4
- declare const getLocaleTranslation: <Content>(
5
- languageContent: LanguageContent<Content>
6
- ) => {
7
- locale: _intlayer_config_client.Locales | undefined;
8
- content: Content;
4
+ /**
5
+ * On the server side, get the translation content based on the locale
6
+ */
7
+ declare const getLocaleTranslation: <Content>(languageContent: LanguageContent<Content>) => {
8
+ locale: _intlayer_config_client.Locales | undefined;
9
+ content: Content;
9
10
  };
10
11
 
11
12
  export { getLocaleTranslation };
@@ -1,17 +1,19 @@
1
1
  import { intlayerIntlConfiguration } from "@intlayer/config/client";
2
2
  import { getTranslationContent } from "@intlayer/core";
3
- import { LocaleServerContext } from "./LocaleServerContextProvider.mjs";
4
- import { getServerContext } from "./serverContext.mjs";
3
+ import { IntlayerServerContext } from './IntlayerServerProvider.mjs';
4
+ import { getServerContext } from './serverContext.mjs';
5
5
  const getLocaleTranslation = (languageContent) => {
6
- const locale = getServerContext(LocaleServerContext);
6
+ const locale = getServerContext(IntlayerServerContext);
7
7
  const content = getTranslationContent(
8
8
  languageContent,
9
9
  locale ?? intlayerIntlConfiguration.defaultLocale
10
10
  );
11
11
  return {
12
12
  locale,
13
- content,
13
+ content
14
14
  };
15
15
  };
16
- export { getLocaleTranslation };
17
- //# sourceMappingURL=getLocaleTranslation.mjs.map
16
+ export {
17
+ getLocaleTranslation
18
+ };
19
+ //# sourceMappingURL=getLocaleTranslation.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/server/getLocaleTranslation.ts"],"sourcesContent":["import { intlayerIntlConfiguration } from '@intlayer/config/client';\nimport { type LanguageContent, getTranslationContent } from '@intlayer/core';\nimport { LocaleServerContext } from './LocaleServerContextProvider';\nimport { getServerContext } from './serverContext';\n\nexport const getLocaleTranslation = <Content>(\n languageContent: LanguageContent<Content>\n) => {\n const locale = getServerContext(LocaleServerContext);\n const content = getTranslationContent<Content>(\n languageContent,\n locale ?? intlayerIntlConfiguration.defaultLocale\n );\n\n return {\n locale,\n content,\n };\n};\n"],"mappings":"AAAA,SAAS,iCAAiC;AAC1C,SAA+B,6BAA6B;AAC5D,SAAS,2BAA2B;AACpC,SAAS,wBAAwB;AAE1B,MAAM,uBAAuB,CAClC,oBACG;AACH,QAAM,SAAS,iBAAiB,mBAAmB;AACnD,QAAM,UAAU;AAAA,IACd;AAAA,IACA,UAAU,0BAA0B;AAAA,EACtC;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../src/server/getLocaleTranslation.ts"],"sourcesContent":["import { intlayerIntlConfiguration } from '@intlayer/config/client';\nimport { type LanguageContent, getTranslationContent } from '@intlayer/core';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\n\n/**\n * On the server side, get the translation content based on the locale\n */\nexport const getLocaleTranslation = <Content>(\n languageContent: LanguageContent<Content>\n) => {\n const locale = getServerContext(IntlayerServerContext);\n const content = getTranslationContent<Content>(\n languageContent,\n locale ?? intlayerIntlConfiguration.defaultLocale\n );\n\n return {\n locale,\n content,\n };\n};\n"],"mappings":"AAAA,SAAS,iCAAiC;AAC1C,SAA+B,6BAA6B;AAC5D,SAAS,6BAA6B;AACtC,SAAS,wBAAwB;AAK1B,MAAM,uBAAuB,CAClC,oBACG;AACH,QAAM,SAAS,iBAAiB,qBAAqB;AACrD,QAAM,UAAU;AAAA,IACd;AAAA,IACA,UAAU,0BAA0B;AAAA,EACtC;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;","names":[]}