react-intlayer 1.2.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (142) hide show
  1. package/dist/cjs/IntlayerProvider.cjs +1 -1
  2. package/dist/cjs/IntlayerProvider.cjs.map +1 -1
  3. package/dist/cjs/cli/react-intlayer.cjs +68 -0
  4. package/dist/cjs/cli/react-intlayer.cjs.map +1 -0
  5. package/dist/cjs/cli/react-intlayer.d.ts +1 -0
  6. package/dist/cjs/client/IntlayerClientProvider.cjs +26 -2
  7. package/dist/cjs/client/IntlayerClientProvider.cjs.map +1 -1
  8. package/dist/cjs/client/IntlayerClientProvider.d.ts +2 -1
  9. package/dist/cjs/client/getBrowserLocale.cjs +170 -0
  10. package/dist/cjs/client/getBrowserLocale.cjs.map +1 -0
  11. package/dist/cjs/client/getBrowserLocale.d.ts +26 -0
  12. package/dist/cjs/client/index.cjs +6 -0
  13. package/dist/cjs/client/index.cjs.map +1 -1
  14. package/dist/cjs/client/index.d.ts +2 -0
  15. package/dist/cjs/client/useContent.cjs +2 -2
  16. package/dist/cjs/client/useContent.cjs.map +1 -1
  17. package/dist/cjs/client/useLocale.cjs +5 -3
  18. package/dist/cjs/client/useLocale.cjs.map +1 -1
  19. package/dist/cjs/client/useLocale.d.ts +1 -0
  20. package/dist/cjs/client/useLocaleBase.cjs +49 -0
  21. package/dist/cjs/client/useLocaleBase.cjs.map +1 -0
  22. package/dist/cjs/client/useLocaleBase.d.ts +14 -0
  23. package/dist/cjs/client/useLocaleCookie.cjs +1 -1
  24. package/dist/cjs/client/useLocaleCookie.cjs.map +1 -1
  25. package/dist/cjs/client/useTraduction.cjs.map +1 -1
  26. package/dist/cjs/client/useTraduction.d.ts +6 -5
  27. package/dist/cjs/craco/craco.config.cjs +32 -0
  28. package/dist/cjs/craco/craco.config.cjs.map +1 -0
  29. package/dist/cjs/craco/craco.config.d.ts +2 -0
  30. package/dist/cjs/craco/intlayerCracoPlugin.cjs +89 -0
  31. package/dist/cjs/craco/intlayerCracoPlugin.cjs.map +1 -0
  32. package/dist/cjs/craco/intlayerCracoPlugin.d.ts +26 -0
  33. package/dist/cjs/getEnumeration.cjs.map +1 -1
  34. package/dist/cjs/getEnumeration.d.ts +8 -5
  35. package/dist/cjs/getTranslation.cjs +1 -1
  36. package/dist/cjs/getTranslation.cjs.map +1 -1
  37. package/dist/cjs/getTranslation.d.ts +3 -2
  38. package/dist/cjs/index.cjs +4 -0
  39. package/dist/cjs/index.cjs.map +1 -1
  40. package/dist/cjs/index.d.ts +2 -0
  41. package/dist/cjs/processDictionary/index.cjs +33 -1
  42. package/dist/cjs/processDictionary/index.cjs.map +1 -1
  43. package/dist/cjs/server/IntlayerServerProvider.cjs +1 -1
  44. package/dist/cjs/server/IntlayerServerProvider.cjs.map +1 -1
  45. package/dist/cjs/server/getLocaleTranslation.cjs +1 -1
  46. package/dist/cjs/server/getLocaleTranslation.cjs.map +1 -1
  47. package/dist/cjs/server/useTraduction.cjs.map +1 -1
  48. package/dist/cjs/server/useTraduction.d.ts +4 -3
  49. package/dist/cjs/vite/intlayerPlugin.cjs +60 -0
  50. package/dist/cjs/vite/intlayerPlugin.cjs.map +1 -0
  51. package/dist/cjs/vite/intlayerPlugin.d.ts +17 -0
  52. package/dist/esm/ContentEditor/ContentEditor.mjs +1 -0
  53. package/dist/esm/ContentEditor/ContentEditor.mjs.map +1 -1
  54. package/dist/esm/ContentEditor/contentRender.mjs +1 -0
  55. package/dist/esm/ContentEditor/contentRender.mjs.map +1 -1
  56. package/dist/esm/IntlayerProvider.mjs +3 -2
  57. package/dist/esm/IntlayerProvider.mjs.map +1 -1
  58. package/dist/esm/chunk-ZNCO4QRF.mjs +9 -0
  59. package/dist/esm/chunk-ZNCO4QRF.mjs.map +1 -0
  60. package/dist/esm/cli/react-intlayer.d.mts +1 -0
  61. package/dist/esm/cli/react-intlayer.mjs +45 -0
  62. package/dist/esm/cli/react-intlayer.mjs.map +1 -0
  63. package/dist/esm/client/IntlayerClientProvider.d.mts +2 -1
  64. package/dist/esm/client/IntlayerClientProvider.mjs +33 -7
  65. package/dist/esm/client/IntlayerClientProvider.mjs.map +1 -1
  66. package/dist/esm/client/getBrowserLocale.d.mts +26 -0
  67. package/dist/esm/client/getBrowserLocale.mjs +146 -0
  68. package/dist/esm/client/getBrowserLocale.mjs.map +1 -0
  69. package/dist/esm/client/index.d.mts +2 -0
  70. package/dist/esm/client/index.mjs +5 -0
  71. package/dist/esm/client/index.mjs.map +1 -1
  72. package/dist/esm/client/useContent.mjs +3 -2
  73. package/dist/esm/client/useContent.mjs.map +1 -1
  74. package/dist/esm/client/useIntlayer.mjs +1 -0
  75. package/dist/esm/client/useIntlayer.mjs.map +1 -1
  76. package/dist/esm/client/useLocale.d.mts +1 -0
  77. package/dist/esm/client/useLocale.mjs +7 -4
  78. package/dist/esm/client/useLocale.mjs.map +1 -1
  79. package/dist/esm/client/useLocaleBase.d.mts +14 -0
  80. package/dist/esm/client/useLocaleBase.mjs +26 -0
  81. package/dist/esm/client/useLocaleBase.mjs.map +1 -0
  82. package/dist/esm/client/useLocaleCookie.mjs +3 -4
  83. package/dist/esm/client/useLocaleCookie.mjs.map +1 -1
  84. package/dist/esm/client/useTraduction.d.mts +6 -5
  85. package/dist/esm/client/useTraduction.mjs +1 -0
  86. package/dist/esm/client/useTraduction.mjs.map +1 -1
  87. package/dist/esm/craco/craco.config.d.mts +2 -0
  88. package/dist/esm/craco/craco.config.mjs +17 -0
  89. package/dist/esm/craco/craco.config.mjs.map +1 -0
  90. package/dist/esm/craco/intlayerCracoPlugin.d.mts +26 -0
  91. package/dist/esm/craco/intlayerCracoPlugin.mjs +54 -0
  92. package/dist/esm/craco/intlayerCracoPlugin.mjs.map +1 -0
  93. package/dist/esm/getEnumeration.d.mts +8 -5
  94. package/dist/esm/getEnumeration.mjs +1 -0
  95. package/dist/esm/getEnumeration.mjs.map +1 -1
  96. package/dist/esm/getTranslation.d.mts +3 -2
  97. package/dist/esm/getTranslation.mjs +3 -4
  98. package/dist/esm/getTranslation.mjs.map +1 -1
  99. package/dist/esm/index.d.mts +2 -0
  100. package/dist/esm/index.mjs +6 -1
  101. package/dist/esm/index.mjs.map +1 -1
  102. package/dist/esm/processDictionary/index.mjs +35 -4
  103. package/dist/esm/processDictionary/index.mjs.map +1 -1
  104. package/dist/esm/server/IntlayerServerProvider.mjs +3 -4
  105. package/dist/esm/server/IntlayerServerProvider.mjs.map +1 -1
  106. package/dist/esm/server/getLocaleTranslation.mjs +3 -2
  107. package/dist/esm/server/getLocaleTranslation.mjs.map +1 -1
  108. package/dist/esm/server/index.mjs +1 -0
  109. package/dist/esm/server/index.mjs.map +1 -1
  110. package/dist/esm/server/serverContext.mjs +1 -0
  111. package/dist/esm/server/serverContext.mjs.map +1 -1
  112. package/dist/esm/server/useIntlayer.mjs +1 -0
  113. package/dist/esm/server/useIntlayer.mjs.map +1 -1
  114. package/dist/esm/server/useTraduction.d.mts +4 -3
  115. package/dist/esm/server/useTraduction.mjs +1 -0
  116. package/dist/esm/server/useTraduction.mjs.map +1 -1
  117. package/dist/esm/useIntlayerBase.mjs +1 -0
  118. package/dist/esm/useIntlayerBase.mjs.map +1 -1
  119. package/dist/esm/vite/intlayerPlugin.d.mts +17 -0
  120. package/dist/esm/vite/intlayerPlugin.mjs +36 -0
  121. package/dist/esm/vite/intlayerPlugin.mjs.map +1 -0
  122. package/package.json +30 -5
  123. package/src/IntlayerProvider.tsx +2 -2
  124. package/src/cli/react-intlayer.ts +60 -0
  125. package/src/client/IntlayerClientProvider.tsx +43 -12
  126. package/src/client/getBrowserLocale.tsx +192 -0
  127. package/src/client/index.ts +2 -0
  128. package/src/client/useContent.ts +2 -2
  129. package/src/client/useLocale.ts +5 -4
  130. package/src/client/useLocaleBase.ts +24 -0
  131. package/src/client/useLocaleCookie.ts +2 -5
  132. package/src/client/useTraduction.ts +6 -5
  133. package/src/craco/craco.config.ts +11 -0
  134. package/src/craco/intlayerCracoPlugin.ts +89 -0
  135. package/src/getEnumeration.ts +8 -5
  136. package/src/getTranslation.ts +5 -7
  137. package/src/index.ts +2 -1
  138. package/src/processDictionary/index.ts +52 -5
  139. package/src/server/IntlayerServerProvider.tsx +2 -5
  140. package/src/server/getLocaleTranslation.ts +2 -2
  141. package/src/server/useTraduction.ts +4 -3
  142. package/src/vite/intlayerPlugin.ts +59 -0
