react-intlayer 1.0.1 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. package/dist/cjs/{LocaleContextProvider.cjs → IntlayerProvider.cjs} +10 -10
  2. package/dist/cjs/IntlayerProvider.cjs.map +1 -0
  3. package/dist/cjs/IntlayerProvider.d.ts +9 -0
  4. package/dist/cjs/client/{LocaleClientContextProvider.cjs → IntlayerClientProvider.cjs} +16 -13
  5. package/dist/cjs/client/IntlayerClientProvider.cjs.map +1 -0
  6. package/dist/cjs/client/IntlayerClientProvider.d.ts +24 -0
  7. package/dist/cjs/client/index.cjs +7 -7
  8. package/dist/cjs/client/index.cjs.map +1 -1
  9. package/dist/cjs/client/index.d.ts +1 -1
  10. package/dist/cjs/client/useContent.cjs.map +1 -1
  11. package/dist/cjs/client/useContent.d.ts +4 -1
  12. package/dist/cjs/client/useIntlayer.cjs +2 -2
  13. package/dist/cjs/client/useIntlayer.cjs.map +1 -1
  14. package/dist/cjs/client/useIntlayer.d.ts +5 -0
  15. package/dist/cjs/client/useLocale.cjs +2 -2
  16. package/dist/cjs/client/useLocale.cjs.map +1 -1
  17. package/dist/cjs/client/useLocale.d.ts +3 -0
  18. package/dist/cjs/client/useLocaleCookie.cjs.map +1 -1
  19. package/dist/cjs/client/useLocaleCookie.d.ts +9 -0
  20. package/dist/cjs/client/useTraduction.cjs +2 -2
  21. package/dist/cjs/client/useTraduction.cjs.map +1 -1
  22. package/dist/cjs/client/useTraduction.d.ts +21 -1
  23. package/dist/cjs/getEnumeration.cjs.map +1 -1
  24. package/dist/cjs/getEnumeration.d.ts +25 -0
  25. package/dist/cjs/getTranslation.cjs.map +1 -1
  26. package/dist/cjs/getTranslation.d.ts +21 -1
  27. package/dist/cjs/index.cjs +4 -6
  28. package/dist/cjs/index.cjs.map +1 -1
  29. package/dist/cjs/index.d.ts +1 -1
  30. package/dist/cjs/processDictionary/index.cjs.map +1 -1
  31. package/dist/cjs/processDictionary/index.d.ts +1 -1
  32. package/dist/cjs/server/{LocaleServerContextProvider.cjs → IntlayerServerProvider.cjs} +19 -13
  33. package/dist/cjs/server/IntlayerServerProvider.cjs.map +1 -0
  34. package/dist/{esm/server/LocaleServerContextProvider.d.mts → cjs/server/IntlayerServerProvider.d.ts} +17 -4
  35. package/dist/cjs/server/getLocaleTranslation.cjs +2 -2
  36. package/dist/cjs/server/getLocaleTranslation.cjs.map +1 -1
  37. package/dist/cjs/server/getLocaleTranslation.d.ts +3 -0
  38. package/dist/cjs/server/index.cjs +6 -6
  39. package/dist/cjs/server/index.cjs.map +1 -1
  40. package/dist/cjs/server/index.d.ts +1 -1
  41. package/dist/cjs/server/serverContext.cjs.map +1 -1
  42. package/dist/cjs/server/serverContext.d.ts +4 -4
  43. package/dist/cjs/server/useIntlayer.cjs +2 -2
  44. package/dist/cjs/server/useIntlayer.cjs.map +1 -1
  45. package/dist/cjs/server/useIntlayer.d.ts +5 -0
  46. package/dist/cjs/server/useTraduction.cjs +2 -2
  47. package/dist/cjs/server/useTraduction.cjs.map +1 -1
  48. package/dist/cjs/server/useTraduction.d.ts +21 -1
  49. package/dist/cjs/useIntlayerBase.cjs.map +1 -1
  50. package/dist/cjs/useIntlayerBase.d.ts +3 -6
  51. package/dist/esm/IntlayerProvider.d.mts +9 -0
  52. package/dist/esm/IntlayerProvider.mjs +17 -0
  53. package/dist/esm/IntlayerProvider.mjs.map +1 -0
  54. package/dist/esm/client/IntlayerClientProvider.d.mts +24 -0
  55. package/dist/esm/client/IntlayerClientProvider.mjs +24 -0
  56. package/dist/esm/client/IntlayerClientProvider.mjs.map +1 -0
  57. package/dist/esm/client/index.d.mts +1 -1
  58. package/dist/esm/client/index.mjs +7 -7
  59. package/dist/esm/client/index.mjs.map +1 -1
  60. package/dist/esm/client/useContent.d.mts +4 -1
  61. package/dist/esm/client/useContent.mjs.map +1 -1
  62. package/dist/esm/client/useIntlayer.d.mts +5 -0
  63. package/dist/esm/client/useIntlayer.mjs +2 -2
  64. package/dist/esm/client/useIntlayer.mjs.map +1 -1
  65. package/dist/esm/client/useLocale.d.mts +3 -0
  66. package/dist/esm/client/useLocale.mjs +2 -2
  67. package/dist/esm/client/useLocale.mjs.map +1 -1
  68. package/dist/esm/client/useLocaleCookie.d.mts +9 -0
  69. package/dist/esm/client/useLocaleCookie.mjs.map +1 -1
  70. package/dist/esm/client/useTraduction.d.mts +21 -1
  71. package/dist/esm/client/useTraduction.mjs +2 -2
  72. package/dist/esm/client/useTraduction.mjs.map +1 -1
  73. package/dist/esm/getEnumeration.d.mts +25 -0
  74. package/dist/esm/getEnumeration.mjs.map +1 -1
  75. package/dist/esm/getTranslation.d.mts +21 -1
  76. package/dist/esm/getTranslation.mjs.map +1 -1
  77. package/dist/esm/index.d.mts +1 -1
  78. package/dist/esm/index.mjs +4 -6
  79. package/dist/esm/index.mjs.map +1 -1
  80. package/dist/esm/processDictionary/index.d.mts +1 -1
  81. package/dist/esm/processDictionary/index.mjs.map +1 -1
  82. package/dist/{cjs/server/LocaleServerContextProvider.d.ts → esm/server/IntlayerServerProvider.d.mts} +17 -4
  83. package/dist/esm/server/IntlayerServerProvider.mjs +21 -0
  84. package/dist/esm/server/IntlayerServerProvider.mjs.map +1 -0
  85. package/dist/esm/server/getLocaleTranslation.d.mts +3 -0
  86. package/dist/esm/server/getLocaleTranslation.mjs +2 -2
  87. package/dist/esm/server/getLocaleTranslation.mjs.map +1 -1
  88. package/dist/esm/server/index.d.mts +1 -1
  89. package/dist/esm/server/index.mjs +5 -5
  90. package/dist/esm/server/index.mjs.map +1 -1
  91. package/dist/esm/server/serverContext.d.mts +4 -4
  92. package/dist/esm/server/serverContext.mjs.map +1 -1
  93. package/dist/esm/server/useIntlayer.d.mts +5 -0
  94. package/dist/esm/server/useIntlayer.mjs +2 -2
  95. package/dist/esm/server/useIntlayer.mjs.map +1 -1
  96. package/dist/esm/server/useTraduction.d.mts +21 -1
  97. package/dist/esm/server/useTraduction.mjs +2 -2
  98. package/dist/esm/server/useTraduction.mjs.map +1 -1
  99. package/dist/esm/useIntlayerBase.d.mts +3 -6
  100. package/dist/esm/useIntlayerBase.mjs.map +1 -1
  101. package/package.json +7 -7
  102. package/src/IntlayerProvider.tsx +24 -0
  103. package/src/client/IntlayerClientProvider.tsx +45 -0
  104. package/src/client/index.ts +5 -5
  105. package/src/client/useContent.ts +3 -0
  106. package/src/client/useIntlayer.ts +7 -2
  107. package/src/client/useLocale.ts +5 -2
  108. package/src/client/useLocaleCookie.ts +9 -1
  109. package/src/client/useTraduction.ts +23 -3
  110. package/src/getEnumeration.ts +25 -0
  111. package/src/getTranslation.ts +21 -1
  112. package/src/index.ts +3 -4
  113. package/src/processDictionary/index.ts +1 -1
  114. package/src/server/IntlayerServerProvider.tsx +39 -0
  115. package/src/server/getLocaleTranslation.ts +5 -2
  116. package/src/server/index.ts +3 -3
  117. package/src/server/serverContext.ts +4 -4
  118. package/src/server/useIntlayer.ts +8 -2
  119. package/src/server/useTraduction.ts +23 -3
  120. package/src/useIntlayerBase.ts +4 -1
  121. package/dist/cjs/LocaleContextProvider.cjs.map +0 -1
  122. package/dist/cjs/LocaleContextProvider.d.ts +0 -9
  123. package/dist/cjs/client/LocaleClientContextProvider.cjs.map +0 -1
  124. package/dist/cjs/client/LocaleClientContextProvider.d.ts +0 -15
  125. package/dist/cjs/server/LocaleServerContextProvider.cjs.map +0 -1
  126. package/dist/esm/LocaleContextProvider.d.mts +0 -9
  127. package/dist/esm/LocaleContextProvider.mjs +0 -17
  128. package/dist/esm/LocaleContextProvider.mjs.map +0 -1
  129. package/dist/esm/client/LocaleClientContextProvider.d.mts +0 -15
  130. package/dist/esm/client/LocaleClientContextProvider.mjs +0 -21
  131. package/dist/esm/client/LocaleClientContextProvider.mjs.map +0 -1
  132. package/dist/esm/server/LocaleServerContextProvider.mjs +0 -16
  133. package/dist/esm/server/LocaleServerContextProvider.mjs.map +0 -1
  134. package/src/LocaleContextProvider.tsx +0 -26
  135. package/src/client/LocaleClientContextProvider.tsx +0 -35
  136. package/src/server/LocaleServerContextProvider.tsx +0 -24
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/server/getLocaleTranslation.ts"],"sourcesContent":["import { intlayerIntlConfiguration } from '@intlayer/config/client';\nimport { type LanguageContent, getTranslationContent } from '@intlayer/core';\nimport { LocaleServerContext } from './LocaleServerContextProvider';\nimport { getServerContext } from './serverContext';\n\nexport const getLocaleTranslation = <Content>(\n languageContent: LanguageContent<Content>\n) => {\n const locale = getServerContext(LocaleServerContext);\n const content = getTranslationContent<Content>(\n languageContent,\n locale ?? intlayerIntlConfiguration.defaultLocale\n );\n\n return {\n locale,\n content,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA0C;AAC1C,kBAA4D;AAC5D,yCAAoC;AACpC,2BAAiC;AAE1B,MAAM,uBAAuB,CAClC,oBACG;AACH,QAAM,aAAS,uCAAiB,sDAAmB;AACnD,QAAM,cAAU;AAAA,IACd;AAAA,IACA,UAAU,wCAA0B;AAAA,EACtC;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../src/server/getLocaleTranslation.ts"],"sourcesContent":["import { intlayerIntlConfiguration } from '@intlayer/config/client';\nimport { type LanguageContent, getTranslationContent } from '@intlayer/core';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\n\n/**\n * On the server side, get the translation content based on the locale\n */\nexport const getLocaleTranslation = <Content>(\n languageContent: LanguageContent<Content>\n) => {\n const locale = getServerContext(IntlayerServerContext);\n const content = getTranslationContent<Content>(\n languageContent,\n locale ?? intlayerIntlConfiguration.defaultLocale\n );\n\n return {\n locale,\n content,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA0C;AAC1C,kBAA4D;AAC5D,oCAAsC;AACtC,2BAAiC;AAK1B,MAAM,uBAAuB,CAClC,oBACG;AACH,QAAM,aAAS,uCAAiB,mDAAqB;AACrD,QAAM,cAAU;AAAA,IACd;AAAA,IACA,UAAU,wCAA0B;AAAA,EACtC;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
@@ -1,6 +1,9 @@
1
1
  import * as _intlayer_config_client from '@intlayer/config/client';
2
2
  import { LanguageContent } from '@intlayer/core';
3
3
 
4
+ /**
5
+ * On the server side, get the translation content based on the locale
6
+ */
4
7
  declare const getLocaleTranslation: <Content>(languageContent: LanguageContent<Content>) => {
5
8
  locale: _intlayer_config_client.Locales | undefined;
6
9
  content: Content;
@@ -18,22 +18,22 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var server_exports = {};
20
20
  __export(server_exports, {
21
- LocaleServerContext: () => import_LocaleServerContextProvider.LocaleServerContext,
22
- LocaleServerContextProvider: () => import_LocaleServerContextProvider.LocaleServerContextProvider,
21
+ IntlayerServer: () => import_IntlayerServerProvider.IntlayerServerContext,
22
+ IntlayerServerProvider: () => import_IntlayerServerProvider.IntlayerServerProvider,
23
23
  getLocaleContent: () => import_getLocaleTranslation.getLocaleTranslation,
24
- locale: () => import_LocaleServerContextProvider.locale,
24
+ locale: () => import_IntlayerServerProvider.locale,
25
25
  useIntlayer: () => import_useIntlayer.useIntlayer,
26
26
  useTraduction: () => import_useTraduction.useTraduction
27
27
  });
28
28
  module.exports = __toCommonJS(server_exports);
29
29
  var import_getLocaleTranslation = require('./getLocaleTranslation.cjs');
30
30
  var import_useTraduction = require('./useTraduction.cjs');
31
- var import_LocaleServerContextProvider = require('./LocaleServerContextProvider.cjs');
31
+ var import_IntlayerServerProvider = require('./IntlayerServerProvider.cjs');
32
32
  var import_useIntlayer = require('./useIntlayer.cjs');
33
33
  // Annotate the CommonJS export names for ESM import in node:
34
34
  0 && (module.exports = {
35
- LocaleServerContext,
36
- LocaleServerContextProvider,
35
+ IntlayerServer,
36
+ IntlayerServerProvider,
37
37
  getLocaleContent,
38
38
  locale,
39
39
  useIntlayer,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/server/index.ts"],"sourcesContent":["export { getLocaleTranslation as getLocaleContent } from './getLocaleTranslation';\nexport { useTraduction } from './useTraduction';\nexport {\n LocaleServerContext,\n locale,\n LocaleServerContextProvider,\n} from './LocaleServerContextProvider';\nexport { useIntlayer } from './useIntlayer';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kCAAyD;AACzD,2BAA8B;AAC9B,yCAIO;AACP,yBAA4B;","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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kCAAyD;AACzD,2BAA8B;AAC9B,oCAIO;AACP,yBAA4B;","names":[]}
@@ -1,6 +1,6 @@
1
1
  export { getLocaleTranslation as getLocaleContent } from './getLocaleTranslation.js';
2
2
  export { useTraduction } from './useTraduction.js';
3
- export { LocaleServerContext, LocaleServerContextProvider, locale } from './LocaleServerContextProvider.js';
3
+ export { IntlayerServerContext as IntlayerServer, IntlayerServerProvider, locale } from './IntlayerServerProvider.js';
4
4
  export { useIntlayer } from './useIntlayer.js';
5
5
  import '@intlayer/config/client';
6
6
  import '@intlayer/core';
@@ -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 LocaleServerContext = createServerContext<string | null>(null);\n *\n * <LocaleServerContext.Provider value={locale}>\n * {children}\n * </LocaleServerContext.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(LocaleServerContext);\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAYA,mBAAkB;AAIlB,MAAM,gBAAgB,MAAM,OAAO,EAAE,OAAO,OAAU;AAE/C,MAAM,sBAAsB,CAAI,iBAAuC;AAC5E,gBAAc;AAEd,QAAM,QAAQ,aAAAA,QAAM,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":["react"]}
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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAYA,mBAAkB;AAIlB,MAAM,gBAAgB,MAAM,OAAO,EAAE,OAAO,OAAU;AAE/C,MAAM,sBAAsB,CAAI,iBAAuC;AAC5E,gBAAc;AAEd,QAAM,QAAQ,aAAAA,QAAM,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":["react"]}
@@ -3,11 +3,11 @@
3
3
  * Attempts to closely mimic the `createContext` API.
4
4
  *
5
5
  * @example
6
- * const LocaleServerContext = createServerContext<string | null>(null);
6
+ * const IntlayerServer = createServerContext<string | null>(null);
7
7
  *
8
- * <LocaleServerContext.Provider value={locale}>
8
+ * <IntlayerServer.Provider value={locale}>
9
9
  * {children}
10
- * </LocaleServerContext.Provider>
10
+ * </IntlayerServer.Provider>
11
11
  */
12
12
  declare const createServerContext: <T>(defaultValue?: T) => ServerContext<T>;
13
13
  /**
@@ -15,7 +15,7 @@ declare const createServerContext: <T>(defaultValue?: T) => ServerContext<T>;
15
15
  * Attempts to closely mimic the `useContext` API.
16
16
  *
17
17
  * @example
18
- * getServerContext(LocaleServerContext);
18
+ * getServerContext(IntlayerServer);
19
19
  */
20
20
  declare const getServerContext: <T>({ _storage, _defaultValue, }: ServerContext<T>) => T | undefined;
21
21
  type ServerContext<T> = {
@@ -22,10 +22,10 @@ __export(useIntlayer_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(useIntlayer_exports);
24
24
  var import_useIntlayerBase = require('../useIntlayerBase.cjs');
25
- var import_LocaleServerContextProvider = require('./LocaleServerContextProvider.cjs');
25
+ var import_IntlayerServerProvider = require('./IntlayerServerProvider.cjs');
26
26
  var import_serverContext = require('./serverContext.cjs');
27
27
  const useIntlayer = (id, locale) => {
28
- const localeTarget = locale ?? (0, import_serverContext.getServerContext)(import_LocaleServerContextProvider.LocaleServerContext);
28
+ const localeTarget = locale ?? (0, import_serverContext.getServerContext)(import_IntlayerServerProvider.IntlayerServerContext);
29
29
  return (0, import_useIntlayerBase.useIntlayerBase)(id, localeTarget);
30
30
  };
31
31
  // Annotate the CommonJS export names for ESM import in node:
@@ -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 { LocaleServerContext } from './LocaleServerContextProvider';\nimport { getServerContext } from './serverContext';\n\nexport const useIntlayer: UseIntlayer = <T extends DictionaryKeys>(\n id: T,\n locale?: Locales\n) => {\n const localeTarget = locale ?? getServerContext<Locales>(LocaleServerContext);\n\n return useIntlayerBase(id, localeTarget);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,6BAIO;AACP,yCAAoC;AACpC,2BAAiC;AAE1B,MAAM,cAA2B,CACtC,IACA,WACG;AACH,QAAM,eAAe,cAAU,uCAA0B,sDAAmB;AAE5E,aAAO,wCAAgB,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":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,6BAIO;AACP,oCAAsC;AACtC,2BAAiC;AAO1B,MAAM,cAA2B,CACtC,IACA,WACG;AACH,QAAM,eACJ,cAAU,uCAA0B,mDAAqB;AAE3D,aAAO,wCAAgB,IAAI,YAAY;AACzC;","names":[]}
@@ -2,6 +2,11 @@ import { UseIntlayer } from '../useIntlayerBase.js';
2
2
  import '@intlayer/config/client';
3
3
  import 'intlayer';
4
4
 
5
+ /**
6
+ * On the server side, Hook that picking one dictionary by its id and return the content
7
+ *
8
+ * If the locale is not provided, it will use the locale from the server context
9
+ */
5
10
  declare const useIntlayer: UseIntlayer;
6
11
 
7
12
  export { useIntlayer };
@@ -22,10 +22,10 @@ __export(useTraduction_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(useTraduction_exports);
24
24
  var import_getTranslation = require('../getTranslation.cjs');
25
- var import_LocaleServerContextProvider = require('./LocaleServerContextProvider.cjs');
25
+ var import_IntlayerServerProvider = require('./IntlayerServerProvider.cjs');
26
26
  var import_serverContext = require('./serverContext.cjs');
27
27
  const useTraduction = (languageContent) => {
28
- const locale = (0, import_serverContext.getServerContext)(import_LocaleServerContextProvider.LocaleServerContext);
28
+ const locale = (0, import_serverContext.getServerContext)(import_IntlayerServerProvider.IntlayerServerContext);
29
29
  return (0, import_getTranslation.getTranslation)(languageContent, locale);
30
30
  };
31
31
  // Annotate the CommonJS export names for ESM import in node:
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/server/useTraduction.ts"],"sourcesContent":["import type { Locales } from '@intlayer/config/client';\nimport type { LanguageContent } from '@intlayer/core';\nimport { getTranslation } from '../getTranslation';\nimport { LocaleServerContext } from './LocaleServerContextProvider';\nimport { getServerContext } from './serverContext';\n\nexport const useTraduction = <Content>(\n languageContent: LanguageContent<Content>\n) => {\n const locale = getServerContext<Locales>(LocaleServerContext);\n\n return getTranslation(languageContent, locale);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,4BAA+B;AAC/B,yCAAoC;AACpC,2BAAiC;AAE1B,MAAM,gBAAgB,CAC3B,oBACG;AACH,QAAM,aAAS,uCAA0B,sDAAmB;AAE5D,aAAO,sCAAe,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 * 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":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,4BAA+B;AAC/B,oCAAsC;AACtC,2BAAiC;AAsB1B,MAAM,gBAAgB,CAC3B,oBACG;AACH,QAAM,aAAS,uCAA0B,mDAAqB;AAE9D,aAAO,sCAAe,iBAAiB,MAAM;AAC/C;","names":[]}
@@ -1,5 +1,25 @@
1
1
  import { LanguageContent } from '@intlayer/core';
2
2
 
3
- declare const useTraduction: <Content>(languageContent: LanguageContent<Content>) => Content;
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
+ * const content = getTranslation<string>({
13
+ * en: 'Hello',
14
+ * fr: 'Bonjour',
15
+ * },
16
+ * 'fr');
17
+ * // 'Bonjour'
18
+ *
19
+ * Using TypeScript:
20
+ * - this function will require each locale to be defined if defined in the project configuration.
21
+ * - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.
22
+ */
23
+ declare const useTraduction: <Content = string>(languageContent: LanguageContent<Content>) => Content;
4
24
 
5
25
  export { useTraduction };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/useIntlayerBase.ts"],"sourcesContent":["/**\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 type { Locales } from '@intlayer/config/client';\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\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,gCAAyB;AAGzB,+BAAkC;AAY3B,MAAM,kBAA+B,CAC1C,IACA,WACG;AACH,QAAM,aAAsB,0BAAAA,QAAa,EAAE;AAE3C,aAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;","names":["dictionaries"]}
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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,gCAAyB;AAGzB,+BAAkC;AAe3B,MAAM,kBAA+B,CAC1C,IACA,WACG;AACH,QAAM,aAAsB,0BAAAA,QAAa,EAAE;AAE3C,aAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;","names":["dictionaries"]}
@@ -1,15 +1,12 @@
1
1
  import { Locales } from '@intlayer/config/client';
2
2
  import { IntlayerDictionaryTypesConnector } from 'intlayer';
3
3
 
4
- /**
5
- * @intlayer/dictionaries-entry is a package that only returns the dictionary entry path.
6
- * Using an external package allow to alias it in the bundle configuration (such as webpack).
7
- * The alias allow hot reload the app (such as nextjs) on any dictionary change.
8
- */
9
-
10
4
  type StringFallback<T> = T extends never ? string : T;
11
5
  type DictionaryKeys = StringFallback<keyof IntlayerDictionaryTypesConnector>;
12
6
  type UseIntlayer = <T extends DictionaryKeys>(id: T, locale?: Locales) => IntlayerDictionaryTypesConnector[T];
7
+ /**
8
+ * Hook that picking one dictionary by its id and return the content.
9
+ */
13
10
  declare const useIntlayerBase: UseIntlayer;
14
11
 
15
12
  export { type DictionaryKeys, type StringFallback, type UseIntlayer, useIntlayerBase };
@@ -0,0 +1,9 @@
1
+ import { FC } from 'react';
2
+ import { IntlayerClientProviderProps } from './client/IntlayerClientProvider.mjs';
3
+ import { IntlayerServerProviderProps } from './server/IntlayerServerProvider.mjs';
4
+ import '@intlayer/config/client';
5
+
6
+ type IntlayerProviderProps = IntlayerClientProviderProps & IntlayerServerProviderProps;
7
+ declare const IntlayerProvider: FC<IntlayerProviderProps>;
8
+
9
+ export { IntlayerProvider };
@@ -0,0 +1,17 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { intlayerIntlConfiguration } from "@intlayer/config/client";
3
+ import {
4
+ IntlayerClientProvider
5
+ } from './client/IntlayerClientProvider.mjs';
6
+ import {
7
+ IntlayerServerProvider
8
+ } from './server/IntlayerServerProvider.mjs';
9
+ const defaultLocale = intlayerIntlConfiguration.defaultLocale;
10
+ const IntlayerProvider = ({
11
+ children,
12
+ locale = defaultLocale
13
+ }) => /* @__PURE__ */ jsx(IntlayerServerProvider, { locale, children: /* @__PURE__ */ jsx(IntlayerClientProvider, { locale, children }) });
14
+ export {
15
+ IntlayerProvider
16
+ };
17
+ //# sourceMappingURL=IntlayerProvider.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/IntlayerProvider.tsx"],"sourcesContent":["import { intlayerIntlConfiguration } from '@intlayer/config/client';\nimport type { FC } from 'react';\nimport {\n IntlayerClientProvider,\n type IntlayerClientProviderProps,\n} from './client/IntlayerClientProvider';\nimport {\n IntlayerServerProvider,\n type IntlayerServerProviderProps,\n} from './server/IntlayerServerProvider';\n\nconst defaultLocale = intlayerIntlConfiguration.defaultLocale;\n\ntype IntlayerProviderProps = IntlayerClientProviderProps &\n IntlayerServerProviderProps;\n\nexport const IntlayerProvider: FC<IntlayerProviderProps> = ({\n children,\n locale = defaultLocale,\n}) => (\n <IntlayerServerProvider locale={locale}>\n <IntlayerClientProvider locale={locale}>{children}</IntlayerClientProvider>\n </IntlayerServerProvider>\n);\n"],"mappings":"AAqBI;AArBJ,SAAS,iCAAiC;AAE1C;AAAA,EACE;AAAA,OAEK;AACP;AAAA,EACE;AAAA,OAEK;AAEP,MAAM,gBAAgB,0BAA0B;AAKzC,MAAM,mBAA8C,CAAC;AAAA,EAC1D;AAAA,EACA,SAAS;AACX,MACE,oBAAC,0BAAuB,QACtB,8BAAC,0BAAuB,QAAiB,UAAS,GACpD;","names":[]}
@@ -0,0 +1,24 @@
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
+ };
8
+ /**
9
+ * Context that store the current locale on the client side
10
+ */
11
+ declare const IntlayerClientContext: react.Context<IntlayerValue>;
12
+ /**
13
+ * Hook that provides the current locale
14
+ */
15
+ declare const useIntlayerContext: () => IntlayerValue;
16
+ type IntlayerClientProviderProps = PropsWithChildren & {
17
+ locale: Locales;
18
+ };
19
+ /**
20
+ * Provider that store the current locale on the client side
21
+ */
22
+ declare const IntlayerClientProvider: FC<IntlayerClientProviderProps>;
23
+
24
+ export { IntlayerClientContext, IntlayerClientProvider, type IntlayerClientProviderProps, useIntlayerContext };
@@ -0,0 +1,24 @@
1
+ "use client";
2
+ import { jsx } from "react/jsx-runtime";
3
+ import {
4
+ intlayerIntlConfiguration
5
+ } from "@intlayer/config/client";
6
+ import {
7
+ createContext,
8
+ useContext
9
+ } from "react";
10
+ import { localeCookie } from './useLocaleCookie.mjs';
11
+ const IntlayerClientContext = createContext({
12
+ locale: localeCookie ?? intlayerIntlConfiguration.defaultLocale
13
+ });
14
+ const useIntlayerContext = () => useContext(IntlayerClientContext);
15
+ const IntlayerClientProvider = ({
16
+ locale,
17
+ children
18
+ }) => /* @__PURE__ */ jsx(IntlayerClientContext.Provider, { value: { locale }, children });
19
+ export {
20
+ IntlayerClientContext,
21
+ IntlayerClientProvider,
22
+ useIntlayerContext
23
+ };
24
+ //# sourceMappingURL=IntlayerClientProvider.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/client/IntlayerClientProvider.tsx"],"sourcesContent":["'use client';\n\nimport {\n intlayerIntlConfiguration,\n type Locales,\n} from '@intlayer/config/client';\nimport {\n type PropsWithChildren,\n createContext,\n useContext,\n type FC,\n} from 'react';\nimport { localeCookie } from './useLocaleCookie';\n\ntype IntlayerValue = {\n locale: Locales;\n};\n\n/**\n * Context that store the current locale on the client side\n */\nexport const IntlayerClientContext = createContext<IntlayerValue>({\n locale: localeCookie ?? intlayerIntlConfiguration.defaultLocale,\n});\n\n/**\n * Hook that provides the current locale\n */\nexport const useIntlayerContext = () => useContext(IntlayerClientContext);\n\nexport type IntlayerClientProviderProps = PropsWithChildren & {\n locale: Locales;\n};\n\n/**\n * Provider that store the current locale on the client side\n */\nexport const IntlayerClientProvider: FC<IntlayerClientProviderProps> = ({\n locale,\n children,\n}) => (\n <IntlayerClientContext.Provider value={{ locale }}>\n {children}\n </IntlayerClientContext.Provider>\n);\n"],"mappings":";AAyCE;AAvCF;AAAA,EACE;AAAA,OAEK;AACP;AAAA,EAEE;AAAA,EACA;AAAA,OAEK;AACP,SAAS,oBAAoB;AAStB,MAAM,wBAAwB,cAA6B;AAAA,EAChE,QAAQ,gBAAgB,0BAA0B;AACpD,CAAC;AAKM,MAAM,qBAAqB,MAAM,WAAW,qBAAqB;AASjE,MAAM,yBAA0D,CAAC;AAAA,EACtE;AAAA,EACA;AACF,MACE,oBAAC,sBAAsB,UAAtB,EAA+B,OAAO,EAAE,OAAO,GAC7C,UACH;","names":[]}
@@ -1,4 +1,4 @@
1
- export { LocaleClientContext, LocaleClientContextProvider, LocaleClientContextProviderProps, useLocaleContext } from './LocaleClientContextProvider.mjs';
1
+ export { IntlayerClientContext as IntlayerClient, IntlayerClientProvider, IntlayerClientProviderProps, useIntlayerContext } from './IntlayerClientProvider.mjs';
2
2
  export { useIntlayer } from './useIntlayer.mjs';
3
3
  export { useLocale } from './useLocale.mjs';
4
4
  export { useTraduction } from './useTraduction.mjs';
@@ -1,8 +1,8 @@
1
1
  import {
2
- LocaleClientContext,
3
- useLocaleContext,
4
- LocaleClientContextProvider
5
- } from './LocaleClientContextProvider.mjs';
2
+ IntlayerClientContext,
3
+ useIntlayerContext,
4
+ IntlayerClientProvider
5
+ } from './IntlayerClientProvider.mjs';
6
6
  import { useIntlayer } from './useIntlayer.mjs';
7
7
  import { useLocale } from './useLocale.mjs';
8
8
  import { useTraduction } from './useTraduction.mjs';
@@ -12,13 +12,13 @@ import {
12
12
  setLocaleCookie
13
13
  } from './useLocaleCookie.mjs';
14
14
  export {
15
- LocaleClientContext,
16
- LocaleClientContextProvider,
15
+ IntlayerClientContext as IntlayerClient,
16
+ IntlayerClientProvider,
17
17
  localeCookie,
18
18
  setLocaleCookie,
19
19
  useIntlayer,
20
+ useIntlayerContext,
20
21
  useLocale,
21
- useLocaleContext,
22
22
  useLocaleCookie,
23
23
  useTraduction
24
24
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/client/index.ts"],"sourcesContent":["export type { LocaleClientContextProviderProps } from './LocaleClientContextProvider';\nexport {\n LocaleClientContext,\n useLocaleContext,\n LocaleClientContextProvider,\n} from './LocaleClientContextProvider';\nexport { useIntlayer } from './useIntlayer';\nexport { useLocale } from './useLocale';\nexport { useTraduction } from './useTraduction';\nexport {\n useLocaleCookie,\n localeCookie,\n setLocaleCookie,\n} from './useLocaleCookie';\n"],"mappings":"AACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,mBAAmB;AAC5B,SAAS,iBAAiB;AAC1B,SAAS,qBAAqB;AAC9B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;","names":[]}
1
+ {"version":3,"sources":["../../../src/client/index.ts"],"sourcesContent":["export type { IntlayerClientProviderProps } from './IntlayerClientProvider';\nexport {\n IntlayerClientContext as IntlayerClient,\n useIntlayerContext,\n IntlayerClientProvider,\n} from './IntlayerClientProvider';\nexport { useIntlayer } from './useIntlayer';\nexport { useLocale } from './useLocale';\nexport { useTraduction } from './useTraduction';\nexport {\n useLocaleCookie,\n localeCookie,\n setLocaleCookie,\n} from './useLocaleCookie';\n"],"mappings":"AACA;AAAA,EAC2B;AAAA,EACzB;AAAA,EACA;AAAA,OACK;AACP,SAAS,mBAAmB;AAC5B,SAAS,iBAAiB;AAC1B,SAAS,qBAAqB;AAC9B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;","names":[]}
@@ -2,10 +2,13 @@ import * as _intlayer_config_client from '@intlayer/config/client';
2
2
  import * as intlayer from 'intlayer';
3
3
  import { LanguageContent } from '@intlayer/core';
4
4
 
5
+ /**
6
+ * On the client side, hook to get the translation content based on the locale
7
+ */
5
8
  declare const useContent: <Content>(languageContent: LanguageContent<Content>) => {
6
9
  locale: intlayer.Locales;
7
10
  content: Content;
8
- t: <Content_1>(languageContent: Partial<Record<_intlayer_config_client.LocalesValues, Content_1>>) => Content_1;
11
+ t: <Content_1 = string>(languageContent: Partial<Record<_intlayer_config_client.LocalesValues, Content_1>>) => Content_1;
9
12
  };
10
13
 
11
14
  export { useContent };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/client/useContent.ts"],"sourcesContent":["import type { LanguageContent } from '@intlayer/core';\nimport { useLocale } from './useLocale';\nimport { useTraduction } from './useTraduction';\n\nexport const useContent = <Content>(\n languageContent: LanguageContent<Content>\n) => {\n const { locale } = useLocale();\n\n const content = useTraduction(languageContent);\n\n return {\n locale,\n content,\n t: useTraduction,\n };\n};\n"],"mappings":"AACA,SAAS,iBAAiB;AAC1B,SAAS,qBAAqB;AAEvB,MAAM,aAAa,CACxB,oBACG;AACH,QAAM,EAAE,OAAO,IAAI,UAAU;AAE7B,QAAM,UAAU,cAAc,eAAe;AAE7C,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EACL;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../src/client/useContent.ts"],"sourcesContent":["import type { LanguageContent } from '@intlayer/core';\nimport { useLocale } from './useLocale';\nimport { useTraduction } from './useTraduction';\n\n/**\n * On the client side, hook to get the translation content based on the locale\n */\nexport const useContent = <Content>(\n languageContent: LanguageContent<Content>\n) => {\n const { locale } = useLocale();\n\n const content = useTraduction(languageContent);\n\n return {\n locale,\n content,\n t: useTraduction,\n };\n};\n"],"mappings":"AACA,SAAS,iBAAiB;AAC1B,SAAS,qBAAqB;AAKvB,MAAM,aAAa,CACxB,oBACG;AACH,QAAM,EAAE,OAAO,IAAI,UAAU;AAE7B,QAAM,UAAU,cAAc,eAAe;AAE7C,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EACL;AACF;","names":[]}
@@ -2,6 +2,11 @@ import { UseIntlayer } from '../useIntlayerBase.mjs';
2
2
  import '@intlayer/config/client';
3
3
  import 'intlayer';
4
4
 
5
+ /**
6
+ * On the client side, Hook that picking one dictionary by its id and return the content
7
+ *
8
+ * If the locale is not provided, it will use the locale from the client context
9
+ */
5
10
  declare const useIntlayer: UseIntlayer;
6
11
 
7
12
  export { useIntlayer };
@@ -3,9 +3,9 @@ import { useContext } from "react";
3
3
  import {
4
4
  useIntlayerBase
5
5
  } from '../useIntlayerBase.mjs';
6
- import { LocaleClientContext } from './LocaleClientContextProvider.mjs';
6
+ import { IntlayerClientContext } from './IntlayerClientProvider.mjs';
7
7
  const useIntlayer = (id, locale) => {
8
- const { locale: currentLocale } = useContext(LocaleClientContext);
8
+ const { locale: currentLocale } = useContext(IntlayerClientContext);
9
9
  const localeTarget = locale ?? currentLocale;
10
10
  return useIntlayerBase(id, localeTarget);
11
11
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["'use client';\n\nimport type { Locales } from '@intlayer/config/client';\nimport { useContext } from 'react';\nimport {\n type DictionaryKeys,\n useIntlayerBase,\n type UseIntlayer,\n} from '../useIntlayerBase';\nimport { LocaleClientContext } from './LocaleClientContextProvider';\n\nexport const useIntlayer: UseIntlayer = <T extends DictionaryKeys>(\n id: T,\n locale?: Locales\n) => {\n const { locale: currentLocale } = useContext(LocaleClientContext);\n const localeTarget = locale ?? currentLocale;\n\n return useIntlayerBase(id, localeTarget);\n};\n"],"mappings":";AAGA,SAAS,kBAAkB;AAC3B;AAAA,EAEE;AAAA,OAEK;AACP,SAAS,2BAA2B;AAE7B,MAAM,cAA2B,CACtC,IACA,WACG;AACH,QAAM,EAAE,QAAQ,cAAc,IAAI,WAAW,mBAAmB;AAChE,QAAM,eAAe,UAAU;AAE/B,SAAO,gBAAgB,IAAI,YAAY;AACzC;","names":[]}
1
+ {"version":3,"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["'use client';\n\nimport type { Locales } from '@intlayer/config/client';\nimport { useContext } from 'react';\nimport {\n type DictionaryKeys,\n useIntlayerBase,\n type UseIntlayer,\n} from '../useIntlayerBase';\nimport { IntlayerClientContext } from './IntlayerClientProvider';\n\n/**\n * On the client side, Hook that picking one dictionary by its id and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useIntlayer: UseIntlayer = <T extends DictionaryKeys>(\n id: T,\n locale?: Locales\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const localeTarget = locale ?? currentLocale;\n\n return useIntlayerBase(id, localeTarget);\n};\n"],"mappings":";AAGA,SAAS,kBAAkB;AAC3B;AAAA,EAEE;AAAA,OAEK;AACP,SAAS,6BAA6B;AAO/B,MAAM,cAA2B,CACtC,IACA,WACG;AACH,QAAM,EAAE,QAAQ,cAAc,IAAI,WAAW,qBAAqB;AAClE,QAAM,eAAe,UAAU;AAE/B,SAAO,gBAAgB,IAAI,YAAY;AACzC;","names":[]}
@@ -1,5 +1,8 @@
1
1
  import * as _intlayer_config_client from '@intlayer/config/client';
2
2
 
3
+ /**
4
+ * On the client side, hook to get the current locale and all related fields
5
+ */
3
6
  declare const useLocale: () => {
4
7
  locale: _intlayer_config_client.Locales;
5
8
  defaultLocale: _intlayer_config_client.Locales;
@@ -2,10 +2,10 @@
2
2
  import { intlayerIntlConfiguration } from "@intlayer/config/client";
3
3
  import { localeList } from "@intlayer/core";
4
4
  import { useContext } from "react";
5
- import { LocaleClientContext } from './LocaleClientContextProvider.mjs';
5
+ import { IntlayerClientContext } from './IntlayerClientProvider.mjs';
6
6
  const { defaultLocale, locales: availableLocales } = intlayerIntlConfiguration;
7
7
  const useLocale = () => {
8
- const { locale } = useContext(LocaleClientContext);
8
+ const { locale } = useContext(IntlayerClientContext);
9
9
  return {
10
10
  locale,
11
11
  // Current locale
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["'use client';\n\nimport { intlayerIntlConfiguration } from '@intlayer/config/client';\nimport { localeList } from '@intlayer/core';\nimport { useContext } from 'react';\nimport { LocaleClientContext } from './LocaleClientContextProvider';\n\nconst { defaultLocale, locales: availableLocales } = intlayerIntlConfiguration;\n\nexport const useLocale = () => {\n const { locale } = useContext(LocaleClientContext);\n\n return {\n locale, // Current locale\n defaultLocale, // Principal locale defined in config\n availableLocales, // List of the available locales defined in config\n localeList, // List of all available locales\n };\n};\n"],"mappings":";AAEA,SAAS,iCAAiC;AAC1C,SAAS,kBAAkB;AAC3B,SAAS,kBAAkB;AAC3B,SAAS,2BAA2B;AAEpC,MAAM,EAAE,eAAe,SAAS,iBAAiB,IAAI;AAE9C,MAAM,YAAY,MAAM;AAC7B,QAAM,EAAE,OAAO,IAAI,WAAW,mBAAmB;AAEjD,SAAO;AAAA,IACL;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["'use client';\n\nimport { intlayerIntlConfiguration } from '@intlayer/config/client';\nimport { localeList } from '@intlayer/core';\nimport { useContext } from 'react';\nimport { IntlayerClientContext } from './IntlayerClientProvider';\n\nconst { defaultLocale, locales: availableLocales } = intlayerIntlConfiguration;\n\n/**\n * On the client side, hook to get the current locale and all related fields\n */\nexport const useLocale = () => {\n const { locale } = useContext(IntlayerClientContext);\n\n return {\n locale, // Current locale\n defaultLocale, // Principal locale defined in config\n availableLocales, // List of the available locales defined in config\n localeList, // List of all available locales\n };\n};\n"],"mappings":";AAEA,SAAS,iCAAiC;AAC1C,SAAS,kBAAkB;AAC3B,SAAS,kBAAkB;AAC3B,SAAS,6BAA6B;AAEtC,MAAM,EAAE,eAAe,SAAS,iBAAiB,IAAI;AAK9C,MAAM,YAAY,MAAM;AAC7B,QAAM,EAAE,OAAO,IAAI,WAAW,qBAAqB;AAEnD,SAAO;AAAA,IACL;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,EACF;AACF;","names":[]}
@@ -1,7 +1,16 @@
1
1
  import { Locales } from '@intlayer/config/client';
2
2
 
3
+ /**
4
+ * Get the locale cookie
5
+ */
3
6
  declare const localeCookie: Locales | undefined;
7
+ /**
8
+ * Set the locale cookie
9
+ */
4
10
  declare const setLocaleCookie: (locale: Locales) => void;
11
+ /**
12
+ * Hook that provides the locale cookie and a function to set it
13
+ */
5
14
  declare const useLocaleCookie: () => {
6
15
  localeCookie: Locales | undefined;
7
16
  setLocaleCookie: (locale: Locales) => void;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/client/useLocaleCookie.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-redundant-type-constituents */\nimport {\n type Locales,\n intlayerMiddlewareConfiguration,\n} from '@intlayer/config/client';\nimport Cookies from 'js-cookie';\n\nconst { cookieName } = intlayerMiddlewareConfiguration;\n\nconst cookieAttributes: Cookies.CookieAttributes = {\n path: '/',\n expires: undefined,\n domain: undefined,\n secure: false,\n sameSite: 'strict',\n};\n\nexport const localeCookie = Cookies.get(cookieName) as Locales | undefined;\n\nexport const setLocaleCookie = (locale: Locales) => {\n Cookies.set(cookieName, locale, cookieAttributes);\n};\n\nexport const useLocaleCookie = () => ({\n localeCookie,\n setLocaleCookie,\n});\n"],"mappings":"AACA;AAAA,EAEE;AAAA,OACK;AACP,OAAO,aAAa;AAEpB,MAAM,EAAE,WAAW,IAAI;AAEvB,MAAM,mBAA6C;AAAA,EACjD,MAAM;AAAA,EACN,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,UAAU;AACZ;AAEO,MAAM,eAAe,QAAQ,IAAI,UAAU;AAE3C,MAAM,kBAAkB,CAAC,WAAoB;AAClD,UAAQ,IAAI,YAAY,QAAQ,gBAAgB;AAClD;AAEO,MAAM,kBAAkB,OAAO;AAAA,EACpC;AAAA,EACA;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../src/client/useLocaleCookie.ts"],"sourcesContent":["import {\n type Locales,\n intlayerMiddlewareConfiguration,\n} from '@intlayer/config/client';\nimport Cookies from 'js-cookie';\n\nconst { cookieName } = intlayerMiddlewareConfiguration;\n\nconst cookieAttributes: Cookies.CookieAttributes = {\n path: '/',\n expires: undefined,\n domain: undefined,\n secure: false,\n sameSite: 'strict',\n};\n\n/**\n * Get the locale cookie\n */\nexport const localeCookie = Cookies.get(cookieName) as Locales | undefined;\n\n/**\n * Set the locale cookie\n */\nexport const setLocaleCookie = (locale: Locales) => {\n Cookies.set(cookieName, locale, cookieAttributes);\n};\n\n/**\n * Hook that provides the locale cookie and a function to set it\n */\nexport const useLocaleCookie = () => ({\n localeCookie,\n setLocaleCookie,\n});\n"],"mappings":"AAAA;AAAA,EAEE;AAAA,OACK;AACP,OAAO,aAAa;AAEpB,MAAM,EAAE,WAAW,IAAI;AAEvB,MAAM,mBAA6C;AAAA,EACjD,MAAM;AAAA,EACN,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,UAAU;AACZ;AAKO,MAAM,eAAe,QAAQ,IAAI,UAAU;AAK3C,MAAM,kBAAkB,CAAC,WAAoB;AAClD,UAAQ,IAAI,YAAY,QAAQ,gBAAgB;AAClD;AAKO,MAAM,kBAAkB,OAAO;AAAA,EACpC;AAAA,EACA;AACF;","names":[]}
@@ -1,5 +1,25 @@
1
1
  import { LanguageContent } from '@intlayer/core';
2
2
 
3
- declare const useTraduction: <Content>(languageContent: LanguageContent<Content>) => Content;
3
+ /**
4
+ * On the client side, Hook that picking one dictionary by its id and return the content.
5
+ *
6
+ * If not locale found, it will return the content related to the default locale.
7
+ *
8
+ * Return either the content editor, or the content itself depending on the configuration.
9
+ *
10
+ * Usage:
11
+ *
12
+ * const content = getTranslation<string>({
13
+ * en: 'Hello',
14
+ * fr: 'Bonjour',
15
+ * },
16
+ * 'fr');
17
+ * // 'Bonjour'
18
+ *
19
+ * Using TypeScript:
20
+ * - this function will require each locale to be defined if defined in the project configuration.
21
+ * - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.
22
+ */
23
+ declare const useTraduction: <Content = string>(languageContent: LanguageContent<Content>) => Content;
4
24
 
5
25
  export { useTraduction };
@@ -1,8 +1,8 @@
1
1
  import { useContext } from "react";
2
2
  import { getTranslation } from '../getTranslation.mjs';
3
- import { LocaleClientContext } from './LocaleClientContextProvider.mjs';
3
+ import { IntlayerClientContext } from './IntlayerClientProvider.mjs';
4
4
  const useTraduction = (languageContent) => {
5
- const { locale } = useContext(LocaleClientContext);
5
+ const { locale } = useContext(IntlayerClientContext);
6
6
  return getTranslation(languageContent, locale);
7
7
  };
8
8
  export {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/client/useTraduction.ts"],"sourcesContent":["import type { LanguageContent } from '@intlayer/core';\nimport { useContext } from 'react';\nimport { getTranslation } from '../getTranslation';\nimport { LocaleClientContext } from './LocaleClientContextProvider';\n\nexport const useTraduction = <Content>(\n languageContent: LanguageContent<Content>\n): Content => {\n const { locale } = useContext(LocaleClientContext);\n\n return getTranslation(languageContent, locale);\n};\n"],"mappings":"AACA,SAAS,kBAAkB;AAC3B,SAAS,sBAAsB;AAC/B,SAAS,2BAA2B;AAE7B,MAAM,gBAAgB,CAC3B,oBACY;AACZ,QAAM,EAAE,OAAO,IAAI,WAAW,mBAAmB;AAEjD,SAAO,eAAe,iBAAiB,MAAM;AAC/C;","names":[]}
1
+ {"version":3,"sources":["../../../src/client/useTraduction.ts"],"sourcesContent":["import type { LanguageContent } from '@intlayer/core';\nimport { useContext } from 'react';\nimport { getTranslation } from '../getTranslation';\nimport { IntlayerClientContext } from './IntlayerClientProvider';\n\n/**\n * On the client side, Hook that picking one dictionary by its id and return the content.\n *\n * If not locale found, it will return the content related to the default locale.\n *\n * Return either the content editor, or the content itself depending on the configuration.\n *\n * Usage:\n *\n * const content = getTranslation<string>({\n * en: 'Hello',\n * fr: 'Bonjour',\n * },\n * 'fr');\n * // 'Bonjour'\n *\n * Using TypeScript:\n * - this function will require each locale to be defined if defined in the project configuration.\n * - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.\n */\nexport const useTraduction = <Content = string>(\n languageContent: LanguageContent<Content>\n): Content => {\n const { locale } = useContext(IntlayerClientContext);\n\n return getTranslation(languageContent, locale);\n};\n"],"mappings":"AACA,SAAS,kBAAkB;AAC3B,SAAS,sBAAsB;AAC/B,SAAS,6BAA6B;AAsB/B,MAAM,gBAAgB,CAC3B,oBACY;AACZ,QAAM,EAAE,OAAO,IAAI,WAAW,qBAAqB;AAEnD,SAAO,eAAe,iBAAiB,MAAM;AAC/C;","names":[]}
@@ -1,5 +1,30 @@
1
1
  import { QuantityContent } from '@intlayer/core';
2
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
+ * const content = getEnumeration({
11
+ * '<=-2.3': 'You have less than -2.3',
12
+ * '<1': 'You have less than one',
13
+ * '2': 'You have two',
14
+ * '>=3': 'You have three or more',
15
+ * },
16
+ * 2);
17
+ * // 'You have two'
18
+ *
19
+ * The order of the keys will define the priority of the content.
20
+ *
21
+ * const content = getEnumeration({
22
+ * '<4': 'You have less than four',
23
+ * '2': 'You have two',
24
+ * });
25
+ * // 'You have less than four'
26
+ *
27
+ */
3
28
  declare const getEnumeration: <Content>(enumerationContent: QuantityContent<Content>, quantity: number) => Content;
4
29
 
5
30
  export { getEnumeration };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/getEnumeration.ts"],"sourcesContent":["import { type QuantityContent, getEnumerationContent } from '@intlayer/core';\nimport { contentRender } from './ContentEditor/contentRender';\n\nexport const getEnumeration = <Content>(\n enumerationContent: QuantityContent<Content>,\n quantity: number\n): Content => {\n const result: Content = getEnumerationContent<Content>(\n enumerationContent,\n quantity\n );\n\n if (typeof result === 'string') {\n return contentRender(result) as Content;\n }\n\n return result;\n};\n"],"mappings":"AAAA,SAA+B,6BAA6B;AAC5D,SAAS,qBAAqB;AAEvB,MAAM,iBAAiB,CAC5B,oBACA,aACY;AACZ,QAAM,SAAkB;AAAA,IACtB;AAAA,IACA;AAAA,EACF;AAEA,MAAI,OAAO,WAAW,UAAU;AAC9B,WAAO,cAAc,MAAM;AAAA,EAC7B;AAEA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../src/getEnumeration.ts"],"sourcesContent":["import { type QuantityContent, getEnumerationContent } from '@intlayer/core';\nimport { contentRender } from './ContentEditor/contentRender';\n\n/**\n * Allow to pick a content based on a quantity.\n *\n * Return either the content editor, or the content itself depending on the configuration.\n *\n * Usage:\n *\n * const content = getEnumeration({\n * '<=-2.3': 'You have less than -2.3',\n * '<1': 'You have less than one',\n * '2': 'You have two',\n * '>=3': 'You have three or more',\n * },\n * 2);\n * // 'You have two'\n *\n * The order of the keys will define the priority of the content.\n *\n * const content = getEnumeration({\n * '<4': 'You have less than four',\n * '2': 'You have two',\n * });\n * // 'You have less than four'\n *\n */\nexport const getEnumeration = <Content>(\n enumerationContent: QuantityContent<Content>,\n quantity: number\n): Content => {\n const result: Content = getEnumerationContent<Content>(\n enumerationContent,\n quantity\n );\n\n if (typeof result === 'string') {\n return contentRender(result) as Content;\n }\n\n return result;\n};\n"],"mappings":"AAAA,SAA+B,6BAA6B;AAC5D,SAAS,qBAAqB;AA2BvB,MAAM,iBAAiB,CAC5B,oBACA,aACY;AACZ,QAAM,SAAkB;AAAA,IACtB;AAAA,IACA;AAAA,EACF;AAEA,MAAI,OAAO,WAAW,UAAU;AAC9B,WAAO,cAAc,MAAM;AAAA,EAC7B;AAEA,SAAO;AACT;","names":[]}
@@ -1,6 +1,26 @@
1
1
  import { Locales } from '@intlayer/config/client';
2
2
  import { LanguageContent } from '@intlayer/core';
3
3
 
4
- declare const getTranslation: <Content>(languageContent: LanguageContent<Content>, locale?: Locales) => Content;
4
+ /**
5
+ *
6
+ * Allow to pick a content based on a locale.
7
+ * If not locale found, it will return the content related to the default locale.
8
+ *
9
+ * Return either the content editor, or the content itself depending on the configuration.
10
+ *
11
+ * Usage:
12
+ *
13
+ * const content = getTranslation<string>({
14
+ * en: 'Hello',
15
+ * fr: 'Bonjour',
16
+ * },
17
+ * 'fr');
18
+ * // 'Bonjour'
19
+ *
20
+ * Using TypeScript:
21
+ * - this function will require each locale to be defined if defined in the project configuration.
22
+ * - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.
23
+ */
24
+ declare const getTranslation: <Content = string>(languageContent: LanguageContent<Content>, locale?: Locales) => Content;
5
25
 
6
26
  export { getTranslation };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/getTranslation.ts"],"sourcesContent":["import {\n type Locales,\n intlayerIntlConfiguration,\n} from '@intlayer/config/client';\nimport { type LanguageContent, getTranslationContent } from '@intlayer/core';\nimport { contentRender } from './ContentEditor/contentRender';\n\nexport const getTranslation = <Content>(\n languageContent: LanguageContent<Content>,\n locale?: Locales\n): Content => {\n const { defaultLocale } = intlayerIntlConfiguration;\n\n const result: Content = getTranslationContent<Content>(\n languageContent,\n locale ?? defaultLocale\n );\n\n if (typeof result === 'string') {\n return contentRender(result) as Content;\n }\n\n return result;\n};\n"],"mappings":"AAAA;AAAA,EAEE;AAAA,OACK;AACP,SAA+B,6BAA6B;AAC5D,SAAS,qBAAqB;AAEvB,MAAM,iBAAiB,CAC5B,iBACA,WACY;AACZ,QAAM,EAAE,cAAc,IAAI;AAE1B,QAAM,SAAkB;AAAA,IACtB;AAAA,IACA,UAAU;AAAA,EACZ;AAEA,MAAI,OAAO,WAAW,UAAU;AAC9B,WAAO,cAAc,MAAM;AAAA,EAC7B;AAEA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../src/getTranslation.ts"],"sourcesContent":["import {\n type Locales,\n intlayerIntlConfiguration,\n} from '@intlayer/config/client';\nimport { type LanguageContent, getTranslationContent } from '@intlayer/core';\nimport { contentRender } from './ContentEditor/contentRender';\n\n/**\n *\n * Allow to pick a content based on a locale.\n * If not locale found, it will return the content related to the default locale.\n *\n * Return either the content editor, or the content itself depending on the configuration.\n *\n * Usage:\n *\n * const content = getTranslation<string>({\n * en: 'Hello',\n * fr: 'Bonjour',\n * },\n * 'fr');\n * // 'Bonjour'\n *\n * Using TypeScript:\n * - this function will require each locale to be defined if defined in the project configuration.\n * - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.\n */\nexport const getTranslation = <Content = string>(\n languageContent: LanguageContent<Content>,\n locale?: Locales\n): Content => {\n const { defaultLocale } = intlayerIntlConfiguration;\n\n const result: Content = getTranslationContent<Content>(\n languageContent,\n locale ?? defaultLocale\n );\n\n if (typeof result === 'string') {\n return contentRender(result) as Content;\n }\n\n return result;\n};\n"],"mappings":"AAAA;AAAA,EAEE;AAAA,OACK;AACP,SAA+B,6BAA6B;AAC5D,SAAS,qBAAqB;AAsBvB,MAAM,iBAAiB,CAC5B,iBACA,WACY;AACZ,QAAM,EAAE,cAAc,IAAI;AAE1B,QAAM,SAAkB;AAAA,IACtB;AAAA,IACA,UAAU;AAAA,EACZ;AAEA,MAAI,OAAO,WAAW,UAAU;AAC9B,WAAO,cAAc,MAAM;AAAA,EAC7B;AAEA,SAAO;AACT;","names":[]}