use-intl 2.9.2 → 2.10.0-alpha.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 (128) hide show
  1. package/CHANGELOG.md +471 -0
  2. package/dist/core/use-intl.esm.js +38 -41
  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 +2 -2
  7. package/dist/core/use-intl.esm4.js +12 -56
  8. package/dist/core/use-intl.esm4.js.map +1 -1
  9. package/dist/core/use-intl.esm5.js +56 -12
  10. package/dist/core/use-intl.esm5.js.map +1 -1
  11. package/dist/core/use-intl.esm6.js +1 -1
  12. package/dist/core/use-intl.esm7.js +2 -2
  13. package/dist/react/use-intl.esm.js +2 -2
  14. package/dist/react/use-intl.esm2.js +41 -17
  15. package/dist/react/use-intl.esm2.js.map +1 -1
  16. package/dist/react/use-intl.esm3.js +21 -20
  17. package/dist/react/use-intl.esm3.js.map +1 -1
  18. package/dist/react/use-intl.esm4.js +21 -4
  19. package/dist/react/use-intl.esm4.js.map +1 -1
  20. package/dist/react/use-intl.esm5.js +4 -46
  21. package/dist/react/use-intl.esm5.js.map +1 -1
  22. package/dist/react/use-intl.esm6.js +4 -4
  23. package/dist/react/use-intl.esm6.js.map +1 -1
  24. package/dist/react/use-intl.esm7.js +12 -3
  25. package/dist/react/use-intl.esm7.js.map +1 -1
  26. package/dist/react/use-intl.esm8.js +38 -9
  27. package/dist/react/use-intl.esm8.js.map +1 -1
  28. package/dist/react/use-intl.esm9.js +3 -41
  29. package/dist/react/use-intl.esm9.js.map +1 -1
  30. package/dist/src/core/AbstractIntlMessages.d.ts +9 -0
  31. package/dist/src/core/AbstractIntlMessages.js +2 -0
  32. package/dist/src/core/AbstractIntlMessages.js.map +1 -0
  33. package/dist/src/core/DateTimeFormatOptions.d.ts +72 -0
  34. package/dist/src/core/DateTimeFormatOptions.js +3 -0
  35. package/dist/src/core/DateTimeFormatOptions.js.map +1 -0
  36. package/dist/src/core/Formats.d.ts +7 -0
  37. package/dist/src/core/Formats.js +2 -0
  38. package/dist/src/core/Formats.js.map +1 -0
  39. package/dist/src/core/IntlConfiguration.d.ts +46 -0
  40. package/dist/src/core/IntlConfiguration.js +2 -0
  41. package/dist/src/core/IntlConfiguration.js.map +1 -0
  42. package/dist/src/core/IntlError.d.ts +13 -0
  43. package/dist/src/core/IntlError.js +23 -0
  44. package/dist/src/core/IntlError.js.map +1 -0
  45. package/dist/src/core/IntlMessages.d.ts +2 -0
  46. package/dist/src/core/IntlMessages.js +4 -0
  47. package/dist/src/core/IntlMessages.js.map +1 -0
  48. package/dist/src/core/NumberFormatOptions.d.ts +2 -0
  49. package/dist/src/core/NumberFormatOptions.js +2 -0
  50. package/dist/src/core/NumberFormatOptions.js.map +1 -0
  51. package/dist/src/core/TranslationValues.d.ts +5 -0
  52. package/dist/src/core/TranslationValues.js +2 -0
  53. package/dist/src/core/TranslationValues.js.map +1 -0
  54. package/dist/src/core/convertFormatsToIntlMessageFormat.d.ts +10 -0
  55. package/dist/src/core/convertFormatsToIntlMessageFormat.js +31 -0
  56. package/dist/src/core/convertFormatsToIntlMessageFormat.js.map +1 -0
  57. package/dist/src/core/createBaseTranslator.d.ts +26 -0
  58. package/dist/src/core/createBaseTranslator.js +181 -0
  59. package/dist/src/core/createBaseTranslator.js.map +1 -0
  60. package/dist/src/core/createIntl.d.ts +17 -0
  61. package/dist/src/core/createIntl.js +126 -0
  62. package/dist/src/core/createIntl.js.map +1 -0
  63. package/dist/src/core/createTranslator.d.ts +48 -0
  64. package/dist/src/core/createTranslator.js +24 -0
  65. package/dist/src/core/createTranslator.js.map +1 -0
  66. package/dist/src/core/createTranslatorImpl.d.ts +14 -0
  67. package/dist/src/core/createTranslatorImpl.js +43 -0
  68. package/dist/src/core/createTranslatorImpl.js.map +1 -0
  69. package/dist/src/core/defaults.d.ts +11 -0
  70. package/dist/src/core/defaults.js +11 -0
  71. package/dist/src/core/defaults.js.map +1 -0
  72. package/dist/src/core/index.d.ts +8 -0
  73. package/dist/src/core/index.js +4 -0
  74. package/dist/src/core/index.js.map +1 -0
  75. package/dist/src/core/resolveNamespace.d.ts +5 -0
  76. package/dist/src/core/resolveNamespace.js +10 -0
  77. package/dist/src/core/resolveNamespace.js.map +1 -0
  78. package/dist/src/core/utils/MessageKeys.d.ts +5 -0
  79. package/dist/src/core/utils/MessageKeys.js +2 -0
  80. package/dist/src/core/utils/MessageKeys.js.map +1 -0
  81. package/dist/src/core/utils/NamespaceKeys.d.ts +5 -0
  82. package/dist/src/core/utils/NamespaceKeys.js +2 -0
  83. package/dist/src/core/utils/NamespaceKeys.js.map +1 -0
  84. package/dist/src/core/utils/NestedKeyOf.d.ts +4 -0
  85. package/dist/src/core/utils/NestedKeyOf.js +2 -0
  86. package/dist/src/core/utils/NestedKeyOf.js.map +1 -0
  87. package/dist/src/core/utils/NestedValueOf.d.ts +2 -0
  88. package/dist/src/core/utils/NestedValueOf.js +2 -0
  89. package/dist/src/core/utils/NestedValueOf.js.map +1 -0
  90. package/dist/src/core/validateMessages.d.ts +3 -0
  91. package/dist/src/core/validateMessages.js +22 -0
  92. package/dist/src/core/validateMessages.js.map +1 -0
  93. package/dist/src/index.d.ts +2 -0
  94. package/dist/src/index.js +3 -0
  95. package/dist/src/index.js.map +1 -0
  96. package/dist/src/react/IntlContext.d.ts +21 -0
  97. package/dist/src/react/IntlContext.js +4 -0
  98. package/dist/src/react/IntlContext.js.map +1 -0
  99. package/dist/src/react/IntlProvider.d.ts +16 -0
  100. package/dist/src/react/IntlProvider.js +16 -0
  101. package/dist/src/react/IntlProvider.js.map +1 -0
  102. package/dist/src/react/index.d.ts +6 -0
  103. package/dist/src/react/index.js +7 -0
  104. package/dist/src/react/index.js.map +1 -0
  105. package/dist/src/react/useIntl.d.ts +5 -0
  106. package/dist/src/react/useIntl.js +14 -0
  107. package/dist/src/react/useIntl.js.map +1 -0
  108. package/dist/src/react/useIntlContext.d.ts +1 -0
  109. package/dist/src/react/useIntlContext.js +12 -0
  110. package/dist/src/react/useIntlContext.js.map +1 -0
  111. package/dist/src/react/useLocale.d.ts +1 -0
  112. package/dist/src/react/useLocale.js +5 -0
  113. package/dist/src/react/useLocale.js.map +1 -0
  114. package/dist/src/react/useNow.d.ts +23 -0
  115. package/dist/src/react/useNow.js +40 -0
  116. package/dist/src/react/useNow.js.map +1 -0
  117. package/dist/src/react/useTimeZone.d.ts +1 -0
  118. package/dist/src/react/useTimeZone.js +5 -0
  119. package/dist/src/react/useTimeZone.js.map +1 -0
  120. package/dist/src/react/useTranslations.d.ts +44 -0
  121. package/dist/src/react/useTranslations.js +21 -0
  122. package/dist/src/react/useTranslations.js.map +1 -0
  123. package/dist/src/react/useTranslationsImpl.d.ts +8 -0
  124. package/dist/src/react/useTranslationsImpl.js +35 -0
  125. package/dist/src/react/useTranslationsImpl.js.map +1 -0
  126. package/dist/use-intl.esm.js +7 -7
  127. package/package.json +7 -6
  128. package/LICENSE +0 -21
@@ -1,15 +1,44 @@
1
- import { useContext } from 'react';
2
- import IntlContext from './use-intl.esm7.js';
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.esm7.js';
3
5
 
4
- function useIntlContext() {
5
- var context = useContext(IntlContext);
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.
6
15
 
7
- if (!context) {
8
- throw new Error(process.env.NODE_ENV !== "production" ? 'No intl context found. Have you configured the provider?' : undefined);
9
- }
10
16
 
11
- return context;
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;
12
41
  }
13
42
 
14
- export { useIntlContext as default };
43
+ export { useTranslationsImpl as default };
15
44
  //# 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/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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AAD,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,44 +1,6 @@
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 { createContext } from 'react';
5
2
 
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.
3
+ var IntlContext = /*#__PURE__*/createContext(undefined);
15
4
 
16
-
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;
41
- }
42
-
43
- export { useTranslationsImpl as default };
5
+ export { IntlContext as default };
44
6
  //# 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","createBaseT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U;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/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;;;;"}
@@ -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
+ };