@@ -0,0 +1,54 @@
1
+ import "../chunk-ZNCO4QRF.mjs";
2
+ import { resolve, relative, join } from "path";
3
+ import { getConfiguration, formatEnvVariable } from "@intlayer/config";
4
+ import { IntLayerPlugin as IntLayerWebpackPlugin } from "@intlayer/webpack";
5
+ import webpack from "webpack";
6
+ const intlayerConfig = getConfiguration();
7
+ const env = formatEnvVariable("react_app");
8
+ const overrideWebpackConfig = ({
9
+ webpackConfig
10
+ }) => {
11
+ webpackConfig.externals = {
12
+ ...typeof webpackConfig.externals === "object" ? webpackConfig.externals : {},
13
+ esbuild: "esbuild",
14
+ module: "module",
15
+ fs: "fs",
16
+ vm: "vm"
17
+ };
18
+ (webpackConfig.module?.rules ?? []).push({
19
+ test: /\.node$/,
20
+ use: "node-loader"
21
+ });
22
+ return webpackConfig;
23
+ };
24
+ const overrideCracoConfig = ({
25
+ cracoConfig
26
+ }) => {
27
+ const { mainDir, baseDir } = intlayerConfig.content;
28
+ const dictionariesPath = join(mainDir, "dictionaries.mjs");
29
+ const relativeDictionariesPath = relative(baseDir, dictionariesPath);
30
+ return {
31
+ ...cracoConfig,
32
+ webpack: {
33
+ ...cracoConfig.webpack,
34
+ plugins: {
35
+ ...cracoConfig.webpack?.plugins,
36
+ add: [new webpack.EnvironmentPlugin(env), new IntLayerWebpackPlugin()]
37
+ },
38
+ alias: {
39
+ ...cracoConfig.webpack?.alias,
40
+ "@intlayer/dictionaries-entry": resolve("./", relativeDictionariesPath)
41
+ }
42
+ }
43
+ };
44
+ };
45
+ const plugin = {
46
+ overrideCracoConfig,
47
+ overrideWebpackConfig
48
+ };
49
+ export {
50
+ overrideCracoConfig,
51
+ overrideWebpackConfig,
52
+ plugin
53
+ };
54
+ //# sourceMappingURL=intlayerCracoPlugin.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/craco/intlayerCracoPlugin.ts"],"sourcesContent":["import { resolve, relative, join } from 'path';\nimport type {\n CracoConfig,\n CracoConfigOverride,\n CracoPlugin,\n WebpackConfigOverride,\n} from '@craco/types';\nimport { getConfiguration, formatEnvVariable } from '@intlayer/config';\nimport { IntLayerPlugin as IntLayerWebpackPlugin } from '@intlayer/webpack';\nimport webpack, { type Configuration as WebpackConfig } from 'webpack';\n\n// Get IntLayer configuration\nconst intlayerConfig = getConfiguration();\n\n// Format environment variables\nconst env: Record<string, string> = formatEnvVariable('react_app');\n\n// Custom CRACO plugin function to override webpack configuration\nexport const overrideWebpackConfig = ({\n webpackConfig,\n}: WebpackConfigOverride): WebpackConfig => {\n webpackConfig.externals = {\n ...(typeof webpackConfig.externals === 'object'\n ? webpackConfig.externals\n : {}),\n esbuild: 'esbuild',\n module: 'module',\n fs: 'fs',\n vm: 'vm',\n };\n\n (webpackConfig.module?.rules ?? []).push({\n test: /\\.node$/,\n use: 'node-loader',\n });\n\n // You can add any custom CRACO plugins here if needed\n // config.plugins.push(new CustomCracoPlugin());\n\n return webpackConfig;\n};\n\n// Return a CRACO configuration object\nexport const overrideCracoConfig = ({\n cracoConfig,\n}: CracoConfigOverride): CracoConfig => {\n const { mainDir, baseDir } = intlayerConfig.content;\n\n const dictionariesPath = join(mainDir, 'dictionaries.mjs');\n const relativeDictionariesPath = relative(baseDir, dictionariesPath);\n\n return {\n ...cracoConfig,\n webpack: {\n ...cracoConfig.webpack,\n plugins: {\n ...cracoConfig.webpack?.plugins,\n add: [new webpack.EnvironmentPlugin(env), new IntLayerWebpackPlugin()],\n },\n alias: {\n ...cracoConfig.webpack?.alias,\n '@intlayer/dictionaries-entry': resolve('./', relativeDictionariesPath),\n },\n },\n };\n};\n\n/**\n * A CRACO plugin that adds the IntLayer configuration to the webpack configuration and sets the environment variables.\n *\n * Usage:\n *\n * ```ts\n * const cracoConfig: CracoConfig = {\n * plugins: [\n * {\n * plugin: intlayerCracoPlugin(),\n * },\n * ],\n * };\n *\n * export default cracoConfig;\n * ```\n *\n */\nexport const plugin: CracoPlugin = {\n overrideCracoConfig,\n overrideWebpackConfig,\n};\n"],"mappings":";AAAA,SAAS,SAAS,UAAU,YAAY;AAOxC,SAAS,kBAAkB,yBAAyB;AACpD,SAAS,kBAAkB,6BAA6B;AACxD,OAAO,aAAsD;AAG7D,MAAM,iBAAiB,iBAAiB;AAGxC,MAAM,MAA8B,kBAAkB,WAAW;AAG1D,MAAM,wBAAwB,CAAC;AAAA,EACpC;AACF,MAA4C;AAC1C,gBAAc,YAAY;AAAA,IACxB,GAAI,OAAO,cAAc,cAAc,WACnC,cAAc,YACd,CAAC;AAAA,IACL,SAAS;AAAA,IACT,QAAQ;AAAA,IACR,IAAI;AAAA,IACJ,IAAI;AAAA,EACN;AAEA,GAAC,cAAc,QAAQ,SAAS,CAAC,GAAG,KAAK;AAAA,IACvC,MAAM;AAAA,IACN,KAAK;AAAA,EACP,CAAC;AAKD,SAAO;AACT;AAGO,MAAM,sBAAsB,CAAC;AAAA,EAClC;AACF,MAAwC;AACtC,QAAM,EAAE,SAAS,QAAQ,IAAI,eAAe;AAE5C,QAAM,mBAAmB,KAAK,SAAS,kBAAkB;AACzD,QAAM,2BAA2B,SAAS,SAAS,gBAAgB;AAEnE,SAAO;AAAA,IACL,GAAG;AAAA,IACH,SAAS;AAAA,MACP,GAAG,YAAY;AAAA,MACf,SAAS;AAAA,QACP,GAAG,YAAY,SAAS;AAAA,QACxB,KAAK,CAAC,IAAI,QAAQ,kBAAkB,GAAG,GAAG,IAAI,sBAAsB,CAAC;AAAA,MACvE;AAAA,MACA,OAAO;AAAA,QACL,GAAG,YAAY,SAAS;AAAA,QACxB,gCAAgC,QAAQ,MAAM,wBAAwB;AAAA,MACxE;AAAA,IACF;AAAA,EACF;AACF;AAoBO,MAAM,SAAsB;AAAA,EACjC;AAAA,EACA;AACF;","names":[]}
@@ -7,22 +7,25 @@ import { QuantityContent } from '@intlayer/core';
7
7
  *
