use-intl 2.9.1 → 2.10.0-alpha.3

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 (162) hide show
  1. package/CHANGELOG.md +463 -0
  2. package/dist/core/use-intl.esm.js +140 -27
  3. package/dist/core/use-intl.esm.js.map +1 -1
  4. package/dist/core/use-intl.esm2.js +41 -38
  5. package/dist/core/use-intl.esm2.js.map +1 -1
  6. package/dist/core/use-intl.esm3.js +35 -151
  7. package/dist/core/use-intl.esm3.js.map +1 -1
  8. package/dist/core/use-intl.esm4.js +12 -56
  9. package/dist/core/use-intl.esm4.js.map +1 -1
  10. package/dist/core/use-intl.esm5.js +56 -12
  11. package/dist/core/use-intl.esm5.js.map +1 -1
  12. package/dist/core/use-intl.esm6.js +7 -29
  13. package/dist/core/use-intl.esm6.js.map +1 -1
  14. package/dist/core/use-intl.esm7.js +9 -9
  15. package/dist/core/use-intl.esm7.js.map +1 -1
  16. package/dist/core/use-intl.esm8.js +29 -7
  17. package/dist/core/use-intl.esm8.js.map +1 -1
  18. package/dist/react/IntlContext.d.ts +2 -19
  19. package/dist/react/IntlContextValue.d.ts +19 -0
  20. package/dist/react/IntlProvider.d.ts +2 -16
  21. package/dist/react/IntlProviderProps.d.ts +15 -0
  22. package/dist/react/getIntlContextValue.d.ts +18 -0
  23. package/dist/react/use-intl.esm.js +6 -25
  24. package/dist/react/use-intl.esm.js.map +1 -1
  25. package/dist/react/use-intl.esm10.js +44 -0
  26. package/dist/react/use-intl.esm10.js.map +1 -0
  27. package/dist/react/use-intl.esm2.js +20 -21
  28. package/dist/react/use-intl.esm2.js.map +1 -1
  29. package/dist/react/use-intl.esm3.js +21 -20
  30. package/dist/react/use-intl.esm3.js.map +1 -1
  31. package/dist/react/use-intl.esm4.js +46 -4
  32. package/dist/react/use-intl.esm4.js.map +1 -1
  33. package/dist/react/use-intl.esm5.js +4 -46
  34. package/dist/react/use-intl.esm5.js.map +1 -1
  35. package/dist/react/use-intl.esm6.js +1 -1
  36. package/dist/react/use-intl.esm7.js.map +1 -1
  37. package/dist/react/use-intl.esm8.js +26 -8
  38. package/dist/react/use-intl.esm8.js.map +1 -1
  39. package/dist/react/use-intl.esm9.js +9 -38
  40. package/dist/react/use-intl.esm9.js.map +1 -1
  41. package/dist/react/useIntlContext.d.ts +1 -1
  42. package/dist/src/core/AbstractIntlMessages.d.ts +9 -0
  43. package/dist/src/core/AbstractIntlMessages.js +2 -0
  44. package/dist/src/core/AbstractIntlMessages.js.map +1 -0
  45. package/dist/src/core/DateTimeFormatOptions.d.ts +72 -0
  46. package/dist/src/core/DateTimeFormatOptions.js +3 -0
  47. package/dist/src/core/DateTimeFormatOptions.js.map +1 -0
  48. package/dist/src/core/Formats.d.ts +7 -0
  49. package/dist/src/core/Formats.js +2 -0
  50. package/dist/src/core/Formats.js.map +1 -0
  51. package/dist/src/core/IntlConfiguration.d.ts +46 -0
  52. package/dist/src/core/IntlConfiguration.js +2 -0
  53. package/dist/src/core/IntlConfiguration.js.map +1 -0
  54. package/dist/src/core/IntlError.d.ts +13 -0
  55. package/dist/src/core/IntlError.js +23 -0
  56. package/dist/src/core/IntlError.js.map +1 -0
  57. package/dist/src/core/IntlMessages.d.ts +2 -0
  58. package/dist/src/core/IntlMessages.js +4 -0
  59. package/dist/src/core/IntlMessages.js.map +1 -0
  60. package/dist/src/core/NumberFormatOptions.d.ts +2 -0
  61. package/dist/src/core/NumberFormatOptions.js +2 -0
  62. package/dist/src/core/NumberFormatOptions.js.map +1 -0
  63. package/dist/src/core/TranslationValues.d.ts +5 -0
  64. package/dist/src/core/TranslationValues.js +2 -0
  65. package/dist/src/core/TranslationValues.js.map +1 -0
  66. package/dist/src/core/convertFormatsToIntlMessageFormat.d.ts +10 -0
  67. package/dist/src/core/convertFormatsToIntlMessageFormat.js +31 -0
  68. package/dist/src/core/convertFormatsToIntlMessageFormat.js.map +1 -0
  69. package/dist/src/core/createBaseTranslator.d.ts +26 -0
  70. package/dist/src/core/createBaseTranslator.js +185 -0
  71. package/dist/src/core/createBaseTranslator.js.map +1 -0
  72. package/dist/src/core/createIntl.d.ts +17 -0
  73. package/dist/src/core/createIntl.js +126 -0
  74. package/dist/src/core/createIntl.js.map +1 -0
  75. package/dist/src/core/createTranslator.d.ts +48 -0
  76. package/dist/src/core/createTranslator.js +24 -0
  77. package/dist/src/core/createTranslator.js.map +1 -0
  78. package/dist/src/core/createTranslatorImpl.d.ts +14 -0
  79. package/dist/src/core/createTranslatorImpl.js +43 -0
  80. package/dist/src/core/createTranslatorImpl.js.map +1 -0
  81. package/dist/src/core/defaults.d.ts +11 -0
  82. package/dist/src/core/defaults.js +11 -0
  83. package/dist/src/core/defaults.js.map +1 -0
  84. package/dist/src/core/index.d.ts +8 -0
  85. package/dist/src/core/index.js +4 -0
  86. package/dist/src/core/index.js.map +1 -0
  87. package/dist/src/core/resolveNamespace.d.ts +5 -0
  88. package/dist/src/core/resolveNamespace.js +10 -0
  89. package/dist/src/core/resolveNamespace.js.map +1 -0
  90. package/dist/src/core/utils/MessageKeys.d.ts +5 -0
  91. package/dist/src/core/utils/MessageKeys.js +2 -0
  92. package/dist/src/core/utils/MessageKeys.js.map +1 -0
  93. package/dist/src/core/utils/NamespaceKeys.d.ts +5 -0
  94. package/dist/src/core/utils/NamespaceKeys.js +2 -0
  95. package/dist/src/core/utils/NamespaceKeys.js.map +1 -0
  96. package/dist/src/core/utils/NestedKeyOf.d.ts +4 -0
  97. package/dist/src/core/utils/NestedKeyOf.js +2 -0
  98. package/dist/src/core/utils/NestedKeyOf.js.map +1 -0
  99. package/dist/src/core/utils/NestedValueOf.d.ts +2 -0
  100. package/dist/src/core/utils/NestedValueOf.js +2 -0
  101. package/dist/src/core/utils/NestedValueOf.js.map +1 -0
  102. package/dist/src/core/validateMessages.d.ts +3 -0
  103. package/dist/src/core/validateMessages.js +22 -0
  104. package/dist/src/core/validateMessages.js.map +1 -0
  105. package/dist/src/index.d.ts +2 -0
  106. package/dist/src/index.js +3 -0
  107. package/dist/src/index.js.map +1 -0
  108. package/dist/src/react/IntlContext.d.ts +4 -0
  109. package/dist/src/react/IntlContext.js +4 -0
  110. package/dist/src/react/IntlContext.js.map +1 -0
  111. package/dist/src/react/IntlContextValue.d.ts +19 -0
  112. package/dist/src/react/IntlContextValue.js +2 -0
  113. package/dist/src/react/IntlContextValue.js.map +1 -0
  114. package/dist/src/react/IntlProvider.d.ts +2 -0
  115. package/dist/src/react/IntlProvider.js +7 -0
  116. package/dist/src/react/IntlProvider.js.map +1 -0
  117. package/dist/src/react/IntlProviderProps.d.ts +15 -0
  118. package/dist/src/react/IntlProviderProps.js +2 -0
  119. package/dist/src/react/IntlProviderProps.js.map +1 -0
  120. package/dist/src/react/getIntlContextValue.d.ts +18 -0
  121. package/dist/src/react/getIntlContextValue.js +21 -0
  122. package/dist/src/react/getIntlContextValue.js.map +1 -0
  123. package/dist/src/react/index.d.ts +6 -0
  124. package/dist/src/react/index.js +7 -0
  125. package/dist/src/react/index.js.map +1 -0
  126. package/dist/src/react/useIntl.d.ts +5 -0
  127. package/dist/src/react/useIntl.js +14 -0
  128. package/dist/src/react/useIntl.js.map +1 -0
  129. package/dist/src/react/useIntlContext.d.ts +1 -0
  130. package/dist/src/react/useIntlContext.js +12 -0
  131. package/dist/src/react/useIntlContext.js.map +1 -0
  132. package/dist/src/react/useLocale.d.ts +1 -0
  133. package/dist/src/react/useLocale.js +5 -0
  134. package/dist/src/react/useLocale.js.map +1 -0
  135. package/dist/src/react/useNow.d.ts +23 -0
  136. package/dist/src/react/useNow.js +40 -0
  137. package/dist/src/react/useNow.js.map +1 -0
  138. package/dist/src/react/useTimeZone.d.ts +1 -0
  139. package/dist/src/react/useTimeZone.js +5 -0
  140. package/dist/src/react/useTimeZone.js.map +1 -0
  141. package/dist/src/react/useTranslations.d.ts +44 -0
  142. package/dist/src/react/useTranslations.js +21 -0
  143. package/dist/src/react/useTranslations.js.map +1 -0
  144. package/dist/src/react/useTranslationsImpl.d.ts +8 -0
  145. package/dist/src/react/useTranslationsImpl.js +35 -0
  146. package/dist/src/react/useTranslationsImpl.js.map +1 -0
  147. package/dist/use-intl.cjs.development.js +37 -28
  148. package/dist/use-intl.cjs.development.js.map +1 -1
  149. package/dist/use-intl.cjs.production.min.js +1 -1
  150. package/dist/use-intl.cjs.production.min.js.map +1 -1
  151. package/dist/use-intl.esm.js +7 -7
  152. package/package.json +6 -5
  153. package/src/core/createBaseTranslator.tsx +11 -7
  154. package/src/core/createIntl.tsx +2 -2
  155. package/src/core/createTranslatorImpl.tsx +1 -1
  156. package/src/react/IntlContext.tsx +2 -20
  157. package/src/react/IntlContextValue.tsx +21 -0
  158. package/src/react/IntlProvider.tsx +5 -36
  159. package/src/react/IntlProviderProps.tsx +17 -0
  160. package/src/react/getIntlContextValue.tsx +30 -0
  161. package/src/react/useIntlContext.tsx +1 -1
  162. package/LICENSE +0 -21
