use-intl 2.13.1 → 2.13.4

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 (91) hide show
  1. package/README.md +1 -1
  2. package/dist/_virtual/use-intl.esm.js +4 -28
  3. package/dist/_virtual/use-intl.esm.js.map +1 -1
  4. package/dist/core/AbstractIntlMessages.d.ts +1 -1
  5. package/dist/core/DateTimeFormatOptions.d.ts +1 -1
  6. package/dist/core/Formats.d.ts +1 -1
  7. package/dist/core/IntlConfig.d.ts +2 -2
  8. package/dist/core/TranslationValues.d.ts +3 -3
  9. package/dist/core/createBaseTranslator.d.ts +3 -3
  10. package/dist/core/createFormatter.d.ts +4 -4
  11. package/dist/core/createIntl.d.ts +1 -1
  12. package/dist/core/createTranslator.d.ts +1 -1
  13. package/dist/core/createTranslatorImpl.d.ts +2 -2
  14. package/dist/core/use-intl.esm.js +0 -9
  15. package/dist/core/use-intl.esm.js.map +1 -1
  16. package/dist/core/use-intl.esm10.js +2 -4
  17. package/dist/core/use-intl.esm10.js.map +1 -1
  18. package/dist/core/use-intl.esm2.js +10 -12
  19. package/dist/core/use-intl.esm2.js.map +1 -1
  20. package/dist/core/use-intl.esm3.js +13 -36
  21. package/dist/core/use-intl.esm3.js.map +1 -1
  22. package/dist/core/use-intl.esm4.js +0 -1
  23. package/dist/core/use-intl.esm4.js.map +1 -1
  24. package/dist/core/use-intl.esm5.js +12 -56
  25. package/dist/core/use-intl.esm5.js.map +1 -1
  26. package/dist/core/use-intl.esm6.js +50 -12
  27. package/dist/core/use-intl.esm6.js.map +1 -1
  28. package/dist/core/use-intl.esm7.js +188 -7
  29. package/dist/core/use-intl.esm7.js.map +1 -1
  30. package/dist/core/use-intl.esm8.js +7 -230
  31. package/dist/core/use-intl.esm8.js.map +1 -1
  32. package/dist/core/use-intl.esm9.js +2 -6
  33. package/dist/core/use-intl.esm9.js.map +1 -1
  34. package/dist/core/utils/MessageKeys.d.ts +1 -1
  35. package/dist/core/utils/NamespaceKeys.d.ts +1 -1
  36. package/dist/core/utils/NestedKeyOf.d.ts +1 -1
  37. package/dist/core/utils/NestedValueOf.d.ts +1 -1
  38. package/dist/react/IntlProvider.d.ts +1 -1
  39. package/dist/react/use-intl.esm.js +1 -2
  40. package/dist/react/use-intl.esm.js.map +1 -1
  41. package/dist/react/use-intl.esm10.js +0 -2
  42. package/dist/react/use-intl.esm10.js.map +1 -1
  43. package/dist/react/use-intl.esm11.js +9 -10
  44. package/dist/react/use-intl.esm11.js.map +1 -1
  45. package/dist/react/use-intl.esm2.js +4 -4
  46. package/dist/react/use-intl.esm2.js.map +1 -1
  47. package/dist/react/use-intl.esm3.js +40 -3
  48. package/dist/react/use-intl.esm3.js.map +1 -1
  49. package/dist/react/use-intl.esm4.js +3 -45
  50. package/dist/react/use-intl.esm4.js.map +1 -1
  51. package/dist/react/use-intl.esm5.js.map +1 -1
  52. package/dist/react/use-intl.esm6.js +15 -10
  53. package/dist/react/use-intl.esm6.js.map +1 -1
  54. package/dist/react/use-intl.esm7.js +9 -18
  55. package/dist/react/use-intl.esm7.js.map +1 -1
  56. package/dist/react/use-intl.esm8.js.map +1 -1
  57. package/dist/react/use-intl.esm9.js +4 -8
  58. package/dist/react/use-intl.esm9.js.map +1 -1
  59. package/dist/react/useFormatter.d.ts +1 -1
  60. package/dist/react/useIntl.d.ts +1 -1
  61. package/dist/react/useNow.d.ts +1 -1
  62. package/dist/src/core/AbstractIntlMessages.d.ts +1 -1
  63. package/dist/src/core/DateTimeFormatOptions.d.ts +1 -1
  64. package/dist/src/core/Formats.d.ts +1 -1
  65. package/dist/src/core/IntlConfig.d.ts +2 -2
  66. package/dist/src/core/TranslationValues.d.ts +3 -3
  67. package/dist/src/core/createBaseTranslator.d.ts +3 -3
  68. package/dist/src/core/createFormatter.d.ts +4 -4
  69. package/dist/src/core/createIntl.d.ts +1 -1
  70. package/dist/src/core/createTranslator.d.ts +1 -1
  71. package/dist/src/core/createTranslator.js +1 -1
  72. package/dist/src/core/createTranslator.js.map +1 -1
  73. package/dist/src/core/createTranslatorImpl.d.ts +2 -2
  74. package/dist/src/core/utils/MessageKeys.d.ts +1 -1
  75. package/dist/src/core/utils/NamespaceKeys.d.ts +1 -1
  76. package/dist/src/core/utils/NestedKeyOf.d.ts +1 -1
  77. package/dist/src/core/utils/NestedValueOf.d.ts +1 -1
  78. package/dist/src/core/validateMessages.js +35 -1
  79. package/dist/src/core/validateMessages.js.map +1 -1
  80. package/dist/src/react/IntlProvider.d.ts +1 -1
  81. package/dist/src/react/useFormatter.d.ts +1 -1
  82. package/dist/src/react/useIntl.d.ts +1 -1
  83. package/dist/src/react/useNow.d.ts +1 -1
  84. package/dist/use-intl.cjs.development.js +92 -222
  85. package/dist/use-intl.cjs.development.js.map +1 -1
  86. package/dist/use-intl.cjs.production.min.js +1 -1
  87. package/dist/use-intl.cjs.production.min.js.map +1 -1
  88. package/dist/use-intl.esm.js +4 -4
  89. package/package.json +17 -17
  90. package/src/core/createTranslator.tsx +1 -1
  91. package/src/core/validateMessages.tsx +37 -3
@@ -1,50 +1,8 @@
1
- import { useState, useEffect } from 'react';
2
1
  import useIntlContext from './use-intl.esm10.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.esm4.js.map
