use-intl 2.17.3 → 2.17.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 (217) hide show
  1. package/dist/core/AbstractIntlMessages.d.mts +10 -0
  2. package/dist/core/AbstractIntlMessages.mjs +1 -0
  3. package/dist/core/AbstractIntlMessages.mjs.map +1 -0
  4. package/dist/core/DateTimeFormatOptions.d.mts +75 -0
  5. package/dist/core/DateTimeFormatOptions.mjs +1 -0
  6. package/dist/core/DateTimeFormatOptions.mjs.map +1 -0
  7. package/dist/core/Formats.d.mts +11 -0
  8. package/dist/core/Formats.mjs +1 -0
  9. package/dist/core/Formats.mjs.map +1 -0
  10. package/dist/core/IntlConfig.d.mts +60 -0
  11. package/dist/core/IntlConfig.mjs +1 -0
  12. package/dist/core/IntlConfig.mjs.map +1 -0
  13. package/dist/core/IntlError.d.mts +15 -0
  14. package/dist/core/IntlError.mjs +2 -0
  15. package/dist/core/IntlError.mjs.map +1 -0
  16. package/dist/core/NumberFormatOptions.d.mts +2 -0
  17. package/dist/core/NumberFormatOptions.mjs +2 -0
  18. package/dist/core/NumberFormatOptions.mjs.map +1 -0
  19. package/dist/core/TimeZone.d.mts +3 -0
  20. package/dist/core/TimeZone.mjs +1 -0
  21. package/dist/core/TimeZone.mjs.map +1 -0
  22. package/dist/core/TranslationValues.d.mts +7 -0
  23. package/dist/core/TranslationValues.mjs +1 -0
  24. package/dist/core/TranslationValues.mjs.map +1 -0
  25. package/dist/core/convertFormatsToIntlMessageFormat.d.mts +16 -0
  26. package/dist/core/convertFormatsToIntlMessageFormat.mjs +2 -0
  27. package/dist/core/convertFormatsToIntlMessageFormat.mjs.map +1 -0
  28. package/dist/core/createBaseTranslator.d.mts +32 -0
  29. package/dist/core/createBaseTranslator.mjs +2 -0
  30. package/dist/core/createBaseTranslator.mjs.map +1 -0
  31. package/dist/core/createFormatter.d.mts +21 -0
  32. package/dist/core/createFormatter.mjs +2 -0
  33. package/dist/core/createFormatter.mjs.map +1 -0
  34. package/dist/core/createIntl.d.mts +15 -0
  35. package/dist/core/createIntl.mjs +2 -0
  36. package/dist/core/createIntl.mjs.map +1 -0
  37. package/dist/core/createTranslator.d.mts +57 -0
  38. package/dist/core/createTranslator.mjs +2 -0
  39. package/dist/core/createTranslator.mjs.map +1 -0
  40. package/dist/core/createTranslatorImpl.d.mts +25 -0
  41. package/dist/core/createTranslatorImpl.mjs +2 -0
  42. package/dist/core/createTranslatorImpl.mjs.map +1 -0
  43. package/dist/core/defaults.d.mts +14 -0
  44. package/dist/core/defaults.mjs +2 -0
  45. package/dist/core/defaults.mjs.map +1 -0
  46. package/dist/core/index.d.mts +17 -0
  47. package/dist/core/index.mjs +2 -0
  48. package/dist/core/index.mjs.map +1 -0
  49. package/dist/core/resolveNamespace.d.mts +7 -0
  50. package/dist/core/resolveNamespace.mjs +2 -0
  51. package/dist/core/resolveNamespace.mjs.map +1 -0
  52. package/dist/core/utils/MessageKeys.d.mts +7 -0
  53. package/dist/core/utils/MessageKeys.mjs +1 -0
  54. package/dist/core/utils/MessageKeys.mjs.map +1 -0
  55. package/dist/core/utils/NamespaceKeys.d.mts +7 -0
  56. package/dist/core/utils/NamespaceKeys.mjs +1 -0
  57. package/dist/core/utils/NamespaceKeys.mjs.map +1 -0
  58. package/dist/core/utils/NestedKeyOf.d.mts +5 -0
  59. package/dist/core/utils/NestedKeyOf.mjs +1 -0
  60. package/dist/core/utils/NestedKeyOf.mjs.map +1 -0
  61. package/dist/core/utils/NestedValueOf.d.mts +3 -0
  62. package/dist/core/utils/NestedValueOf.mjs +1 -0
  63. package/dist/core/utils/NestedValueOf.mjs.map +1 -0
  64. package/dist/core/validateMessages.d.mts +6 -0
  65. package/dist/core/validateMessages.mjs +34 -0
  66. package/dist/core/validateMessages.mjs.map +1 -0
  67. package/dist/index.d.mts +25 -0
  68. package/dist/index.mjs +2 -0
  69. package/dist/index.mjs.map +1 -0
  70. package/dist/react/IntlContext.d.mts +13 -0
  71. package/dist/react/IntlContext.mjs +2 -0
  72. package/dist/react/IntlContext.mjs.map +1 -0
  73. package/dist/react/IntlProvider.d.mts +16 -0
  74. package/dist/react/IntlProvider.mjs +2 -0
  75. package/dist/react/IntlProvider.mjs.map +1 -0
  76. package/dist/react/getInitializedConfig.d.mts +24 -0
  77. package/dist/react/getInitializedConfig.mjs +2 -0
  78. package/dist/react/getInitializedConfig.mjs.map +1 -0
  79. package/dist/react/index.d.mts +21 -0
  80. package/dist/react/index.mjs +2 -0
  81. package/dist/react/index.mjs.map +1 -0
  82. package/dist/react/useFormatter.d.mts +12 -0
  83. package/dist/react/useFormatter.mjs +2 -0
  84. package/dist/react/useFormatter.mjs.map +1 -0
  85. package/dist/react/useIntl.d.mts +12 -0
  86. package/dist/react/useIntl.mjs +2 -0
  87. package/dist/react/useIntl.mjs.map +1 -0
  88. package/dist/react/useIntlContext.d.mts +13 -0
  89. package/dist/react/useIntlContext.mjs +2 -0
  90. package/dist/react/useIntlContext.mjs.map +1 -0
  91. package/dist/react/useLocale.d.mts +3 -0
  92. package/dist/react/useLocale.mjs +2 -0
  93. package/dist/react/useLocale.mjs.map +1 -0
  94. package/dist/react/useMessages.d.mts +5 -0
  95. package/dist/react/useMessages.mjs +2 -0
  96. package/dist/react/useMessages.mjs.map +1 -0
  97. package/dist/react/useNow.d.mts +24 -0
  98. package/dist/react/useNow.mjs +2 -0
  99. package/dist/react/useNow.mjs.map +1 -0
  100. package/dist/react/useTimeZone.d.mts +5 -0
  101. package/dist/react/useTimeZone.mjs +2 -0
  102. package/dist/react/useTimeZone.mjs.map +1 -0
  103. package/dist/react/useTranslations.d.mts +50 -0
  104. package/dist/react/useTranslations.mjs +2 -0
  105. package/dist/react/useTranslations.mjs.map +1 -0
  106. package/dist/react/useTranslationsImpl.d.mts +16 -0
  107. package/dist/react/useTranslationsImpl.mjs +2 -0
  108. package/dist/react/useTranslationsImpl.mjs.map +1 -0
  109. package/dist/src/core/AbstractIntlMessages.d.mts +10 -0
  110. package/dist/src/core/AbstractIntlMessages.mjs +1 -0
  111. package/dist/src/core/AbstractIntlMessages.mjs.map +1 -0
  112. package/dist/src/core/DateTimeFormatOptions.d.mts +75 -0
  113. package/dist/src/core/DateTimeFormatOptions.mjs +1 -0
  114. package/dist/src/core/DateTimeFormatOptions.mjs.map +1 -0
  115. package/dist/src/core/Formats.d.mts +11 -0
  116. package/dist/src/core/Formats.mjs +1 -0
  117. package/dist/src/core/Formats.mjs.map +1 -0
  118. package/dist/src/core/IntlConfig.d.mts +60 -0
  119. package/dist/src/core/IntlConfig.mjs +1 -0
  120. package/dist/src/core/IntlConfig.mjs.map +1 -0
  121. package/dist/src/core/IntlError.d.mts +15 -0
  122. package/dist/src/core/IntlError.mjs +2 -0
  123. package/dist/src/core/IntlError.mjs.map +1 -0
  124. package/dist/src/core/NumberFormatOptions.d.mts +2 -0
  125. package/dist/src/core/NumberFormatOptions.mjs +2 -0
  126. package/dist/src/core/NumberFormatOptions.mjs.map +1 -0
  127. package/dist/src/core/TimeZone.d.mts +3 -0
  128. package/dist/src/core/TimeZone.mjs +1 -0
  129. package/dist/src/core/TimeZone.mjs.map +1 -0
  130. package/dist/src/core/TranslationValues.d.mts +7 -0
  131. package/dist/src/core/TranslationValues.mjs +1 -0
  132. package/dist/src/core/TranslationValues.mjs.map +1 -0
  133. package/dist/src/core/convertFormatsToIntlMessageFormat.d.mts +16 -0
  134. package/dist/src/core/convertFormatsToIntlMessageFormat.mjs +2 -0
  135. package/dist/src/core/convertFormatsToIntlMessageFormat.mjs.map +1 -0
  136. package/dist/src/core/createBaseTranslator.d.mts +32 -0
  137. package/dist/src/core/createBaseTranslator.mjs +2 -0
  138. package/dist/src/core/createBaseTranslator.mjs.map +1 -0
  139. package/dist/src/core/createFormatter.d.mts +21 -0
  140. package/dist/src/core/createFormatter.mjs +2 -0
  141. package/dist/src/core/createFormatter.mjs.map +1 -0
  142. package/dist/src/core/createIntl.d.mts +15 -0
  143. package/dist/src/core/createIntl.mjs +2 -0
  144. package/dist/src/core/createIntl.mjs.map +1 -0
  145. package/dist/src/core/createTranslator.d.mts +57 -0
  146. package/dist/src/core/createTranslator.mjs +2 -0
  147. package/dist/src/core/createTranslator.mjs.map +1 -0
  148. package/dist/src/core/createTranslatorImpl.d.mts +25 -0
  149. package/dist/src/core/createTranslatorImpl.mjs +2 -0
  150. package/dist/src/core/createTranslatorImpl.mjs.map +1 -0
  151. package/dist/src/core/defaults.d.mts +14 -0
  152. package/dist/src/core/defaults.mjs +2 -0
  153. package/dist/src/core/defaults.mjs.map +1 -0
  154. package/dist/src/core/index.d.mts +17 -0
  155. package/dist/src/core/index.mjs +2 -0
  156. package/dist/src/core/index.mjs.map +1 -0
  157. package/dist/src/core/resolveNamespace.d.mts +7 -0
  158. package/dist/src/core/resolveNamespace.mjs +2 -0
  159. package/dist/src/core/resolveNamespace.mjs.map +1 -0
  160. package/dist/src/core/utils/MessageKeys.d.mts +7 -0
  161. package/dist/src/core/utils/MessageKeys.mjs +1 -0
  162. package/dist/src/core/utils/MessageKeys.mjs.map +1 -0
  163. package/dist/src/core/utils/NamespaceKeys.d.mts +7 -0
  164. package/dist/src/core/utils/NamespaceKeys.mjs +1 -0
  165. package/dist/src/core/utils/NamespaceKeys.mjs.map +1 -0
  166. package/dist/src/core/utils/NestedKeyOf.d.mts +5 -0
  167. package/dist/src/core/utils/NestedKeyOf.mjs +1 -0
  168. package/dist/src/core/utils/NestedKeyOf.mjs.map +1 -0
  169. package/dist/src/core/utils/NestedValueOf.d.mts +3 -0
  170. package/dist/src/core/utils/NestedValueOf.mjs +1 -0
  171. package/dist/src/core/utils/NestedValueOf.mjs.map +1 -0
  172. package/dist/src/core/validateMessages.d.mts +6 -0
  173. package/dist/src/core/validateMessages.mjs +34 -0
  174. package/dist/src/core/validateMessages.mjs.map +1 -0
  175. package/dist/src/index.d.mts +25 -0
  176. package/dist/src/index.mjs +2 -0
  177. package/dist/src/index.mjs.map +1 -0
  178. package/dist/src/react/IntlContext.d.mts +13 -0
  179. package/dist/src/react/IntlContext.mjs +2 -0
  180. package/dist/src/react/IntlContext.mjs.map +1 -0
  181. package/dist/src/react/IntlProvider.d.mts +16 -0
  182. package/dist/src/react/IntlProvider.mjs +2 -0
  183. package/dist/src/react/IntlProvider.mjs.map +1 -0
  184. package/dist/src/react/getInitializedConfig.d.mts +24 -0
  185. package/dist/src/react/getInitializedConfig.mjs +2 -0
  186. package/dist/src/react/getInitializedConfig.mjs.map +1 -0
  187. package/dist/src/react/index.d.mts +21 -0
  188. package/dist/src/react/index.mjs +2 -0
  189. package/dist/src/react/index.mjs.map +1 -0
  190. package/dist/src/react/useFormatter.d.mts +12 -0
  191. package/dist/src/react/useFormatter.mjs +2 -0
  192. package/dist/src/react/useFormatter.mjs.map +1 -0
  193. package/dist/src/react/useIntl.d.mts +12 -0
  194. package/dist/src/react/useIntl.mjs +2 -0
  195. package/dist/src/react/useIntl.mjs.map +1 -0
  196. package/dist/src/react/useIntlContext.d.mts +13 -0
  197. package/dist/src/react/useIntlContext.mjs +2 -0
  198. package/dist/src/react/useIntlContext.mjs.map +1 -0
  199. package/dist/src/react/useLocale.d.mts +3 -0
  200. package/dist/src/react/useLocale.mjs +2 -0
  201. package/dist/src/react/useLocale.mjs.map +1 -0
  202. package/dist/src/react/useMessages.d.mts +5 -0
  203. package/dist/src/react/useMessages.mjs +2 -0
  204. package/dist/src/react/useMessages.mjs.map +1 -0
  205. package/dist/src/react/useNow.d.mts +24 -0
  206. package/dist/src/react/useNow.mjs +2 -0
  207. package/dist/src/react/useNow.mjs.map +1 -0
  208. package/dist/src/react/useTimeZone.d.mts +5 -0
  209. package/dist/src/react/useTimeZone.mjs +2 -0
  210. package/dist/src/react/useTimeZone.mjs.map +1 -0
  211. package/dist/src/react/useTranslations.d.mts +50 -0
  212. package/dist/src/react/useTranslations.mjs +2 -0
  213. package/dist/src/react/useTranslations.mjs.map +1 -0
  214. package/dist/src/react/useTranslationsImpl.d.mts +16 -0
  215. package/dist/src/react/useTranslationsImpl.mjs +2 -0
  216. package/dist/src/react/useTranslationsImpl.mjs.map +1 -0
  217. package/package.json +3 -2