@@ -1 +1 @@
1
- {"version":3,"file":"use-intl.esm4.js","sources":["../../src/react/useLocale.tsx"],"sourcesContent":["import useIntlContext from './useIntlContext';\n\nexport default function useLocale() {\n return useIntlContext().locale;\n}\n"],"names":["useLocale","useIntlContext","locale"],"mappings":";;AAEc,SAAUA,SAAV,GAAmB;AAC/B,EAAOC,OAAAA,cAAc,GAAGC,MAAxB,CAAA;AACD;;;;"}
1
+ {"version":3,"file":"use-intl.esm4.js","sources":["../../src/react/useNow.tsx"],"sourcesContent":["import {useState, useEffect} from 'react';\nimport useIntlContext from './useIntlContext';\n\ntype Options = {\n updateInterval?: number;\n};\n\nfunction getNow() {\n return new Date();\n}\n\n/**\n * Reading the current date via `new Date()` in components should be avoided, as\n * it causes components to be impure and can lead to flaky tests. Instead, this\n * hook can be used.\n *\n * By default, it returns the time when the component mounts. If `updateInterval`\n * is specified, the value will be updated based on the interval.\n *\n * You can however also return a static value from this hook, if you\n * configure the `now` parameter on the context provider. Note however,\n * that if `updateInterval` is configured in this case, the component\n * will initialize with the global value, but will afterwards update\n * continuously based on the interval.\n *\n * For unit tests, this can be mocked to a constant value. For end-to-end\n * testing, an environment parameter can be passed to the `now` parameter\n * of the provider to mock this to a static value.\n */\nexport default function useNow(options?: Options) {\n const updateInterval = options?.updateInterval;\n\n const {now: globalNow} = useIntlContext();\n const [now, setNow] = useState(globalNow || getNow());\n\n useEffect(() => {\n if (!updateInterval) return;\n\n const intervalId = setInterval(() => {\n setNow(getNow());\n }, updateInterval);\n\n return () => {\n clearInterval(intervalId);\n };\n }, [globalNow, updateInterval]);\n\n return now;\n}\n"],"names":["getNow","Date","useNow","options","updateInterval","useIntlContext","globalNow","now","useState","setNow","useEffect","intervalId","setInterval","clearInterval"],"mappings":";;;AAOA,SAASA,MAAT,GAAe;AACb,EAAO,OAAA,IAAIC,IAAJ,EAAP,CAAA;AACD,CAAA;AAED;;;;;;;;;;;;;;;;;AAiBG;;;AACqB,SAAAC,MAAA,CAAOC,OAAP,EAAwB;AAC9C,EAAA,IAAMC,cAAc,GAAGD,OAAH,IAAGA,IAAAA,GAAAA,KAAAA,CAAAA,GAAAA,OAAO,CAAEC,cAAhC,CAAA;;AAEA,EAAA,IAAA,eAAA,GAAyBC,cAAc,EAAvC;AAAA,MAAYC,SAAZ,mBAAOC,GAAP,CAAA;;AACA,EAAA,IAAA,SAAA,GAAsBC,QAAQ,CAACF,SAAS,IAAIN,MAAM,EAApB,CAA9B;AAAA,MAAOO,GAAP,GAAA,SAAA,CAAA,CAAA,CAAA;AAAA,MAAYE,MAAZ,GAAA,SAAA,CAAA,CAAA,CAAA,CAAA;;AAEAC,EAAAA,SAAS,CAAC,YAAK;AACb,IAAI,IAAA,CAACN,cAAL,EAAqB,OAAA;AAErB,IAAA,IAAMO,UAAU,GAAGC,WAAW,CAAC,YAAK;AAClCH,MAAAA,MAAM,CAACT,MAAM,EAAP,CAAN,CAAA;AACD,KAF6B,EAE3BI,cAF2B,CAA9B,CAAA;AAIA,IAAA,OAAO,YAAK;AACVS,MAAAA,aAAa,CAACF,UAAD,CAAb,CAAA;AACD,KAFD,CAAA;AAGD,GAVQ,EAUN,CAACL,SAAD,EAAYF,cAAZ,CAVM,CAAT,CAAA;AAYA,EAAA,OAAOG,GAAP,CAAA;AACD;;;;"}
@@ -1,50 +1,8 @@
1
- import { useState, useEffect } from 'react';
2
- import useIntlContext from './use-intl.esm8.js';
1
+ import useIntlContext from './use-intl.esm9.js';
3
2
 