@@ -1 +1 @@
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
+ {"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","useIntlContext","globalNow","now","_useState","useState","setNow","useEffect","intervalId","setInterval","clearInterval"],"mappings":";;;AAOA,SAASA,MAAMA,GAAA;EACb,OAAO,IAAIC,IAAI,EAAE,CAAA;AACnB,CAAA;AAEA;;;;;;;;;;;;;;;;;AAiBG;AACqB,SAAAC,MAAMA,CAACC,OAAiB,EAAA;AAC9C,EAAA,IAAMC,cAAc,GAAGD,OAAO,IAAPA,IAAAA,GAAAA,KAAAA,CAAAA,GAAAA,OAAO,CAAEC,cAAc,CAAA;AAE9C,EAAA,IAAAC,eAAA,GAAyBC,cAAc,EAAE;IAA7BC,SAAS,GAAAF,eAAA,CAAdG,GAAG,CAAA;EACV,IAAAC,SAAA,GAAsBC,QAAQ,CAACH,SAAS,IAAIP,MAAM,EAAE,CAAC;AAA9CQ,IAAAA,GAAG,GAAAC,SAAA,CAAA,CAAA,CAAA;AAAEE,IAAAA,MAAM,GAAAF,SAAA,CAAA,CAAA,CAAA,CAAA;AAElBG,EAAAA,SAAS,CAAC,YAAK;IACb,IAAI,CAACR,cAAc,EAAE,OAAA;AAErB,IAAA,IAAMS,UAAU,GAAGC,WAAW,CAAC,YAAK;AAClCH,MAAAA,MAAM,CAACX,MAAM,EAAE,CAAC,CAAA;KACjB,EAAEI,cAAc,CAAC,CAAA;AAElB,IAAA,OAAO,YAAK;MACVW,aAAa,CAACF,UAAU,CAAC,CAAA;KAC1B,CAAA;AACH,GAAC,EAAE,CAACN,SAAS,EAAEH,cAAc,CAAC,CAAC,CAAA;AAE/B,EAAA,OAAOI,GAAG,CAAA;AACZ;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"use-intl.esm5.js","sources":["../../src/react/useTimeZone.tsx"],"sourcesContent":["import useIntlContext from './useIntlContext';\n\nexport default function useTimeZone() {\n return useIntlContext().timeZone;\n}\n"],"names":["useTimeZone","useIntlContext","timeZone"],"mappings":";;AAEc,SAAUA,WAAV,GAAqB;AACjC,EAAOC,OAAAA,cAAc,GAAGC,QAAxB,CAAA;AACD;;;;"}
1
+ {"version":3,"file":"use-intl.esm5.js","sources":["../../src/react/useIntl.tsx"],"sourcesContent":["import {useMemo} from 'react';\nimport createIntl from '../core/createIntl';\nimport useIntlContext from './useIntlContext';\n\nlet hasWarned = false;\n\n/** @deprecated Switch to `useFormatter` instead. */\nexport default function useIntl() {\n const {formats, locale, now: globalNow, onError, timeZone} = useIntlContext();\n\n if (!hasWarned) {\n hasWarned = true;\n console.warn(\n '`useIntl()` is deprecated and will be removed in the next major version. Please switch to `useFormatter()`.'\n );\n }\n\n return useMemo(\n () =>\n createIntl({\n formats,\n locale,\n now: globalNow,\n onError,\n timeZone\n }),\n [formats, globalNow, locale, onError, timeZone]\n );\n}\n"],"names":["hasWarned","useIntl","_useIntlContext","useIntlContext","formats","locale","globalNow","now","onError","timeZone","console","warn","useMemo","createIntl"],"mappings":";;;;AAIA,IAAIA,SAAS,GAAG,KAAK,CAAA;AAErB;AACc,SAAUC,OAAOA,GAAA;AAC7B,EAAA,IAAAC,eAAA,GAA6DC,cAAc,EAAE;IAAtEC,OAAO,GAAAF,eAAA,CAAPE,OAAO;IAAEC,MAAM,GAAAH,eAAA,CAANG,MAAM;IAAOC,SAAS,GAAAJ,eAAA,CAAdK,GAAG;IAAaC,OAAO,GAAAN,eAAA,CAAPM,OAAO;IAAEC,QAAQ,GAAAP,eAAA,CAARO,QAAQ,CAAA;EAEzD,IAAI,CAACT,SAAS,EAAE;AACdA,IAAAA,SAAS,GAAG,IAAI,CAAA;AAChBU,IAAAA,OAAO,CAACC,IAAI,CACV,6GAA6G,CAC9G,CAAA;AACF,GAAA;AAED,EAAA,OAAOC,OAAO,CACZ,YAAA;AAAA,IAAA,OACEC,UAAU,CAAC;AACTT,MAAAA,OAAO,EAAPA,OAAO;AACPC,MAAAA,MAAM,EAANA,MAAM;AACNE,MAAAA,GAAG,EAAED,SAAS;AACdE,MAAAA,OAAO,EAAPA,OAAO;AACPC,MAAAA,QAAQ,EAARA,QAAAA;AACD,KAAA,CAAC,CAAA;GACJ,EAAA,CAACL,OAAO,EAAEE,SAAS,EAAED,MAAM,EAAEG,OAAO,EAAEC,QAAQ,CAAC,CAChD,CAAA;AACH;;;;"}
@@ -1,17 +1,22 @@
1
1
  import { useMemo } from 'react';
2
- import createFormatter from '../core/use-intl.esm3.js';
2
+ import createIntl from '../core/use-intl.esm4.js';
3
3
  import useIntlContext from './use-intl.esm10.js';
4
4
 