8
8
  * Usage:
9
9
  *
10
+ * ```ts
10
11
  * const content = getEnumeration({
11
12
  * '<=-2.3': 'You have less than -2.3',
12
13
  * '<1': 'You have less than one',
13
14
  * '2': 'You have two',
14
15
  * '>=3': 'You have three or more',
15
- * },
16
- * 2);
16
+ * }, 2);
17
17
  * // 'You have two'
18
+ * ```
18
19
  *
19
20
  * The order of the keys will define the priority of the content.
20
21
  *
22
+ * ```ts
21
23
  * const content = getEnumeration({
22
- * '<4': 'You have less than four',
23
- * '2': 'You have two',
24
- * });
24
+ * '<4': 'You have less than four',
25
+ * '2': 'You have two',
26
+ * }, 2);
25
27
  * // 'You have less than four'
28
+ * ```
26
29
  *
27
30
  */
28
31
  declare const getEnumeration: <Content>(enumerationContent: QuantityContent<Content>, quantity: number) => Content;
@@ -1,3 +1,4 @@
1
+ import "./chunk-ZNCO4QRF.mjs";
1
2
  import { getEnumerationContent } from "@intlayer/core";
2
3
  import { contentRender } from './ContentEditor/contentRender.mjs';
3
4
  const getEnumeration = (enumerationContent, quantity) => {
@@ -1 +1 @@
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
+ {"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 * ```ts\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 * }, 2);\n * // 'You have two'\n * ```\n *\n * The order of the keys will define the priority of the content.\n *\n * ```ts\n * const content = getEnumeration({\n * '<4': 'You have less than four',\n * '2': 'You have two',\n * }, 2);\n * // 'You have less than four'\n * ```\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;AA8BvB,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":[]}
@@ -10,12 +10,13 @@ import { LanguageContent } from '@intlayer/core';
10
10
  *
11
11
  * Usage:
12
12
  *
13
+ * ```ts
13
14
  * const content = getTranslation<string>({
14
15
  * en: 'Hello',
15
16
  * fr: 'Bonjour',
16
- * },
17
- * 'fr');
17
+ * }, 'fr');
18
18
  * // 'Bonjour'
19
+ * ```
19
20
  *
20
21
  * Using TypeScript:
21
22
  * - this function will require each locale to be defined if defined in the project configuration.
@@ -1,10 +1,9 @@
1
- import {
2
- intlayerIntlConfiguration
3
- } from "@intlayer/config/client";
1
+ import "./chunk-ZNCO4QRF.mjs";
2
+ import { getConfiguration } from "@intlayer/config/client";
4
3
  import { getTranslationContent } from "@intlayer/core";
5
4
  import { contentRender } from './ContentEditor/contentRender.mjs';
6
5
  const getTranslation = (languageContent, locale) => {
7
- const { defaultLocale } = intlayerIntlConfiguration;
6
+ const { defaultLocale } = getConfiguration().internationalization;
8
7
  const result = getTranslationContent(
9
8
  languageContent,
10
9
  locale ?? defaultLocale
@@ -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\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
+ {"version":3,"sources":["../../src/getTranslation.ts"],"sourcesContent":["import { type Locales, getConfiguration } 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 * ```ts\n * const content = getTranslation<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 getTranslation = <Content = string>(\n languageContent: LanguageContent<Content>,\n locale?: Locales\n): Content => {\n const { defaultLocale } = getConfiguration().internationalization;\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,SAAuB,wBAAwB;AAC/C,SAA+B,6BAA6B;AAC5D,SAAS,qBAAqB;AAuBvB,MAAM,iBAAiB,CAC5B,iBACA,WACY;AACZ,QAAM,EAAE,cAAc,IAAI,iBAAiB,EAAE;AAE7C,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,9 +1,11 @@
1
1
  export { getTranslation } from './getTranslation.mjs';
2
2
  export { IntlayerClientContext as IntlayerClient, IntlayerClientProvider, IntlayerClientProviderProps } from './client/IntlayerClientProvider.mjs';
3
3
  export { useIntlayer } from './client/useIntlayer.mjs';
4
+ export { useLocaleBase } from './client/useLocaleBase.mjs';
4
5
  export { useLocale } from './client/useLocale.mjs';
5
6
  export { useTraduction } from './client/useTraduction.mjs';
6
7
  export { localeCookie, setLocaleCookie, useLocaleCookie } from './client/useLocaleCookie.mjs';
8
+ export { getBrowserLocale } from './client/getBrowserLocale.mjs';
7
9
  import '@intlayer/config/client';
8
10
  import '@intlayer/core';
9
11
  import 'react';
@@ -1,3 +1,4 @@
1
+ import "./chunk-ZNCO4QRF.mjs";
1
2
  import { getTranslation } from './getTranslation.mjs';
2
3
  import {
3
4
  IntlayerClientProvider,
@@ -7,16 +8,20 @@ import {
7
8
  useTraduction,
8
9
  useLocaleCookie,
9
10
  localeCookie,
10
- setLocaleCookie
11
+ setLocaleCookie,
12
+ getBrowserLocale,
13
+ useLocaleBase
11
14
  } from './client/index.mjs';
12
15
  export {
13
16
  IntlayerClient,
14
17
  IntlayerClientProvider,
18
+ getBrowserLocale,
15
19
  getTranslation,
16
20
  localeCookie,
17
21
  setLocaleCookie,
18
22
  useIntlayer,
19
23
  useLocale,
24
+ useLocaleBase,
20
25
  useLocaleCookie,
21
26
  useTraduction
22
27
  };
@@ -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} 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
+ {"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,SAAS,sBAAsB;AAC/B;AAAA,EACE;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;","names":[]}
@@ -1,12 +1,12 @@
1
- import {
2
- intlayerIntlConfiguration
3
- } from "@intlayer/config/client";
1
+ import "../chunk-ZNCO4QRF.mjs";
2
+ import { getConfiguration } from "@intlayer/config/client";
4
3
  import {
5
4
  NodeType
6
5
  } from "@intlayer/core";
6
+ import { createElement } from "react";
7
7
  import { getEnumeration } from '../getEnumeration.mjs';
8
8
  import { getTranslation } from '../getTranslation.mjs';
9
- const defaultLocale = intlayerIntlConfiguration.defaultLocale;
9
+ const { defaultLocale } = getConfiguration().internationalization;
10
10
  const processTranslation = (languageContent, locale) => {
11
11
  const translationResult = getTranslation(
12
12
  languageContent,
@@ -23,6 +23,7 @@ const processEnumeration = (enumerationContent, locale) => {
23
23
  return processDictionary(enumerationResult, locale);
24
24
  };
25
25
  };
26
+ const isReactNode = (node) => typeof node?.key !== "undefined" && typeof node?.props !== "undefined";
26
27
  const processNode = (field, locale) => {
27
28
  if (typeof field !== "object" || field === null) {
28
29
  return field;
@@ -41,7 +42,37 @@ const processNode = (field, locale) => {
41
42
  }
42
43
  return field;
43
44
  };
45
+ const createReactElement = (element) => {
46
+ if (typeof element === "string") {
47
+ return element;
48
+ }
49
+ const convertChildrenAsArray = (element2) => {
50
+ if (element2?.props && typeof element2.props.children === "object") {
51
+ const childrenResult = [];
52
+ const { children } = element2.props;
53
+ Object.keys(children).forEach((key) => {
54
+ childrenResult.push(createReactElement(children[key]));
55
+ });
56
+ return {
57
+ ...element2,
58
+ props: { ...element2.props, children: childrenResult }
59
+ };
60
+ }
61
+ return {
62
+ ...element2,
63
+ props: { ...element2.props, children: element2.props.children }
64
+ };
65
+ };
66
+ const fixedElement = convertChildrenAsArray(element);
67
+ const { type, props } = fixedElement;
68
+ return createElement(type ?? "div", props, ...props.children);
69
+ };
44
70
  const processDictionary = (content, locale = defaultLocale) => {
71
+ if (isReactNode(content)) {
72
+ return createReactElement(
73
+ content
74
+ );
75
+ }
45
76
  if (content && typeof content === "object") {
46
77
  const result = {};
47
78
  for (const key of Object.keys(content)) {
@@ -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 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":[]}
1
+ {"version":3,"sources":["../../../src/processDictionary/index.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { type Locales, getConfiguration } from '@intlayer/config/client';\nimport {\n NodeType,\n type QuantityContent,\n type LanguageContent,\n} from '@intlayer/core';\nimport { type ReactElement, createElement, type ReactNode } from 'react';\nimport { getEnumeration } from '../getEnumeration';\nimport { getTranslation } from '../getTranslation';\nimport type {\n Content,\n ContentValue,\n TransformedContent,\n TransformedContentValue,\n} from './contentDictionary';\n\nconst { defaultLocale } = getConfiguration().internationalization;\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\nconst isReactNode = (node: Record<string, unknown>): boolean =>\n typeof node?.key !== 'undefined' && typeof node?.props !== 'undefined';\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// This function recursively creates React elements from a given JSON-like structure\nconst createReactElement = (element: ReactElement) => {\n if (typeof element === 'string') {\n // If it's a string, simply return it (used for text content)\n return element;\n }\n\n // Destructure the component properties\n\n const convertChildrenAsArray = (element: ReactElement): ReactElement => {\n if (element?.props && typeof element.props.children === 'object') {\n const childrenResult: ReactNode[] = [];\n const { children } = element.props;\n\n // Create the children elements recursively, if any\n Object.keys(children).forEach((key) => {\n childrenResult.push(createReactElement(children[key]));\n });\n\n return {\n ...element,\n props: { ...element.props, children: childrenResult },\n };\n }\n\n return {\n ...element,\n props: { ...element.props, children: element.props.children },\n };\n };\n\n const fixedElement = convertChildrenAsArray(element);\n\n const { type, props } = fixedElement;\n\n // Create and return the React element\n return createElement(type ?? 'div', props, ...props.children);\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 it's a React element, render it\n if (isReactNode(content)) {\n return createReactElement(\n content as unknown as ReactElement\n ) as unknown as TransformedContent;\n }\n\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,SAAuB,wBAAwB;AAC/C;AAAA,EACE;AAAA,OAGK;AACP,SAA4B,qBAAqC;AACjE,SAAS,sBAAsB;AAC/B,SAAS,sBAAsB;AAQ/B,MAAM,EAAE,cAAc,IAAI,iBAAiB,EAAE;AAE7C,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;AAEA,MAAM,cAAc,CAAC,SACnB,OAAO,MAAM,QAAQ,eAAe,OAAO,MAAM,UAAU;AAEtD,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;AAGA,MAAM,qBAAqB,CAAC,YAA0B;AACpD,MAAI,OAAO,YAAY,UAAU;AAE/B,WAAO;AAAA,EACT;AAIA,QAAM,yBAAyB,CAACA,aAAwC;AACtE,QAAIA,UAAS,SAAS,OAAOA,SAAQ,MAAM,aAAa,UAAU;AAChE,YAAM,iBAA8B,CAAC;AACrC,YAAM,EAAE,SAAS,IAAIA,SAAQ;AAG7B,aAAO,KAAK,QAAQ,EAAE,QAAQ,CAAC,QAAQ;AACrC,uBAAe,KAAK,mBAAmB,SAAS,GAAG,CAAC,CAAC;AAAA,MACvD,CAAC;AAED,aAAO;AAAA,QACL,GAAGA;AAAA,QACH,OAAO,EAAE,GAAGA,SAAQ,OAAO,UAAU,eAAe;AAAA,MACtD;AAAA,IACF;AAEA,WAAO;AAAA,MACL,GAAGA;AAAA,MACH,OAAO,EAAE,GAAGA,SAAQ,OAAO,UAAUA,SAAQ,MAAM,SAAS;AAAA,IAC9D;AAAA,EACF;AAEA,QAAM,eAAe,uBAAuB,OAAO;AAEnD,QAAM,EAAE,MAAM,MAAM,IAAI;AAGxB,SAAO,cAAc,QAAQ,OAAO,OAAO,GAAG,MAAM,QAAQ;AAC9D;AAKO,MAAM,oBAAoB,CAC/B,SACA,SAAkB,kBACK;AAEvB,MAAI,YAAY,OAAO,GAAG;AACxB,WAAO;AAAA,MACL;AAAA,IACF;AAAA,EACF;AAEA,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":["element"]}
@@ -1,10 +1,9 @@
1
+ import "../chunk-ZNCO4QRF.mjs";
1
2
  import { jsx } from "react/jsx-runtime";
2
- import {
3
- intlayerIntlConfiguration
4
- } from "@intlayer/config/client";
3
+ import { getConfiguration } from "@intlayer/config/client";
5
4
  import { createServerContext, getServerContext } from './serverContext.mjs';
6
5
  const IntlayerServerContext = createServerContext(
7
- intlayerIntlConfiguration.defaultLocale
6
+ getConfiguration().internationalization.defaultLocale
8
7
  );
9
8
  const useIntlayer = () => getServerContext(IntlayerServerContext);
10
9
  const locale = getServerContext(IntlayerServerContext);
@@ -1 +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
+ {"version":3,"sources":["../../../src/server/IntlayerServerProvider.tsx"],"sourcesContent":["import { type Locales, getConfiguration } 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 getConfiguration().internationalization.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":";AAgCE;AAhCF,SAAuB,wBAAwB;AAE/C,SAAS,qBAAqB,wBAAwB;AAK/C,MAAM,wBAAwB;AAAA,EACnC,iBAAiB,EAAE,qBAAqB;AAC1C;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,4 +1,5 @@
1
- import { intlayerIntlConfiguration } from "@intlayer/config/client";
1
+ import "../chunk-ZNCO4QRF.mjs";
2
+ import { getConfiguration } from "@intlayer/config/client";
2
3
  import { getTranslationContent } from "@intlayer/core";
3
4
  import { IntlayerServerContext } from './IntlayerServerProvider.mjs';
4
5
  import { getServerContext } from './serverContext.mjs';
@@ -6,7 +7,7 @@ const getLocaleTranslation = (languageContent) => {
6
7
  const locale = getServerContext(IntlayerServerContext);
7
8
  const content = getTranslationContent(
8
9
  languageContent,
9
- locale ?? intlayerIntlConfiguration.defaultLocale
10
+ locale ?? getConfiguration().internationalization.defaultLocale
10
11
  );
11
12
  return {
12
13
  locale,
@@ -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 { 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":[]}
1
+ {"version":3,"sources":["../../../src/server/getLocaleTranslation.ts"],"sourcesContent":["import { getConfiguration } 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 ?? getConfiguration().internationalization.defaultLocale\n );\n\n return {\n locale,\n content,\n };\n};\n"],"mappings":";AAAA,SAAS,wBAAwB;AACjC,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,iBAAiB,EAAE,qBAAqB;AAAA,EACpD;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
@@ -1,3 +1,4 @@
1
+ import "../chunk-ZNCO4QRF.mjs";
1
2
  import { getLocaleTranslation } from './getLocaleTranslation.mjs';
2
3
  import { useTraduction } from './useTraduction.mjs';
3
4
  import {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/server/index.ts"],"sourcesContent":["export { getLocaleTranslation as getLocaleContent } from './getLocaleTranslation';\nexport { useTraduction } from './useTraduction';\nexport {\n IntlayerServerContext as IntlayerServer,\n locale,\n IntlayerServerProvider,\n} from './IntlayerServerProvider';\nexport { useIntlayer } from './useIntlayer';\n"],"mappings":"AAAA,SAAiC,4BAAwB;AACzD,SAAS,qBAAqB;AAC9B;AAAA,EAC2B;AAAA,EACzB;AAAA,EACA;AAAA,OACK;AACP,SAAS,mBAAmB;","names":[]}
1
+ {"version":3,"sources":["../../../src/server/index.ts"],"sourcesContent":["export { getLocaleTranslation as getLocaleContent } from './getLocaleTranslation';\nexport { useTraduction } from './useTraduction';\nexport {\n IntlayerServerContext as IntlayerServer,\n locale,\n IntlayerServerProvider,\n} from './IntlayerServerProvider';\nexport { useIntlayer } from './useIntlayer';\n"],"mappings":";AAAA,SAAiC,4BAAwB;AACzD,SAAS,qBAAqB;AAC9B;AAAA,EAC2B;AAAA,EACzB;AAAA,EACA;AAAA,OACK;AACP,SAAS,mBAAmB;","names":[]}
@@ -1,3 +1,4 @@
1
+ import "../chunk-ZNCO4QRF.mjs";
1
2
  import react from "react";
2
3
  const cacheFallback = () => () => ({ value: void 0 });
3
4
  const createServerContext = (defaultValue) => {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/server/serverContext.ts"],"sourcesContent":["/**\n * Creates a new datastore for a given server context.\n * Attempts to closely mimic the `createContext` API.\n *\n * @example\n * const IntlayerServer = createServerContext<string | null>(null);\n *\n * <IntlayerServer.Provider value={locale}>\n * {children}\n * </IntlayerServer.Provider>\n */\n\nimport react from 'react';\n\ntype CacheType<T> = () => { value: T | undefined };\n\nconst cacheFallback = () => () => ({ value: undefined });\n\nexport const createServerContext = <T>(defaultValue?: T): ServerContext<T> => {\n throwInClient();\n\n const cache = react.cache<CacheType<T>> ?? cacheFallback;\n\n const getCache = cache(() => ({\n value: undefined,\n }));\n\n return {\n Provider: ({ children, value }) => {\n getCache().value = value;\n return children;\n },\n Consumer: ({ children }) => {\n const store = getCache();\n return children(store ? store.value : defaultValue);\n },\n _storage: getCache,\n _defaultValue: defaultValue,\n };\n};\n\n/**\n * Fetches a value present in a given server context.\n * Attempts to closely mimic the `useContext` API.\n *\n * @example\n * getServerContext(IntlayerServer);\n */\nexport const getServerContext = <T>({\n _storage,\n _defaultValue,\n}: ServerContext<T>) => {\n // throwInClient();\n const store = _storage();\n if (!store) return _defaultValue;\n return store.value;\n};\n\ntype ServerContext<T> = {\n Provider: ({\n children,\n value,\n }: {\n children: React.ReactNode;\n value: T;\n }) => React.ReactNode;\n Consumer: ({\n children,\n }: {\n children: (context: T | undefined) => React.ReactNode;\n }) => React.ReactNode;\n _storage: () => { value: T | undefined };\n _defaultValue: T | undefined;\n};\n\n/**\n * Throws if called within a client component environment.\n * Useful to help prevent mistakes.\n */\nconst throwInClient = (): void | never => {\n // If window.document is defined we're in a client component\n if (typeof window !== 'undefined') {\n throw new Error(`createServerContext only works in Server Components`);\n }\n};\n"],"mappings":"AAYA,OAAO,WAAW;AAIlB,MAAM,gBAAgB,MAAM,OAAO,EAAE,OAAO,OAAU;AAE/C,MAAM,sBAAsB,CAAI,iBAAuC;AAC5E,gBAAc;AAEd,QAAM,QAAQ,MAAM,SAAuB;AAE3C,QAAM,WAAW,MAAM,OAAO;AAAA,IAC5B,OAAO;AAAA,EACT,EAAE;AAEF,SAAO;AAAA,IACL,UAAU,CAAC,EAAE,UAAU,MAAM,MAAM;AACjC,eAAS,EAAE,QAAQ;AACnB,aAAO;AAAA,IACT;AAAA,IACA,UAAU,CAAC,EAAE,SAAS,MAAM;AAC1B,YAAM,QAAQ,SAAS;AACvB,aAAO,SAAS,QAAQ,MAAM,QAAQ,YAAY;AAAA,IACpD;AAAA,IACA,UAAU;AAAA,IACV,eAAe;AAAA,EACjB;AACF;AASO,MAAM,mBAAmB,CAAI;AAAA,EAClC;AAAA,EACA;AACF,MAAwB;AAEtB,QAAM,QAAQ,SAAS;AACvB,MAAI,CAAC;AAAO,WAAO;AACnB,SAAO,MAAM;AACf;AAuBA,MAAM,gBAAgB,MAAoB;AAExC,MAAI,OAAO,WAAW,aAAa;AACjC,UAAM,IAAI,MAAM,qDAAqD;AAAA,EACvE;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../src/server/serverContext.ts"],"sourcesContent":["/**\n * Creates a new datastore for a given server context.\n * Attempts to closely mimic the `createContext` API.\n *\n * @example\n * const IntlayerServer = createServerContext<string | null>(null);\n *\n * <IntlayerServer.Provider value={locale}>\n * {children}\n * </IntlayerServer.Provider>\n */\n\nimport react from 'react';\n\ntype CacheType<T> = () => { value: T | undefined };\n\nconst cacheFallback = () => () => ({ value: undefined });\n\nexport const createServerContext = <T>(defaultValue?: T): ServerContext<T> => {\n throwInClient();\n\n const cache = react.cache<CacheType<T>> ?? cacheFallback;\n\n const getCache = cache(() => ({\n value: undefined,\n }));\n\n return {\n Provider: ({ children, value }) => {\n getCache().value = value;\n return children;\n },\n Consumer: ({ children }) => {\n const store = getCache();\n return children(store ? store.value : defaultValue);\n },\n _storage: getCache,\n _defaultValue: defaultValue,\n };\n};\n\n/**\n * Fetches a value present in a given server context.\n * Attempts to closely mimic the `useContext` API.\n *\n * @example\n * getServerContext(IntlayerServer);\n */\nexport const getServerContext = <T>({\n _storage,\n _defaultValue,\n}: ServerContext<T>) => {\n // throwInClient();\n const store = _storage();\n if (!store) return _defaultValue;\n return store.value;\n};\n\ntype ServerContext<T> = {\n Provider: ({\n children,\n value,\n }: {\n children: React.ReactNode;\n value: T;\n }) => React.ReactNode;\n Consumer: ({\n children,\n }: {\n children: (context: T | undefined) => React.ReactNode;\n }) => React.ReactNode;\n _storage: () => { value: T | undefined };\n _defaultValue: T | undefined;\n};\n\n/**\n * Throws if called within a client component environment.\n * Useful to help prevent mistakes.\n */\nconst throwInClient = (): void | never => {\n // If window.document is defined we're in a client component\n if (typeof window !== 'undefined') {\n throw new Error(`createServerContext only works in Server Components`);\n }\n};\n"],"mappings":";AAYA,OAAO,WAAW;AAIlB,MAAM,gBAAgB,MAAM,OAAO,EAAE,OAAO,OAAU;AAE/C,MAAM,sBAAsB,CAAI,iBAAuC;AAC5E,gBAAc;AAEd,QAAM,QAAQ,MAAM,SAAuB;AAE3C,QAAM,WAAW,MAAM,OAAO;AAAA,IAC5B,OAAO;AAAA,EACT,EAAE;AAEF,SAAO;AAAA,IACL,UAAU,CAAC,EAAE,UAAU,MAAM,MAAM;AACjC,eAAS,EAAE,QAAQ;AACnB,aAAO;AAAA,IACT;AAAA,IACA,UAAU,CAAC,EAAE,SAAS,MAAM;AAC1B,YAAM,QAAQ,SAAS;AACvB,aAAO,SAAS,QAAQ,MAAM,QAAQ,YAAY;AAAA,IACpD;AAAA,IACA,UAAU;AAAA,IACV,eAAe;AAAA,EACjB;AACF;AASO,MAAM,mBAAmB,CAAI;AAAA,EAClC;AAAA,EACA;AACF,MAAwB;AAEtB,QAAM,QAAQ,SAAS;AACvB,MAAI,CAAC;AAAO,WAAO;AACnB,SAAO,MAAM;AACf;AAuBA,MAAM,gBAAgB,MAAoB;AAExC,MAAI,OAAO,WAAW,aAAa;AACjC,UAAM,IAAI,MAAM,qDAAqD;AAAA,EACvE;AACF;","names":[]}
@@ -1,3 +1,4 @@
1
+ import "../chunk-ZNCO4QRF.mjs";
1
2
  import {
2
3
  useIntlayerBase
3
4
  } from '../useIntlayerBase.mjs';
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/server/useIntlayer.ts"],"sourcesContent":["import type { Locales } from '@intlayer/config/client';\nimport {\n type DictionaryKeys,\n useIntlayerBase,\n type UseIntlayer,\n} from '../useIntlayerBase';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\n\n/**\n * On the server 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 server context\n */\nexport const useIntlayer: UseIntlayer = <T extends DictionaryKeys>(\n id: T,\n locale?: Locales\n) => {\n const localeTarget =\n locale ?? getServerContext<Locales>(IntlayerServerContext);\n\n return useIntlayerBase(id, localeTarget);\n};\n"],"mappings":"AACA;AAAA,EAEE;AAAA,OAEK;AACP,SAAS,6BAA6B;AACtC,SAAS,wBAAwB;AAO1B,MAAM,cAA2B,CACtC,IACA,WACG;AACH,QAAM,eACJ,UAAU,iBAA0B,qBAAqB;AAE3D,SAAO,gBAAgB,IAAI,YAAY;AACzC;","names":[]}
1
+ {"version":3,"sources":["../../../src/server/useIntlayer.ts"],"sourcesContent":["import type { Locales } from '@intlayer/config/client';\nimport {\n type DictionaryKeys,\n useIntlayerBase,\n type UseIntlayer,\n} from '../useIntlayerBase';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\n\n/**\n * On the server 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 server context\n */\nexport const useIntlayer: UseIntlayer = <T extends DictionaryKeys>(\n id: T,\n locale?: Locales\n) => {\n const localeTarget =\n locale ?? getServerContext<Locales>(IntlayerServerContext);\n\n return useIntlayerBase(id, localeTarget);\n};\n"],"mappings":";AACA;AAAA,EAEE;AAAA,OAEK;AACP,SAAS,6BAA6B;AACtC,SAAS,wBAAwB;AAO1B,MAAM,cAA2B,CACtC,IACA,WACG;AACH,QAAM,eACJ,UAAU,iBAA0B,qBAAqB;AAE3D,SAAO,gBAAgB,IAAI,YAAY;AACzC;","names":[]}
@@ -9,12 +9,13 @@ import { LanguageContent } from '@intlayer/core';
9
9
  *
10
10
  * Usage:
11
11
  *
12
- * const content = getTranslation<string>({
12
+ * ```ts
13
+ * const content = useTraduction<string>({
13
14
  * en: 'Hello',
14
15
  * fr: 'Bonjour',
15
- * },
16
- * 'fr');
16
+ * }, 'fr');
17
17
  * // 'Bonjour'
18
+ * ```
18
19
  *
19
20
  * Using TypeScript:
20
21
  * - this function will require each locale to be defined if defined in the project configuration.
@@ -1,3 +1,4 @@
1
+ import "../chunk-ZNCO4QRF.mjs";
1
2
  import { getTranslation } from '../getTranslation.mjs';
2
3
  import { IntlayerServerContext } from './IntlayerServerProvider.mjs';
3
4
  import { getServerContext } from './serverContext.mjs';
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/server/useTraduction.ts"],"sourcesContent":["import type { Locales } from '@intlayer/config/client';\nimport type { LanguageContent } from '@intlayer/core';\nimport { getTranslation } from '../getTranslation';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\n\n/**\n * On the server side, hook to get the translation content based on the locale\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) => {\n const locale = getServerContext<Locales>(IntlayerServerContext);\n\n return getTranslation(languageContent, locale);\n};\n"],"mappings":"AAEA,SAAS,sBAAsB;AAC/B,SAAS,6BAA6B;AACtC,SAAS,wBAAwB;AAsB1B,MAAM,gBAAgB,CAC3B,oBACG;AACH,QAAM,SAAS,iBAA0B,qBAAqB;AAE9D,SAAO,eAAe,iBAAiB,MAAM;AAC/C;","names":[]}
1
+ {"version":3,"sources":["../../../src/server/useTraduction.ts"],"sourcesContent":["import type { Locales } from '@intlayer/config/client';\nimport type { LanguageContent } from '@intlayer/core';\nimport { getTranslation } from '../getTranslation';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\n\n/**\n * On the server side, hook to get the translation content based on the locale\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 * ```ts\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) => {\n const locale = getServerContext<Locales>(IntlayerServerContext);\n\n return getTranslation(languageContent, locale);\n};\n"],"mappings":";AAEA,SAAS,sBAAsB;AAC/B,SAAS,6BAA6B;AACtC,SAAS,wBAAwB;AAuB1B,MAAM,gBAAgB,CAC3B,oBACG;AACH,QAAM,SAAS,iBAA0B,qBAAqB;AAE9D,SAAO,eAAe,iBAAiB,MAAM;AAC/C;","names":[]}
@@ -1,3 +1,4 @@
1
+ import "./chunk-ZNCO4QRF.mjs";
1
2
  import dictionaries from "@intlayer/dictionaries-entry";
2
3
  import { processDictionary } from './processDictionary/index.mjs';
3
4
  const useIntlayerBase = (id, locale) => {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/useIntlayerBase.ts"],"sourcesContent":["import type { Locales } from '@intlayer/config/client';\n/**\n * @intlayer/dictionaries-entry is a package that only returns the dictionary entry path.\n * Using an external package allow to alias it in the bundle configuration (such as webpack).\n * The alias allow hot reload the app (such as nextjs) on any dictionary change.\n */\nimport dictionaries from '@intlayer/dictionaries-entry';\nimport type { IntlayerDictionaryTypesConnector } from 'intlayer';\nimport type { Content } from './processDictionary/contentDictionary';\nimport { processDictionary } from './processDictionary/index';\n\nexport type StringFallback<T> = T extends never ? string : T; // If no keys are found, return string to disable error, and accept any string as dictionary key\nexport type DictionaryKeys = StringFallback<\n keyof IntlayerDictionaryTypesConnector\n>;\n\nexport type UseIntlayer = <T extends DictionaryKeys>(\n id: T,\n locale?: Locales\n) => IntlayerDictionaryTypesConnector[T];\n\n/**\n * Hook that picking one dictionary by its id and return the content.\n */\nexport const useIntlayerBase: UseIntlayer = <T extends DictionaryKeys>(\n id: T,\n locale?: Locales\n) => {\n const dictionary: Content = dictionaries[id];\n\n return processDictionary(\n dictionary,\n locale\n ) as IntlayerDictionaryTypesConnector[T];\n};\n"],"mappings":"AAMA,OAAO,kBAAkB;AAGzB,SAAS,yBAAyB;AAe3B,MAAM,kBAA+B,CAC1C,IACA,WACG;AACH,QAAM,aAAsB,aAAa,EAAE;AAE3C,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/useIntlayerBase.ts"],"sourcesContent":["import type { Locales } from '@intlayer/config/client';\n/**\n * @intlayer/dictionaries-entry is a package that only returns the dictionary entry path.\n * Using an external package allow to alias it in the bundle configuration (such as webpack).\n * The alias allow hot reload the app (such as nextjs) on any dictionary change.\n */\nimport dictionaries from '@intlayer/dictionaries-entry';\nimport type { IntlayerDictionaryTypesConnector } from 'intlayer';\nimport type { Content } from './processDictionary/contentDictionary';\nimport { processDictionary } from './processDictionary/index';\n\nexport type StringFallback<T> = T extends never ? string : T; // If no keys are found, return string to disable error, and accept any string as dictionary key\nexport type DictionaryKeys = StringFallback<\n keyof IntlayerDictionaryTypesConnector\n>;\n\nexport type UseIntlayer = <T extends DictionaryKeys>(\n id: T,\n locale?: Locales\n) => IntlayerDictionaryTypesConnector[T];\n\n/**\n * Hook that picking one dictionary by its id and return the content.\n */\nexport const useIntlayerBase: UseIntlayer = <T extends DictionaryKeys>(\n id: T,\n locale?: Locales\n) => {\n const dictionary: Content = dictionaries[id];\n\n return processDictionary(\n dictionary,\n locale\n ) as IntlayerDictionaryTypesConnector[T];\n};\n"],"mappings":";AAMA,OAAO,kBAAkB;AAGzB,SAAS,yBAAyB;AAe3B,MAAM,kBAA+B,CAC1C,IACA,WACG;AACH,QAAM,aAAsB,aAAa,EAAE;AAE3C,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
@@ -0,0 +1,17 @@
1
+ import { Plugin } from 'vite';
2
+
3
+ type PluginOptions = {};
4
+ /**
5
+ *
6
+ * A Vite plugin that integrates IntLayer configuration into the build process
7
+ *
8
+ * ```ts
9
+ * // Example usage of the plugin in a Vite configuration
10
+ * export default defineConfig({
11
+ * plugins: [ intLayerPlugin() ],
12
+ * });
13
+ * ```
14
+ * */
15
+ declare const intLayerPlugin: (_pluginOptions?: PluginOptions) => Plugin;
16
+
17
+ export { intLayerPlugin };
@@ -0,0 +1,36 @@
1
+ import "../chunk-ZNCO4QRF.mjs";
2
+ import { join, relative, resolve } from "path";
3
+ import { watch } from "@intlayer/chokidar";
4
+ import { getConfiguration, formatEnvVariable } from "@intlayer/config";
5
+ import { loadEnv } from "vite";
6
+ const intLayerPlugin = (_pluginOptions = {}) => ({
7
+ name: "vite-intlayer-plugin",
8
+ config: (config, { mode }) => {
9
+ const intlayerConfig = getConfiguration();
10
+ const env = formatEnvVariable("vite");
11
+ process.env = { ...process.env, ...loadEnv(mode, process.cwd()), ...env };
12
+ const { mainDir, baseDir } = intlayerConfig.content;
13
+ const dictionariesPath = join(mainDir, "dictionaries.mjs");
14
+ const relativeDictionariesPath = relative(baseDir, dictionariesPath);
15
+ config.resolve = {
16
+ ...config.resolve,
17
+ alias: {
18
+ ...config.resolve?.alias,
19
+ "@intlayer/dictionaries-entry": resolve(relativeDictionariesPath)
20
+ }
21
+ };
22
+ return config;
23
+ },
24
+ buildStart: () => {
25
+ watch({
26
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
27
+ persistent: import.meta.env === "development"
28
+ });
29
+ },
30
+ configureServer: (server) => {
31
+ }
32
+ });
33
+ export {
34
+ intLayerPlugin
35
+ };
36
+ //# sourceMappingURL=intlayerPlugin.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/vite/intlayerPlugin.ts"],"sourcesContent":["import { join, relative, resolve } from 'path';\nimport { watch } from '@intlayer/chokidar';\nimport { getConfiguration, formatEnvVariable } from '@intlayer/config';\nimport { loadEnv, type Plugin } from 'vite';\n\n// Plugin options type definition\ntype PluginOptions = {\n // Custom options for your plugin, if any\n};\n\n/**\n *\n * A Vite plugin that integrates IntLayer configuration into the build process\n *\n * ```ts\n * // Example usage of the plugin in a Vite configuration\n * export default defineConfig({\n * plugins: [ intLayerPlugin() ],\n * });\n * ```\n * */\nexport const intLayerPlugin = (_pluginOptions: PluginOptions = {}): Plugin => ({\n name: 'vite-intlayer-plugin',\n\n config: (config, { mode }) => {\n const intlayerConfig = getConfiguration();\n\n // Set all configuration values as environment variables\n const env = formatEnvVariable('vite');\n\n process.env = { ...process.env, ...loadEnv(mode, process.cwd()), ...env };\n\n const { mainDir, baseDir } = intlayerConfig.content;\n const dictionariesPath = join(mainDir, 'dictionaries.mjs');\n const relativeDictionariesPath = relative(baseDir, dictionariesPath);\n\n // Update Vite's resolve alias\n config.resolve = {\n ...config.resolve,\n alias: {\n ...config.resolve?.alias,\n '@intlayer/dictionaries-entry': resolve(relativeDictionariesPath),\n },\n };\n\n return config;\n },\n\n buildStart: () => {\n // Code to run when Vite build starts\n watch({\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n persistent: (import.meta as any).env === 'development',\n });\n },\n configureServer: (server) => {\n // Custom server configuration, if needed\n },\n});\n"],"mappings":";AAAA,SAAS,MAAM,UAAU,eAAe;AACxC,SAAS,aAAa;AACtB,SAAS,kBAAkB,yBAAyB;AACpD,SAAS,eAA4B;AAkB9B,MAAM,iBAAiB,CAAC,iBAAgC,CAAC,OAAe;AAAA,EAC7E,MAAM;AAAA,EAEN,QAAQ,CAAC,QAAQ,EAAE,KAAK,MAAM;AAC5B,UAAM,iBAAiB,iBAAiB;AAGxC,UAAM,MAAM,kBAAkB,MAAM;AAEpC,YAAQ,MAAM,EAAE,GAAG,QAAQ,KAAK,GAAG,QAAQ,MAAM,QAAQ,IAAI,CAAC,GAAG,GAAG,IAAI;AAExE,UAAM,EAAE,SAAS,QAAQ,IAAI,eAAe;AAC5C,UAAM,mBAAmB,KAAK,SAAS,kBAAkB;AACzD,UAAM,2BAA2B,SAAS,SAAS,gBAAgB;AAGnE,WAAO,UAAU;AAAA,MACf,GAAG,OAAO;AAAA,MACV,OAAO;AAAA,QACL,GAAG,OAAO,SAAS;AAAA,QACnB,gCAAgC,QAAQ,wBAAwB;AAAA,MAClE;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AAAA,EAEA,YAAY,MAAM;AAEhB,UAAM;AAAA;AAAA,MAEJ,YAAa,YAAoB,QAAQ;AAAA,IAC3C,CAAC;AAAA,EACH;AAAA,EACA,iBAAiB,CAAC,WAAW;AAAA,EAE7B;AACF;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-intlayer",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "private": false,
5
5
  "description": "Internationalization layer for React applications - Layer of abstraction between the business logic and the data access layer. Manage internationalization in a simple way, through TypeScript, JavaScript or JSON declaration file.",
6
6
  "keywords": [
@@ -37,6 +37,21 @@
37
37
  "require": "./dist/cjs/server/index.cjs",
38
38
  "import": "./dist/esm/server/index.mjs"
39
39
  },
40
+ "./craco-plugin": {
41
+ "types": "./dist/esm/craco/intlayerCracoPlugin.d.mts",
42
+ "require": "./dist/cjs/craco/intlayerCracoPlugin.cjs",
43
+ "import": "./dist/esm/craco/intlayerCracoPlugin.mjs"
44
+ },
45
+ "./craco-config": {
46
+ "types": "./dist/esm/craco/craco.config.d.mts",
47
+ "require": "./dist/cjs/craco/craco.config.cjs",
48
+ "import": "./dist/esm/craco/craco.config.mjs"
49
+ },
50
+ "./vite-plugin": {
51
+ "types": "./dist/esm/vite/intlayerPlugin.d.mts",
52
+ "require": "./dist/cjs/vite/intlayerPlugin.cjs",
53
+ "import": "./dist/esm/vite/intlayerPlugin.mjs"
54
+ },
40
55
  "./package.json": "./package.json"
41
56
  },
42
57
  "main": "./src/index.ts",
@@ -47,20 +62,30 @@
47
62
  ]
48
63
  }
49
64
  },
65
+ "bin": {
66
+ "react-intlayer": "./dist/cjs/cli/react-intlayer.cjs"
67
+ },
50
68
  "files": [
51
69
  "./dist",
52
70
  "./src",
53
71
  "./package.json"
54
72
  ],
55
73
  "dependencies": {
74
+ "cross-spawn": "^7.0.3",
56
75
  "js-cookie": "^3.0.5",
57
76
  "react-cookie": "^7.1.4",
58
- "@intlayer/config": "^1.2.0",
59
- "@intlayer/core": "^1.2.0",
60
- "@intlayer/dictionaries-entry": "^1.2.0",
61
- "intlayer": "^1.2.0"
77
+ "vite": "^5.2.0",
78
+ "webpack": "^5.91.0",
79
+ "@intlayer/chokidar": "^1.2.1",
80
+ "@intlayer/config": "^1.2.1",
81
+ "@intlayer/core": "^1.2.1",
82
+ "@intlayer/dictionaries-entry": "^1.2.1",
83
+ "@intlayer/webpack": "^1.2.1",
84
+ "intlayer": "^1.2.1"
62
85
  },
63
86
  "devDependencies": {
87
+ "@craco/types": "^7.1.0",
88
+ "@types/cross-spawn": "^6.0.6",
64
89
  "@types/js-cookie": "^3.0.6",
65
90
  "@types/node": "^20.12.7",
66
91
  "@types/react": "^18.2.79",
@@ -1,4 +1,4 @@
1
- import { intlayerIntlConfiguration } from '@intlayer/config/client';
1
+ import { getConfiguration } from '@intlayer/config/client';
2
2
  import type { FC } from 'react';
3
3
  import {
4
4
  IntlayerClientProvider,
@@ -9,7 +9,7 @@ import {
9
9
  type IntlayerServerProviderProps,
10
10
  } from './server/IntlayerServerProvider';
11
11
 
12
- const defaultLocale = intlayerIntlConfiguration.defaultLocale;
12
+ const { defaultLocale } = getConfiguration().internationalization;
13
13
 
14
14
  type IntlayerProviderProps = IntlayerClientProviderProps &
15
15
  IntlayerServerProviderProps;