4
- function getNow() {
5
- return new Date();
3
+ function useLocale() {
4
+ return useIntlContext().locale;
6
5
  }
7
- /**
8
- * Reading the current date via `new Date()` in components should be avoided, as
9
- * it causes components to be impure and can lead to flaky tests. Instead, this
10
- * hook can be used.
11
- *
12
- * By default, it returns the time when the component mounts. If `updateInterval`
13
- * is specified, the value will be updated based on the interval.
14
- *
15
- * You can however also return a static value from this hook, if you
16
- * configure the `now` parameter on the context provider. Note however,
17
- * that if `updateInterval` is configured in this case, the component
18
- * will initialize with the global value, but will afterwards update
19
- * continuously based on the interval.
20
- *
21
- * For unit tests, this can be mocked to a constant value. For end-to-end
22
- * testing, an environment parameter can be passed to the `now` parameter
23
- * of the provider to mock this to a static value.
24
- */
25
6
 
26
-
27
- function useNow(options) {
28
- var updateInterval = options == null ? void 0 : options.updateInterval;
29
-
30
- var _useIntlContext = useIntlContext(),
31
- globalNow = _useIntlContext.now;
32
-
33
- var _useState = useState(globalNow || getNow()),
34
- now = _useState[0],
35
- setNow = _useState[1];
36
-
37
- useEffect(function () {
38
- if (!updateInterval) return;
39
- var intervalId = setInterval(function () {
40
- setNow(getNow());
41
- }, updateInterval);
42
- return function () {
43
- clearInterval(intervalId);
44
- };
45
- }, [globalNow, updateInterval]);
46
- return now;
47
- }
48
-
49
- export { useNow as default };
7
+ export { useLocale as default };
50
8
  //# sourceMappingURL=use-intl.esm5.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-intl.esm5.js","sources":["../../src/react/useNow.tsx"],"sourcesContent":["import {useState, useEffect} from 'react';\nimport useIntlContext from './useIntlContext';\n\ntype Options = {\n updateInterval?: number;\n};\n\nfunction getNow() {\n return new Date();\n}\n\n/**\n * Reading the current date via `new Date()` in components should be avoided, as\n * it causes components to be impure and can lead to flaky tests. Instead, this\n * hook can be used.\n *\n * By default, it returns the time when the component mounts. If `updateInterval`\n * is specified, the value will be updated based on the interval.\n *\n * You can however also return a static value from this hook, if you\n * configure the `now` parameter on the context provider. Note however,\n * that if `updateInterval` is configured in this case, the component\n * will initialize with the global value, but will afterwards update\n * continuously based on the interval.\n *\n * For unit tests, this can be mocked to a constant value. For end-to-end\n * testing, an environment parameter can be passed to the `now` parameter\n * of the provider to mock this to a static value.\n */\nexport default function useNow(options?: Options) {\n const updateInterval = options?.updateInterval;\n\n const {now: globalNow} = useIntlContext();\n const [now, setNow] = useState(globalNow || getNow());\n\n useEffect(() => {\n if (!updateInterval) return;\n\n const intervalId = setInterval(() => {\n setNow(getNow());\n }, updateInterval);\n\n return () => {\n clearInterval(intervalId);\n };\n }, [globalNow, updateInterval]);\n\n return now;\n}\n"],"names":["getNow","Date","useNow","options","updateInterval","useIntlContext","globalNow","now","useState","setNow","useEffect","intervalId","setInterval","clearInterval"],"mappings":";;;AAOA,SAASA,MAAT,GAAe;AACb,EAAO,OAAA,IAAIC,IAAJ,EAAP,CAAA;AACD,CAAA;AAED;;;;;;;;;;;;;;;;;AAiBG;;;AACqB,SAAAC,MAAA,CAAOC,OAAP,EAAwB;AAC9C,EAAA,IAAMC,cAAc,GAAGD,OAAH,IAAGA,IAAAA,GAAAA,KAAAA,CAAAA,GAAAA,OAAO,CAAEC,cAAhC,CAAA;;AAEA,EAAA,IAAA,eAAA,GAAyBC,cAAc,EAAvC;AAAA,MAAYC,SAAZ,mBAAOC,GAAP,CAAA;;AACA,EAAA,IAAA,SAAA,GAAsBC,QAAQ,CAACF,SAAS,IAAIN,MAAM,EAApB,CAA9B;AAAA,MAAOO,GAAP,GAAA,SAAA,CAAA,CAAA,CAAA;AAAA,MAAYE,MAAZ,GAAA,SAAA,CAAA,CAAA,CAAA,CAAA;;AAEAC,EAAAA,SAAS,CAAC,YAAK;AACb,IAAI,IAAA,CAACN,cAAL,EAAqB,OAAA;AAErB,IAAA,IAAMO,UAAU,GAAGC,WAAW,CAAC,YAAK;AAClCH,MAAAA,MAAM,CAACT,MAAM,EAAP,CAAN,CAAA;AACD,KAF6B,EAE3BI,cAF2B,CAA9B,CAAA;AAIA,IAAA,OAAO,YAAK;AACVS,MAAAA,aAAa,CAACF,UAAD,CAAb,CAAA;AACD,KAFD,CAAA;AAGD,GAVQ,EAUN,CAACL,SAAD,EAAYF,cAAZ,CAVM,CAAT,CAAA;AAYA,EAAA,OAAOG,GAAP,CAAA;AACD;;;;"}
1
+ {"version":3,"file":"use-intl.esm5.js","sources":["../../src/react/useLocale.tsx"],"sourcesContent":["import useIntlContext from './useIntlContext';\n\nexport default function useLocale() {\n return useIntlContext().locale;\n}\n"],"names":["useLocale","useIntlContext","locale"],"mappings":";;AAEc,SAAUA,SAAV,GAAmB;AAC/B,EAAOC,OAAAA,cAAc,GAAGC,MAAxB,CAAA;AACD;;;;"}
@@ -1,4 +1,4 @@
1
- import useIntlContext from './use-intl.esm8.js';
1
+ import useIntlContext from './use-intl.esm9.js';
2
2
 
3
3
  function useTimeZone() {
4
4
  return useIntlContext().timeZone;
@@ -1 +1 @@
1
- {"version":3,"file":"use-intl.esm7.js","sources":["../../src/react/IntlContext.tsx"],"sourcesContent":["import {createContext} from 'react';\nimport AbstractIntlMessages from '../core/AbstractIntlMessages';\nimport Formats from '../core/Formats';\nimport IntlError from '../core/IntlError';\nimport {RichTranslationValues} from '../core/TranslationValues';\n\nexport type IntlContextShape = {\n messages?: AbstractIntlMessages;\n locale: string;\n formats?: Partial<Formats>;\n timeZone?: string;\n onError(error: IntlError): void;\n getMessageFallback(info: {\n error: IntlError;\n key: string;\n namespace?: string;\n }): string;\n now?: Date;\n defaultTranslationValues?: RichTranslationValues;\n};\n\nconst IntlContext = createContext<IntlContextShape | undefined>(undefined);\n\nexport default IntlContext;\n"],"names":["IntlContext","createContext","undefined"],"mappings":";;AAqBA,IAAMA,WAAW,gBAAGC,aAAa,CAA+BC,SAA/B;;;;"}
1
+ {"version":3,"file":"use-intl.esm7.js","sources":["../../src/react/IntlContext.tsx"],"sourcesContent":["import {createContext} from 'react';\nimport IntlContextValue from './IntlContextValue';\n\nconst IntlContext = createContext<IntlContextValue | undefined>(undefined);\n\nexport default IntlContext;\n"],"names":["IntlContext","createContext","undefined"],"mappings":";;AAGA,IAAMA,WAAW,gBAAGC,aAAa,CAA+BC,SAA/B;;;;"}
@@ -1,15 +1,33 @@
1
- import { useContext } from 'react';
2
- import IntlContext from './use-intl.esm7.js';
1
+ import { objectWithoutPropertiesLoose as _objectWithoutPropertiesLoose, extends as _extends } from '../_virtual/use-intl.esm.js';
2
+ import { defaultOnError, defaultGetMessageFallback } from '../core/use-intl.esm4.js';
3
+ import validateMessages from '../core/use-intl.esm8.js';
3
4
 
4
- function useIntlContext() {
5
- var context = useContext(IntlContext);
5
+ var _excluded = ["getMessageFallback", "messages", "onError"];
6
+ /**
7
+ * Enhances the incoming props with defaults.
8
+ */
6
9
 
7
- if (!context) {
8
- throw new Error(process.env.NODE_ENV !== "production" ? 'No intl context found. Have you configured the provider?' : undefined);
10
+ function getIntlContextValue(_ref) {
11
+ var getMessageFallback = _ref.getMessageFallback,
12
+ messages = _ref.messages,
13
+ onError = _ref.onError,
14
+ rest = _objectWithoutPropertiesLoose(_ref, _excluded);
15
+
16
+ var finalOnError = onError || defaultOnError;
17
+ var finalGetMessageFallback = getMessageFallback || defaultGetMessageFallback;
18
+
19
+ if (process.env.NODE_ENV !== 'production') {
20
+ if (messages) {
21
+ validateMessages(messages, finalOnError);
22
+ }
9
23
  }
10
24
 
11
- return context;
25
+ return _extends({}, rest, {
26
+ messages: messages,
27
+ onError: finalOnError,
28
+ getMessageFallback: finalGetMessageFallback
29
+ });
12
30
  }
13
31
 
14
- export { useIntlContext as default };
32
+ export { getIntlContextValue as default };
15
33
  //# sourceMappingURL=use-intl.esm8.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-intl.esm8.js","sources":["../../src/react/useIntlContext.tsx"],"sourcesContent":["import {useContext} from 'react';\nimport IntlContext from './IntlContext';\n\nexport default function useIntlContext() {\n const context = useContext(IntlContext);\n\n if (!context) {\n throw new Error(\n __DEV__\n ? 'No intl context found. Have you configured the provider?'\n : undefined\n );\n }\n\n return context;\n}\n"],"names":["useIntlContext","context","useContext","IntlContext","Error","undefined"],"mappings":";;;AAGc,SAAUA,cAAV,GAAwB;AACpC,EAAA,IAAMC,OAAO,GAAGC,UAAU,CAACC,WAAD,CAA1B,CAAA;;AAEA,EAAI,IAAA,CAACF,OAAL,EAAc;AACZ,IAAA,MAAM,IAAIG,KAAJ,CACJ,wCACI,0DADJ,GAEIC,SAHA,CAAN,CAAA;AAKD,GAAA;;AAED,EAAA,OAAOJ,OAAP,CAAA;AACD;;;;"}
1
+ {"version":3,"file":"use-intl.esm8.js","sources":["../../src/react/getIntlContextValue.tsx"],"sourcesContent":["import {defaultGetMessageFallback, defaultOnError} from '../core/defaults';\nimport validateMessages from '../core/validateMessages';\nimport IntlProviderProps from './IntlProviderProps';\n\n/**\n * Enhances the incoming props with defaults.\n */\nexport default function getIntlContextValue({\n getMessageFallback,\n messages,\n onError,\n ...rest\n}: Omit<IntlProviderProps, 'children'>) {\n const finalOnError = onError || defaultOnError;\n const finalGetMessageFallback =\n getMessageFallback || defaultGetMessageFallback;\n\n if (process.env.NODE_ENV !== 'production') {\n if (messages) {\n validateMessages(messages, finalOnError);\n }\n }\n\n return {\n ...rest,\n messages,\n onError: finalOnError,\n getMessageFallback: finalGetMessageFallback\n };\n}\n"],"names":["getIntlContextValue","getMessageFallback","messages","onError","rest","finalOnError","defaultOnError","finalGetMessageFallback","defaultGetMessageFallback","process","env","NODE_ENV","validateMessages"],"mappings":";;;;;AAIA;;AAEG;;AACqB,SAAAA,mBAAA,CAKc,IAAA,EAAA;AAAA,EAJpCC,IAAAA,kBAIoC,QAJpCA,kBAIoC;AAAA,MAHpCC,QAGoC,QAHpCA,QAGoC;AAAA,MAFpCC,OAEoC,QAFpCA,OAEoC;AAAA,MADjCC,IACiC,GAAA,6BAAA,CAAA,IAAA,EAAA,SAAA,CAAA,CAAA;;AACpC,EAAA,IAAMC,YAAY,GAAGF,OAAO,IAAIG,cAAhC,CAAA;AACA,EAAA,IAAMC,uBAAuB,GAC3BN,kBAAkB,IAAIO,yBADxB,CAAA;;AAGA,EAAA,IAAIC,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YAA7B,EAA2C;AACzC,IAAA,IAAIT,QAAJ,EAAc;AACZU,MAAAA,gBAAgB,CAACV,QAAD,EAAWG,YAAX,CAAhB,CAAA;AACD,KAAA;AACF,GAAA;;AAED,EAAA,OAAA,QAAA,CAAA,EAAA,EACKD,IADL,EAAA;AAEEF,IAAAA,QAAQ,EAARA,QAFF;AAGEC,IAAAA,OAAO,EAAEE,YAHX;AAIEJ,IAAAA,kBAAkB,EAAEM,uBAAAA;AAJtB,GAAA,CAAA,CAAA;AAMD;;;;"}
@@ -1,44 +1,15 @@
1
- import { useRef, useMemo } from 'react';
2
- import createBaseTranslator, { getMessagesOrError } from '../core/use-intl.esm7.js';
3
- import resolveNamespace from '../core/use-intl.esm8.js';
4
- import useIntlContext from './use-intl.esm8.js';
1
+ import { useContext } from 'react';
2
+ import IntlContext from './use-intl.esm7.js';
5
3
 
6
- function useTranslationsImpl(allMessages, namespace, namespacePrefix) {
7
- var _useIntlContext = useIntlContext(),
8
- defaultTranslationValues = _useIntlContext.defaultTranslationValues,
9
- globalFormats = _useIntlContext.formats,
10
- getMessageFallback = _useIntlContext.getMessageFallback,
11
- locale = _useIntlContext.locale,
12
- onError = _useIntlContext.onError,
13
- timeZone = _useIntlContext.timeZone; // The `namespacePrefix` is part of the type system.
14
- // See the comment in the hook invocation.
4
+ function useIntlContext() {
5
+ var context = useContext(IntlContext);
15
6
 
7
+ if (!context) {
8
+ throw new Error(process.env.NODE_ENV !== 'production' ? 'No intl context found. Have you configured the provider?' : undefined);
9
+ }
16
10
 
17
- allMessages = allMessages[namespacePrefix];
18
- namespace = resolveNamespace(namespace, namespacePrefix);
19
- var cachedFormatsByLocaleRef = useRef({});
20
- var messagesOrError = useMemo(function () {
21
- return getMessagesOrError({
22
- messages: allMessages,
23
- namespace: namespace,
24
- onError: onError
25
- });
26
- }, [allMessages, namespace, onError]);
27
- var translate = useMemo(function () {
28
- return createBaseTranslator({
29
- cachedFormatsByLocale: cachedFormatsByLocaleRef.current,
30
- getMessageFallback: getMessageFallback,
31
- messagesOrError: messagesOrError,
32
- defaultTranslationValues: defaultTranslationValues,
33
- namespace: namespace,
34
- onError: onError,
35
- formats: globalFormats,
36
- locale: locale,
37
- timeZone: timeZone
38
- });
39
- }, [getMessageFallback, messagesOrError, defaultTranslationValues, namespace, onError, globalFormats, locale, timeZone]);
40
- return translate;
11
+ return context;
41
12
  }
42
13
 
43
- export { useTranslationsImpl as default };
14
+ export { useIntlContext as default };
44
15
  //# sourceMappingURL=use-intl.esm9.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-intl.esm9.js","sources":["../../src/react/useTranslationsImpl.tsx"],"sourcesContent":["import {IntlMessageFormat} from 'intl-messageformat';\nimport {useMemo, useRef} from 'react';\nimport AbstractIntlMessages from '../core/AbstractIntlMessages';\nimport createBaseTranslator, {\n getMessagesOrError\n} from '../core/createBaseTranslator';\nimport resolveNamespace from '../core/resolveNamespace';\nimport NestedKeyOf from '../core/utils/NestedKeyOf';\nimport useIntlContext from './useIntlContext';\n\nexport default function useTranslationsImpl<\n Messages extends AbstractIntlMessages,\n NestedKey extends NestedKeyOf<Messages>\n>(allMessages: Messages, namespace: NestedKey, namespacePrefix: string) {\n const {\n defaultTranslationValues,\n formats: globalFormats,\n getMessageFallback,\n locale,\n onError,\n timeZone\n } = useIntlContext();\n\n // The `namespacePrefix` is part of the type system.\n // See the comment in the hook invocation.\n allMessages = allMessages[namespacePrefix] as Messages;\n namespace = resolveNamespace(namespace, namespacePrefix) as NestedKey;\n\n const cachedFormatsByLocaleRef = useRef<\n Record<string, Record<string, IntlMessageFormat>>\n >({});\n\n const messagesOrError = useMemo(\n () => getMessagesOrError({messages: allMessages, namespace, onError}),\n [allMessages, namespace, onError]\n );\n\n const translate = useMemo(\n () =>\n createBaseTranslator({\n cachedFormatsByLocale: cachedFormatsByLocaleRef.current,\n getMessageFallback,\n messagesOrError,\n defaultTranslationValues,\n namespace,\n onError,\n formats: globalFormats,\n locale,\n timeZone\n }),\n [\n getMessageFallback,\n messagesOrError,\n defaultTranslationValues,\n namespace,\n onError,\n globalFormats,\n locale,\n timeZone\n ]\n );\n\n return translate;\n}\n"],"names":["useTranslationsImpl","allMessages","namespace","namespacePrefix","useIntlContext","defaultTranslationValues","globalFormats","formats","getMessageFallback","locale","onError","timeZone","resolveNamespace","cachedFormatsByLocaleRef","useRef","messagesOrError","useMemo","getMessagesOrError","messages","translate","createBaseTranslator","cachedFormatsByLocale","current"],"mappings":";;;;;AAUwB,SAAAA,mBAAA,CAGtBC,WAHsB,EAGCC,SAHD,EAGuBC,eAHvB,EAG8C;AACpE,EAAA,IAAA,eAAA,GAOIC,cAAc,EAPlB;AAAA,MACEC,wBADF,mBACEA,wBADF;AAAA,MAEWC,aAFX,mBAEEC,OAFF;AAAA,MAGEC,kBAHF,mBAGEA,kBAHF;AAAA,MAIEC,MAJF,mBAIEA,MAJF;AAAA,MAKEC,OALF,mBAKEA,OALF;AAAA,MAMEC,QANF,GAAA,eAAA,CAMEA,QANF,CADoE;AAWpE;;;AACAV,EAAAA,WAAW,GAAGA,WAAW,CAACE,eAAD,CAAzB,CAAA;AACAD,EAAAA,SAAS,GAAGU,gBAAgB,CAACV,SAAD,EAAYC,eAAZ,CAA5B,CAAA;AAEA,EAAA,IAAMU,wBAAwB,GAAGC,MAAM,CAErC,EAFqC,CAAvC,CAAA;AAIA,EAAMC,IAAAA,eAAe,GAAGC,OAAO,CAC7B,YAAA;AAAA,IAAA,OAAMC,kBAAkB,CAAC;AAACC,MAAAA,QAAQ,EAAEjB,WAAX;AAAwBC,MAAAA,SAAS,EAATA,SAAxB;AAAmCQ,MAAAA,OAAO,EAAPA,OAAAA;AAAnC,KAAD,CAAxB,CAAA;AAAA,GAD6B,EAE7B,CAACT,WAAD,EAAcC,SAAd,EAAyBQ,OAAzB,CAF6B,CAA/B,CAAA;AAKA,EAAMS,IAAAA,SAAS,GAAGH,OAAO,CACvB,YAAA;AAAA,IAAA,OACEI,oBAAoB,CAAC;AACnBC,MAAAA,qBAAqB,EAAER,wBAAwB,CAACS,OAD7B;AAEnBd,MAAAA,kBAAkB,EAAlBA,kBAFmB;AAGnBO,MAAAA,eAAe,EAAfA,eAHmB;AAInBV,MAAAA,wBAAwB,EAAxBA,wBAJmB;AAKnBH,MAAAA,SAAS,EAATA,SALmB;AAMnBQ,MAAAA,OAAO,EAAPA,OANmB;AAOnBH,MAAAA,OAAO,EAAED,aAPU;AAQnBG,MAAAA,MAAM,EAANA,MARmB;AASnBE,MAAAA,QAAQ,EAARA,QAAAA;AATmB,KAAD,CADtB,CAAA;AAAA,GADuB,EAavB,CACEH,kBADF,EAEEO,eAFF,EAGEV,wBAHF,EAIEH,SAJF,EAKEQ,OALF,EAMEJ,aANF,EAOEG,MAPF,EAQEE,QARF,CAbuB,CAAzB,CAAA;AAyBA,EAAA,OAAOQ,SAAP,CAAA;AACD;;;;"}
1
+ {"version":3,"file":"use-intl.esm9.js","sources":["../../src/react/useIntlContext.tsx"],"sourcesContent":["import {useContext} from 'react';\nimport IntlContext from './IntlContext';\n\nexport default function useIntlContext() {\n const context = useContext(IntlContext);\n\n if (!context) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? 'No intl context found. Have you configured the provider?'\n : undefined\n );\n }\n\n return context;\n}\n"],"names":["useIntlContext","context","useContext","IntlContext","Error","process","env","NODE_ENV","undefined"],"mappings":";;;AAGc,SAAUA,cAAV,GAAwB;AACpC,EAAA,IAAMC,OAAO,GAAGC,UAAU,CAACC,WAAD,CAA1B,CAAA;;AAEA,EAAI,IAAA,CAACF,OAAL,EAAc;AACZ,IAAA,MAAM,IAAIG,KAAJ,CACJC,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YAAzB,GACI,0DADJ,GAEIC,SAHA,CAAN,CAAA;AAKD,GAAA;;AAED,EAAA,OAAOP,OAAP,CAAA;AACD;;;;"}
@@ -1 +1 @@
1
- export default function useIntlContext(): import("./IntlContext").IntlContextShape;
1
+ export default function useIntlContext(): import("./IntlContextValue").default;
@@ -0,0 +1,9 @@
1
+ /** A generic type that describes the shape of messages.
2
+ *
3
+ * Optionally `IntlMessages` can be provided to get type safety for message
4
+ * namespaces and keys. See https://next-intl-docs.vercel.app/docs/usage/typescript
5
+ */
6
+ declare type AbstractIntlMessages = {
7
+ [id: string]: AbstractIntlMessages | string;
8
+ };
9
+ export default AbstractIntlMessages;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=AbstractIntlMessages.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AbstractIntlMessages.js","sourceRoot":"","sources":["../../../src/core/AbstractIntlMessages.tsx"],"names":[],"mappings":""}
@@ -0,0 +1,72 @@
1
+ /**
2
+ * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat
3
+ */
4
+ declare type DateTimeFormatOptions = Intl.DateTimeFormatOptions & {
5
+ /**
6
+ * Examples:
7
+ * - numeric: "2021"
8
+ * - 2-digit: "21"
9
+ */
10
+ year?: 'numeric' | '2-digit';
11
+ /** Examples:
12
+ * - numeric: "3"
13
+ * - 2-digit: "03"
14
+ * - long: "March"
15
+ * - short: "Mar"
16
+ * - narrow: "M"
17
+ */
18
+ month?: 'numeric' | '2-digit' | 'long' | 'short' | 'narrow';
19
+ /** Examples:
20
+ * - numeric: "2"
21
+ * - 2-digit: "02"
22
+ */
23
+ day?: 'numeric' | '2-digit';
24
+ /** Examples:
25
+ * - numeric: "2"
26
+ * - 2-digit: "02"
27
+ */
28
+ hour?: 'numeric' | '2-digit';
29
+ /** Examples:
30
+ * - numeric: "2"
31
+ * - 2-digit: "02"
32
+ */
33
+ minute?: 'numeric' | '2-digit';
34
+ /** Examples:
35
+ * - numeric: "2"
36
+ * - 2-digit: "02"
37
+ */
38
+ second?: 'numeric' | '2-digit';
39
+ /** Examples:
40
+ * - long: "Thursday"
41
+ * - short: "Thu"
42
+ * - narrow: "T"
43
+ */
44
+ weekday?: 'long' | 'short' | 'narrow';
45
+ /** Examples:
46
+ * - long: "Anno Domini"
47
+ * - short: "AD", narrow "A"
48
+ */
49
+ era?: 'long' | 'short' | 'narrow';
50
+ /** If this is set to `true`, a 12-hour am/pm format is used. Otherwise a 24-hour time.
51
+ *
52
+ */
53
+ hour12?: boolean;
54
+ /** Examples:
55
+ * - long: "Pacific Daylight Time"
56
+ * - short: "PDT"
57
+ */
58
+ timeZoneName?: 'long' | 'short';
59
+ /**
60
+ * One of the [database names from the TZ database](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List).
61
+ */
62
+ timeZone?: string;
63
+ localeMatcher?: 'best fit' | 'lookup';
64
+ formatMatcher?: 'best fit' | 'basic';
65
+ dateStyle?: 'full' | 'long' | 'medium' | 'short';
66
+ timeStyle?: 'full' | 'long' | 'medium' | 'short';
67
+ calendar?: 'buddhist' | 'chinese' | 'coptic' | 'ethiopia' | 'ethiopic' | 'gregory' | 'hebrew' | 'indian' | 'islamic' | 'iso8601' | 'japanese' | 'persian' | 'roc';
68
+ dayPeriod?: 'narrow' | 'short' | 'long';
69
+ numberingSystem?: 'arab' | 'arabext' | 'bali' | 'beng' | 'deva' | 'fullwide' | 'gujr' | 'guru' | 'hanidec' | 'khmr' | 'knda' | 'laoo' | 'latn' | 'limb' | 'mlym' | 'mong' | 'mymr' | 'orya' | 'tamldec' | 'telu' | 'thai' | 'tibt';
70
+ hourCycle?: 'h11' | 'h12' | 'h23' | 'h24';
71
+ };
72
+ export default DateTimeFormatOptions;
@@ -0,0 +1,3 @@
1
+ // https://github.com/microsoft/TypeScript/issues/35865
2
+ export {};
3
+ //# sourceMappingURL=DateTimeFormatOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DateTimeFormatOptions.js","sourceRoot":"","sources":["../../../src/core/DateTimeFormatOptions.tsx"],"names":[],"mappings":"AAAA,uDAAuD"}
@@ -0,0 +1,7 @@
1
+ import DateTimeFormatOptions from './DateTimeFormatOptions';
2
+ import NumberFormatOptions from './NumberFormatOptions';
3
+ declare type Formats = {
4
+ number: Record<string, NumberFormatOptions>;
5
+ dateTime: Record<string, DateTimeFormatOptions>;
6
+ };
7
+ export default Formats;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=Formats.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Formats.js","sourceRoot":"","sources":["../../../src/core/Formats.tsx"],"names":[],"mappings":""}
@@ -0,0 +1,46 @@
1
+ import Formats from './Formats';
2
+ import IntlError from './IntlError';
3
+ /**
4
+ * Should be used for entry points that configure the library.
5
+ */
6
+ declare type IntlConfiguration = {
7
+ /** A valid Unicode locale tag (e.g. "en" or "en-GB"). */
8
+ locale: string;
9
+ /** Global formats can be provided to achieve consistent
10
+ * formatting across components. */
11
+ formats?: Partial<Formats>;
12
+ /** A time zone as defined in [the tz database](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones) which will be applied when formatting dates and times. If this is absent, the user time zone will be used. You can override this by supplying an explicit time zone to `formatDateTime`. */
13
+ timeZone?: string;
14
+ /** This callback will be invoked when an error is encountered during
15
+ * resolving a message or formatting it. This defaults to `console.error` to
16
+ * keep your app running. You can customize the handling by taking
17
+ * `error.code` into account. */
18
+ onError?(error: IntlError): void;
19
+ /** Will be called when a message couldn't be resolved or formatting it led to
20
+ * an error. This defaults to `${namespace}.${key}` You can use this to
21
+ * customize what will be rendered in this case. */
22
+ getMessageFallback?(info: {
23
+ error: IntlError;
24
+ key: string;
25
+ namespace?: string;
26
+ }): string;
27
+ /**
28
+ * Providing this value will have two effects:
29
+ * 1. It will be used as the default for the `now` argument of
30
+ * `useIntl().formatRelativeTime` if no explicit value is provided.
31
+ * 2. It will be returned as a static value from the `useNow` hook. Note
32
+ * however that when `updateInterval` is configured on the `useNow` hook,
33
+ * the global `now` value will only be used for the initial render, but
34
+ * afterwards the current date will be returned continuously.
35
+ */
36
+ now?: Date;
37
+ };
38
+ /**
39
+ * A stricter set of the configuration that should be used internally
40
+ * once defaults are assigned to `IntlConfiguration`.
41
+ */
42
+ export declare type InitializedIntlConfiguration = IntlConfiguration & {
43
+ onError: NonNullable<IntlConfiguration['onError']>;
44
+ getMessageFallback: NonNullable<IntlConfiguration['getMessageFallback']>;
45
+ };
46
+ export default IntlConfiguration;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=IntlConfiguration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IntlConfiguration.js","sourceRoot":"","sources":["../../../src/core/IntlConfiguration.tsx"],"names":[],"mappings":""}
@@ -0,0 +1,13 @@
1
+ export declare enum IntlErrorCode {
2
+ MISSING_MESSAGE = "MISSING_MESSAGE",
3
+ MISSING_FORMAT = "MISSING_FORMAT",
4
+ INSUFFICIENT_PATH = "INSUFFICIENT_PATH",
5
+ INVALID_MESSAGE = "INVALID_MESSAGE",
6
+ INVALID_KEY = "INVALID_KEY",
7
+ FORMATTING_ERROR = "FORMATTING_ERROR"
8
+ }
9
+ export default class IntlError extends Error {
10
+ readonly code: IntlErrorCode;
11
+ readonly originalMessage: string | undefined;
12
+ constructor(code: IntlErrorCode, originalMessage?: string);
13
+ }
@@ -0,0 +1,23 @@
1
+ export var IntlErrorCode;
2
+ (function (IntlErrorCode) {
3
+ IntlErrorCode["MISSING_MESSAGE"] = "MISSING_MESSAGE";
4
+ IntlErrorCode["MISSING_FORMAT"] = "MISSING_FORMAT";
5
+ IntlErrorCode["INSUFFICIENT_PATH"] = "INSUFFICIENT_PATH";
6
+ IntlErrorCode["INVALID_MESSAGE"] = "INVALID_MESSAGE";
7
+ IntlErrorCode["INVALID_KEY"] = "INVALID_KEY";
8
+ IntlErrorCode["FORMATTING_ERROR"] = "FORMATTING_ERROR";
9
+ })(IntlErrorCode || (IntlErrorCode = {}));
10
+ export default class IntlError extends Error {
11
+ constructor(code, originalMessage) {
12
+ let message = code;
13
+ if (originalMessage) {
14
+ message += ': ' + originalMessage;
15
+ }
16
+ super(message);
17
+ this.code = code;
18
+ if (originalMessage) {
19
+ this.originalMessage = originalMessage;
20
+ }
21
+ }
22
+ }
23
+ //# sourceMappingURL=IntlError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IntlError.js","sourceRoot":"","sources":["../../../src/core/IntlError.tsx"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,aAOX;AAPD,WAAY,aAAa;IACvB,oDAAmC,CAAA;IACnC,kDAAiC,CAAA;IACjC,wDAAuC,CAAA;IACvC,oDAAmC,CAAA;IACnC,4CAA2B,CAAA;IAC3B,sDAAqC,CAAA;AACvC,CAAC,EAPW,aAAa,KAAb,aAAa,QAOxB;AAED,MAAM,CAAC,OAAO,OAAO,SAAU,SAAQ,KAAK;IAI1C,YAAY,IAAmB,EAAE,eAAwB;QACvD,IAAI,OAAO,GAAW,IAAI,CAAC;QAC3B,IAAI,eAAe,EAAE;YACnB,OAAO,IAAI,IAAI,GAAG,eAAe,CAAC;SACnC;QACD,KAAK,CAAC,OAAO,CAAC,CAAC;QAEf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,eAAe,EAAE;YACnB,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;SACxC;IACH,CAAC;CACF"}
@@ -0,0 +1,2 @@
1
+ declare interface IntlMessages extends Record<string, any> {
2
+ }
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ // This module is intended to be overridden
3
+ // by the consumer for optional type safety
4
+ //# sourceMappingURL=IntlMessages.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IntlMessages.js","sourceRoot":"","sources":["../../../src/core/IntlMessages.tsx"],"names":[],"mappings":";AAAA,2CAA2C;AAC3C,2CAA2C"}
@@ -0,0 +1,2 @@
1
+ import type { NumberFormatOptions } from '@formatjs/ecma402-abstract/types/number';
2
+ export default NumberFormatOptions;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=NumberFormatOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NumberFormatOptions.js","sourceRoot":"","sources":["../../../src/core/NumberFormatOptions.tsx"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ import { ReactNode } from 'react';
2
+ export declare type TranslationValue = string | number | boolean | Date | null | undefined;
3
+ declare type TranslationValues = Record<string, TranslationValue>;
4
+ export declare type RichTranslationValues = Record<string, TranslationValue | ((chunks: ReactNode) => ReactNode)>;
5
+ export default TranslationValues;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=TranslationValues.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TranslationValues.js","sourceRoot":"","sources":["../../../src/core/TranslationValues.tsx"],"names":[],"mappings":""}
@@ -0,0 +1,10 @@
1
+ import { Formats as IntlFormats } from 'intl-messageformat';
2
+ import Formats from './Formats';
3
+ /**
4
+ * `intl-messageformat` uses separate keys for `date` and `time`, but there's
5
+ * only one native API: `Intl.DateTimeFormat`. Additionally you might want to
6
+ * include both a time and a date in a value, therefore the separation doesn't
7
+ * seem so useful. We offer a single `dateTime` namespace instead, but we have
8
+ * to convert the format before `intl-messageformat` can be used.
9
+ */
10
+ export default function convertFormatsToIntlMessageFormat(formats: Partial<Formats>, timeZone?: string): Partial<IntlFormats>;
@@ -0,0 +1,31 @@
1
+ function setTimeZoneInFormats(formats, timeZone) {
2
+ if (!formats)
3
+ return formats;
4
+ // The only way to set a time zone with `intl-messageformat` is to merge it into the formats
5
+ // https://github.com/formatjs/formatjs/blob/8256c5271505cf2606e48e3c97ecdd16ede4f1b5/packages/intl/src/message.ts#L15
6
+ return Object.keys(formats).reduce((acc, key) => {
7
+ acc[key] = {
8
+ timeZone,
9
+ ...formats[key]
10
+ };
11
+ return acc;
12
+ }, {});
13
+ }
14
+ /**
15
+ * `intl-messageformat` uses separate keys for `date` and `time`, but there's
16
+ * only one native API: `Intl.DateTimeFormat`. Additionally you might want to
17
+ * include both a time and a date in a value, therefore the separation doesn't
18
+ * seem so useful. We offer a single `dateTime` namespace instead, but we have
19
+ * to convert the format before `intl-messageformat` can be used.
20
+ */
21
+ export default function convertFormatsToIntlMessageFormat(formats, timeZone) {
22
+ const formatsWithTimeZone = timeZone
23
+ ? { ...formats, dateTime: setTimeZoneInFormats(formats.dateTime, timeZone) }
24
+ : formats;
25
+ return {
26
+ ...formatsWithTimeZone,
27
+ date: formatsWithTimeZone?.dateTime,
28
+ time: formatsWithTimeZone?.dateTime
29
+ };
30
+ }
31
+ //# sourceMappingURL=convertFormatsToIntlMessageFormat.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"convertFormatsToIntlMessageFormat.js","sourceRoot":"","sources":["../../../src/core/convertFormatsToIntlMessageFormat.tsx"],"names":[],"mappings":"AAIA,SAAS,oBAAoB,CAC3B,OAA0D,EAC1D,QAAgB;IAEhB,IAAI,CAAC,OAAO;QAAE,OAAO,OAAO,CAAC;IAE7B,4FAA4F;IAC5F,sHAAsH;IACtH,OAAO,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,CAChC,CAAC,GAA0C,EAAE,GAAG,EAAE,EAAE;QAClD,GAAG,CAAC,GAAG,CAAC,GAAG;YACT,QAAQ;YACR,GAAG,OAAO,CAAC,GAAG,CAAC;SAChB,CAAC;QACF,OAAO,GAAG,CAAC;IACb,CAAC,EACD,EAAE,CACH,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,iCAAiC,CACvD,OAAyB,EACzB,QAAiB;IAEjB,MAAM,mBAAmB,GAAG,QAAQ;QAClC,CAAC,CAAC,EAAC,GAAG,OAAO,EAAE,QAAQ,EAAE,oBAAoB,CAAC,OAAO,CAAC,QAAQ,EAAE,QAAQ,CAAC,EAAC;QAC1E,CAAC,CAAC,OAAO,CAAC;IAEZ,OAAO;QACL,GAAG,mBAAmB;QACtB,IAAI,EAAE,mBAAmB,EAAE,QAAQ;QACnC,IAAI,EAAE,mBAAmB,EAAE,QAAQ;KACpC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,26 @@
1
+ import IntlMessageFormat from 'intl-messageformat';
2
+ import { ReactElement, ReactNodeArray } from 'react';
3
+ import AbstractIntlMessages from './AbstractIntlMessages';
4
+ import Formats from './Formats';
5
+ import { InitializedIntlConfiguration } from './IntlConfiguration';
6
+ import IntlError from './IntlError';
7
+ import TranslationValues, { RichTranslationValues } from './TranslationValues';
8
+ import MessageKeys from './utils/MessageKeys';
9
+ import NestedKeyOf from './utils/NestedKeyOf';
10
+ import NestedValueOf from './utils/NestedValueOf';
11
+ export declare function getMessagesOrError<Messages extends AbstractIntlMessages>({ messages, namespace, onError }: {
12
+ messages: Messages;
13
+ namespace?: string;
14
+ onError?(error: IntlError): void;
15
+ }): AbstractIntlMessages | IntlError;
16
+ export declare type CreateBaseTranslatorProps<Messages> = InitializedIntlConfiguration & {
17
+ cachedFormatsByLocale?: Record<string, Record<string, IntlMessageFormat>>;
18
+ defaultTranslationValues?: RichTranslationValues;
19
+ namespace?: string;
20
+ messagesOrError: Messages | IntlError;
21
+ };
22
+ export default function createBaseTranslator<Messages extends AbstractIntlMessages, NestedKey extends NestedKeyOf<Messages>>({ cachedFormatsByLocale, defaultTranslationValues, formats: globalFormats, getMessageFallback, locale, messagesOrError, namespace, onError, timeZone }: CreateBaseTranslatorProps<Messages>): {
23
+ <TargetKey extends MessageKeys<NestedValueOf<Messages, NestedKey>, NestedKeyOf<NestedValueOf<Messages, NestedKey>>>>(key: TargetKey, values?: TranslationValues | undefined, formats?: Partial<Formats> | undefined): string;
24
+ rich: (key: string, values?: RichTranslationValues | undefined, formats?: Partial<Formats> | undefined) => string | ReactElement | ReactNodeArray;
25
+ raw(key: string): any;
26
+ };