5
- function useFormatter() {
5
+ var hasWarned = false;
6
+ /** @deprecated Switch to `useFormatter` instead. */
7
+ function useIntl() {
6
8
  var _useIntlContext = useIntlContext(),
7
- formats = _useIntlContext.formats,
8
- locale = _useIntlContext.locale,
9
- globalNow = _useIntlContext.now,
10
- onError = _useIntlContext.onError,
11
- timeZone = _useIntlContext.timeZone;
12
-
9
+ formats = _useIntlContext.formats,
10
+ locale = _useIntlContext.locale,
11
+ globalNow = _useIntlContext.now,
12
+ onError = _useIntlContext.onError,
13
+ timeZone = _useIntlContext.timeZone;
14
+ if (!hasWarned) {
15
+ hasWarned = true;
16
+ console.warn('`useIntl()` is deprecated and will be removed in the next major version. Please switch to `useFormatter()`.');
17
+ }
13
18
  return useMemo(function () {
14
- return createFormatter({
19
+ return createIntl({
15
20
  formats: formats,
16
21
  locale: locale,
17
22
  now: globalNow,
@@ -21,5 +26,5 @@ function useFormatter() {
21
26
  }, [formats, globalNow, locale, onError, timeZone]);
22
27
  }
23
28
 
24
- export { useFormatter as default };
29
+ export { useIntl as default };
25
30
  //# sourceMappingURL=use-intl.esm6.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-intl.esm6.js","sources":["../../src/react/useFormatter.tsx"],"sourcesContent":["import {useMemo} from 'react';\nimport createFormatter from '../core/createFormatter';\nimport useIntlContext from './useIntlContext';\n\nexport default function useFormatter() {\n const {formats, locale, now: globalNow, onError, timeZone} = useIntlContext();\n\n return useMemo(\n () =>\n createFormatter({\n formats,\n locale,\n now: globalNow,\n onError,\n timeZone\n }),\n [formats, globalNow, locale, onError, timeZone]\n );\n}\n"],"names":["useFormatter","useIntlContext","formats","locale","globalNow","now","onError","timeZone","useMemo","createFormatter"],"mappings":";;;;AAIc,SAAUA,YAAV,GAAsB;AAClC,EAAA,IAAA,eAAA,GAA6DC,cAAc,EAA3E;AAAA,MAAOC,OAAP,mBAAOA,OAAP;AAAA,MAAgBC,MAAhB,mBAAgBA,MAAhB;AAAA,MAA6BC,SAA7B,mBAAwBC,GAAxB;AAAA,MAAwCC,OAAxC,mBAAwCA,OAAxC;AAAA,MAAiDC,QAAjD,mBAAiDA,QAAjD,CAAA;;AAEA,EAAA,OAAOC,OAAO,CACZ,YAAA;AAAA,IAAA,OACEC,eAAe,CAAC;AACdP,MAAAA,OAAO,EAAPA,OADc;AAEdC,MAAAA,MAAM,EAANA,MAFc;AAGdE,MAAAA,GAAG,EAAED,SAHS;AAIdE,MAAAA,OAAO,EAAPA,OAJc;AAKdC,MAAAA,QAAQ,EAARA,QAAAA;AALc,KAAD,CADjB,CAAA;AAAA,GADY,EASZ,CAACL,OAAD,EAAUE,SAAV,EAAqBD,MAArB,EAA6BG,OAA7B,EAAsCC,QAAtC,CATY,CAAd,CAAA;AAWD;;;;"}
1
+ {"version":3,"file":"use-intl.esm6.js","sources":["../../src/react/useTimeZone.tsx"],"sourcesContent":["import useIntlContext from './useIntlContext';\n\nexport default function useTimeZone() {\n return useIntlContext().timeZone;\n}\n"],"names":["useTimeZone","useIntlContext","timeZone"],"mappings":";;AAEc,SAAUA,WAAWA,GAAA;AACjC,EAAA,OAAOC,cAAc,EAAE,CAACC,QAAQ,CAAA;AAClC;;;;"}
@@ -1,25 +1,16 @@
1
1
  import { useMemo } from 'react';
2
- import createIntl from '../core/use-intl.esm4.js';
2
+ import createFormatter from '../core/use-intl.esm3.js';
3
3
  import useIntlContext from './use-intl.esm10.js';
4
4
 
5
- var hasWarned = false;
6
- /** @deprecated Switch to `useFormatter` instead. */
7
-
8
- function useIntl() {
5
+ function useFormatter() {
9
6
  var _useIntlContext = useIntlContext(),
10
- formats = _useIntlContext.formats,
11
- locale = _useIntlContext.locale,
12
- globalNow = _useIntlContext.now,
13
- onError = _useIntlContext.onError,
14
- timeZone = _useIntlContext.timeZone;
15
-
16
- if (!hasWarned) {
17
- hasWarned = true;
18
- console.warn('`useIntl()` is deprecated and will be removed in the next major version. Please switch to `useFormatter()`.');
19
- }
20
-
7
+ formats = _useIntlContext.formats,
8
+ locale = _useIntlContext.locale,
9
+ globalNow = _useIntlContext.now,
10
+ onError = _useIntlContext.onError,
11
+ timeZone = _useIntlContext.timeZone;
21
12
  return useMemo(function () {
22
- return createIntl({
13
+ return createFormatter({
23
14
  formats: formats,
24
15
  locale: locale,
25
16
  now: globalNow,
@@ -29,5 +20,5 @@ function useIntl() {
29
20
  }, [formats, globalNow, locale, onError, timeZone]);
30
21
  }
31
22
 
32
- export { useIntl as default };
23
+ export { useFormatter as default };
33
24
  //# sourceMappingURL=use-intl.esm7.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-intl.esm7.js","sources":["../../src/react/useIntl.tsx"],"sourcesContent":["import {useMemo} from 'react';\nimport createIntl from '../core/createIntl';\nimport useIntlContext from './useIntlContext';\n\nlet hasWarned = false;\n\n/** @deprecated Switch to `useFormatter` instead. */\nexport default function useIntl() {\n const {formats, locale, now: globalNow, onError, timeZone} = useIntlContext();\n\n if (!hasWarned) {\n hasWarned = true;\n console.warn(\n '`useIntl()` is deprecated and will be removed in the next major version. Please switch to `useFormatter()`.'\n );\n }\n\n return useMemo(\n () =>\n createIntl({\n formats,\n locale,\n now: globalNow,\n onError,\n timeZone\n }),\n [formats, globalNow, locale, onError, timeZone]\n );\n}\n"],"names":["hasWarned","useIntl","useIntlContext","formats","locale","globalNow","now","onError","timeZone","console","warn","useMemo","createIntl"],"mappings":";;;;AAIA,IAAIA,SAAS,GAAG,KAAhB,CAAA;AAEA;;AACc,SAAUC,OAAV,GAAiB;AAC7B,EAAA,IAAA,eAAA,GAA6DC,cAAc,EAA3E;AAAA,MAAOC,OAAP,mBAAOA,OAAP;AAAA,MAAgBC,MAAhB,mBAAgBA,MAAhB;AAAA,MAA6BC,SAA7B,mBAAwBC,GAAxB;AAAA,MAAwCC,OAAxC,mBAAwCA,OAAxC;AAAA,MAAiDC,QAAjD,mBAAiDA,QAAjD,CAAA;;AAEA,EAAI,IAAA,CAACR,SAAL,EAAgB;AACdA,IAAAA,SAAS,GAAG,IAAZ,CAAA;AACAS,IAAAA,OAAO,CAACC,IAAR,CACE,6GADF,CAAA,CAAA;AAGD,GAAA;;AAED,EAAA,OAAOC,OAAO,CACZ,YAAA;AAAA,IAAA,OACEC,UAAU,CAAC;AACTT,MAAAA,OAAO,EAAPA,OADS;AAETC,MAAAA,MAAM,EAANA,MAFS;AAGTE,MAAAA,GAAG,EAAED,SAHI;AAITE,MAAAA,OAAO,EAAPA,OAJS;AAKTC,MAAAA,QAAQ,EAARA,QAAAA;AALS,KAAD,CADZ,CAAA;AAAA,GADY,EASZ,CAACL,OAAD,EAAUE,SAAV,EAAqBD,MAArB,EAA6BG,OAA7B,EAAsCC,QAAtC,CATY,CAAd,CAAA;AAWD;;;;"}
1
+ {"version":3,"file":"use-intl.esm7.js","sources":["../../src/react/useFormatter.tsx"],"sourcesContent":["import {useMemo} from 'react';\nimport createFormatter from '../core/createFormatter';\nimport useIntlContext from './useIntlContext';\n\nexport default function useFormatter() {\n const {formats, locale, now: globalNow, onError, timeZone} = useIntlContext();\n\n return useMemo(\n () =>\n createFormatter({\n formats,\n locale,\n now: globalNow,\n onError,\n timeZone\n }),\n [formats, globalNow, locale, onError, timeZone]\n );\n}\n"],"names":["useFormatter","_useIntlContext","useIntlContext","formats","locale","globalNow","now","onError","timeZone","useMemo","createFormatter"],"mappings":";;;;AAIc,SAAUA,YAAYA,GAAA;AAClC,EAAA,IAAAC,eAAA,GAA6DC,cAAc,EAAE;IAAtEC,OAAO,GAAAF,eAAA,CAAPE,OAAO;IAAEC,MAAM,GAAAH,eAAA,CAANG,MAAM;IAAOC,SAAS,GAAAJ,eAAA,CAAdK,GAAG;IAAaC,OAAO,GAAAN,eAAA,CAAPM,OAAO;IAAEC,QAAQ,GAAAP,eAAA,CAARO,QAAQ,CAAA;AAEzD,EAAA,OAAOC,OAAO,CACZ,YAAA;AAAA,IAAA,OACEC,eAAe,CAAC;AACdP,MAAAA,OAAO,EAAPA,OAAO;AACPC,MAAAA,MAAM,EAANA,MAAM;AACNE,MAAAA,GAAG,EAAED,SAAS;AACdE,MAAAA,OAAO,EAAPA,OAAO;AACPC,MAAAA,QAAQ,EAARA,QAAAA;AACD,KAAA,CAAC,CAAA;GACJ,EAAA,CAACL,OAAO,EAAEE,SAAS,EAAED,MAAM,EAAEG,OAAO,EAAEC,QAAQ,CAAC,CAChD,CAAA;AACH;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"use-intl.esm8.js","sources":["../../src/react/IntlContext.tsx"],"sourcesContent":["import {createContext} from 'react';\nimport {InitializedIntlConfig} from '../core/IntlConfig';\n\nconst IntlContext = createContext<InitializedIntlConfig | undefined>(undefined);\n\nexport default IntlContext;\n"],"names":["IntlContext","createContext","undefined"],"mappings":";;AAGA,IAAMA,WAAW,gBAAGC,aAAa,CAAoCC,SAApC;;;;"}
1
+ {"version":3,"file":"use-intl.esm8.js","sources":["../../src/react/useTranslationsImpl.tsx"],"sourcesContent":["// eslint-disable-next-line import/no-named-as-default -- False positive\nimport 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","useIntlContext","defaultTranslationValues","globalFormats","formats","getMessageFallback","locale","onError","timeZone","resolveNamespace","cachedFormatsByLocaleRef","useRef","messagesOrError","useMemo","getMessagesOrError","messages","translate","createBaseTranslator","cachedFormatsByLocale","current"],"mappings":";;;;;AAWwB,SAAAA,mBAAmBA,CAGzCC,WAAqB,EAAEC,SAAoB,EAAEC,eAAuB,EAAA;AACpE,EAAA,IAAAC,eAAA,GAOIC,cAAc,EAAE;IANlBC,wBAAwB,GAAAF,eAAA,CAAxBE,wBAAwB;IACfC,aAAa,GAAAH,eAAA,CAAtBI,OAAO;IACPC,kBAAkB,GAAAL,eAAA,CAAlBK,kBAAkB;IAClBC,MAAM,GAAAN,eAAA,CAANM,MAAM;IACNC,OAAO,GAAAP,eAAA,CAAPO,OAAO;IACPC,QAAQ,GAAAR,eAAA,CAARQ,QAAQ,CAAA;AAGV;AACA;AACAX,EAAAA,WAAW,GAAGA,WAAW,CAACE,eAAe,CAAa,CAAA;AACtDD,EAAAA,SAAS,GAAGW,gBAAgB,CAACX,SAAS,EAAEC,eAAe,CAAc,CAAA;AAErE,EAAA,IAAMW,wBAAwB,GAAGC,MAAM,CAErC,EAAE,CAAC,CAAA;EAEL,IAAMC,eAAe,GAAGC,OAAO,CAC7B,YAAA;AAAA,IAAA,OAAMC,kBAAkB,CAAC;AAACC,MAAAA,QAAQ,EAAElB,WAAW;AAAEC,MAAAA,SAAS,EAATA,SAAS;AAAES,MAAAA,OAAO,EAAPA,OAAAA;AAAO,KAAC,CAAC,CAAA;AAAA,GAAA,EACrE,CAACV,WAAW,EAAEC,SAAS,EAAES,OAAO,CAAC,CAClC,CAAA;EAED,IAAMS,SAAS,GAAGH,OAAO,CACvB,YAAA;AAAA,IAAA,OACEI,oBAAoB,CAAC;MACnBC,qBAAqB,EAAER,wBAAwB,CAACS,OAAO;AACvDd,MAAAA,kBAAkB,EAAlBA,kBAAkB;AAClBO,MAAAA,eAAe,EAAfA,eAAe;AACfV,MAAAA,wBAAwB,EAAxBA,wBAAwB;AACxBJ,MAAAA,SAAS,EAATA,SAAS;AACTS,MAAAA,OAAO,EAAPA,OAAO;AACPH,MAAAA,OAAO,EAAED,aAAa;AACtBG,MAAAA,MAAM,EAANA,MAAM;AACNE,MAAAA,QAAQ,EAARA,QAAAA;AACD,KAAA,CAAC,CAAA;AAAA,GAAA,EACJ,CACEH,kBAAkB,EAClBO,eAAe,EACfV,wBAAwB,EACxBJ,SAAS,EACTS,OAAO,EACPJ,aAAa,EACbG,MAAM,EACNE,QAAQ,CACT,CACF,CAAA;AAED,EAAA,OAAOQ,SAAS,CAAA;AAClB;;;;"}
@@ -1,27 +1,23 @@
1
1
  import { objectWithoutPropertiesLoose as _objectWithoutPropertiesLoose, extends as _extends } from '../_virtual/use-intl.esm.js';
2
- import { defaultOnError, defaultGetMessageFallback } from '../core/use-intl.esm6.js';
2
+ import { defaultOnError, defaultGetMessageFallback } from '../core/use-intl.esm5.js';
3
3
  import validateMessages from '../core/use-intl.esm9.js';
4
4
 
5
5
  var _excluded = ["getMessageFallback", "messages", "onError"];
6
6
  /**
7
7
  * Enhances the incoming props with defaults.
8
8
  */
9
-
10
9
  function getInitializedConfig(_ref) {
11
10
  var getMessageFallback = _ref.getMessageFallback,
12
- messages = _ref.messages,
13
- onError = _ref.onError,
14
- rest = _objectWithoutPropertiesLoose(_ref, _excluded);
15
-
11
+ messages = _ref.messages,
12
+ onError = _ref.onError,
13
+ rest = _objectWithoutPropertiesLoose(_ref, _excluded);
16
14
  var finalOnError = onError || defaultOnError;
17
15
  var finalGetMessageFallback = getMessageFallback || defaultGetMessageFallback;
18
-
19
16
  if (process.env.NODE_ENV !== 'production') {
20
17
  if (messages) {
21
18
  validateMessages(messages, finalOnError);
22
19
  }
23
20
  }
24
-
25
21
  return _extends({}, rest, {
26
22
  messages: messages,
27
23
  onError: finalOnError,
@@ -1 +1 @@
1
- {"version":3,"file":"use-intl.esm9.js","sources":["../../src/react/getInitializedConfig.tsx"],"sourcesContent":["import IntlConfig from '../core/IntlConfig';\nimport {defaultGetMessageFallback, defaultOnError} from '../core/defaults';\nimport validateMessages from '../core/validateMessages';\n\n/**\n * Enhances the incoming props with defaults.\n */\nexport default function getInitializedConfig<\n // This is a generic to allow for stricter typing. E.g.\n // the RSC integration always provides a `now` value.\n Props extends Omit<IntlConfig, 'children'>\n>({getMessageFallback, messages, onError, ...rest}: Props) {\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":["getInitializedConfig","getMessageFallback","messages","onError","rest","finalOnError","defaultOnError","finalGetMessageFallback","defaultGetMessageFallback","process","env","NODE_ENV","validateMessages"],"mappings":";;;;;AAIA;;AAEG;;AACqB,SAAAA,oBAAA,CAIiC,IAAA,EAAA;AAAA,EAAtDC,IAAAA,kBAAsD,QAAtDA,kBAAsD;AAAA,MAAlCC,QAAkC,QAAlCA,QAAkC;AAAA,MAAxBC,OAAwB,QAAxBA,OAAwB;AAAA,MAAZC,IAAY,GAAA,6BAAA,CAAA,IAAA,EAAA,SAAA,CAAA,CAAA;;AACvD,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
+ {"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,cAAcA,GAAA;AACpC,EAAA,IAAMC,OAAO,GAAGC,UAAU,CAACC,WAAW,CAAC,CAAA;EAEvC,IAAI,CAACF,OAAO,EAAE;AACZ,IAAA,MAAM,IAAIG,KAAK,CACbC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,GACjC,0DAA0D,GAC1DC,SAAS,CACd,CAAA;AACF,GAAA;AAED,EAAA,OAAOP,OAAO,CAAA;AAChB;;;;"}
@@ -1,5 +1,5 @@
1
1
  export default function useFormatter(): {
2
2
  dateTime: (value: number | Date, formatOrOptions?: string | import("../core/DateTimeFormatOptions").default | undefined) => string;
3
- number: (value: number | bigint, formatOrOptions?: string | import("@formatjs/ecma402-abstract").NumberFormatOptions | undefined) => string;
3
+ number: (value: number | bigint, formatOrOptions?: string | import("@formatjs/ecma402-abstract/types/number").NumberFormatOptions | undefined) => string;
4
4
  relativeTime: (date: number | Date, now?: number | Date | undefined) => string;
5
5
  };
@@ -1,6 +1,6 @@
1
1
  /** @deprecated Switch to `useFormatter` instead. */
2
2
  export default function useIntl(): {
3
3
  formatDateTime: (value: number | Date, formatOrOptions?: string | import("../core/DateTimeFormatOptions").default | undefined) => string;
4
- formatNumber: (value: number | bigint, formatOrOptions?: string | import("@formatjs/ecma402-abstract").NumberFormatOptions | undefined) => string;
4
+ formatNumber: (value: number | bigint, formatOrOptions?: string | import("@formatjs/ecma402-abstract/types/number").NumberFormatOptions | undefined) => string;
5
5
  formatRelativeTime: (date: number | Date, now?: number | Date | undefined) => string;
6
6
  };
@@ -1,4 +1,4 @@
1
- declare type Options = {
1
+ type Options = {
2
2
  updateInterval?: number;
3
3
  };
4
4
  /**
@@ -3,7 +3,7 @@
3
3
  * Optionally `IntlMessages` can be provided to get type safety for message
4
4
  * namespaces and keys. See https://next-intl-docs.vercel.app/docs/usage/typescript
5
5
  */
6
- declare type AbstractIntlMessages = {
6
+ type AbstractIntlMessages = {
7
7
  [id: string]: AbstractIntlMessages | string;
8
8
  };
9
9
  export default AbstractIntlMessages;
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat
3
3
  */
4
- declare type DateTimeFormatOptions = Intl.DateTimeFormatOptions & {
4
+ type DateTimeFormatOptions = Intl.DateTimeFormatOptions & {
5
5
  /**
6
6
  * Examples:
7
7
  * - numeric: "2021"
@@ -1,6 +1,6 @@
1
1
  import DateTimeFormatOptions from './DateTimeFormatOptions';
2
2
  import NumberFormatOptions from './NumberFormatOptions';
3
- declare type Formats = {
3
+ type Formats = {
4
4
  number: Record<string, NumberFormatOptions>;
5
5
  dateTime: Record<string, DateTimeFormatOptions>;
6
6
  };
@@ -4,7 +4,7 @@ import { AbstractIntlMessages, RichTranslationValues } from '.';
4
4
  /**
5
5
  * Should be used for entry points that configure the library.
6
6
  */
7
- declare type IntlConfig<Messages = AbstractIntlMessages> = {
7
+ type IntlConfig<Messages = AbstractIntlMessages> = {
8
8
  /** A valid Unicode locale tag (e.g. "en" or "en-GB"). */
9
9
  locale: string;
10
10
  /** Global formats can be provided to achieve consistent
@@ -46,7 +46,7 @@ declare type IntlConfig<Messages = AbstractIntlMessages> = {
46
46
  * A stricter set of the configuration that should be used internally
47
47
  * once defaults are assigned to `IntlConfiguration`.
48
48
  */
49
- export declare type InitializedIntlConfig<Messages = AbstractIntlMessages> = IntlConfig<Messages> & {
49
+ export type InitializedIntlConfig<Messages = AbstractIntlMessages> = IntlConfig<Messages> & {
50
50
  onError: NonNullable<IntlConfig<Messages>['onError']>;
51
51
  getMessageFallback: NonNullable<IntlConfig<Messages>['getMessageFallback']>;
52
52
  };
@@ -1,5 +1,5 @@
1
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)>;
2
+ export type TranslationValue = string | number | boolean | Date | null | undefined;
3
+ type TranslationValues = Record<string, TranslationValue>;
4
+ export type RichTranslationValues = Record<string, TranslationValue | ((chunks: ReactNode) => ReactNode)>;
5
5
  export default TranslationValues;
@@ -13,14 +13,14 @@ export declare function getMessagesOrError<Messages extends AbstractIntlMessages
13
13
  namespace?: string;
14
14
  onError?(error: IntlError): void;
15
15
  }): AbstractIntlMessages | IntlError;
16
- export declare type CreateBaseTranslatorProps<Messages> = InitializedIntlConfig & {
16
+ export type CreateBaseTranslatorProps<Messages> = InitializedIntlConfig & {
17
17
  cachedFormatsByLocale?: Record<string, Record<string, IntlMessageFormat>>;
18
18
  defaultTranslationValues?: RichTranslationValues;
19
19
  namespace?: string;
20
20
  messagesOrError: Messages | IntlError;
21
21
  };
22
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;
23
+ <TargetKey extends MessageKeys<NestedValueOf<Messages, NestedKey>, NestedKeyOf<NestedValueOf<Messages, NestedKey>>>>(key: TargetKey, values?: TranslationValues, formats?: Partial<Formats>): string;
24
+ rich: (key: string, values?: RichTranslationValues, formats?: Partial<Formats>) => string | ReactElement | ReactNodeArray;
25
25
  raw(key: string): any;
26
26
  };
@@ -2,7 +2,7 @@ import DateTimeFormatOptions from './DateTimeFormatOptions';
2
2
  import Formats from './Formats';
3
3
  import IntlError from './IntlError';
4
4
  import NumberFormatOptions from './NumberFormatOptions';
5
- declare type Props = {
5
+ type Props = {
6
6
  locale: string;
7
7
  timeZone?: string;
8
8
  onError?(error: IntlError): void;
@@ -10,8 +10,8 @@ declare type Props = {
10
10
  now?: Date;
11
11
  };
12
12
  export default function createFormatter({ formats, locale, now: globalNow, onError, timeZone }: Props): {
13
- dateTime: (value: Date | number, formatOrOptions?: string | DateTimeFormatOptions | undefined) => string;
14
- number: (value: number | bigint, formatOrOptions?: string | NumberFormatOptions | undefined) => string;
15
- relativeTime: (date: number | Date, now?: number | Date | undefined) => string;
13
+ dateTime: (value: Date | number, formatOrOptions?: string | DateTimeFormatOptions) => string;
14
+ number: (value: number | bigint, formatOrOptions?: string | NumberFormatOptions) => string;
15
+ relativeTime: (date: number | Date, now?: number | Date) => string;
16
16
  };
17
17
  export {};
@@ -2,6 +2,6 @@ import createFormatter from './createFormatter';
2
2
  /** @deprecated Switch to `createFormatter` */
3
3
  export default function createIntl(...args: Parameters<typeof createFormatter>): {
4
4
  formatDateTime: (value: number | Date, formatOrOptions?: string | import("./DateTimeFormatOptions").default | undefined) => string;
5
- formatNumber: (value: number | bigint, formatOrOptions?: string | import("@formatjs/ecma402-abstract").NumberFormatOptions | undefined) => string;
5
+ formatNumber: (value: number | bigint, formatOrOptions?: string | import("@formatjs/ecma402-abstract/types/number").NumberFormatOptions | undefined) => string;
6
6
  formatRelativeTime: (date: number | Date, now?: number | Date | undefined) => string;
7
7
  };
@@ -14,7 +14,7 @@ import NestedValueOf from './utils/NestedValueOf';
14
14
  * The namespace can also indicate nesting by using a dot
15
15
  * (e.g. `namespace.Component`).
16
16
  */
17
- export default function createTranslator<NestedKey extends NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>> = never>({ onError, getMessageFallback, messages, namespace, ...rest }: Omit<IntlConfig<IntlMessages>, 'defaultTranslationValues' | 'messages'> & {
17
+ export default function createTranslator<NestedKey extends NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>> = never>({ getMessageFallback, messages, namespace, onError, ...rest }: Omit<IntlConfig<IntlMessages>, 'defaultTranslationValues' | 'messages'> & {
18
18
  messages: NonNullable<IntlConfig<IntlMessages>['messages']>;
19
19
  namespace?: NestedKey;
20
20
  }): {
@@ -8,7 +8,7 @@ import { defaultGetMessageFallback, defaultOnError } from './defaults';
8
8
  * The namespace can also indicate nesting by using a dot
9
9
  * (e.g. `namespace.Component`).
10
10
  */
11
- export default function createTranslator({ onError = defaultOnError, getMessageFallback = defaultGetMessageFallback, messages, namespace, ...rest }) {
11
+ export default function createTranslator({ getMessageFallback = defaultGetMessageFallback, messages, namespace, onError = defaultOnError, ...rest }) {
12
12
  // We have to wrap the actual function so the type inference for the optional
13
13
  // namespace works correctly. See https://stackoverflow.com/a/71529575/343045
14
14
  // The prefix ("!") is arbitrary.
@@ -1 +1 @@
1
- {"version":3,"file":"createTranslator.js","sourceRoot":"","sources":["../../../src/core/createTranslator.tsx"],"names":[],"mappings":"AAGA,OAAO,oBAEN,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAC,yBAAyB,EAAE,cAAc,EAAC,MAAM,YAAY,CAAC;AAMrE;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAKtC,EACA,OAAO,GAAG,cAAc,EACxB,kBAAkB,GAAG,yBAAyB,EAC9C,QAAQ,EACR,SAAS,EACT,GAAG,IAAI,EAIR;IA4DC,6EAA6E;IAC7E,6EAA6E;IAC7E,iCAAiC;IACjC,OAAO,oBAAoB,CAIzB;QACE,GAAG,IAAI;QACP,OAAO;QACP,kBAAkB;QAClB,QAAQ,EAAE,EAAC,GAAG,EAAE,QAAQ,EAAC;QACzB,aAAa;QACb,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC,KAAK,SAAS,EAAE,CAAC,CAAC,CAAC,GAAG;KAC9C,EACD,GAAG,CACJ,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"createTranslator.js","sourceRoot":"","sources":["../../../src/core/createTranslator.tsx"],"names":[],"mappings":"AAGA,OAAO,oBAEN,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAC,yBAAyB,EAAE,cAAc,EAAC,MAAM,YAAY,CAAC;AAMrE;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAKtC,EACA,kBAAkB,GAAG,yBAAyB,EAC9C,QAAQ,EACR,SAAS,EACT,OAAO,GAAG,cAAc,EACxB,GAAG,IAAI,EAIR;IA4DC,6EAA6E;IAC7E,6EAA6E;IAC7E,iCAAiC;IACjC,OAAO,oBAAoB,CAIzB;QACE,GAAG,IAAI;QACP,OAAO;QACP,kBAAkB;QAClB,QAAQ,EAAE,EAAC,GAAG,EAAE,QAAQ,EAAC;QACzB,aAAa;QACb,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC,KAAK,SAAS,EAAE,CAAC,CAAC,CAAC,GAAG;KAC9C,EACD,GAAG,CACJ,CAAC;AACJ,CAAC"}
@@ -2,8 +2,8 @@ import AbstractIntlMessages from './AbstractIntlMessages';
2
2
  import { InitializedIntlConfig } from './IntlConfig';
3
3
  import { TranslationValue } from './TranslationValues';
4
4
  import NestedKeyOf from './utils/NestedKeyOf';
5
- export declare type CoreRichTranslationValues = Record<string, TranslationValue | ((chunks: string) => string)>;
6
- export declare type CreateTranslatorImplProps<Messages> = Omit<InitializedIntlConfig, 'messages'> & {
5
+ export type CoreRichTranslationValues = Record<string, TranslationValue | ((chunks: string) => string)>;
6
+ export type CreateTranslatorImplProps<Messages> = Omit<InitializedIntlConfig, 'messages'> & {
7
7
  namespace: string;
8
8
  messages: Messages;
9
9
  };
@@ -1,5 +1,5 @@
1
1
  import NestedValueOf from './NestedValueOf';
2
- declare type MessageKeys<ObjectType, Keys extends string> = {
2
+ type MessageKeys<ObjectType, Keys extends string> = {
3
3
  [Property in Keys]: NestedValueOf<ObjectType, Property> extends string ? Property : never;
4
4
  }[Keys];
5
5
  export default MessageKeys;
@@ -1,5 +1,5 @@
1
1
  import NestedValueOf from './NestedValueOf';
2
- declare type NamespaceKeys<ObjectType, Keys extends string> = {
2
+ type NamespaceKeys<ObjectType, Keys extends string> = {
3
3
  [Property in Keys]: NestedValueOf<ObjectType, Property> extends string ? never : Property;
4
4
  }[Keys];
5
5
  export default NamespaceKeys;
@@ -1,4 +1,4 @@
1
- declare type NestedKeyOf<ObjectType> = ObjectType extends object ? {
1
+ type NestedKeyOf<ObjectType> = ObjectType extends object ? {
2
2
  [Key in keyof ObjectType]: `${Key & string}` | `${Key & string}.${NestedKeyOf<ObjectType[Key]>}`;
3
3
  }[keyof ObjectType] : never;
4
4
  export default NestedKeyOf;
@@ -1,2 +1,2 @@
1
- declare type NestedValueOf<ObjectType, Property extends string> = Property extends `${infer Key}.${infer Rest}` ? Key extends keyof ObjectType ? NestedValueOf<ObjectType[Key], Rest> : never : Property extends keyof ObjectType ? ObjectType[Property] : never;
1
+ type NestedValueOf<ObjectType, Property extends string> = Property extends `${infer Key}.${infer Rest}` ? Key extends keyof ObjectType ? NestedValueOf<ObjectType[Key], Rest> : never : Property extends keyof ObjectType ? ObjectType[Property] : never;
2
2
  export default NestedValueOf;
@@ -16,7 +16,41 @@ export default function validateMessages(messages, onError) {
16
16
  const invalidKeyLabels = [];
17
17
  validateMessagesSegment(messages, invalidKeyLabels);
18
18
  if (invalidKeyLabels.length > 0) {
19
- onError(new IntlError(IntlErrorCode.INVALID_KEY, `Namespace keys can not contain the character "." as this is used to express nesting. Please remove it or replace it with another character.\n\nInvalid ${invalidKeyLabels.length === 1 ? 'key' : 'keys'}: ${invalidKeyLabels.join(', ')}`));
19
+ onError(new IntlError(IntlErrorCode.INVALID_KEY, process.env.NODE_ENV !== 'production'
20
+ ? `Namespace keys can not contain the character "." as this is used to express nesting. Please remove it or replace it with another character.
21
+
22
+ Invalid ${invalidKeyLabels.length === 1 ? 'key' : 'keys'}: ${invalidKeyLabels.join(', ')}
23
+
24
+ If you're migrating from a flat structure, you can convert your messages as follows:
25
+
26
+ import {set} from "lodash";
27
+
28
+ const input = {
29
+ "one.one": "1.1",
30
+ "one.two": "1.2",
31
+ "two.one.one": "2.1.1"
32
+ };
33
+
34
+ const output = Object.entries(input).reduce(
35
+ (acc, [key, value]) => set(acc, key, value),
36
+ {}
37
+ );
38
+
39
+ // Output:
40
+ //
41
+ // {
42
+ // "one": {
43
+ // "one": "1.1",
44
+ // "two": "1.2"
45
+ // },
46
+ // "two": {
47
+ // "one": {
48
+ // "one": "2.1.1"
49
+ // }
50
+ // }
51
+ // }
52
+ `
53
+ : undefined));
20
54
  }
21
55
  }
22
56
  //# sourceMappingURL=validateMessages.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"validateMessages.js","sourceRoot":"","sources":["../../../src/core/validateMessages.tsx"],"names":[],"mappings":"AACA,OAAO,SAAS,EAAE,EAAC,aAAa,EAAC,MAAM,aAAa,CAAC;AAErD,SAAS,uBAAuB,CAC9B,QAA8B,EAC9B,gBAA+B,EAC/B,UAAmB;IAEnB,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,iBAAiB,CAAC,EAAE,EAAE;QAC5D,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;YACrB,IAAI,QAAQ,GAAG,GAAG,CAAC;YACnB,IAAI,UAAU;gBAAE,QAAQ,IAAI,QAAQ,UAAU,GAAG,CAAC;YAClD,gBAAgB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;SACjC;QAED,IAAI,iBAAiB,IAAI,IAAI,IAAI,OAAO,iBAAiB,KAAK,QAAQ,EAAE;YACtE,uBAAuB,CACrB,iBAAiB,EACjB,gBAAgB,EAChB,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAC3D,CAAC;SACH;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,CAAC,OAAO,UAAU,gBAAgB,CACtC,QAA8B,EAC9B,OAAmC;IAEnC,MAAM,gBAAgB,GAAkB,EAAE,CAAC;IAC3C,uBAAuB,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAC;IAEpD,IAAI,gBAAgB,CAAC,MAAM,GAAG,CAAC,EAAE;QAC/B,OAAO,CACL,IAAI,SAAS,CACX,aAAa,CAAC,WAAW,EACzB,0JACE,gBAAgB,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAC1C,KAAK,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CACnC,CACF,CAAC;KACH;AACH,CAAC"}
1
+ {"version":3,"file":"validateMessages.js","sourceRoot":"","sources":["../../../src/core/validateMessages.tsx"],"names":[],"mappings":"AACA,OAAO,SAAS,EAAE,EAAC,aAAa,EAAC,MAAM,aAAa,CAAC;AAErD,SAAS,uBAAuB,CAC9B,QAA8B,EAC9B,gBAA+B,EAC/B,UAAmB;IAEnB,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,iBAAiB,CAAC,EAAE,EAAE;QAC5D,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;YACrB,IAAI,QAAQ,GAAG,GAAG,CAAC;YACnB,IAAI,UAAU;gBAAE,QAAQ,IAAI,QAAQ,UAAU,GAAG,CAAC;YAClD,gBAAgB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;SACjC;QAED,IAAI,iBAAiB,IAAI,IAAI,IAAI,OAAO,iBAAiB,KAAK,QAAQ,EAAE;YACtE,uBAAuB,CACrB,iBAAiB,EACjB,gBAAgB,EAChB,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAC3D,CAAC;SACH;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,CAAC,OAAO,UAAU,gBAAgB,CACtC,QAA8B,EAC9B,OAAmC;IAEnC,MAAM,gBAAgB,GAAkB,EAAE,CAAC;IAC3C,uBAAuB,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAC;IAEpD,IAAI,gBAAgB,CAAC,MAAM,GAAG,CAAC,EAAE;QAC/B,OAAO,CACL,IAAI,SAAS,CACX,aAAa,CAAC,WAAW,EACzB,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY;YACnC,CAAC,CAAC;;UAGE,gBAAgB,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAC1C,KAAK,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8B3C;YACS,CAAC,CAAC,SAAS,CACd,CACF,CAAC;KACH;AACH,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import { ReactNode } from 'react';
2
2
  import IntlConfig from '../core/IntlConfig';
3
- declare type Props = IntlConfig & {
3
+ type Props = IntlConfig & {
4
4
  children: ReactNode;
5
5
  };
6
6
  export default function IntlProvider({ children, ...props }: Props): JSX.Element;
@@ -1,5 +1,5 @@
1
1
  export default function useFormatter(): {
2
2
  dateTime: (value: number | Date, formatOrOptions?: string | import("../core/DateTimeFormatOptions").default | undefined) => string;
3
- number: (value: number | bigint, formatOrOptions?: string | import("@formatjs/ecma402-abstract").NumberFormatOptions | undefined) => string;
3
+ number: (value: number | bigint, formatOrOptions?: string | import("@formatjs/ecma402-abstract/types/number").NumberFormatOptions | undefined) => string;
4
4
  relativeTime: (date: number | Date, now?: number | Date | undefined) => string;
5
5
  };
@@ -1,6 +1,6 @@
1
1
  /** @deprecated Switch to `useFormatter` instead. */
2
2
  export default function useIntl(): {
3
3
  formatDateTime: (value: number | Date, formatOrOptions?: string | import("../core/DateTimeFormatOptions").default | undefined) => string;
4
- formatNumber: (value: number | bigint, formatOrOptions?: string | import("@formatjs/ecma402-abstract").NumberFormatOptions | undefined) => string;
4
+ formatNumber: (value: number | bigint, formatOrOptions?: string | import("@formatjs/ecma402-abstract/types/number").NumberFormatOptions | undefined) => string;
5
5
  formatRelativeTime: (date: number | Date, now?: number | Date | undefined) => string;
6
6
  };
@@ -1,4 +1,4 @@
1
- declare type Options = {
1
+ type Options = {
2
2
  updateInterval?: number;
3
3
  };
4
4
  /**