react-intlayer 2.0.12 → 3.0.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 (167) hide show
  1. package/README.md +51 -51
  2. package/dist/cjs/client/IntlayerProvider.cjs +2 -2
  3. package/dist/cjs/client/IntlayerProvider.cjs.map +1 -1
  4. package/dist/cjs/client/getBrowserLocale.cjs.map +1 -1
  5. package/dist/cjs/client/index.cjs +6 -0
  6. package/dist/cjs/client/index.cjs.map +1 -1
  7. package/dist/cjs/client/t.cjs +37 -0
  8. package/dist/cjs/client/t.cjs.map +1 -0
  9. package/dist/cjs/client/useDictionary.cjs +37 -0
  10. package/dist/cjs/client/useDictionary.cjs.map +1 -0
  11. package/dist/cjs/client/useIntlayer.cjs +2 -2
  12. package/dist/cjs/client/useIntlayer.cjs.map +1 -1
  13. package/dist/cjs/craco/craco.config.cjs.map +1 -1
  14. package/dist/cjs/craco/intlayerCracoPlugin.cjs.map +1 -1
  15. package/dist/cjs/index.cjs +4 -0
  16. package/dist/cjs/index.cjs.map +1 -1
  17. package/dist/cjs/processDictionary/index.cjs +3 -2
  18. package/dist/cjs/processDictionary/index.cjs.map +1 -1
  19. package/dist/cjs/server/index.cjs +6 -0
  20. package/dist/cjs/server/index.cjs.map +1 -1
  21. package/dist/cjs/server/serverContext.cjs.map +1 -1
  22. package/dist/cjs/server/t.cjs +36 -0
  23. package/dist/cjs/server/t.cjs.map +1 -0
  24. package/dist/cjs/server/useDictionary.cjs +35 -0
  25. package/dist/cjs/server/useDictionary.cjs.map +1 -0
  26. package/dist/cjs/server/useIntlayer.cjs +2 -2
  27. package/dist/cjs/server/useIntlayer.cjs.map +1 -1
  28. package/dist/cjs/useDictionaryBase.cjs +69 -0
  29. package/dist/cjs/useDictionaryBase.cjs.map +1 -0
  30. package/dist/cjs/useIntlayerBase.cjs +10 -29
  31. package/dist/cjs/useIntlayerBase.cjs.map +1 -1
  32. package/dist/cjs/vite/intlayerPlugin.cjs.map +1 -1
  33. package/dist/esm/client/IntlayerProvider.mjs +1 -1
  34. package/dist/esm/client/IntlayerProvider.mjs.map +1 -1
  35. package/dist/esm/client/getBrowserLocale.mjs.map +1 -1
  36. package/dist/esm/client/index.mjs +4 -0
  37. package/dist/esm/client/index.mjs.map +1 -1
  38. package/dist/esm/client/t.mjs +14 -0
  39. package/dist/esm/client/t.mjs.map +1 -0
  40. package/dist/esm/client/useDictionary.mjs +14 -0
  41. package/dist/esm/client/useDictionary.mjs.map +1 -0
  42. package/dist/esm/client/useIntlayer.mjs +2 -2
  43. package/dist/esm/client/useIntlayer.mjs.map +1 -1
  44. package/dist/esm/craco/craco.config.mjs.map +1 -1
  45. package/dist/esm/craco/intlayerCracoPlugin.mjs.map +1 -1
  46. package/dist/esm/index.mjs +5 -1
  47. package/dist/esm/index.mjs.map +1 -1
  48. package/dist/esm/processDictionary/index.mjs +3 -2
  49. package/dist/esm/processDictionary/index.mjs.map +1 -1
  50. package/dist/esm/server/index.mjs +4 -0
  51. package/dist/esm/server/index.mjs.map +1 -1
  52. package/dist/esm/server/serverContext.mjs.map +1 -1
  53. package/dist/esm/server/t.mjs +13 -0
  54. package/dist/esm/server/t.mjs.map +1 -0
  55. package/dist/esm/server/useDictionary.mjs +12 -0
  56. package/dist/esm/server/useDictionary.mjs.map +1 -0
  57. package/dist/esm/server/useIntlayer.mjs +2 -2
  58. package/dist/esm/server/useIntlayer.mjs.map +1 -1
  59. package/dist/esm/useDictionaryBase.mjs +45 -0
  60. package/dist/esm/useDictionaryBase.mjs.map +1 -0
  61. package/dist/esm/useIntlayerBase.mjs +12 -28
  62. package/dist/esm/useIntlayerBase.mjs.map +1 -1
  63. package/dist/esm/vite/intlayerPlugin.mjs.map +1 -1
  64. package/dist/types/cli/react-intlayer.d.ts +9 -0
  65. package/dist/types/cli/react-intlayer.d.ts.map +1 -0
  66. package/dist/types/client/IntlayerProvider.d.ts +25 -0
  67. package/dist/types/client/IntlayerProvider.d.ts.map +1 -0
  68. package/dist/{cjs → types}/client/getBrowserLocale.d.ts +5 -6
  69. package/dist/types/client/getBrowserLocale.d.ts.map +1 -0
  70. package/dist/types/client/index.d.ts +10 -0
  71. package/dist/types/client/index.d.ts.map +1 -0
  72. package/dist/types/client/t.d.ts +9 -0
  73. package/dist/types/client/t.d.ts.map +1 -0
  74. package/dist/types/client/useContent.d.ts +10 -0
  75. package/dist/types/client/useContent.d.ts.map +1 -0
  76. package/dist/types/client/useDictionary.d.ts +8 -0
  77. package/dist/types/client/useDictionary.d.ts.map +1 -0
  78. package/dist/types/client/useIntlayer.d.ts +8 -0
  79. package/dist/types/client/useIntlayer.d.ts.map +1 -0
  80. package/dist/types/client/useLocale.d.ts +11 -0
  81. package/dist/types/client/useLocale.d.ts.map +1 -0
  82. package/dist/types/client/useLocaleBase.d.ts +11 -0
  83. package/dist/types/client/useLocaleBase.d.ts.map +1 -0
  84. package/dist/types/client/useLocaleCookie.d.ts +17 -0
  85. package/dist/types/client/useLocaleCookie.d.ts.map +1 -0
  86. package/dist/{cjs → types}/client/useTraduction.d.ts +3 -5
  87. package/dist/types/client/useTraduction.d.ts.map +1 -0
  88. package/dist/types/craco/craco.config.d.ts +2 -0
  89. package/dist/types/craco/craco.config.d.ts.map +1 -0
  90. package/dist/types/craco/intlayerCracoPlugin.d.ts +24 -0
  91. package/dist/types/craco/intlayerCracoPlugin.d.ts.map +1 -0
  92. package/dist/{cjs → types}/getEnumeration.d.ts +3 -5
  93. package/dist/types/getEnumeration.d.ts.map +1 -0
  94. package/dist/{cjs → types}/getTranslation.d.ts +4 -6
  95. package/dist/types/getTranslation.d.ts.map +1 -0
  96. package/dist/types/index.d.ts +4 -0
  97. package/dist/types/index.d.ts.map +1 -0
  98. package/dist/types/processDictionary/contentDictionary.d.ts +14 -0
  99. package/dist/types/processDictionary/contentDictionary.d.ts.map +1 -0
  100. package/dist/types/processDictionary/index.d.ts +9 -0
  101. package/dist/types/processDictionary/index.d.ts.map +1 -0
  102. package/dist/types/server/IntlayerServerProvider.d.ts +34 -0
  103. package/dist/types/server/IntlayerServerProvider.d.ts.map +1 -0
  104. package/dist/types/server/getLocaleTranslation.d.ts +9 -0
  105. package/dist/types/server/getLocaleTranslation.d.ts.map +1 -0
  106. package/dist/types/server/index.d.ts +7 -0
  107. package/dist/types/server/index.d.ts.map +1 -0
  108. package/dist/{cjs → types}/server/serverContext.d.ts +4 -15
  109. package/dist/types/server/serverContext.d.ts.map +1 -0
  110. package/dist/types/server/t.d.ts +9 -0
  111. package/dist/types/server/t.d.ts.map +1 -0
  112. package/dist/types/server/useDictionary.d.ts +8 -0
  113. package/dist/types/server/useDictionary.d.ts.map +1 -0
  114. package/dist/types/server/useIntlayer.d.ts +8 -0
  115. package/dist/types/server/useIntlayer.d.ts.map +1 -0
  116. package/dist/{cjs → types}/server/useTraduction.d.ts +3 -5
  117. package/dist/types/server/useTraduction.d.ts.map +1 -0
  118. package/dist/types/useDictionaryBase.d.ts +37 -0
  119. package/dist/types/useDictionaryBase.d.ts.map +1 -0
  120. package/dist/types/useIntlayerBase.d.ts +39 -0
  121. package/dist/types/useIntlayerBase.d.ts.map +1 -0
  122. package/dist/{cjs → types}/vite/intlayerPlugin.d.ts +4 -5
  123. package/dist/types/vite/intlayerPlugin.d.ts.map +1 -0
  124. package/package.json +38 -28
  125. package/dist/cjs/cli/react-intlayer.d.ts +0 -1
  126. package/dist/cjs/client/IntlayerProvider.d.ts +0 -27
  127. package/dist/cjs/client/index.d.ts +0 -13
  128. package/dist/cjs/client/useContent.d.ts +0 -13
  129. package/dist/cjs/client/useIntlayer.d.ts +0 -14
  130. package/dist/cjs/client/useLocale.d.ts +0 -14
  131. package/dist/cjs/client/useLocaleBase.d.ts +0 -14
  132. package/dist/cjs/client/useLocaleCookie.d.ts +0 -19
  133. package/dist/cjs/craco/craco.config.d.ts +0 -2
  134. package/dist/cjs/craco/intlayerCracoPlugin.d.ts +0 -26
  135. package/dist/cjs/index.d.ts +0 -14
  136. package/dist/cjs/processDictionary/contentDictionary.d.ts +0 -16
  137. package/dist/cjs/processDictionary/index.d.ts +0 -12
  138. package/dist/cjs/server/IntlayerServerProvider.d.ts +0 -36
  139. package/dist/cjs/server/getLocaleTranslation.d.ts +0 -12
  140. package/dist/cjs/server/index.d.ts +0 -10
  141. package/dist/cjs/server/useIntlayer.d.ts +0 -14
  142. package/dist/cjs/useIntlayerBase.d.ts +0 -70
  143. package/dist/esm/cli/react-intlayer.d.mts +0 -1
  144. package/dist/esm/client/IntlayerProvider.d.mts +0 -27
  145. package/dist/esm/client/getBrowserLocale.d.mts +0 -26
  146. package/dist/esm/client/index.d.mts +0 -13
  147. package/dist/esm/client/useContent.d.mts +0 -13
  148. package/dist/esm/client/useIntlayer.d.mts +0 -14
  149. package/dist/esm/client/useLocale.d.mts +0 -14
  150. package/dist/esm/client/useLocaleBase.d.mts +0 -14
  151. package/dist/esm/client/useLocaleCookie.d.mts +0 -19
  152. package/dist/esm/client/useTraduction.d.mts +0 -26
  153. package/dist/esm/craco/craco.config.d.mts +0 -2
  154. package/dist/esm/craco/intlayerCracoPlugin.d.mts +0 -26
  155. package/dist/esm/getEnumeration.d.mts +0 -33
  156. package/dist/esm/getTranslation.d.mts +0 -27
  157. package/dist/esm/index.d.mts +0 -14
  158. package/dist/esm/processDictionary/contentDictionary.d.mts +0 -16
  159. package/dist/esm/processDictionary/index.d.mts +0 -12
  160. package/dist/esm/server/IntlayerServerProvider.d.mts +0 -36
  161. package/dist/esm/server/getLocaleTranslation.d.mts +0 -12
  162. package/dist/esm/server/index.d.mts +0 -10
  163. package/dist/esm/server/serverContext.d.mts +0 -35
  164. package/dist/esm/server/useIntlayer.d.mts +0 -14
  165. package/dist/esm/server/useTraduction.d.mts +0 -26
  166. package/dist/esm/useIntlayerBase.d.mts +0 -70
  167. package/dist/esm/vite/intlayerPlugin.d.mts +0 -17