@@ -0,0 +1,10 @@
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
+ type AbstractIntlMessages = {
7
+ [id: string]: AbstractIntlMessages | string;
8
+ };
9
+
10
+ export { AbstractIntlMessages as default };
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=AbstractIntlMessages.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,75 @@
1
+ import TimeZone from './TimeZone.mjs';
2
+
3
+ /**
4
+ * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat
5
+ */
6
+ type DateTimeFormatOptions = Intl.DateTimeFormatOptions & {
7
+ /**
8
+ * Examples:
9
+ * - numeric: "2021"
10
+ * - 2-digit: "21"
11
+ */
12
+ year?: 'numeric' | '2-digit';
13
+ /** Examples:
14
+ * - numeric: "3"
15
+ * - 2-digit: "03"
16
+ * - long: "March"
17
+ * - short: "Mar"
18
+ * - narrow: "M"
19
+ */
20
+ month?: 'numeric' | '2-digit' | 'long' | 'short' | 'narrow';
21
+ /** Examples:
22
+ * - numeric: "2"
23
+ * - 2-digit: "02"
24
+ */
25
+ day?: 'numeric' | '2-digit';
26
+ /** Examples:
27
+ * - numeric: "2"
28
+ * - 2-digit: "02"
29
+ */
30
+ hour?: 'numeric' | '2-digit';
31
+ /** Examples:
32
+ * - numeric: "2"
33
+ * - 2-digit: "02"
34
+ */
35
+ minute?: 'numeric' | '2-digit';
36
+ /** Examples:
37
+ * - numeric: "2"
38
+ * - 2-digit: "02"
39
+ */
40
+ second?: 'numeric' | '2-digit';
41
+ /** Examples:
42
+ * - long: "Thursday"
43
+ * - short: "Thu"
44
+ * - narrow: "T"
45
+ */
46
+ weekday?: 'long' | 'short' | 'narrow';
47
+ /** Examples:
48
+ * - long: "Anno Domini"
49
+ * - short: "AD", narrow "A"
50
+ */
51
+ era?: 'long' | 'short' | 'narrow';
52
+ /** If this is set to `true`, a 12-hour am/pm format is used. Otherwise a 24-hour time.
53
+ *
54
+ */
55
+ hour12?: boolean;
56
+ /** Examples:
57
+ * - long: "Pacific Daylight Time"
58
+ * - short: "PDT"
59
+ */
60
+ timeZoneName?: 'long' | 'short';
61
+ /**
62
+ * One of the [database names from the TZ database](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List).
63
+ */
64
+ timeZone?: TimeZone;
65
+ localeMatcher?: 'best fit' | 'lookup';
66
+ formatMatcher?: 'best fit' | 'basic';
67
+ dateStyle?: 'full' | 'long' | 'medium' | 'short';
68
+ timeStyle?: 'full' | 'long' | 'medium' | 'short';
69
+ calendar?: 'buddhist' | 'chinese' | 'coptic' | 'ethiopia' | 'ethiopic' | 'gregory' | 'hebrew' | 'indian' | 'islamic' | 'iso8601' | 'japanese' | 'persian' | 'roc';
70
+ dayPeriod?: 'narrow' | 'short' | 'long';
71
+ numberingSystem?: 'arab' | 'arabext' | 'bali' | 'beng' | 'deva' | 'fullwide' | 'gujr' | 'guru' | 'hanidec' | 'khmr' | 'knda' | 'laoo' | 'latn' | 'limb' | 'mlym' | 'mong' | 'mymr' | 'orya' | 'tamldec' | 'telu' | 'thai' | 'tibt';
72
+ hourCycle?: 'h11' | 'h12' | 'h23' | 'h24';
73
+ };
74
+
75
+ export { DateTimeFormatOptions as default };
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=DateTimeFormatOptions.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,11 @@
1
+ import DateTimeFormatOptions from './DateTimeFormatOptions.mjs';
2
+ import { NumberFormatOptions } from '@formatjs/ecma402-abstract/types/number';
3
+ import './TimeZone.mjs';
4
+
5
+ type Formats = {
6
+ number: Record<string, NumberFormatOptions>;
7
+ dateTime: Record<string, DateTimeFormatOptions>;
8
+ list: Record<string, Intl.ListFormatOptions>;
9
+ };
10
+
11
+ export { Formats as default };
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=Formats.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,60 @@
1
+ import Formats from './Formats.mjs';
2
+ import IntlError from './IntlError.mjs';
3
+ import TimeZone from './TimeZone.mjs';
4
+ import AbstractIntlMessages from './AbstractIntlMessages.mjs';
5
+ import { RichTranslationValues } from './TranslationValues.mjs';
6
+ import './DateTimeFormatOptions.mjs';
7
+ import '@formatjs/ecma402-abstract/types/number';
8
+ import 'react';
9
+
10
+ /**
11
+ * Should be used for entry points that configure the library.
12
+ */
13
+ type IntlConfig<Messages = AbstractIntlMessages> = {
14
+ /** A valid Unicode locale tag (e.g. "en" or "en-GB"). */
15
+ locale: string;
16
+ /** Global formats can be provided to achieve consistent
17
+ * formatting across components. */
18
+ formats?: Partial<Formats>;
19
+ /** 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`. */
20
+ timeZone?: TimeZone;
21
+ /** This callback will be invoked when an error is encountered during
22
+ * resolving a message or formatting it. This defaults to `console.error` to
23
+ * keep your app running. You can customize the handling by taking
24
+ * `error.code` into account. */
25
+ onError?(error: IntlError): void;
26
+ /** Will be called when a message couldn't be resolved or formatting it led to
27
+ * an error. This defaults to `${namespace}.${key}` You can use this to
28
+ * customize what will be rendered in this case. */
29
+ getMessageFallback?(info: {
30
+ error: IntlError;
31
+ key: string;
32
+ namespace?: string;
33
+ }): string;
34
+ /**
35
+ * Providing this value will have two effects:
36
+ * 1. It will be used as the default for the `now` argument of
37
+ * `useIntl().formatRelativeTime` if no explicit value is provided.
38
+ * 2. It will be returned as a static value from the `useNow` hook. Note
39
+ * however that when `updateInterval` is configured on the `useNow` hook,
40
+ * the global `now` value will only be used for the initial render, but
41
+ * afterwards the current date will be returned continuously.
42
+ */
43
+ now?: Date;
44
+ /** All messages that will be available. */
45
+ messages?: Messages;
46
+ /** Global default values for translation values and rich text elements.
47
+ * Can be used for consistent usage or styling of rich text elements.
48
+ * Defaults will be overidden by locally provided values. */
49
+ defaultTranslationValues?: RichTranslationValues;
50
+ };
51
+ /**
52
+ * A stricter set of the configuration that should be used internally
53
+ * once defaults are assigned to `IntlConfiguration`.
54
+ */
55
+ type InitializedIntlConfig<Messages = AbstractIntlMessages> = IntlConfig<Messages> & {
56
+ onError: NonNullable<IntlConfig<Messages>['onError']>;
57
+ getMessageFallback: NonNullable<IntlConfig<Messages>['getMessageFallback']>;
58
+ };
59
+
60
+ export { InitializedIntlConfig, IntlConfig as default };
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=IntlConfig.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,15 @@
1
+ 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
+ declare class IntlError extends Error {
10
+ readonly code: IntlErrorCode;
11
+ readonly originalMessage: string | undefined;
12
+ constructor(code: IntlErrorCode, originalMessage?: string);
13
+ }
14
+
15
+ export { IntlErrorCode, IntlError as default };
@@ -0,0 +1,2 @@
1
+ var E=(I=>(I.MISSING_MESSAGE="MISSING_MESSAGE",I.MISSING_FORMAT="MISSING_FORMAT",I.INSUFFICIENT_PATH="INSUFFICIENT_PATH",I.INVALID_MESSAGE="INVALID_MESSAGE",I.INVALID_KEY="INVALID_KEY",I.FORMATTING_ERROR="FORMATTING_ERROR",I))(E||{});class _ extends Error{constructor(A,S){let N=A;S&&(N+=": "+S);super(N);this.code=A,S&&(this.originalMessage=S)}}export{E as IntlErrorCode,_ as default};
2
+ //# sourceMappingURL=IntlError.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/core/IntlError.tsx"],"sourcesContent":["export enum IntlErrorCode {\n MISSING_MESSAGE = 'MISSING_MESSAGE',\n MISSING_FORMAT = 'MISSING_FORMAT',\n INSUFFICIENT_PATH = 'INSUFFICIENT_PATH',\n INVALID_MESSAGE = 'INVALID_MESSAGE',\n INVALID_KEY = 'INVALID_KEY',\n FORMATTING_ERROR = 'FORMATTING_ERROR'\n}\n\nexport default class IntlError extends Error {\n public readonly code: IntlErrorCode;\n public readonly originalMessage: string | undefined;\n\n constructor(code: IntlErrorCode, originalMessage?: string) {\n let message: string = code;\n if (originalMessage) {\n message += ': ' + originalMessage;\n }\n super(message);\n\n this.code = code;\n if (originalMessage) {\n this.originalMessage = originalMessage;\n }\n }\n}\n"],"mappings":"AAAO,IAAKA,OACVA,EAAA,gBAAkB,kBAClBA,EAAA,eAAiB,iBACjBA,EAAA,kBAAoB,oBACpBA,EAAA,gBAAkB,kBAClBA,EAAA,YAAc,cACdA,EAAA,iBAAmB,mBANTA,OAAA,IASZ,MAAOC,UAAgC,KAAM,CAI3C,YAAYC,EAAqBC,EAA0B,CACzD,IAAIC,EAAkBF,EAClBC,IACFC,GAAW,KAAOD,GAEpB,MAAMC,CAAO,EAEb,KAAK,KAAOF,EACRC,IACF,KAAK,gBAAkBA,EAE3B,CACF","names":["IntlErrorCode","IntlError","code","originalMessage","message"]}
@@ -0,0 +1,2 @@
1
+ import { NumberFormatOptions } from '@formatjs/ecma402-abstract/types/number';
2
+ export { NumberFormatOptions as default } from '@formatjs/ecma402-abstract/types/number';
@@ -0,0 +1,2 @@
1
+ var t=NumberFormatOptions;export{t as default};
2
+ //# sourceMappingURL=NumberFormatOptions.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/core/NumberFormatOptions.tsx"],"sourcesContent":["import type {NumberFormatOptions} from '@formatjs/ecma402-abstract/types/number';\n\nexport default NumberFormatOptions;\n"],"mappings":"AAEA,IAAOA,EAAQ","names":["NumberFormatOptions_default"]}
@@ -0,0 +1,3 @@
1
+ type TimeZone = 'Africa/Abidjan' | 'Africa/Accra' | 'Africa/Addis_Ababa' | 'Africa/Algiers' | 'Africa/Asmara' | 'Africa/Bamako' | 'Africa/Bangui' | 'Africa/Banjul' | 'Africa/Bissau' | 'Africa/Blantyre' | 'Africa/Brazzaville' | 'Africa/Bujumbura' | 'Africa/Cairo' | 'Africa/Casablanca' | 'Africa/Ceuta' | 'Africa/Conakry' | 'Africa/Dakar' | 'Africa/Dar_es_Salaam' | 'Africa/Djibouti' | 'Africa/Douala' | 'Africa/El_Aaiun' | 'Africa/Freetown' | 'Africa/Gaborone' | 'Africa/Harare' | 'Africa/Johannesburg' | 'Africa/Juba' | 'Africa/Kampala' | 'Africa/Khartoum' | 'Africa/Kigali' | 'Africa/Kinshasa' | 'Africa/Lagos' | 'Africa/Libreville' | 'Africa/Lome' | 'Africa/Luanda' | 'Africa/Lubumbashi' | 'Africa/Lusaka' | 'Africa/Malabo' | 'Africa/Maputo' | 'Africa/Maseru' | 'Africa/Mbabane' | 'Africa/Mogadishu' | 'Africa/Monrovia' | 'Africa/Nairobi' | 'Africa/Ndjamena' | 'Africa/Niamey' | 'Africa/Nouakchott' | 'Africa/Ouagadougou' | 'Africa/Porto-Novo' | 'Africa/Sao_Tome' | 'Africa/Tripoli' | 'Africa/Tunis' | 'Africa/Windhoek' | 'America/Adak' | 'America/Anchorage' | 'America/Anguilla' | 'America/Antigua' | 'America/Araguaina' | 'America/Argentina/Buenos_Aires' | 'America/Argentina/Catamarca' | 'America/Argentina/Cordoba' | 'America/Argentina/Jujuy' | 'America/Argentina/La_Rioja' | 'America/Argentina/Mendoza' | 'America/Argentina/Rio_Gallegos' | 'America/Argentina/Salta' | 'America/Argentina/San_Juan' | 'America/Argentina/San_Luis' | 'America/Argentina/Tucuman' | 'America/Argentina/Ushuaia' | 'America/Aruba' | 'America/Asuncion' | 'America/Atikokan' | 'America/Bahia' | 'America/Bahia_Banderas' | 'America/Barbados' | 'America/Belem' | 'America/Belize' | 'America/Blanc-Sablon' | 'America/Boa_Vista' | 'America/Bogota' | 'America/Boise' | 'America/Cambridge_Bay' | 'America/Campo_Grande' | 'America/Cancun' | 'America/Caracas' | 'America/Cayenne' | 'America/Cayman' | 'America/Chicago' | 'America/Chihuahua' | 'America/Costa_Rica' | 'America/Creston' | 'America/Cuiaba' | 'America/Curacao' | 'America/Danmarkshavn' | 'America/Dawson' | 'America/Dawson_Creek' | 'America/Denver' | 'America/Detroit' | 'America/Dominica' | 'America/Edmonton' | 'America/Eirunepe' | 'America/El_Salvador' | 'America/Fort_Nelson' | 'America/Fortaleza' | 'America/Glace_Bay' | 'America/Godthab' | 'America/Goose_Bay' | 'America/Grand_Turk' | 'America/Grenada' | 'America/Guadeloupe' | 'America/Guatemala' | 'America/Guayaquil' | 'America/Guyana' | 'America/Halifax' | 'America/Havana' | 'America/Hermosillo' | 'America/Indiana/Indianapolis' | 'America/Indiana/Knox' | 'America/Indiana/Marengo' | 'America/Indiana/Petersburg' | 'America/Indiana/Tell_City' | 'America/Indiana/Vevay' | 'America/Indiana/Vincennes' | 'America/Indiana/Winamac' | 'America/Inuvik' | 'America/Iqaluit' | 'America/Jamaica' | 'America/Juneau' | 'America/Kentucky/Louisville' | 'America/Kentucky/Monticello' | 'America/Kralendijk' | 'America/La_Paz' | 'America/Lima' | 'America/Los_Angeles' | 'America/Lower_Princes' | 'America/Maceio' | 'America/Managua' | 'America/Manaus' | 'America/Marigot' | 'America/Martinique' | 'America/Matamoros' | 'America/Mazatlan' | 'America/Menominee' | 'America/Merida' | 'America/Metlakatla' | 'America/Mexico_City' | 'America/Miquelon' | 'America/Moncton' | 'America/Monterrey' | 'America/Montevideo' | 'America/Montserrat' | 'America/Nassau' | 'America/New_York' | 'America/Nipigon' | 'America/Nome' | 'America/Noronha' | 'America/North_Dakota/Beulah' | 'America/North_Dakota/Center' | 'America/North_Dakota/New_Salem' | 'America/Ojinaga' | 'America/Panama' | 'America/Pangnirtung' | 'America/Paramaribo' | 'America/Phoenix' | 'America/Port-au-Prince' | 'America/Port_of_Spain' | 'America/Porto_Velho' | 'America/Puerto_Rico' | 'America/Punta_Arenas' | 'America/Rainy_River' | 'America/Rankin_Inlet' | 'America/Recife' | 'America/Regina' | 'America/Resolute' | 'America/Rio_Branco' | 'America/Santarem' | 'America/Santiago' | 'America/Santo_Domingo' | 'America/Sao_Paulo' | 'America/Scoresbysund' | 'America/Sitka' | 'America/St_Barthelemy' | 'America/St_Johns' | 'America/St_Kitts' | 'America/St_Lucia' | 'America/St_Thomas' | 'America/St_Vincent' | 'America/Swift_Current' | 'America/Tegucigalpa' | 'America/Thule' | 'America/Thunder_Bay' | 'America/Tijuana' | 'America/Toronto' | 'America/Tortola' | 'America/Vancouver' | 'America/Whitehorse' | 'America/Winnipeg' | 'America/Yakutat' | 'America/Yellowknife' | 'Antarctica/Casey' | 'Antarctica/Davis' | 'Antarctica/DumontDUrville' | 'Antarctica/Macquarie' | 'Antarctica/Mawson' | 'Antarctica/Palmer' | 'Antarctica/Rothera' | 'Antarctica/Syowa' | 'Antarctica/Troll' | 'Antarctica/Vostok' | 'Arctic/Longyearbyen' | 'Asia/Almaty' | 'Asia/Amman' | 'Asia/Anadyr' | 'Asia/Aqtau' | 'Asia/Aqtobe' | 'Asia/Ashgabat' | 'Asia/Atyrau' | 'Asia/Baghdad' | 'Asia/Baku' | 'Asia/Bangkok' | 'Asia/Barnaul' | 'Asia/Beirut' | 'Asia/Bishkek' | 'Asia/Brunei' | 'Asia/Chita' | 'Asia/Choibalsan' | 'Asia/Colombo' | 'Asia/Damascus' | 'Asia/Dhaka' | 'Asia/Dili' | 'Asia/Dubai' | 'Asia/Dushanbe' | 'Asia/Famagusta' | 'Asia/Gaza' | 'Asia/Hebron' | 'Asia/Ho_Chi_Minh' | 'Asia/Hong_Kong' | 'Asia/Hovd' | 'Asia/Irkutsk' | 'Asia/Jakarta' | 'Asia/Jayapura' | 'Asia/Jerusalem' | 'Asia/Kabul' | 'Asia/Kamchatka' | 'Asia/Karachi' | 'Asia/Kathmandu' | 'Asia/Khandyga' | 'Asia/Kolkata' | 'Asia/Krasnoyarsk' | 'Asia/Kuala_Lumpur' | 'Asia/Kuching' | 'Asia/Macau' | 'Asia/Magadan' | 'Asia/Makassar' | 'Asia/Manila' | 'Asia/Nicosia' | 'Asia/Novokuznetsk' | 'Asia/Novosibirsk' | 'Asia/Omsk' | 'Asia/Oral' | 'Asia/Phnom_Penh' | 'Asia/Pontianak' | 'Asia/Pyongyang' | 'Asia/Qatar' | 'Asia/Qostanay' | 'Asia/Qyzylorda' | 'Asia/Riyadh' | 'Asia/Sakhalin' | 'Asia/Samarkand' | 'Asia/Seoul' | 'Asia/Shanghai' | 'Asia/Singapore' | 'Asia/Srednekolymsk' | 'Asia/Taipei' | 'Asia/Tashkent' | 'Asia/Tbilisi' | 'Asia/Tehran' | 'Asia/Thimphu' | 'Asia/Tokyo' | 'Asia/Tomsk' | 'Asia/Ulaanbaatar' | 'Asia/Urumqi' | 'Asia/Ust-Nera' | 'Asia/Vladivostok' | 'Asia/Yakutsk' | 'Asia/Yangon' | 'Asia/Yekaterinburg' | 'Asia/Yerevan' | 'Atlantic/Azores' | 'Atlantic/Bermuda' | 'Atlantic/Canary' | 'Atlantic/Cape_Verde' | 'Atlantic/Faroe' | 'Atlantic/Madeira' | 'Atlantic/Reykjavik' | 'Atlantic/South_Georgia' | 'Atlantic/St_Helena' | 'Atlantic/Stanley' | 'Australia/Adelaide' | 'Australia/Brisbane' | 'Australia/Broken_Hill' | 'Australia/Currie' | 'Australia/Darwin' | 'Australia/Eucla' | 'Australia/Hobart' | 'Australia/Lindeman' | 'Australia/Lord_Howe' | 'Australia/Melbourne' | 'Australia/Perth' | 'Australia/Sydney' | 'Europe/Amsterdam' | 'Europe/Andorra' | 'Europe/Astrakhan' | 'Europe/Athens' | 'Europe/Belgrade' | 'Europe/Berlin' | 'Europe/Bratislava' | 'Europe/Brussels' | 'Europe/Bucharest' | 'Europe/Budapest' | 'Europe/Busingen' | 'Europe/Chisinau' | 'Europe/Copenhagen' | 'Europe/Dublin' | 'Europe/Gibraltar' | 'Europe/Guernsey' | 'Europe/Helsinki' | 'Europe/Isle_of_Man' | 'Europe/Istanbul' | 'Europe/Jersey' | 'Europe/Kaliningrad' | 'Europe/Kiev' | 'Europe/Kirov' | 'Europe/Lisbon' | 'Europe/Ljubljana' | 'Europe/London' | 'Europe/Luxembourg' | 'Europe/Madrid' | 'Europe/Malta' | 'Europe/Mariehamn' | 'Europe/Minsk' | 'Europe/Monaco' | 'Europe/Moscow' | 'Europe/Oslo' | 'Europe/Paris' | 'Europe/Podgorica' | 'Europe/Prague' | 'Europe/Riga' | 'Europe/Rome' | 'Europe/Samara' | 'Europe/San_Marino' | 'Europe/Sarajevo' | 'Europe/Saratov' | 'Europe/Simferopol' | 'Europe/Skopje' | 'Europe/Sofia' | 'Europe/Stockholm' | 'Europe/Tallinn' | 'Europe/Tirane' | 'Europe/Ulyanovsk' | 'Europe/Uzhgorod' | 'Europe/Vaduz' | 'Europe/Vatican' | 'Europe/Vienna' | 'Europe/Vilnius' | 'Europe/Volgograd' | 'Europe/Warsaw' | 'Europe/Zagreb' | 'Europe/Zaporozhye' | 'Europe/Zurich' | 'Indian/Antananarivo' | 'Indian/Chagos' | 'Indian/Christmas' | 'Indian/Cocos' | 'Indian/Comoro' | 'Indian/Kerguelen' | 'Indian/Mahe' | 'Indian/Maldives' | 'Indian/Mauritius' | 'Indian/Mayotte' | 'Indian/Reunion' | 'Pacific/Apia' | 'Pacific/Auckland' | 'Pacific/Bougainville' | 'Pacific/Chatham' | 'Pacific/Chuuk' | 'Pacific/Easter' | 'Pacific/Efate' | 'Pacific/Enderbury' | 'Pacific/Fakaofo' | 'Pacific/Fiji' | 'Pacific/Funafuti' | 'Pacific/Galapagos' | 'Pacific/Gambier' | 'Pacific/Guadalcanal' | 'Pacific/Guam' | 'Pacific/Honolulu' | 'Pacific/Kiritimati' | 'Pacific/Kosrae' | 'Pacific/Kwajalein' | 'Pacific/Majuro' | 'Pacific/Marquesas' | 'Pacific/Nauru' | 'Pacific/Niue' | 'Pacific/Norfolk' | 'Pacific/Noumea' | 'Pacific/Pago_Pago' | 'Pacific/Palau' | 'Pacific/Pitcairn' | 'Pacific/Pohnpei' | 'Pacific/Port_Moresby' | 'Pacific/Rarotonga' | 'Pacific/Tahiti' | 'Pacific/Tarawa' | 'Pacific/Tongatapu' | 'Pacific/Wake' | 'Pacific/Wallis' | 'UTC' | 'W-SU' | 'WET' | 'Zulu' | (string & {});
2
+
3
+ export { TimeZone as default };
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=TimeZone.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,7 @@
1
+ import { ReactNode } from 'react';
2
+
3
+ type TranslationValue = string | number | boolean | Date | null | undefined;
4
+ type TranslationValues = Record<string, TranslationValue>;
5
+ type RichTranslationValues = Record<string, TranslationValue | ((chunks: ReactNode) => ReactNode)>;
6
+
7
+ export { RichTranslationValues, TranslationValue, TranslationValues as default };
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=TranslationValues.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,16 @@
1
+ import { Formats as Formats$1 } from 'intl-messageformat';
2
+ import Formats from './Formats.mjs';
3
+ import TimeZone from './TimeZone.mjs';
4
+ import './DateTimeFormatOptions.mjs';
5
+ import '@formatjs/ecma402-abstract/types/number';
6
+
7
+ /**
8
+ * `intl-messageformat` uses separate keys for `date` and `time`, but there's
9
+ * only one native API: `Intl.DateTimeFormat`. Additionally you might want to
10
+ * include both a time and a date in a value, therefore the separation doesn't
11
+ * seem so useful. We offer a single `dateTime` namespace instead, but we have
12
+ * to convert the format before `intl-messageformat` can be used.
13
+ */
14
+ declare function convertFormatsToIntlMessageFormat(formats: Partial<Formats>, timeZone?: TimeZone): Partial<Formats$1>;
15
+
16
+ export { convertFormatsToIntlMessageFormat as default };
@@ -0,0 +1,2 @@
1
+ function i(t,r){return t&&Object.keys(t).reduce((e,o)=>(e[o]={timeZone:r,...t[o]},e),{})}function m(t,r){const e=r?{...t,dateTime:i(t.dateTime,r)}:t;return{...e,date:e?.dateTime,time:e?.dateTime}}export{m as default};
2
+ //# sourceMappingURL=convertFormatsToIntlMessageFormat.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/core/convertFormatsToIntlMessageFormat.tsx"],"sourcesContent":["import {Formats as IntlFormats} from 'intl-messageformat';\nimport DateTimeFormatOptions from './DateTimeFormatOptions';\nimport Formats from './Formats';\nimport TimeZone from './TimeZone';\n\nfunction setTimeZoneInFormats(\n formats: Record<string, DateTimeFormatOptions> | undefined,\n timeZone: TimeZone\n) {\n if (!formats) return formats;\n\n // The only way to set a time zone with `intl-messageformat` is to merge it into the formats\n // https://github.com/formatjs/formatjs/blob/8256c5271505cf2606e48e3c97ecdd16ede4f1b5/packages/intl/src/message.ts#L15\n return Object.keys(formats).reduce(\n (acc: Record<string, DateTimeFormatOptions>, key) => {\n acc[key] = {\n timeZone,\n ...formats[key]\n };\n return acc;\n },\n {}\n );\n}\n\n/**\n * `intl-messageformat` uses separate keys for `date` and `time`, but there's\n * only one native API: `Intl.DateTimeFormat`. Additionally you might want to\n * include both a time and a date in a value, therefore the separation doesn't\n * seem so useful. We offer a single `dateTime` namespace instead, but we have\n * to convert the format before `intl-messageformat` can be used.\n */\nexport default function convertFormatsToIntlMessageFormat(\n formats: Partial<Formats>,\n timeZone?: TimeZone\n): Partial<IntlFormats> {\n const formatsWithTimeZone = timeZone\n ? {...formats, dateTime: setTimeZoneInFormats(formats.dateTime, timeZone)}\n : formats;\n\n return {\n ...formatsWithTimeZone,\n date: formatsWithTimeZone?.dateTime,\n time: formatsWithTimeZone?.dateTime\n };\n}\n"],"mappings":"AAKA,SAASA,EACPC,EACAC,EACA,CACA,OAAKD,GAIE,OAAO,KAAKA,CAAO,EAAE,OAC1B,CAACE,EAA4CC,KAC3CD,EAAIC,CAAG,EAAI,CACT,SAAAF,EACA,GAAGD,EAAQG,CAAG,CAChB,EACOD,GAET,CAAC,CACH,CACF,CASe,SAARE,EACLJ,EACAC,EACsB,CACtB,MAAMI,EAAsBJ,EACxB,CAAC,GAAGD,EAAS,SAAUD,EAAqBC,EAAQ,SAAUC,CAAQ,CAAC,EACvED,EAEJ,MAAO,CACL,GAAGK,EACH,KAAMA,GAAqB,SAC3B,KAAMA,GAAqB,QAC7B,CACF","names":["setTimeZoneInFormats","formats","timeZone","acc","key","convertFormatsToIntlMessageFormat","formatsWithTimeZone"]}
@@ -0,0 +1,32 @@
1
+ import IntlMessageFormat from 'intl-messageformat';
2
+ import { ReactElement, ReactNodeArray } from 'react';
3
+ import AbstractIntlMessages from './AbstractIntlMessages.mjs';
4
+ import Formats from './Formats.mjs';
5
+ import { InitializedIntlConfig } from './IntlConfig.mjs';
6
+ import IntlError from './IntlError.mjs';
7
+ import TranslationValues, { RichTranslationValues } from './TranslationValues.mjs';
8
+ import MessageKeys from './utils/MessageKeys.mjs';
9
+ import NestedKeyOf from './utils/NestedKeyOf.mjs';
10
+ import NestedValueOf from './utils/NestedValueOf.mjs';
11
+ import './DateTimeFormatOptions.mjs';
12
+ import './TimeZone.mjs';
13
+ import '@formatjs/ecma402-abstract/types/number';
14
+
15
+ declare function getMessagesOrError<Messages extends AbstractIntlMessages>({ messages, namespace, onError }: {
16
+ messages: Messages;
17
+ namespace?: string;
18
+ onError?(error: IntlError): void;
19
+ }): AbstractIntlMessages | IntlError;
20
+ type CreateBaseTranslatorProps<Messages> = InitializedIntlConfig & {
21
+ cachedFormatsByLocale?: Record<string, Record<string, IntlMessageFormat>>;
22
+ defaultTranslationValues?: RichTranslationValues;
23
+ namespace?: string;
24
+ messagesOrError: Messages | IntlError;
25
+ };
26
+ declare function createBaseTranslator<Messages extends AbstractIntlMessages, NestedKey extends NestedKeyOf<Messages>>({ cachedFormatsByLocale, defaultTranslationValues, formats: globalFormats, getMessageFallback, locale, messagesOrError, namespace, onError, timeZone }: CreateBaseTranslatorProps<Messages>): {
27
+ <TargetKey extends MessageKeys<NestedValueOf<Messages, NestedKey>, NestedKeyOf<NestedValueOf<Messages, NestedKey>>>>(key: TargetKey, values?: TranslationValues, formats?: Partial<Formats>): string;
28
+ rich: (key: string, values?: RichTranslationValues, formats?: Partial<Formats>) => string | ReactElement | ReactNodeArray;
29
+ raw(key: string): any;
30
+ };
31
+
32
+ export { CreateBaseTranslatorProps, createBaseTranslator as default, getMessagesOrError };
@@ -0,0 +1,2 @@
1
+ import y from"intl-messageformat";import{cloneElement as R,isValidElement as v}from"react";import I,{IntlErrorCode as u}from"./IntlError";import w from"./convertFormatsToIntlMessageFormat";import{defaultGetMessageFallback as O,defaultOnError as _}from"./defaults";function A(t,i,f){if(!t)throw new Error(process.env.NODE_ENV!=="production"?`No messages available at \`${f}\`.`:void 0);let n=t;return i.split(".").forEach(s=>{const a=n[s];if(s==null||a==null)throw new Error(process.env.NODE_ENV!=="production"?`Could not resolve \`${i}\` in ${f?`\`${f}\``:"messages"}.`:void 0);n=a}),n}function $(t){if(Object.keys(t).length===0)return;const i={};return Object.keys(t).forEach(f=>{let n=0;const s=t[f];let a;typeof s=="function"?a=o=>{const E=s(o);return v(E)?R(E,{key:f+n++}):E}:a=s,i[f]=a}),i}function tr({messages:t,namespace:i,onError:f=_}){try{if(!t)throw new Error(process.env.NODE_ENV!=="production"?"No messages were configured on the provider.":void 0);const n=i?A(t,i):t;if(!n)throw new Error(process.env.NODE_ENV!=="production"?`No messages for namespace \`${i}\` found.`:void 0);return n}catch(n){const s=new I(u.MISSING_MESSAGE,n.message);return f(s),s}}function b({cachedFormatsByLocale:t,defaultTranslationValues:i,formats:f,getMessageFallback:n=O,locale:s,messagesOrError:a,namespace:o,onError:E,timeZone:T}){function c(r,l,d){const g=new I(l,d);return E(g),n({error:g,key:r,namespace:o})}function S(r,l,d){if(a instanceof I)return n({error:a,key:r,namespace:o});const g=a;let m;try{m=A(g,r,o)}catch(e){return c(r,u.MISSING_MESSAGE,e.message)}function V(e){return e.filter(N=>N!=null).join(".")}const h=V([o,r,String(m)]);let p;if(t?.[s]?.[h])p=t?.[s][h];else{if(typeof m=="object"){let e,N;return Array.isArray(m)?(e=u.INVALID_MESSAGE,process.env.NODE_ENV!=="production"&&(N=`Message at \`${V([o,r])}\` resolved to an array, but only strings are supported. See https://next-intl-docs.vercel.app/docs/usage/messages#arrays-of-messages`)):(e=u.INSUFFICIENT_PATH,process.env.NODE_ENV!=="production"&&(N=`Message at \`${V([o,r])}\` resolved to an object, but only strings are supported. Use a \`.\` to retrieve nested messages. See https://next-intl-docs.vercel.app/docs/usage/messages#structuring-messages`)),c(r,e,N)}try{p=new y(m,s,w({...f,...d},T))}catch(e){return c(r,u.INVALID_MESSAGE,e.message)}t&&(t[s]||(t[s]={}),t[s][h]=p)}try{const e=p.format($({...i,...l}));if(e==null)throw new Error(process.env.NODE_ENV!=="production"?`Unable to format \`${r}\` in ${o?`namespace \`${o}\``:"messages"}`:void 0);return v(e)||Array.isArray(e)||typeof e=="string"?e:String(e)}catch(e){return c(r,u.FORMATTING_ERROR,e.message)}}function M(r,l,d){const g=S(r,l,d);return typeof g!="string"?c(r,u.INVALID_MESSAGE,process.env.NODE_ENV!=="production"?`The message \`${r}\` in ${o?`namespace \`${o}\``:"messages"} didn't resolve to a string. If you want to format rich text, use \`t.rich\` instead.`:void 0):g}return M.rich=S,M.raw=r=>{if(a instanceof I)return n({error:a,key:r,namespace:o});const l=a;try{return A(l,r,o)}catch(d){return c(r,u.MISSING_MESSAGE,d.message)}},M}export{b as default,tr as getMessagesOrError};
2
+ //# sourceMappingURL=createBaseTranslator.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/core/createBaseTranslator.tsx"],"sourcesContent":["// eslint-disable-next-line import/no-named-as-default -- False positive\nimport IntlMessageFormat from 'intl-messageformat';\nimport {\n cloneElement,\n isValidElement,\n ReactElement,\n ReactNode,\n ReactNodeArray\n} from 'react';\nimport AbstractIntlMessages from './AbstractIntlMessages';\nimport Formats from './Formats';\nimport {InitializedIntlConfig} from './IntlConfig';\nimport IntlError, {IntlErrorCode} from './IntlError';\nimport TranslationValues, {RichTranslationValues} from './TranslationValues';\nimport convertFormatsToIntlMessageFormat from './convertFormatsToIntlMessageFormat';\nimport {defaultGetMessageFallback, defaultOnError} from './defaults';\nimport MessageKeys from './utils/MessageKeys';\nimport NestedKeyOf from './utils/NestedKeyOf';\nimport NestedValueOf from './utils/NestedValueOf';\n\nfunction resolvePath(\n messages: AbstractIntlMessages | undefined,\n key: string,\n namespace?: string\n) {\n if (!messages) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? `No messages available at \\`${namespace}\\`.`\n : undefined\n );\n }\n\n let message = messages;\n\n key.split('.').forEach((part) => {\n const next = (message as any)[part];\n\n if (part == null || next == null) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? `Could not resolve \\`${key}\\` in ${\n namespace ? `\\`${namespace}\\`` : 'messages'\n }.`\n : undefined\n );\n }\n\n message = next;\n });\n\n return message;\n}\n\nfunction prepareTranslationValues(values: RichTranslationValues) {\n if (Object.keys(values).length === 0) return undefined;\n\n // Workaround for https://github.com/formatjs/formatjs/issues/1467\n const transformedValues: RichTranslationValues = {};\n Object.keys(values).forEach((key) => {\n let index = 0;\n const value = values[key];\n\n let transformed;\n if (typeof value === 'function') {\n transformed = (chunks: ReactNode) => {\n const result = value(chunks);\n\n return isValidElement(result)\n ? cloneElement(result, {key: key + index++})\n : result;\n };\n } else {\n transformed = value;\n }\n\n transformedValues[key] = transformed;\n });\n\n return transformedValues;\n}\n\nexport function getMessagesOrError<Messages extends AbstractIntlMessages>({\n messages,\n namespace,\n onError = defaultOnError\n}: {\n messages: Messages;\n namespace?: string;\n onError?(error: IntlError): void;\n}) {\n try {\n if (!messages) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? `No messages were configured on the provider.`\n : undefined\n );\n }\n\n const retrievedMessages = namespace\n ? resolvePath(messages, namespace)\n : messages;\n\n if (!retrievedMessages) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? `No messages for namespace \\`${namespace}\\` found.`\n : undefined\n );\n }\n\n return retrievedMessages;\n } catch (error) {\n const intlError = new IntlError(\n IntlErrorCode.MISSING_MESSAGE,\n (error as Error).message\n );\n onError(intlError);\n return intlError;\n }\n}\n\nexport type CreateBaseTranslatorProps<Messages> = InitializedIntlConfig & {\n cachedFormatsByLocale?: Record<string, Record<string, IntlMessageFormat>>;\n defaultTranslationValues?: RichTranslationValues;\n namespace?: string;\n messagesOrError: Messages | IntlError;\n};\n\nexport default function createBaseTranslator<\n Messages extends AbstractIntlMessages,\n NestedKey extends NestedKeyOf<Messages>\n>({\n cachedFormatsByLocale,\n defaultTranslationValues,\n formats: globalFormats,\n getMessageFallback = defaultGetMessageFallback,\n locale,\n messagesOrError,\n namespace,\n onError,\n timeZone\n}: CreateBaseTranslatorProps<Messages>) {\n function getFallbackFromErrorAndNotify(\n key: string,\n code: IntlErrorCode,\n message?: string\n ) {\n const error = new IntlError(code, message);\n onError(error);\n return getMessageFallback({error, key, namespace});\n }\n\n function translateBaseFn(\n /** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */\n key: string,\n /** Key value pairs for values to interpolate into the message. */\n values?: RichTranslationValues,\n /** Provide custom formats for numbers, dates and times. */\n formats?: Partial<Formats>\n ): string | ReactElement | ReactNodeArray {\n if (messagesOrError instanceof IntlError) {\n // We have already warned about this during render\n return getMessageFallback({\n error: messagesOrError,\n key,\n namespace\n });\n }\n const messages = messagesOrError;\n\n let message;\n try {\n message = resolvePath(messages, key, namespace);\n } catch (error) {\n return getFallbackFromErrorAndNotify(\n key,\n IntlErrorCode.MISSING_MESSAGE,\n (error as Error).message\n );\n }\n\n function joinPath(parts: Array<string | undefined>) {\n return parts.filter((part) => part != null).join('.');\n }\n\n const cacheKey = joinPath([namespace, key, String(message)]);\n\n let messageFormat;\n if (cachedFormatsByLocale?.[locale]?.[cacheKey]) {\n messageFormat = cachedFormatsByLocale?.[locale][cacheKey];\n } else {\n if (typeof message === 'object') {\n let code, errorMessage;\n if (Array.isArray(message)) {\n code = IntlErrorCode.INVALID_MESSAGE;\n if (process.env.NODE_ENV !== 'production') {\n errorMessage = `Message at \\`${joinPath([\n namespace,\n key\n ])}\\` resolved to an array, but only strings are supported. See https://next-intl-docs.vercel.app/docs/usage/messages#arrays-of-messages`;\n }\n } else {\n code = IntlErrorCode.INSUFFICIENT_PATH;\n if (process.env.NODE_ENV !== 'production') {\n errorMessage = `Message at \\`${joinPath([\n namespace,\n key\n ])}\\` resolved to an object, but only strings are supported. Use a \\`.\\` to retrieve nested messages. See https://next-intl-docs.vercel.app/docs/usage/messages#structuring-messages`;\n }\n }\n\n return getFallbackFromErrorAndNotify(key, code, errorMessage);\n }\n\n try {\n messageFormat = new IntlMessageFormat(\n message,\n locale,\n convertFormatsToIntlMessageFormat(\n {...globalFormats, ...formats},\n timeZone\n )\n );\n } catch (error) {\n return getFallbackFromErrorAndNotify(\n key,\n IntlErrorCode.INVALID_MESSAGE,\n (error as Error).message\n );\n }\n\n if (cachedFormatsByLocale) {\n if (!cachedFormatsByLocale[locale]) {\n cachedFormatsByLocale[locale] = {};\n }\n cachedFormatsByLocale[locale][cacheKey] = messageFormat;\n }\n }\n\n try {\n const formattedMessage = messageFormat.format(\n // @ts-ignore `intl-messageformat` expects a different format\n // for rich text elements since a recent minor update. This\n // needs to be evaluated in detail, possibly also in regards\n // to be able to format to parts.\n prepareTranslationValues({...defaultTranslationValues, ...values})\n );\n\n if (formattedMessage == null) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? `Unable to format \\`${key}\\` in ${\n namespace ? `namespace \\`${namespace}\\`` : 'messages'\n }`\n : undefined\n );\n }\n\n // Limit the function signature to return strings or React elements\n return isValidElement(formattedMessage) ||\n // Arrays of React elements\n Array.isArray(formattedMessage) ||\n typeof formattedMessage === 'string'\n ? formattedMessage\n : String(formattedMessage);\n } catch (error) {\n return getFallbackFromErrorAndNotify(\n key,\n IntlErrorCode.FORMATTING_ERROR,\n (error as Error).message\n );\n }\n }\n\n function translateFn<\n TargetKey extends MessageKeys<\n NestedValueOf<Messages, NestedKey>,\n NestedKeyOf<NestedValueOf<Messages, NestedKey>>\n >\n >(\n /** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */\n key: TargetKey,\n /** Key value pairs for values to interpolate into the message. */\n values?: TranslationValues,\n /** Provide custom formats for numbers, dates and times. */\n formats?: Partial<Formats>\n ): string {\n const result = translateBaseFn(key, values, formats);\n\n if (typeof result !== 'string') {\n return getFallbackFromErrorAndNotify(\n key,\n IntlErrorCode.INVALID_MESSAGE,\n process.env.NODE_ENV !== 'production'\n ? `The message \\`${key}\\` in ${\n namespace ? `namespace \\`${namespace}\\`` : 'messages'\n } didn't resolve to a string. If you want to format rich text, use \\`t.rich\\` instead.`\n : undefined\n );\n }\n\n return result;\n }\n\n translateFn.rich = translateBaseFn;\n\n translateFn.raw = (\n /** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */\n key: string\n ): any => {\n if (messagesOrError instanceof IntlError) {\n // We have already warned about this during render\n return getMessageFallback({\n error: messagesOrError,\n key,\n namespace\n });\n }\n const messages = messagesOrError;\n\n try {\n return resolvePath(messages, key, namespace);\n } catch (error) {\n return getFallbackFromErrorAndNotify(\n key,\n IntlErrorCode.MISSING_MESSAGE,\n (error as Error).message\n );\n }\n };\n\n return translateFn;\n}\n"],"mappings":"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","names":["IntlMessageFormat","cloneElement","isValidElement","IntlError","IntlErrorCode","convertFormatsToIntlMessageFormat","defaultGetMessageFallback","defaultOnError","resolvePath","messages","key","namespace","message","part","next","prepareTranslationValues","values","transformedValues","index","value","transformed","chunks","result","getMessagesOrError","onError","retrievedMessages","error","intlError","createBaseTranslator","cachedFormatsByLocale","defaultTranslationValues","globalFormats","getMessageFallback","locale","messagesOrError","timeZone","getFallbackFromErrorAndNotify","code","translateBaseFn","formats","joinPath","parts","cacheKey","messageFormat","errorMessage","formattedMessage","translateFn"]}
@@ -0,0 +1,21 @@
1
+ import DateTimeFormatOptions from './DateTimeFormatOptions.mjs';
2
+ import Formats from './Formats.mjs';
3
+ import IntlError from './IntlError.mjs';
4
+ import { NumberFormatOptions } from '@formatjs/ecma402-abstract/types/number';
5
+ import TimeZone from './TimeZone.mjs';
6
+
7
+ type Props = {
8
+ locale: string;
9
+ timeZone?: TimeZone;
10
+ onError?(error: IntlError): void;
11
+ formats?: Partial<Formats>;
12
+ now?: Date;
13
+ };
14
+ declare function createFormatter({ formats, locale, now: globalNow, onError, timeZone }: Props): {
15
+ dateTime: (value: Date | number, formatOrOptions?: string | DateTimeFormatOptions) => string;
16
+ number: (value: number | bigint, formatOrOptions?: string | NumberFormatOptions) => string;
17
+ relativeTime: (date: number | Date, now?: number | Date) => string;
18
+ list: (value: Iterable<string>, formatOrOptions?: string | Intl.ListFormatOptions) => string;
19
+ };
20
+
21
+ export { createFormatter as default };
@@ -0,0 +1,2 @@
1
+ import l,{IntlErrorCode as p}from"./IntlError";import{defaultOnError as M}from"./defaults";const d=60,g=d*60,u=g*24,F=u*7,O=u*(365/12),h=u*365;function N(n){const i=Math.abs(n);let a,o;return i<d?(o="second",a=Math.round(n)):i<g?(o="minute",a=Math.round(n/d)):i<u?(o="hour",a=Math.round(n/g)):i<F?(o="day",a=Math.round(n/u)):i<O?(o="week",a=Math.round(n/F)):i<h?(o="month",a=Math.round(n/O)):(o="year",a=Math.round(n/h)),{value:a,unit:o}}function v({formats:n,locale:i,now:a,onError:o=M,timeZone:T}){function b(r,e){let t;if(typeof e=="string"){const s=e;if(t=r?.[s],!t){const m=new l(p.MISSING_FORMAT,process.env.NODE_ENV!=="production"?`Format \`${s}\` is not available. You can configure it on the provider or provide custom options.`:void 0);throw o(m),m}}else t=e;return t}function c(r,e,t,s){let m;try{m=b(t,e)}catch{return String(r)}try{return s(m)}catch(f){return o(new l(p.FORMATTING_ERROR,f.message)),String(r)}}function D(r,e){return c(r,e,n?.dateTime,t=>(T&&!t?.timeZone&&(t={...t,timeZone:T}),new Intl.DateTimeFormat(i,t).format(r)))}function E(r,e){return c(r,e,n?.number,t=>new Intl.NumberFormat(i,t).format(r))}function R(r,e){try{if(!e)if(a)e=a;else throw new Error(process.env.NODE_ENV!=="production"?"The `now` parameter wasn't provided and there was no global fallback configured on the provider.":void 0);const t=r instanceof Date?r:new Date(r),s=e instanceof Date?e:new Date(e),m=(t.getTime()-s.getTime())/1e3,{unit:f,value:w}=N(m);return new Intl.RelativeTimeFormat(i,{numeric:"auto"}).format(w,f)}catch(t){return o(new l(p.FORMATTING_ERROR,t.message)),String(r)}}function I(r,e){return c(r,e,n?.list,t=>new Intl.ListFormat(i,t).format(r))}return{dateTime:D,number:E,relativeTime:R,list:I}}export{v as default};
2
+ //# sourceMappingURL=createFormatter.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/core/createFormatter.tsx"],"sourcesContent":["import DateTimeFormatOptions from './DateTimeFormatOptions';\nimport Formats from './Formats';\nimport IntlError, {IntlErrorCode} from './IntlError';\nimport NumberFormatOptions from './NumberFormatOptions';\nimport TimeZone from './TimeZone';\nimport {defaultOnError} from './defaults';\n\nconst MINUTE = 60;\nconst HOUR = MINUTE * 60;\nconst DAY = HOUR * 24;\nconst WEEK = DAY * 7;\nconst MONTH = DAY * (365 / 12); // Approximation\nconst YEAR = DAY * 365;\n\nfunction getRelativeTimeFormatConfig(seconds: number) {\n const absValue = Math.abs(seconds);\n let value, unit: Intl.RelativeTimeFormatUnit;\n\n // We have to round the resulting values, as `Intl.RelativeTimeFormat`\n // will include fractions like '2.1 hours ago'.\n\n if (absValue < MINUTE) {\n unit = 'second';\n value = Math.round(seconds);\n } else if (absValue < HOUR) {\n unit = 'minute';\n value = Math.round(seconds / MINUTE);\n } else if (absValue < DAY) {\n unit = 'hour';\n value = Math.round(seconds / HOUR);\n } else if (absValue < WEEK) {\n unit = 'day';\n value = Math.round(seconds / DAY);\n } else if (absValue < MONTH) {\n unit = 'week';\n value = Math.round(seconds / WEEK);\n } else if (absValue < YEAR) {\n unit = 'month';\n value = Math.round(seconds / MONTH);\n } else {\n unit = 'year';\n value = Math.round(seconds / YEAR);\n }\n\n return {value, unit};\n}\n\ntype Props = {\n locale: string;\n timeZone?: TimeZone;\n onError?(error: IntlError): void;\n formats?: Partial<Formats>;\n now?: Date;\n};\n\nexport default function createFormatter({\n formats,\n locale,\n now: globalNow,\n onError = defaultOnError,\n timeZone\n}: Props) {\n function resolveFormatOrOptions<Options>(\n typeFormats: Record<string, Options> | undefined,\n formatOrOptions?: string | Options\n ) {\n let options;\n if (typeof formatOrOptions === 'string') {\n const formatName = formatOrOptions;\n options = typeFormats?.[formatName];\n\n if (!options) {\n const error = new IntlError(\n IntlErrorCode.MISSING_FORMAT,\n process.env.NODE_ENV !== 'production'\n ? `Format \\`${formatName}\\` is not available. You can configure it on the provider or provide custom options.`\n : undefined\n );\n onError(error);\n throw error;\n }\n } else {\n options = formatOrOptions;\n }\n\n return options;\n }\n\n function getFormattedValue<Value, Options>(\n value: Value,\n formatOrOptions: string | Options | undefined,\n typeFormats: Record<string, Options> | undefined,\n formatter: (options?: Options) => string\n ) {\n let options;\n try {\n options = resolveFormatOrOptions(typeFormats, formatOrOptions);\n } catch (error) {\n return String(value);\n }\n\n try {\n return formatter(options);\n } catch (error) {\n onError(\n new IntlError(IntlErrorCode.FORMATTING_ERROR, (error as Error).message)\n );\n return String(value);\n }\n }\n\n function dateTime(\n /** If a number is supplied, this is interpreted as a UTC timestamp. */\n value: Date | number,\n /** If a time zone is supplied, the `value` is converted to that time zone.\n * Otherwise the user time zone will be used. */\n formatOrOptions?: string | DateTimeFormatOptions\n ) {\n return getFormattedValue(\n value,\n formatOrOptions,\n formats?.dateTime,\n (options) => {\n if (timeZone && !options?.timeZone) {\n options = {...options, timeZone};\n }\n\n return new Intl.DateTimeFormat(locale, options).format(value);\n }\n );\n }\n\n function number(\n value: number | bigint,\n formatOrOptions?: string | NumberFormatOptions\n ) {\n return getFormattedValue(\n value,\n formatOrOptions,\n formats?.number,\n (options) => new Intl.NumberFormat(locale, options).format(value)\n );\n }\n\n function relativeTime(\n /** The date time that needs to be formatted. */\n date: number | Date,\n /** The reference point in time to which `date` will be formatted in relation to. */\n now?: number | Date\n ) {\n try {\n if (!now) {\n if (globalNow) {\n now = globalNow;\n } else {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? `The \\`now\\` parameter wasn't provided and there was no global fallback configured on the provider.`\n : undefined\n );\n }\n }\n\n const dateDate = date instanceof Date ? date : new Date(date);\n const nowDate = now instanceof Date ? now : new Date(now);\n\n const seconds = (dateDate.getTime() - nowDate.getTime()) / 1000;\n const {unit, value} = getRelativeTimeFormatConfig(seconds);\n\n return new Intl.RelativeTimeFormat(locale, {\n numeric: 'auto'\n }).format(value, unit);\n } catch (error) {\n onError(\n new IntlError(IntlErrorCode.FORMATTING_ERROR, (error as Error).message)\n );\n return String(date);\n }\n }\n\n function list(\n value: Iterable<string>,\n formatOrOptions?: string | Intl.ListFormatOptions\n ) {\n return getFormattedValue(value, formatOrOptions, formats?.list, (options) =>\n new Intl.ListFormat(locale, options).format(value)\n );\n }\n\n return {dateTime, number, relativeTime, list};\n}\n"],"mappings":"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","names":["IntlError","IntlErrorCode","defaultOnError","MINUTE","HOUR","DAY","WEEK","MONTH","YEAR","getRelativeTimeFormatConfig","seconds","absValue","value","unit","createFormatter","formats","locale","globalNow","onError","timeZone","resolveFormatOrOptions","typeFormats","formatOrOptions","options","formatName","error","getFormattedValue","formatter","dateTime","number","relativeTime","date","now","dateDate","nowDate","list"]}
@@ -0,0 +1,15 @@
1
+ import * as _formatjs_ecma402_abstract_types_number from '@formatjs/ecma402-abstract/types/number';
2
+ import DateTimeFormatOptions from './DateTimeFormatOptions.mjs';
3
+ import createFormatter from './createFormatter.mjs';
4
+ import './TimeZone.mjs';
5
+ import './Formats.mjs';
6
+ import './IntlError.mjs';
7
+
8
+ /** @deprecated Switch to `createFormatter` */
9
+ declare function createIntl(...args: Parameters<typeof createFormatter>): {
10
+ formatDateTime: (value: number | Date, formatOrOptions?: string | DateTimeFormatOptions | undefined) => string;
11
+ formatNumber: (value: number | bigint, formatOrOptions?: string | _formatjs_ecma402_abstract_types_number.NumberFormatOptions | undefined) => string;
12
+ formatRelativeTime: (date: number | Date, now?: number | Date | undefined) => string;
13
+ };
14
+
15
+ export { createIntl as default };
@@ -0,0 +1,2 @@
1
+ import r from"./createFormatter";function a(...t){const e=r(...t);return{formatDateTime:e.dateTime,formatNumber:e.number,formatRelativeTime:e.relativeTime}}export{a as default};
2
+ //# sourceMappingURL=createIntl.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/core/createIntl.tsx"],"sourcesContent":["import createFormatter from './createFormatter';\n\n/** @deprecated Switch to `createFormatter` */\nexport default function createIntl(\n ...args: Parameters<typeof createFormatter>\n) {\n const formatter = createFormatter(...args);\n return {\n formatDateTime: formatter.dateTime,\n formatNumber: formatter.number,\n formatRelativeTime: formatter.relativeTime\n };\n}\n"],"mappings":"AAAA,OAAOA,MAAqB,oBAGb,SAARC,KACFC,EACH,CACA,MAAMC,EAAYH,EAAgB,GAAGE,CAAI,EACzC,MAAO,CACL,eAAgBC,EAAU,SAC1B,aAAcA,EAAU,OACxB,mBAAoBA,EAAU,YAChC,CACF","names":["createFormatter","createIntl","args","formatter"]}
@@ -0,0 +1,57 @@
1
+ import Formats from './Formats.mjs';
2
+ import IntlConfig from './IntlConfig.mjs';
3
+ import TranslationValues from './TranslationValues.mjs';
4
+ import { CoreRichTranslationValues } from './createTranslatorImpl.mjs';
5
+ import MessageKeys from './utils/MessageKeys.mjs';
6
+ import NamespaceKeys from './utils/NamespaceKeys.mjs';
7
+ import NestedKeyOf from './utils/NestedKeyOf.mjs';
8
+ import NestedValueOf from './utils/NestedValueOf.mjs';
9
+ import './DateTimeFormatOptions.mjs';
10
+ import './TimeZone.mjs';
11
+ import '@formatjs/ecma402-abstract/types/number';
12
+ import './IntlError.mjs';
13
+ import './AbstractIntlMessages.mjs';
14
+ import 'react';
15
+
16
+ /**
17
+ * Translates messages from the given namespace by using the ICU syntax.
18
+ * See https://formatjs.io/docs/core-concepts/icu-syntax.
19
+ *
20
+ * If no namespace is provided, all available messages are returned.
21
+ * The namespace can also indicate nesting by using a dot
22
+ * (e.g. `namespace.Component`).
23
+ */
24
+ declare function createTranslator<NestedKey extends NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>> = never>({ getMessageFallback, messages, namespace, onError, ...rest }: Omit<IntlConfig<IntlMessages>, 'defaultTranslationValues' | 'messages'> & {
25
+ messages: NonNullable<IntlConfig<IntlMessages>['messages']>;
26
+ namespace?: NestedKey;
27
+ }): {
28
+ <TargetKey extends MessageKeys<NestedValueOf<{
29
+ '!': IntlMessages;
30
+ }, [
31
+ NestedKey
32
+ ] extends [never] ? '!' : `!.${NestedKey}`>, NestedKeyOf<NestedValueOf<{
33
+ '!': IntlMessages;
34
+ }, [
35
+ NestedKey
36
+ ] extends [never] ? '!' : `!.${NestedKey}`>>>>(key: TargetKey, values?: TranslationValues, formats?: Partial<Formats>): string;
37
+ rich<TargetKey extends MessageKeys<NestedValueOf<{
38
+ '!': IntlMessages;
39
+ }, [
40
+ NestedKey
41
+ ] extends [never] ? '!' : `!.${NestedKey}`>, NestedKeyOf<NestedValueOf<{
42
+ '!': IntlMessages;
43
+ }, [
44
+ NestedKey
45
+ ] extends [never] ? '!' : `!.${NestedKey}`>>>>(key: TargetKey, values?: CoreRichTranslationValues, formats?: Partial<Formats>): string;
46
+ raw<TargetKey extends MessageKeys<NestedValueOf<{
47
+ '!': IntlMessages;
48
+ }, [
49
+ NestedKey
50
+ ] extends [never] ? '!' : `!.${NestedKey}`>, NestedKeyOf<NestedValueOf<{
51
+ '!': IntlMessages;
52
+ }, [
53
+ NestedKey
54
+ ] extends [never] ? '!' : `!.${NestedKey}`>>>>(key: TargetKey): any;
55
+ };
56
+
57
+ export { createTranslator as default };
@@ -0,0 +1,2 @@
1
+ import n from"./createTranslatorImpl";import{defaultGetMessageFallback as l,defaultOnError as d}from"./defaults";function o({getMessageFallback:s=l,messages:t,namespace:e,onError:a=d,...r}){return n({...r,onError:a,getMessageFallback:s,messages:{"!":t},namespace:e?`!.${e}`:"!"},"!")}export{o as default};
2
+ //# sourceMappingURL=createTranslator.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/core/createTranslator.tsx"],"sourcesContent":["import Formats from './Formats';\nimport IntlConfig from './IntlConfig';\nimport TranslationValues from './TranslationValues';\nimport createTranslatorImpl, {\n CoreRichTranslationValues\n} from './createTranslatorImpl';\nimport {defaultGetMessageFallback, defaultOnError} from './defaults';\nimport MessageKeys from './utils/MessageKeys';\nimport NamespaceKeys from './utils/NamespaceKeys';\nimport NestedKeyOf from './utils/NestedKeyOf';\nimport NestedValueOf from './utils/NestedValueOf';\n\n/**\n * Translates messages from the given namespace by using the ICU syntax.\n * See https://formatjs.io/docs/core-concepts/icu-syntax.\n *\n * If no namespace is provided, all available messages are returned.\n * The namespace can also indicate nesting by using a dot\n * (e.g. `namespace.Component`).\n */\nexport default function createTranslator<\n NestedKey extends NamespaceKeys<\n IntlMessages,\n NestedKeyOf<IntlMessages>\n > = never\n>({\n getMessageFallback = defaultGetMessageFallback,\n messages,\n namespace,\n onError = defaultOnError,\n ...rest\n}: Omit<IntlConfig<IntlMessages>, 'defaultTranslationValues' | 'messages'> & {\n messages: NonNullable<IntlConfig<IntlMessages>['messages']>;\n namespace?: NestedKey;\n}): // Explicitly defining the return type is necessary as TypeScript would get it wrong\n{\n // Default invocation\n <\n TargetKey extends MessageKeys<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >,\n NestedKeyOf<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >\n >\n >\n >(\n key: TargetKey,\n values?: TranslationValues,\n formats?: Partial<Formats>\n ): string;\n\n // `rich`\n rich<\n TargetKey extends MessageKeys<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >,\n NestedKeyOf<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >\n >\n >\n >(\n key: TargetKey,\n values?: CoreRichTranslationValues,\n formats?: Partial<Formats>\n ): string;\n\n // `raw`\n raw<\n TargetKey extends MessageKeys<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >,\n NestedKeyOf<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >\n >\n >\n >(\n key: TargetKey\n ): any;\n} {\n // We have to wrap the actual function so the type inference for the optional\n // namespace works correctly. See https://stackoverflow.com/a/71529575/343045\n // The prefix (\"!\") is arbitrary.\n return createTranslatorImpl<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >(\n {\n ...rest,\n onError,\n getMessageFallback,\n messages: {'!': messages},\n // @ts-ignore\n namespace: namespace ? `!.${namespace}` : '!'\n },\n '!'\n );\n}\n"],"mappings":"AAGA,OAAOA,MAEA,yBACP,OAAQ,6BAAAC,EAA2B,kBAAAC,MAAqB,aAczC,SAARC,EAKL,CACA,mBAAAC,EAAqBH,EACrB,SAAAI,EACA,UAAAC,EACA,QAAAC,EAAUL,EACV,GAAGM,CACL,EA8DE,CAIA,OAAOR,EAIL,CACE,GAAGQ,EACH,QAAAD,EACA,mBAAAH,EACA,SAAU,CAAC,IAAKC,CAAQ,EAExB,UAAWC,EAAY,KAAKA,CAAS,GAAK,GAC5C,EACA,GACF,CACF","names":["createTranslatorImpl","defaultGetMessageFallback","defaultOnError","createTranslator","getMessageFallback","messages","namespace","onError","rest"]}
@@ -0,0 +1,25 @@
1
+ import Formats from './Formats.mjs';
2
+ import TranslationValues, { TranslationValue } from './TranslationValues.mjs';
3
+ import MessageKeys from './utils/MessageKeys.mjs';
4
+ import NestedValueOf from './utils/NestedValueOf.mjs';
5
+ import AbstractIntlMessages from './AbstractIntlMessages.mjs';
6
+ import { InitializedIntlConfig } from './IntlConfig.mjs';
7
+ import NestedKeyOf from './utils/NestedKeyOf.mjs';
8
+ import './DateTimeFormatOptions.mjs';
9
+ import './TimeZone.mjs';
10
+ import '@formatjs/ecma402-abstract/types/number';
11
+ import 'react';
12
+ import './IntlError.mjs';
13
+
14
+ type CoreRichTranslationValues = Record<string, TranslationValue | ((chunks: string) => string)>;
15
+ type CreateTranslatorImplProps<Messages> = Omit<InitializedIntlConfig, 'messages'> & {
16
+ namespace: string;
17
+ messages: Messages;
18
+ };
19
+ declare function createTranslatorImpl<Messages extends AbstractIntlMessages, NestedKey extends NestedKeyOf<Messages>>({ getMessageFallback, messages, namespace, onError, ...rest }: CreateTranslatorImplProps<Messages>, namespacePrefix: string): {
20
+ (key: MessageKeys<NestedValueOf<Messages, NestedKey>, NestedKeyOf<NestedValueOf<Messages, NestedKey>>>, values?: TranslationValues | undefined, formats?: Partial<Formats> | undefined): string;
21
+ rich(key: string, values: CoreRichTranslationValues, formats?: Partial<Formats> | undefined): string;
22
+ raw: (key: string) => any;
23
+ };
24
+
25
+ export { CoreRichTranslationValues, CreateTranslatorImplProps, createTranslatorImpl as default };
@@ -0,0 +1,2 @@
1
+ import u,{IntlErrorCode as d}from"./IntlError";import h,{getMessagesOrError as I}from"./createBaseTranslator";import T from"./resolveNamespace";function R({getMessageFallback:o,messages:s,namespace:r,onError:t,...g},i){s=s[i],r=T(r,i);const a=h({...g,onError:t,getMessageFallback:o,messagesOrError:I({messages:s,namespace:r,onError:t})}),f=a.rich;function n(...e){return a(...e)}return n.rich=(e,p,m)=>{const l=f(e,p,m);if(typeof l!="string"){const c=new u(d.FORMATTING_ERROR,process.env.NODE_ENV!=="production"?"`createTranslator` only accepts functions for rich text formatting that receive and return strings.\n\nE.g. t.rich('rich', {b: (chunks) => `<b>${chunks}</b>`})":void 0);return t(c),o({error:c,key:e,namespace:r})}return l},n.raw=a.raw,n}export{R as default};
2
+ //# sourceMappingURL=createTranslatorImpl.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/core/createTranslatorImpl.tsx"],"sourcesContent":["import AbstractIntlMessages from './AbstractIntlMessages';\nimport {InitializedIntlConfig} from './IntlConfig';\nimport IntlError, {IntlErrorCode} from './IntlError';\nimport {RichTranslationValues, TranslationValue} from './TranslationValues';\nimport createBaseTranslator, {getMessagesOrError} from './createBaseTranslator';\nimport resolveNamespace from './resolveNamespace';\nimport NestedKeyOf from './utils/NestedKeyOf';\n\nexport type CoreRichTranslationValues = Record<\n string,\n TranslationValue | ((chunks: string) => string)\n>;\n\nexport type CreateTranslatorImplProps<Messages> = Omit<\n InitializedIntlConfig,\n 'messages'\n> & {\n namespace: string;\n messages: Messages;\n};\n\nexport default function createTranslatorImpl<\n Messages extends AbstractIntlMessages,\n NestedKey extends NestedKeyOf<Messages>\n>(\n {\n getMessageFallback,\n messages,\n namespace,\n onError,\n ...rest\n }: CreateTranslatorImplProps<Messages>,\n namespacePrefix: string\n) {\n // The `namespacePrefix` is part of the type system.\n // See the comment in the function invocation.\n messages = messages[namespacePrefix] as Messages;\n namespace = resolveNamespace(namespace, namespacePrefix) as NestedKey;\n\n const translator = createBaseTranslator<Messages, NestedKey>({\n ...rest,\n onError,\n getMessageFallback,\n messagesOrError: getMessagesOrError({\n messages,\n namespace,\n onError\n }) as Messages | IntlError\n });\n\n const originalRich = translator.rich;\n\n function base(...args: Parameters<typeof translator>) {\n return translator(...args);\n }\n\n // Augment `t.rich` to return plain strings\n base.rich = (\n key: Parameters<typeof originalRich>[0],\n /** Key value pairs for values to interpolate into the message. */\n values: CoreRichTranslationValues,\n formats?: Parameters<typeof originalRich>[2]\n ): string => {\n // `chunks` is returned as a string when no React element\n // is used, therefore it's safe to cast this type.\n const result = originalRich(key, values as RichTranslationValues, formats);\n\n // When only string chunks are provided to the parser, only strings should be returned here.\n if (typeof result !== 'string') {\n const error = new IntlError(\n IntlErrorCode.FORMATTING_ERROR,\n process.env.NODE_ENV !== 'production'\n ? \"`createTranslator` only accepts functions for rich text formatting that receive and return strings.\\n\\nE.g. t.rich('rich', {b: (chunks) => `<b>${chunks}</b>`})\"\n : undefined\n );\n\n onError(error);\n return getMessageFallback({error, key, namespace});\n }\n\n return result;\n };\n\n base.raw = translator.raw;\n\n return base;\n}\n"],"mappings":"AAEA,OAAOA,GAAY,iBAAAC,MAAoB,cAEvC,OAAOC,GAAuB,sBAAAC,MAAyB,yBACvD,OAAOC,MAAsB,qBAgBd,SAARC,EAIL,CACE,mBAAAC,EACA,SAAAC,EACA,UAAAC,EACA,QAAAC,EACA,GAAGC,CACL,EACAC,EACA,CAGAJ,EAAWA,EAASI,CAAe,EACnCH,EAAYJ,EAAiBI,EAAWG,CAAe,EAEvD,MAAMC,EAAaV,EAA0C,CAC3D,GAAGQ,EACH,QAAAD,EACA,mBAAAH,EACA,gBAAiBH,EAAmB,CAClC,SAAAI,EACA,UAAAC,EACA,QAAAC,CACF,CAAC,CACH,CAAC,EAEKI,EAAeD,EAAW,KAEhC,SAASE,KAAQC,EAAqC,CACpD,OAAOH,EAAW,GAAGG,CAAI,CAC3B,CAGA,OAAAD,EAAK,KAAO,CACVE,EAEAC,EACAC,IACW,CAGX,MAAMC,EAASN,EAAaG,EAAKC,EAAiCC,CAAO,EAGzE,GAAI,OAAOC,GAAW,SAAU,CAC9B,MAAMC,EAAQ,IAAIpB,EAChBC,EAAc,iBACd,QAAQ,IAAI,WAAa,aACrB,kKACA,MACN,EAEA,OAAAQ,EAAQW,CAAK,EACNd,EAAmB,CAAC,MAAAc,EAAO,IAAAJ,EAAK,UAAAR,CAAS,CAAC,CACnD,CAEA,OAAOW,CACT,EAEAL,EAAK,IAAMF,EAAW,IAEfE,CACT","names":["IntlError","IntlErrorCode","createBaseTranslator","getMessagesOrError","resolveNamespace","createTranslatorImpl","getMessageFallback","messages","namespace","onError","rest","namespacePrefix","translator","originalRich","base","args","key","values","formats","result","error"]}