@@ -1,10 +0,0 @@
1
- export { getLocaleTranslation as getLocaleContent } from './getLocaleTranslation.js';
2
- export { useTraduction } from './useTraduction.js';
3
- export { IntlayerServerContext as IntlayerServer, IntlayerServerProvider, locale } from './IntlayerServerProvider.js';
4
- export { useIntlayer } from './useIntlayer.js';
5
- import '@intlayer/config/client';
6
- import '@intlayer/core';
7
- import 'react';
8
- import '../useIntlayerBase.js';
9
- import '@intlayer/config';
10
- import 'intlayer';
@@ -1,14 +0,0 @@
1
- import { UseIntlayer } from '../useIntlayerBase.js';
2
- import '@intlayer/config';
3
- import '@intlayer/core';
4
- import 'intlayer';
5
- import 'react';
6
-
7
- /**
8
- * On the server side, Hook that picking one dictionary by its id and return the content
9
- *
10
- * If the locale is not provided, it will use the locale from the server context
11
- */
12
- declare const useIntlayer: UseIntlayer;
13
-
14
- export { useIntlayer };
@@ -1,70 +0,0 @@
1
- import { Locales } from '@intlayer/config';
2
- import { NodeType } from '@intlayer/core';
3
- import { IntlayerDictionaryTypesConnector } from 'intlayer';
4
- import { ReactNode } from 'react';
5
-
6
- /**
7
- * Provides a fallback to string type if the generic type T is never,
8
- * otherwise returns T. This is useful for handling cases where no keys are found.
9
- * Example: StringFallback<never> -> string; StringFallback<'key'> -> 'key'
10
- */
11
- type StringFallback<T> = T extends never ? string : T;
12
- /**
13
- * Represents the keys of the IntlayerDictionaryTypesConnector,
14
- * ensuring they are valid dictionary keys or fallback to string if none exist.
15
- *
16
- * Example:
17
- * ```ts
18
- * DictionaryKeys -> 'key1' | 'key2'
19
- * // or if IntlayerDictionaryTypesConnector is not defined,
20
- * DictionaryKeys -> string
21
- * ```
22
- */
23
- type DictionaryKeys = StringFallback<keyof IntlayerDictionaryTypesConnector>;
24
- type IntlayerNode<T = string> = ReactNode & {
25
- value: T;
26
- };
27
- type TransformNodeType<T, L extends Locales> = T extends {
28
- [NodeType.Enumeration]: {
29
- '1': any;
30
- };
31
- } ? (quantity: number) => DeepTransformContent<T[NodeType.Enumeration]['1'], L> : T extends {
32
- [NodeType.Translation]: object;
33
- } ? L extends keyof T[NodeType.Translation] ? DeepTransformContent<T[NodeType.Translation][L], L> : never : T;
34
- type DeepTransformContent<T, L extends Locales> = T extends object ? T extends (infer U)[] ? DeepTransformContent<U, L>[] : T extends {
35
- nodeType: NodeType | string;
36
- } ? TransformNodeType<T, L> : T extends {
37
- _owner: any;
38
- key: any;
39
- props: any;
40
- ref: any;
41
- } ? ReactNode : {
42
- [K in keyof T]: DeepTransformContent<T[K], L>;
43
- } : T extends undefined ? never : IntlayerNode<T>;
44
- /**
45
- * Excludes the 'id' and 'filePath' keys from the dictionary content,
46
- * as they are not part of the IntlayerDictionaryTypesConnector type.
47
- */
48
- type ExcludeIntlayerUtilsKeys<T> = Omit<T, 'id' | 'filePath'>;
49
- /**
50
- * Represents the data type returned by the useIntlayer hook,
51
- * excluding the 'id' and 'filePath' keys from the dictionary content.
52
- */
53
- type Data<T extends DictionaryKeys, K extends Locales> = ExcludeIntlayerUtilsKeys<DeepTransformContent<IntlayerDictionaryTypesConnector[T], K>>;
54
- /**
55
- * Parcourt the object. If a object has a keyPath, render the intlayer editor if editor enabled.
56
- */
57
- declare const recursiveTransformContent: (value: any) => object;
58
- /**
59
- * Type definition for the useIntlayer hook, which takes a dictionary ID and an optional locale,
60
- * and returns the deeply transformed dictionary content.
61
- *
62
- */
63
- type UseIntlayer = <T extends DictionaryKeys, L extends Locales>(id: T, locale?: L) => Data<T, L>;
64
- /**
65
- * Hook that picks one dictionary by its ID and returns the content,
66
- * deeply transformed according to the dictionary structure and metadata.
67
- */
68
- declare const useIntlayerBase: UseIntlayer;
69
-
70
- export { type DictionaryKeys, type IntlayerNode, type StringFallback, type UseIntlayer, recursiveTransformContent, useIntlayerBase };
@@ -1 +0,0 @@
1
- #!/usr/bin/env node
@@ -1,27 +0,0 @@
1
- import * as react from 'react';
2
- import { PropsWithChildren, FC } from 'react';
3
- import { Locales } from '@intlayer/config/client';
4
-
5
- type IntlayerValue = {
6
- locale: Locales;
7
- setLocale: (newLocale: Locales) => void;
8
- };
9
- /**
10
- * Context that store the current locale on the client side
11
- */
12
- declare const IntlayerClientContext: react.Context<IntlayerValue>;
13
- /**
14
- * Hook that provides the current locale
15
- */
16
- declare const useIntlayerContext: () => IntlayerValue;
17
- type IntlayerProviderProps = PropsWithChildren & {
18
- locale?: Locales;
19
- setLocale?: (locale: Locales) => void;
20
- editorEnabled?: boolean;
21
- };
22
- /**
23
- * Provider that store the current locale on the client side
24
- */
25
- declare const IntlayerProvider: FC<IntlayerProviderProps>;
26
-
27
- export { IntlayerClientContext, IntlayerProvider, type IntlayerProviderProps, useIntlayerContext };
@@ -1,26 +0,0 @@
1
- import { Locales } from '@intlayer/config/client';
2
-
3
- declare enum LanguageDetector {
4
- Querystring = "querystring",
5
- Cookie = "cookie",
6
- LocalStorage = "localStorage",
7
- SessionStorage = "sessionStorage",
8
- Navigator = "navigator",
9
- HtmlTag = "htmlTag"
10
- }
11
- type LanguageDetectorOptions = {
12
- order?: LanguageDetector[];
13
- lookupQuerystring?: string;
14
- lookupCookie?: string;
15
- lookupLocalStorage?: string;
16
- lookupSessionStorage?: string;
17
- excludeCacheFor?: string[];
18
- htmlTag?: HTMLElement | null;
19
- };
20
- /**
21
- * Core language detector function
22
- * const detectedLanguages = detectLanguage(['LanguageDetector.Cookie', 'LanguageDetector.LocalStorage'], { lookupCookie: 'myCookie' });
23
- */
24
- declare const getBrowserLocale: (userOptions?: LanguageDetectorOptions | undefined) => Locales;
25
-
26
- export { LanguageDetector, getBrowserLocale };
@@ -1,13 +0,0 @@
1
- export { IntlayerClientContext, IntlayerProvider, IntlayerProviderProps, useIntlayerContext } from './IntlayerProvider.mjs';
2
- export { useIntlayer } from './useIntlayer.mjs';
3
- export { useLocaleBase } from './useLocaleBase.mjs';
4
- export { useLocale } from './useLocale.mjs';
5
- export { useTraduction } from './useTraduction.mjs';
6
- export { localeCookie, setLocaleCookie, useLocaleCookie } from './useLocaleCookie.mjs';
7
- export { getBrowserLocale } from './getBrowserLocale.mjs';
8
- import 'react';
9
- import '@intlayer/config/client';
10
- import '../useIntlayerBase.mjs';
11
- import '@intlayer/config';
12
- import '@intlayer/core';
13
- import 'intlayer';
@@ -1,13 +0,0 @@
1
- import * as intlayer from 'intlayer';
2
- import { LanguageContent } from '@intlayer/core';
3
-
4
- /**
5
- * On the client side, hook to get the translation content based on the locale
6
- */
7
- declare const useContent: <Content>(languageContent: LanguageContent<Content>) => {
8
- locale: intlayer.Locales;
9
- content: Content;
10
- t: <Content_1 = string>(languageContent: LanguageContent<Content_1>) => Content_1;
11
- };
12
-
13
- export { useContent };
@@ -1,14 +0,0 @@
1
- import { UseIntlayer } from '../useIntlayerBase.mjs';
2
- import '@intlayer/config';
3
- import '@intlayer/core';
4
- import 'intlayer';
5
- import 'react';
6
-
7
- /**
8
- * On the client side, Hook that picking one dictionary by its id and return the content
9
- *
10
- * If the locale is not provided, it will use the locale from the client context
11
- */
12
- declare const useIntlayer: UseIntlayer;
13
-
14
- export { useIntlayer };
@@ -1,14 +0,0 @@
1
- import * as _intlayer_config_client from '@intlayer/config/client';
2
-
3
- /**
4
- * On the client side, hook to get the current locale and all related fields
5
- */
6
- declare const useLocale: () => {
7
- locale: _intlayer_config_client.Locales;
8
- defaultLocale: _intlayer_config_client.Locales;
9
- availableLocales: _intlayer_config_client.Locales[];
10
- localeList: _intlayer_config_client.Locales[];
11
- setLocale: (newLocale: _intlayer_config_client.Locales) => void;
12
- };
13
-
14
- export { useLocale };
@@ -1,14 +0,0 @@
1
- import * as _intlayer_config_client from '@intlayer/config/client';
2
-
3
- /**
4
- * On the client side, hook to get the current locale and all related fields
5
- */
6
- declare const useLocaleBase: () => {
7
- locale: _intlayer_config_client.Locales;
8
- defaultLocale: _intlayer_config_client.Locales;
9
- availableLocales: _intlayer_config_client.Locales[];
10
- localeList: _intlayer_config_client.Locales[];
11
- setLocale: (newLocale: _intlayer_config_client.Locales) => void;
12
- };
13
-
14
- export { useLocaleBase };
@@ -1,19 +0,0 @@
1
- import { Locales } from '@intlayer/config/client';
2
-
3
- /**
4
- * Get the locale cookie
5
- */
6
- declare const localeCookie: Locales | undefined;
7
- /**
8
- * Set the locale cookie
9
- */
10
- declare const setLocaleCookie: (locale: Locales) => void;
11
- /**
12
- * Hook that provides the locale cookie and a function to set it
13
- */
14
- declare const useLocaleCookie: () => {
15
- localeCookie: Locales | undefined;
16
- setLocaleCookie: (locale: Locales) => void;
17
- };
18
-
19
- export { localeCookie, setLocaleCookie, useLocaleCookie };
@@ -1,26 +0,0 @@
1
- import { LanguageContent } from '@intlayer/core';
2
-
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
- * ```tsx
13
- * const content = useTraduction<string>({
14
- * en: 'Hello',
15
- * fr: 'Bonjour',
16
- * }, 'fr');
17
- * // 'Bonjour'
18
- * ```
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 useTraduction: <Content = string>(languageContent: LanguageContent<Content>) => Content;
25
-
26
- export { useTraduction };
@@ -1,2 +0,0 @@
1
-
2
- export { }
@@ -1,26 +0,0 @@
1
- import { WebpackConfigOverride, CracoConfigOverride, CracoConfig, CracoPlugin } from '@craco/types';
2
- import { Configuration } from 'webpack';
3
-
4
- declare const overrideWebpackConfig: ({ webpackConfig, }: WebpackConfigOverride) => Configuration;
5
- declare const overrideCracoConfig: ({ cracoConfig, }: CracoConfigOverride) => CracoConfig;
6
- /**
7
- * A CRACO plugin that adds the IntLayer configuration to the webpack configuration and sets the environment variables.
8
- *
9
- * Usage:
10
- *
11
- * ```ts
12
- * const cracoConfig: CracoConfig = {
13
- * plugins: [
14
- * {
15
- * plugin: intlayerCracoPlugin(),
16
- * },
17
- * ],
18
- * };
19
- *
20
- * export default cracoConfig;
21
- * ```
22
- *
23
- */
24
- declare const plugin: CracoPlugin;
25
-
26
- export { overrideCracoConfig, overrideWebpackConfig, plugin };
@@ -1,33 +0,0 @@
1
- import { QuantityContent } from '@intlayer/core';
2
-
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
- * ```ts
11
- * const content = getEnumeration({
12
- * '<=-2.3': 'You have less than -2.3',
13
- * '<1': 'You have less than one',
14
- * '2': 'You have two',
15
- * '>=3': 'You have three or more',
16
- * }, 2);
17
- * // 'You have two'
18
- * ```
19
- *
20
- * The order of the keys will define the priority of the content.
21
- *
22
- * ```ts
23
- * const content = getEnumeration({
24
- * '<4': 'You have less than four',
25
- * '2': 'You have two',
26
- * }, 2);
27
- * // 'You have less than four'
28
- * ```
29
- *
30
- */
31
- declare const getEnumeration: <Content>(enumerationContent: QuantityContent<Content>, quantity: number) => Content;
32
-
33
- export { getEnumeration };
@@ -1,27 +0,0 @@
1
- import { Locales } from '@intlayer/config/client';
2
- import { LanguageContent } from '@intlayer/core';
3
-
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
- * ```ts
14
- * const content = getTranslation<string>({
15
- * en: 'Hello',
16
- * fr: 'Bonjour',
17
- * }, 'fr');
18
- * // 'Bonjour'
19
- * ```
20
- *
21
- * Using TypeScript:
22
- * - this function will require each locale to be defined if defined in the project configuration.
23
- * - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.
24
- */
25
- declare const getTranslation: <Content = string>(languageContent: LanguageContent<Content>, locale?: Locales) => Content;
26
-
27
- export { getTranslation };
@@ -1,14 +0,0 @@
1
- export { getTranslation } from './getTranslation.mjs';
2
- export { IntlayerClientContext, IntlayerProvider, IntlayerProviderProps } from './client/IntlayerProvider.mjs';
3
- export { useIntlayer } from './client/useIntlayer.mjs';
4
- export { useLocaleBase } from './client/useLocaleBase.mjs';
5
- export { useLocale } from './client/useLocale.mjs';
6
- export { useTraduction } from './client/useTraduction.mjs';
7
- export { localeCookie, setLocaleCookie, useLocaleCookie } from './client/useLocaleCookie.mjs';
8
- export { getBrowserLocale } from './client/getBrowserLocale.mjs';
9
- export { IntlayerNode } from './useIntlayerBase.mjs';
10
- import '@intlayer/config/client';
11
- import '@intlayer/core';
12
- import 'react';
13
- import '@intlayer/config';
14
- import 'intlayer';
@@ -1,16 +0,0 @@
1
- import { KeyPath, Locales } from '@intlayer/core';
2
- import { ReactNode } from 'react';
3
-
4
- type TransformedContentValue = string | ReactNode | {
5
- [key: string]: TransformedContentValue;
6
- } | undefined | ((quantity: number) => TransformedContentValue);
7
- type TransformedContentObject = {
8
- dictionaryId: string;
9
- dictionaryPath: string;
10
- keyPath: KeyPath[];
11
- locale: Locales;
12
- content: TransformedContentValue | TransformedContentValue[] | undefined;
13
- };
14
- type TransformedContent = Record<string, TransformedContentValue | TransformedContentValue[] | TransformedContentObject | undefined> | ReactNode;
15
-
16
- export type { TransformedContent, TransformedContentObject, TransformedContentValue };
@@ -1,12 +0,0 @@
1
- import { Locales } from '@intlayer/config/client';
2
- import { DictionaryValue, KeyPath, Dictionary } from '@intlayer/core';
3
- import { TransformedContentValue, TransformedContent } from './contentDictionary.mjs';
4
- import 'react';
5
-
6
- declare const processNode: (field: DictionaryValue | undefined, locale: Locales, dictionaryId: string, dictionaryPath: string, keyPath?: KeyPath[]) => TransformedContentValue;
7
- /**
8
- * Function that process a dictionary and return the result to be used in the application.
9
- */
10
- declare const processDictionary: (content: Dictionary | DictionaryValue, dictionaryId: string, dictionaryPath: string, keyPath?: KeyPath[], locale?: Locales) => TransformedContent;
11
-
12
- export { processDictionary, processNode };
@@ -1,36 +0,0 @@
1
- import { Locales } from '@intlayer/config/client';
2
- import { PropsWithChildren, FC } from 'react';
3
-
4
- /**
5
- * Context that store the current locale on the server side
6
- */
7
- declare const IntlayerServerContext: {
8
- Provider: ({ children, value, }: {
9
- children: React.ReactNode;
10
- value: Locales;
11
- }) => React.ReactNode;
12
- Consumer: ({ children, }: {
13
- children: (context: Locales | undefined) => React.ReactNode;
14
- }) => React.ReactNode;
15
- _storage: () => {
16
- value: Locales | undefined;
17
- };
18
- _defaultValue: Locales | undefined;
19
- };
20
- /**
21
- * Hook that provides the current locale
22
- */
23
- declare const useIntlayer: () => Locales | undefined;
24
- /**
25
- * Get the current locale
26
- */
27
- declare const locale: Locales | undefined;
28
- type IntlayerServerProviderProps = PropsWithChildren & {
29
- locale?: Locales;
30
- };
31
- /**
32
- * Provider that store the current locale on the server side
33
- */
34
- declare const IntlayerServerProvider: FC<IntlayerServerProviderProps>;
35
-
36
- export { IntlayerServerContext, IntlayerServerProvider, type IntlayerServerProviderProps, locale, useIntlayer };
@@ -1,12 +0,0 @@
1
- import * as _intlayer_config_client from '@intlayer/config/client';
2
- import { LanguageContent } from '@intlayer/core';
3
-
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;
10
- };
11
-
12
- export { getLocaleTranslation };
@@ -1,10 +0,0 @@
1
- export { getLocaleTranslation as getLocaleContent } from './getLocaleTranslation.mjs';
2
- export { useTraduction } from './useTraduction.mjs';
3
- export { IntlayerServerContext as IntlayerServer, IntlayerServerProvider, locale } from './IntlayerServerProvider.mjs';
4
- export { useIntlayer } from './useIntlayer.mjs';
5
- import '@intlayer/config/client';
6
- import '@intlayer/core';
7
- import 'react';
8
- import '../useIntlayerBase.mjs';
9
- import '@intlayer/config';
10
- import 'intlayer';
@@ -1,35 +0,0 @@
1
- /**
2
- * Creates a new datastore for a given server context.
3
- * Attempts to closely mimic the `createContext` API.
4
- *
5
- * @example
6
- * const IntlayerServer = createServerContext<string | null>(null);
7
- *
8
- * <IntlayerServer.Provider value={locale}>
9
- * {children}
10
- * </IntlayerServer.Provider>
11
- */
12
- declare const createServerContext: <T>(defaultValue?: T) => ServerContext<T>;
13
- /**
14
- * Fetches a value present in a given server context.
15
- * Attempts to closely mimic the `useContext` API.
16
- *
17
- * @example
18
- * getServerContext(IntlayerServer);
19
- */
20
- declare const getServerContext: <T>({ _storage, _defaultValue, }: ServerContext<T>) => T | undefined;
21
- type ServerContext<T> = {
22
- Provider: ({ children, value, }: {
23
- children: React.ReactNode;
24
- value: T;
25
- }) => React.ReactNode;
26
- Consumer: ({ children, }: {
27
- children: (context: T | undefined) => React.ReactNode;
28
- }) => React.ReactNode;
29
- _storage: () => {
30
- value: T | undefined;
31
- };
32
- _defaultValue: T | undefined;
33
- };
34
-
35
- export { createServerContext, getServerContext };
@@ -1,14 +0,0 @@
1
- import { UseIntlayer } from '../useIntlayerBase.mjs';
2
- import '@intlayer/config';
3
- import '@intlayer/core';
4
- import 'intlayer';
5
- import 'react';
6
-
7
- /**
8
- * On the server side, Hook that picking one dictionary by its id and return the content
9
- *
10
- * If the locale is not provided, it will use the locale from the server context
11
- */
12
- declare const useIntlayer: UseIntlayer;
13
-
14
- export { useIntlayer };
@@ -1,26 +0,0 @@
1
- import { LanguageContent } from '@intlayer/core';
2
-
3
- /**
4
- * On the server side, hook to get the translation content based on the locale
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
- * ```ts
13
- * const content = useTraduction<string>({
14
- * en: 'Hello',
15
- * fr: 'Bonjour',
16
- * }, 'fr');
17
- * // 'Bonjour'
18
- * ```
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 useTraduction: <Content = string>(languageContent: LanguageContent<Content>) => Content;
25
-
26
- export { useTraduction };
@@ -1,70 +0,0 @@
1
- import { Locales } from '@intlayer/config';
2
- import { NodeType } from '@intlayer/core';
3
- import { IntlayerDictionaryTypesConnector } from 'intlayer';
4
- import { ReactNode } from 'react';
5
-
6
- /**
7
- * Provides a fallback to string type if the generic type T is never,
8
- * otherwise returns T. This is useful for handling cases where no keys are found.
9
- * Example: StringFallback<never> -> string; StringFallback<'key'> -> 'key'
10
- */
11
- type StringFallback<T> = T extends never ? string : T;
12
- /**
13
- * Represents the keys of the IntlayerDictionaryTypesConnector,
14
- * ensuring they are valid dictionary keys or fallback to string if none exist.
15
- *
16
- * Example:
17
- * ```ts
18
- * DictionaryKeys -> 'key1' | 'key2'
19
- * // or if IntlayerDictionaryTypesConnector is not defined,
20
- * DictionaryKeys -> string
21
- * ```
22
- */
23
- type DictionaryKeys = StringFallback<keyof IntlayerDictionaryTypesConnector>;
24
- type IntlayerNode<T = string> = ReactNode & {
25
- value: T;
26
- };
27
- type TransformNodeType<T, L extends Locales> = T extends {
28
- [NodeType.Enumeration]: {
29
- '1': any;
30
- };
31
- } ? (quantity: number) => DeepTransformContent<T[NodeType.Enumeration]['1'], L> : T extends {
32
- [NodeType.Translation]: object;
33
- } ? L extends keyof T[NodeType.Translation] ? DeepTransformContent<T[NodeType.Translation][L], L> : never : T;
34
- type DeepTransformContent<T, L extends Locales> = T extends object ? T extends (infer U)[] ? DeepTransformContent<U, L>[] : T extends {
35
- nodeType: NodeType | string;
36
- } ? TransformNodeType<T, L> : T extends {
37
- _owner: any;
38
- key: any;
39
- props: any;
40
- ref: any;
41
- } ? ReactNode : {
42
- [K in keyof T]: DeepTransformContent<T[K], L>;
43
- } : T extends undefined ? never : IntlayerNode<T>;
44
- /**
45
- * Excludes the 'id' and 'filePath' keys from the dictionary content,
46
- * as they are not part of the IntlayerDictionaryTypesConnector type.
47
- */
48
- type ExcludeIntlayerUtilsKeys<T> = Omit<T, 'id' | 'filePath'>;
49
- /**
50
- * Represents the data type returned by the useIntlayer hook,
51
- * excluding the 'id' and 'filePath' keys from the dictionary content.
52
- */
53
- type Data<T extends DictionaryKeys, K extends Locales> = ExcludeIntlayerUtilsKeys<DeepTransformContent<IntlayerDictionaryTypesConnector[T], K>>;
54
- /**
55
- * Parcourt the object. If a object has a keyPath, render the intlayer editor if editor enabled.
56
- */
57
- declare const recursiveTransformContent: (value: any) => object;
58
- /**
59
- * Type definition for the useIntlayer hook, which takes a dictionary ID and an optional locale,
60
- * and returns the deeply transformed dictionary content.
61
- *
62
- */
63
- type UseIntlayer = <T extends DictionaryKeys, L extends Locales>(id: T, locale?: L) => Data<T, L>;
64
- /**
65
- * Hook that picks one dictionary by its ID and returns the content,
66
- * deeply transformed according to the dictionary structure and metadata.
67
- */
68
- declare const useIntlayerBase: UseIntlayer;
69
-
70
- export { type DictionaryKeys, type IntlayerNode, type StringFallback, type UseIntlayer, recursiveTransformContent, useIntlayerBase };
@@ -1,17 +0,0 @@
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 };