use-intl 2.7.6 → 2.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/dist/{AbstractIntlMessages.d.ts → core/AbstractIntlMessages.d.ts} +0 -0
  2. package/dist/{DateTimeFormatOptions.d.ts → core/DateTimeFormatOptions.d.ts} +0 -0
  3. package/dist/{Formats.d.ts → core/Formats.d.ts} +0 -0
  4. package/dist/{IntlProvider.d.ts → core/IntlConfiguration.d.ts} +15 -16
  5. package/dist/{IntlError.d.ts → core/IntlError.d.ts} +0 -0
  6. package/dist/{IntlMessages.d.ts → core/IntlMessages.d.ts} +0 -0
  7. package/dist/{NumberFormatOptions.d.ts → core/NumberFormatOptions.d.ts} +0 -0
  8. package/dist/{TranslationValues.d.ts → core/TranslationValues.d.ts} +2 -2
  9. package/dist/{convertFormatsToIntlMessageFormat.d.ts → core/convertFormatsToIntlMessageFormat.d.ts} +0 -0
  10. package/dist/core/createBaseTranslator.d.ts +26 -0
  11. package/dist/{useIntl.d.ts → core/createIntl.d.ts} +11 -1
  12. package/dist/core/createTranslator.d.ts +48 -0
  13. package/dist/core/createTranslatorImpl.d.ts +14 -0
  14. package/dist/core/defaults.d.ts +11 -0
  15. package/dist/core/index.d.ts +8 -0
  16. package/dist/core/resolveNamespace.d.ts +5 -0
  17. package/dist/{use-intl.esm8.js → core/use-intl.esm.js} +2 -2
  18. package/dist/core/use-intl.esm.js.map +1 -0
  19. package/dist/core/use-intl.esm2.js +39 -0
  20. package/dist/core/use-intl.esm2.js.map +1 -0
  21. package/dist/{use-intl.esm4.js → core/use-intl.esm3.js} +12 -12
  22. package/dist/core/use-intl.esm3.js.map +1 -0
  23. package/dist/core/use-intl.esm4.js +59 -0
  24. package/dist/core/use-intl.esm4.js.map +1 -0
  25. package/dist/core/use-intl.esm5.js +15 -0
  26. package/dist/core/use-intl.esm5.js.map +1 -0
  27. package/dist/{use-intl.esm9.js → core/use-intl.esm6.js} +2 -2
  28. package/dist/core/use-intl.esm6.js.map +1 -0
  29. package/dist/core/use-intl.esm7.js +213 -0
  30. package/dist/core/use-intl.esm7.js.map +1 -0
  31. package/dist/core/use-intl.esm8.js +10 -0
  32. package/dist/core/use-intl.esm8.js.map +1 -0
  33. package/dist/{use-intl.esm13.js → core/use-intl.esm9.js} +2 -2
  34. package/dist/core/use-intl.esm9.js.map +1 -0
  35. package/dist/{utils → core/utils}/MessageKeys.d.ts +0 -0
  36. package/dist/{utils → core/utils}/NamespaceKeys.d.ts +0 -0
  37. package/dist/{utils → core/utils}/NestedKeyOf.d.ts +0 -0
  38. package/dist/{utils → core/utils}/NestedValueOf.d.ts +0 -0
  39. package/dist/{validateMessages.d.ts → core/validateMessages.d.ts} +0 -0
  40. package/dist/index.d.ts +2 -12
  41. package/dist/{IntlContext.d.ts → react/IntlContext.d.ts} +4 -4
  42. package/dist/react/IntlProvider.d.ts +16 -0
  43. package/dist/react/index.d.ts +6 -0
  44. package/dist/react/use-intl.esm.js +36 -0
  45. package/dist/react/use-intl.esm.js.map +1 -0
  46. package/dist/{use-intl.esm3.js → react/use-intl.esm2.js} +4 -4
  47. package/dist/react/use-intl.esm2.js.map +1 -0
  48. package/dist/react/use-intl.esm3.js +25 -0
  49. package/dist/react/use-intl.esm3.js.map +1 -0
  50. package/dist/{use-intl.esm5.js → react/use-intl.esm4.js} +2 -2
  51. package/dist/react/use-intl.esm4.js.map +1 -0
  52. package/dist/{use-intl.esm7.js → react/use-intl.esm5.js} +2 -2
  53. package/dist/react/use-intl.esm5.js.map +1 -0
  54. package/dist/{use-intl.esm6.js → react/use-intl.esm6.js} +1 -1
  55. package/dist/react/use-intl.esm6.js.map +1 -0
  56. package/dist/{use-intl.esm10.js → react/use-intl.esm7.js} +1 -1
  57. package/dist/react/use-intl.esm7.js.map +1 -0
  58. package/dist/{use-intl.esm11.js → react/use-intl.esm8.js} +2 -2
  59. package/dist/react/use-intl.esm8.js.map +1 -0
  60. package/dist/react/use-intl.esm9.js +44 -0
  61. package/dist/react/use-intl.esm9.js.map +1 -0
  62. package/dist/react/useIntl.d.ts +5 -0
  63. package/dist/{useIntlContext.d.ts → react/useIntlContext.d.ts} +0 -0
  64. package/dist/{useLocale.d.ts → react/useLocale.d.ts} +0 -0
  65. package/dist/{useNow.d.ts → react/useNow.d.ts} +0 -0
  66. package/dist/{useTimeZone.d.ts → react/useTimeZone.d.ts} +0 -0
  67. package/dist/{useTranslations.d.ts → react/useTranslations.d.ts} +6 -6
  68. package/dist/react/useTranslationsImpl.d.ts +8 -0
  69. package/dist/use-intl.cjs.development.js +381 -229
  70. package/dist/use-intl.cjs.development.js.map +1 -1
  71. package/dist/use-intl.cjs.production.min.js +1 -1
  72. package/dist/use-intl.cjs.production.min.js.map +1 -1
  73. package/dist/use-intl.esm.js +9 -7
  74. package/dist/use-intl.esm.js.map +1 -1
  75. package/package.json +3 -2
  76. package/src/{AbstractIntlMessages.tsx → core/AbstractIntlMessages.tsx} +0 -0
  77. package/src/{DateTimeFormatOptions.tsx → core/DateTimeFormatOptions.tsx} +0 -0
  78. package/src/{Formats.tsx → core/Formats.tsx} +0 -0
  79. package/src/{IntlProvider.tsx → core/IntlConfiguration.tsx} +16 -53
  80. package/src/{IntlError.tsx → core/IntlError.tsx} +0 -0
  81. package/src/{IntlMessages.tsx → core/IntlMessages.tsx} +0 -0
  82. package/src/{NumberFormatOptions.tsx → core/NumberFormatOptions.tsx} +0 -0
  83. package/src/core/TranslationValues.tsx +22 -0
  84. package/src/{convertFormatsToIntlMessageFormat.tsx → core/convertFormatsToIntlMessageFormat.tsx} +0 -0
  85. package/src/core/createBaseTranslator.tsx +316 -0
  86. package/src/{useIntl.tsx → core/createIntl.tsx} +17 -4
  87. package/src/core/createTranslator.tsx +112 -0
  88. package/src/core/createTranslatorImpl.tsx +85 -0
  89. package/src/core/defaults.tsx +18 -0
  90. package/src/core/index.tsx +11 -0
  91. package/src/core/resolveNamespace.tsx +12 -0
  92. package/src/{utils → core/utils}/MessageKeys.tsx +0 -0
  93. package/src/{utils → core/utils}/NamespaceKeys.tsx +0 -0
  94. package/src/{utils → core/utils}/NestedKeyOf.tsx +0 -0
  95. package/src/{utils → core/utils}/NestedValueOf.tsx +0 -0
  96. package/src/{validateMessages.tsx → core/validateMessages.tsx} +0 -0
  97. package/src/index.tsx +2 -15
  98. package/src/{IntlContext.tsx → react/IntlContext.tsx} +4 -4
  99. package/src/react/IntlProvider.tsx +43 -0
  100. package/src/react/index.tsx +6 -0
  101. package/src/react/useIntl.tsx +19 -0
  102. package/src/{useIntlContext.tsx → react/useIntlContext.tsx} +0 -0
  103. package/src/{useLocale.tsx → react/useLocale.tsx} +0 -0
  104. package/src/{useNow.tsx → react/useNow.tsx} +0 -0
  105. package/src/{useTimeZone.tsx → react/useTimeZone.tsx} +0 -0
  106. package/src/{useTranslations.tsx → react/useTranslations.tsx} +9 -7
  107. package/src/react/useTranslationsImpl.tsx +64 -0
  108. package/dist/use-intl.esm10.js.map +0 -1
  109. package/dist/use-intl.esm11.js.map +0 -1
  110. package/dist/use-intl.esm12.js +0 -213
  111. package/dist/use-intl.esm12.js.map +0 -1
  112. package/dist/use-intl.esm13.js.map +0 -1
  113. package/dist/use-intl.esm2.js +0 -48
  114. package/dist/use-intl.esm2.js.map +0 -1
  115. package/dist/use-intl.esm3.js.map +0 -1
  116. package/dist/use-intl.esm4.js.map +0 -1
  117. package/dist/use-intl.esm5.js.map +0 -1
  118. package/dist/use-intl.esm6.js.map +0 -1
  119. package/dist/use-intl.esm7.js.map +0 -1
  120. package/dist/use-intl.esm8.js.map +0 -1
  121. package/dist/use-intl.esm9.js.map +0 -1
  122. package/dist/useTranslationsImpl.d.ts +0 -12
  123. package/src/TranslationValues.tsx +0 -13
  124. package/src/useTranslationsImpl.tsx +0 -328
@@ -0,0 +1,213 @@
1
+ import { extends as _extends } from '../_virtual/use-intl.esm.js';
2
+ import IntlMessageFormat from 'intl-messageformat';
3
+ import { isValidElement, cloneElement } from 'react';
4
+ import IntlError, { IntlErrorCode } from './use-intl.esm.js';
5
+ import convertFormatsToIntlMessageFormat from './use-intl.esm9.js';
6
+ import { defaultOnError, defaultGetMessageFallback } from './use-intl.esm5.js';
7
+
8
+ function resolvePath(messages, key, namespace) {
9
+ if (!messages) {
10
+ throw new Error(process.env.NODE_ENV !== "production" ? "No messages available at `" + namespace + "`." : undefined);
11
+ }
12
+
13
+ var message = messages;
14
+ key.split('.').forEach(function (part) {
15
+ var next = message[part];
16
+
17
+ if (part == null || next == null) {
18
+ throw new Error(process.env.NODE_ENV !== "production" ? "Could not resolve `" + key + "` in " + (namespace ? "`" + namespace + "`" : 'messages') + "." : undefined);
19
+ }
20
+
21
+ message = next;
22
+ });
23
+ return message;
24
+ }
25
+
26
+ function prepareTranslationValues(values) {
27
+ if (Object.keys(values).length === 0) return undefined; // Workaround for https://github.com/formatjs/formatjs/issues/1467
28
+
29
+ var transformedValues = {};
30
+ Object.keys(values).forEach(function (key) {
31
+ var index = 0;
32
+ var value = values[key];
33
+ var transformed;
34
+
35
+ if (typeof value === 'function') {
36
+ transformed = function transformed(chunks) {
37
+ var result = value(chunks);
38
+ return isValidElement(result) ? cloneElement(result, {
39
+ key: key + index++
40
+ }) : result;
41
+ };
42
+ } else {
43
+ transformed = value;
44
+ }
45
+
46
+ transformedValues[key] = transformed;
47
+ });
48
+ return transformedValues;
49
+ }
50
+
51
+ function getMessagesOrError(_ref) {
52
+ var messages = _ref.messages,
53
+ namespace = _ref.namespace,
54
+ _ref$onError = _ref.onError,
55
+ onError = _ref$onError === void 0 ? defaultOnError : _ref$onError;
56
+
57
+ try {
58
+ if (!messages) {
59
+ throw new Error(process.env.NODE_ENV !== "production" ? "No messages were configured on the provider." : undefined);
60
+ }
61
+
62
+ var retrievedMessages = namespace ? resolvePath(messages, namespace) : messages;
63
+
64
+ if (!retrievedMessages) {
65
+ throw new Error(process.env.NODE_ENV !== "production" ? "No messages for namespace `" + namespace + "` found." : undefined);
66
+ }
67
+
68
+ return retrievedMessages;
69
+ } catch (error) {
70
+ var intlError = new IntlError(IntlErrorCode.MISSING_MESSAGE, error.message);
71
+ onError(intlError);
72
+ return intlError;
73
+ }
74
+ }
75
+ function createBaseTranslator(_ref2) {
76
+ var cachedFormatsByLocale = _ref2.cachedFormatsByLocale,
77
+ defaultTranslationValues = _ref2.defaultTranslationValues,
78
+ globalFormats = _ref2.formats,
79
+ _ref2$getMessageFallb = _ref2.getMessageFallback,
80
+ getMessageFallback = _ref2$getMessageFallb === void 0 ? defaultGetMessageFallback : _ref2$getMessageFallb,
81
+ locale = _ref2.locale,
82
+ messagesOrError = _ref2.messagesOrError,
83
+ namespace = _ref2.namespace,
84
+ onError = _ref2.onError,
85
+ timeZone = _ref2.timeZone;
86
+
87
+ function getFallbackFromErrorAndNotify(key, code, message) {
88
+ var error = new IntlError(code, message);
89
+ onError(error);
90
+ return getMessageFallback({
91
+ error: error,
92
+ key: key,
93
+ namespace: namespace
94
+ });
95
+ }
96
+
97
+ function translateBaseFn(
98
+ /** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */
99
+ key,
100
+ /** Key value pairs for values to interpolate into the message. */
101
+ values,
102
+ /** Provide custom formats for numbers, dates and times. */
103
+ formats) {
104
+ var _cachedFormatsByLocal;
105
+
106
+ if (messagesOrError instanceof IntlError) {
107
+ // We have already warned about this during render
108
+ return getMessageFallback({
109
+ error: messagesOrError,
110
+ key: key,
111
+ namespace: namespace
112
+ });
113
+ }
114
+
115
+ var messages = messagesOrError;
116
+ var cacheKey = [namespace, key].filter(function (part) {
117
+ return part != null;
118
+ }).join('.');
119
+ var messageFormat;
120
+
121
+ if (cachedFormatsByLocale != null && (_cachedFormatsByLocal = cachedFormatsByLocale[locale]) != null && _cachedFormatsByLocal[cacheKey]) {
122
+ messageFormat = cachedFormatsByLocale == null ? void 0 : cachedFormatsByLocale[locale][cacheKey];
123
+ } else {
124
+ var message;
125
+
126
+ try {
127
+ message = resolvePath(messages, key, namespace);
128
+ } catch (error) {
129
+ return getFallbackFromErrorAndNotify(key, IntlErrorCode.MISSING_MESSAGE, error.message);
130
+ }
131
+
132
+ if (typeof message === 'object') {
133
+ return getFallbackFromErrorAndNotify(key, IntlErrorCode.INSUFFICIENT_PATH, process.env.NODE_ENV !== "production" ? "Insufficient path specified for `" + key + "` in `" + (namespace ? "`" + namespace + "`" : 'messages') + "`." : undefined);
134
+ }
135
+
136
+ try {
137
+ messageFormat = new IntlMessageFormat(message, locale, convertFormatsToIntlMessageFormat(_extends({}, globalFormats, formats), timeZone));
138
+ } catch (error) {
139
+ return getFallbackFromErrorAndNotify(key, IntlErrorCode.INVALID_MESSAGE, error.message);
140
+ }
141
+
142
+ if (cachedFormatsByLocale) {
143
+ if (!cachedFormatsByLocale[locale]) {
144
+ cachedFormatsByLocale[locale] = {};
145
+ }
146
+
147
+ cachedFormatsByLocale[locale][cacheKey] = messageFormat;
148
+ }
149
+ }
150
+
151
+ try {
152
+ var formattedMessage = messageFormat.format( // @ts-ignore `intl-messageformat` expects a different format
153
+ // for rich text elements since a recent minor update. This
154
+ // needs to be evaluated in detail, possibly also in regards
155
+ // to be able to format to parts.
156
+ prepareTranslationValues(_extends({}, defaultTranslationValues, values)));
157
+
158
+ if (formattedMessage == null) {
159
+ throw new Error(process.env.NODE_ENV !== "production" ? "Unable to format `" + key + "` in " + (namespace ? "namespace `" + namespace + "`" : 'messages') : undefined);
160
+ } // Limit the function signature to return strings or React elements
161
+
162
+
163
+ return isValidElement(formattedMessage) || // Arrays of React elements
164
+ Array.isArray(formattedMessage) || typeof formattedMessage === 'string' ? formattedMessage : String(formattedMessage);
165
+ } catch (error) {
166
+ return getFallbackFromErrorAndNotify(key, IntlErrorCode.FORMATTING_ERROR, error.message);
167
+ }
168
+ }
169
+
170
+ function translateFn(
171
+ /** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */
172
+ key,
173
+ /** Key value pairs for values to interpolate into the message. */
174
+ values,
175
+ /** Provide custom formats for numbers, dates and times. */
176
+ formats) {
177
+ var result = translateBaseFn(key, values, formats);
178
+
179
+ if (typeof result !== 'string') {
180
+ return getFallbackFromErrorAndNotify(key, IntlErrorCode.INVALID_MESSAGE, process.env.NODE_ENV !== "production" ? "The message `" + key + "` in " + (namespace ? "namespace `" + namespace + "`" : 'messages') + " didn't resolve to a string. If you want to format rich text, use `t.rich` instead." : undefined);
181
+ }
182
+
183
+ return result;
184
+ }
185
+
186
+ translateFn.rich = translateBaseFn;
187
+
188
+ translateFn.raw = function (
189
+ /** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */
190
+ key) {
191
+ if (messagesOrError instanceof IntlError) {
192
+ // We have already warned about this during render
193
+ return getMessageFallback({
194
+ error: messagesOrError,
195
+ key: key,
196
+ namespace: namespace
197
+ });
198
+ }
199
+
200
+ var messages = messagesOrError;
201
+
202
+ try {
203
+ return resolvePath(messages, key, namespace);
204
+ } catch (error) {
205
+ return getFallbackFromErrorAndNotify(key, IntlErrorCode.MISSING_MESSAGE, error.message);
206
+ }
207
+ };
208
+
209
+ return translateFn;
210
+ }
211
+
212
+ export { createBaseTranslator as default, getMessagesOrError };
213
+ //# sourceMappingURL=use-intl.esm7.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-intl.esm7.js","sources":["../../src/core/createBaseTranslator.tsx"],"sourcesContent":["import 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 {InitializedIntlConfiguration} from './IntlConfiguration';\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 __DEV__ ? `No messages available at \\`${namespace}\\`.` : 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 __DEV__\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 __DEV__ ? `No messages were configured on the provider.` : undefined\n );\n }\n\n const retrievedMessages = namespace\n ? resolvePath(messages, namespace)\n : messages;\n\n if (!retrievedMessages) {\n throw new Error(\n __DEV__\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> =\n InitializedIntlConfiguration & {\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 const cacheKey = [namespace, key].filter((part) => part != null).join('.');\n\n let messageFormat;\n if (cachedFormatsByLocale?.[locale]?.[cacheKey]) {\n messageFormat = cachedFormatsByLocale?.[locale][cacheKey];\n } else {\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 if (typeof message === 'object') {\n return getFallbackFromErrorAndNotify(\n key,\n IntlErrorCode.INSUFFICIENT_PATH,\n __DEV__\n ? `Insufficient path specified for \\`${key}\\` in \\`${\n namespace ? `\\`${namespace}\\`` : 'messages'\n }\\`.`\n : undefined\n );\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 __DEV__\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 __DEV__\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"],"names":["resolvePath","messages","key","namespace","Error","undefined","message","split","forEach","part","next","prepareTranslationValues","values","Object","keys","length","transformedValues","index","value","transformed","chunks","result","isValidElement","cloneElement","getMessagesOrError","onError","defaultOnError","retrievedMessages","error","intlError","IntlError","IntlErrorCode","MISSING_MESSAGE","createBaseTranslator","cachedFormatsByLocale","defaultTranslationValues","globalFormats","formats","getMessageFallback","defaultGetMessageFallback","locale","messagesOrError","timeZone","getFallbackFromErrorAndNotify","code","translateBaseFn","cacheKey","filter","join","messageFormat","INSUFFICIENT_PATH","IntlMessageFormat","convertFormatsToIntlMessageFormat","INVALID_MESSAGE","formattedMessage","format","Array","isArray","String","FORMATTING_ERROR","translateFn","rich","raw"],"mappings":";;;;;;;AAmBA,SAASA,WAAT,CACEC,QADF,EAEEC,GAFF,EAGEC,SAHF,EAGoB;AAElB,EAAI,IAAA,CAACF,QAAL,EAAe;AACb,IAAA,MAAM,IAAIG,KAAJ,CACJ,uEAAwCD,SAAxC,GAAA,IAAA,GAAyDE,SADrD,CAAN,CAAA;AAGD,GAAA;;AAED,EAAIC,IAAAA,OAAO,GAAGL,QAAd,CAAA;AAEAC,EAAAA,GAAG,CAACK,KAAJ,CAAU,GAAV,EAAeC,OAAf,CAAuB,UAACC,IAAD,EAAS;AAC9B,IAAA,IAAMC,IAAI,GAAIJ,OAAe,CAACG,IAAD,CAA7B,CAAA;;AAEA,IAAA,IAAIA,IAAI,IAAI,IAAR,IAAgBC,IAAI,IAAI,IAA5B,EAAkC;AAChC,MAAA,MAAM,IAAIN,KAAJ,CACJ,OAAA,CAAA,GAAA,CAAA,QAAA,KAAA,YAAA,GAAA,qBAAA,GAC2BF,GAD3B,GAAA,OAAA,IAEMC,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the namespace into
3
+ * a mandatory prefix. See https://stackoverflow.com/a/71529575/343045
4
+ */
5
+ function resolveNamespace(namespace, namespacePrefix) {
6
+ return namespace === namespacePrefix ? undefined : namespace.slice((namespacePrefix + '.').length);
7
+ }
8
+
9
+ export { resolveNamespace as default };
10
+ //# sourceMappingURL=use-intl.esm8.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-intl.esm8.js","sources":["../../src/core/resolveNamespace.tsx"],"sourcesContent":["/**\n * For the strictly typed messages to work we have to wrap the namespace into\n * a mandatory prefix. See https://stackoverflow.com/a/71529575/343045\n */\nexport default function resolveNamespace(\n namespace: string,\n namespacePrefix: string\n) {\n return namespace === namespacePrefix\n ? undefined\n : namespace.slice((namespacePrefix + '.').length);\n}\n"],"names":["resolveNamespace","namespace","namespacePrefix","undefined","slice","length"],"mappings":"AAAA;;;AAGG;AACW,SAAUA,gBAAV,CACZC,SADY,EAEZC,eAFY,EAEW;AAEvB,EAAA,OAAOD,SAAS,KAAKC,eAAd,GACHC,SADG,GAEHF,SAAS,CAACG,KAAV,CAAgB,CAACF,eAAe,GAAG,GAAnB,EAAwBG,MAAxC,CAFJ,CAAA;AAGD;;;;"}
@@ -1,4 +1,4 @@
1
- import { extends as _extends } from './_virtual/use-intl.esm.js';
1
+ import { extends as _extends } from '../_virtual/use-intl.esm.js';
2
2
 
3
3
  function setTimeZoneInFormats(formats, timeZone) {
4
4
  if (!formats) return formats; // The only way to set a time zone with `intl-messageformat` is to merge it into the formats
@@ -31,4 +31,4 @@ function convertFormatsToIntlMessageFormat(formats, timeZone) {
31
31
  }
32
32
 
33
33
  export { convertFormatsToIntlMessageFormat as default };
34
- //# sourceMappingURL=use-intl.esm13.js.map
34
+ //# sourceMappingURL=use-intl.esm9.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-intl.esm9.js","sources":["../../src/core/convertFormatsToIntlMessageFormat.tsx"],"sourcesContent":["import {Formats as IntlFormats} from 'intl-messageformat';\nimport DateTimeFormatOptions from './DateTimeFormatOptions';\nimport Formats from './Formats';\n\nfunction setTimeZoneInFormats(\n formats: Record<string, DateTimeFormatOptions> | undefined,\n timeZone: string\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?: string\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"],"names":["setTimeZoneInFormats","formats","timeZone","Object","keys","reduce","acc","key","convertFormatsToIntlMessageFormat","formatsWithTimeZone","dateTime","date","time"],"mappings":";;AAIA,SAASA,oBAAT,CACEC,OADF,EAEEC,QAFF,EAEkB;AAEhB,EAAA,IAAI,CAACD,OAAL,EAAc,OAAOA,OAAP,CAFE;AAKhB;;AACA,EAAA,OAAOE,MAAM,CAACC,IAAP,CAAYH,OAAZ,CAAA,CAAqBI,MAArB,CACL,UAACC,GAAD,EAA6CC,GAA7C,EAAoD;AAClDD,IAAAA,GAAG,CAACC,GAAD,CAAH,GAAA,QAAA,CAAA;AACEL,MAAAA,QAAQ,EAARA,QAAAA;AADF,KAEKD,EAAAA,OAAO,CAACM,GAAD,CAFZ,CAAA,CAAA;AAIA,IAAA,OAAOD,GAAP,CAAA;AACD,GAPI,EAQL,EARK,CAAP,CAAA;AAUD,CAAA;AAED;;;;;;AAMG;;;AACW,SAAUE,iCAAV,CACZP,OADY,EAEZC,QAFY,EAEK;AAEjB,EAAA,IAAMO,mBAAmB,GAAGP,QAAQ,GAAA,QAAA,CAAA,EAAA,EAC5BD,OAD4B,EAAA;AACnBS,IAAAA,QAAQ,EAAEV,oBAAoB,CAACC,OAAO,CAACS,QAAT,EAAmBR,QAAnB,CAAA;AADX,GAAA,CAAA,GAEhCD,OAFJ,CAAA;AAIA,EAAA,OAAA,QAAA,CAAA,EAAA,EACKQ,mBADL,EAAA;AAEEE,IAAAA,IAAI,EAAEF,mBAAF,IAAEA,IAAAA,GAAAA,KAAAA,CAAAA,GAAAA,mBAAmB,CAAEC,QAF7B;AAGEE,IAAAA,IAAI,EAAEH,mBAAF,IAAA,IAAA,GAAA,KAAA,CAAA,GAAEA,mBAAmB,CAAEC,QAAAA;AAH7B,GAAA,CAAA,CAAA;AAKD;;;;"}
File without changes
File without changes
File without changes
File without changes
package/dist/index.d.ts CHANGED
@@ -1,12 +1,2 @@
1
- export { default as IntlProvider } from './IntlProvider';
2
- export { default as AbstractIntlMessages } from './AbstractIntlMessages';
3
- export { default as useTranslations } from './useTranslations';
4
- export { default as TranslationValues, RichTranslationValues } from './TranslationValues';
5
- export { default as useIntl } from './useIntl';
6
- export { default as useLocale } from './useLocale';
7
- export { default as useNow } from './useNow';
8
- export { default as useTimeZone } from './useTimeZone';
9
- export { default as Formats } from './Formats';
10
- export { default as DateTimeFormatOptions } from './DateTimeFormatOptions';
11
- export { default as NumberFormatOptions } from './NumberFormatOptions';
12
- export { default as IntlError, IntlErrorCode } from './IntlError';
1
+ export * from './core';
2
+ export * from './react';
@@ -1,8 +1,8 @@
1
1
  /// <reference types="react" />
2
- import AbstractIntlMessages from './AbstractIntlMessages';
3
- import Formats from './Formats';
4
- import IntlError from './IntlError';
5
- import { RichTranslationValues } from './TranslationValues';
2
+ import AbstractIntlMessages from '../core/AbstractIntlMessages';
3
+ import Formats from '../core/Formats';
4
+ import IntlError from '../core/IntlError';
5
+ import { RichTranslationValues } from '../core/TranslationValues';
6
6
  export declare type IntlContextShape = {
7
7
  messages?: AbstractIntlMessages;
8
8
  locale: string;
@@ -0,0 +1,16 @@
1
+ import { ReactNode } from 'react';
2
+ import { AbstractIntlMessages } from '../core';
3
+ import IntlConfiguration from '../core/IntlConfiguration';
4
+ import { RichTranslationValues } from '../core/TranslationValues';
5
+ declare type Props = IntlConfiguration & {
6
+ /** All components that use the provided hooks should be within this tree. */
7
+ children: ReactNode;
8
+ /** Global default values for translation values and rich text elements.
9
+ * Can be used for consistent usage or styling of rich text elements.
10
+ * Defaults will be overidden by locally provided values. */
11
+ defaultTranslationValues?: RichTranslationValues;
12
+ /** All messages that will be available in your components. */
13
+ messages?: AbstractIntlMessages;
14
+ };
15
+ export default function IntlProvider({ children, onError, getMessageFallback, messages, ...contextValues }: Props): JSX.Element;
16
+ export {};
@@ -0,0 +1,6 @@
1
+ export { default as IntlProvider } from './IntlProvider';
2
+ export { default as useTranslations } from './useTranslations';
3
+ export { default as useIntl } from './useIntl';
4
+ export { default as useLocale } from './useLocale';
5
+ export { default as useNow } from './useNow';
6
+ export { default as useTimeZone } from './useTimeZone';
@@ -0,0 +1,36 @@
1
+ import { objectWithoutPropertiesLoose as _objectWithoutPropertiesLoose, extends as _extends } from '../_virtual/use-intl.esm.js';
2
+ import React, { useEffect } from 'react';
3
+ import { defaultOnError, defaultGetMessageFallback } from '../core/use-intl.esm5.js';
4
+ import validateMessages from '../core/use-intl.esm6.js';
5
+ import IntlContext from './use-intl.esm7.js';
6
+
7
+ var _excluded = ["children", "onError", "getMessageFallback", "messages"];
8
+ function IntlProvider(_ref) {
9
+ var children = _ref.children,
10
+ _ref$onError = _ref.onError,
11
+ onError = _ref$onError === void 0 ? defaultOnError : _ref$onError,
12
+ _ref$getMessageFallba = _ref.getMessageFallback,
13
+ getMessageFallback = _ref$getMessageFallba === void 0 ? defaultGetMessageFallback : _ref$getMessageFallba,
14
+ messages = _ref.messages,
15
+ contextValues = _objectWithoutPropertiesLoose(_ref, _excluded);
16
+
17
+ if (process.env.NODE_ENV !== "production") {
18
+ // eslint-disable-next-line react-hooks/rules-of-hooks
19
+ useEffect(function () {
20
+ if (messages) {
21
+ validateMessages(messages, onError);
22
+ }
23
+ }, [messages, onError]);
24
+ }
25
+
26
+ return React.createElement(IntlContext.Provider, {
27
+ value: _extends({}, contextValues, {
28
+ messages: messages,
29
+ onError: onError,
30
+ getMessageFallback: getMessageFallback
31
+ })
32
+ }, children);
33
+ }
34
+
35
+ export { IntlProvider as default };
36
+ //# sourceMappingURL=use-intl.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-intl.esm.js","sources":["../../src/react/IntlProvider.tsx"],"sourcesContent":["import React, {ReactNode, useEffect} from 'react';\nimport {AbstractIntlMessages} from '../core';\nimport IntlConfiguration from '../core/IntlConfiguration';\nimport {RichTranslationValues} from '../core/TranslationValues';\nimport {defaultGetMessageFallback, defaultOnError} from '../core/defaults';\nimport validateMessages from '../core/validateMessages';\nimport IntlContext from './IntlContext';\n\ntype Props = IntlConfiguration & {\n /** All components that use the provided hooks should be within this tree. */\n children: ReactNode;\n /** Global default values for translation values and rich text elements.\n * Can be used for consistent usage or styling of rich text elements.\n * Defaults will be overidden by locally provided values. */\n defaultTranslationValues?: RichTranslationValues;\n /** All messages that will be available in your components. */\n messages?: AbstractIntlMessages;\n};\n\nexport default function IntlProvider({\n children,\n onError = defaultOnError,\n getMessageFallback = defaultGetMessageFallback,\n messages,\n ...contextValues\n}: Props) {\n if (__DEV__) {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useEffect(() => {\n if (messages) {\n validateMessages(messages, onError);\n }\n }, [messages, onError]);\n }\n\n return (\n <IntlContext.Provider\n value={{...contextValues, messages, onError, getMessageFallback}}\n >\n {children}\n </IntlContext.Provider>\n );\n}\n"],"names":["IntlProvider","children","onError","defaultOnError","getMessageFallback","defaultGetMessageFallback","messages","contextValues","useEffect","validateMessages","React","IntlContext","Provider","value"],"mappings":";;;;;;;AAmBwB,SAAAA,YAAA,CAMhB,IAAA,EAAA;AAAA,EALNC,IAAAA,QAKM,QALNA,QAKM;AAAA,MAAA,YAAA,GAAA,IAAA,CAJNC,OAIM;AAAA,MAJNA,OAIM,6BAJIC,cAIJ,GAAA,YAAA;AAAA,MAAA,qBAAA,GAAA,IAAA,CAHNC,kBAGM;AAAA,MAHNA,kBAGM,sCAHeC,yBAGf,GAAA,qBAAA;AAAA,MAFNC,QAEM,QAFNA,QAEM;AAAA,MADHC,aACG,GAAA,6BAAA,CAAA,IAAA,EAAA,SAAA,CAAA,CAAA;;AACN,EAAa,IAAA,OAAA,CAAA,GAAA,CAAA,QAAA,KAAA,YAAA,EAAA;AACX;AACAC,IAAAA,SAAS,CAAC,YAAK;AACb,MAAA,IAAIF,QAAJ,EAAc;AACZG,QAAAA,gBAAgB,CAACH,QAAD,EAAWJ,OAAX,CAAhB,CAAA;AACD,OAAA;AACF,KAJQ,EAIN,CAACI,QAAD,EAAWJ,OAAX,CAJM,CAAT,CAAA;AAKD,GAAA;;AAED,EAAA,OACEQ,mBAAA,CAACC,WAAW,CAACC,QAAb,EACE;AAAAC,IAAAA,KAAK,eAAMN,aAAN,EAAA;AAAqBD,MAAAA,QAAQ,EAARA,QAArB;AAA+BJ,MAAAA,OAAO,EAAPA,OAA/B;AAAwCE,MAAAA,kBAAkB,EAAlBA,kBAAAA;AAAxC,KAAA,CAAA;AAAL,GADF,EAGGH,QAHH,CADF,CAAA;AAOD;;;;"}
@@ -1,5 +1,5 @@
1
- import useIntlContext from './use-intl.esm11.js';
2
- import useTranslationsImpl from './use-intl.esm12.js';
1
+ import useIntlContext from './use-intl.esm8.js';
2
+ import useTranslationsImpl from './use-intl.esm9.js';
3
3
 
4
4
  /**
5
5
  * Translates messages from the given namespace by using the ICU syntax.
@@ -14,7 +14,7 @@ function useTranslations(namespace) {
14
14
  var context = useIntlContext();
15
15
  var messages = context.messages; // We have to wrap the actual hook so the type inference for the optional
16
16
  // namespace works correctly. See https://stackoverflow.com/a/71529575/343045
17
- // The prefix ("!"") is arbitrary, but we have to use some.
17
+ // The prefix ("!") is arbitrary.
18
18
 
19
19
  return useTranslationsImpl({
20
20
  '!': messages
@@ -23,4 +23,4 @@ function useTranslations(namespace) {
23
23
  }
24
24
 
25
25
  export { useTranslations as default };
26
- //# sourceMappingURL=use-intl.esm3.js.map
26
+ //# sourceMappingURL=use-intl.esm2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-intl.esm2.js","sources":["../../src/react/useTranslations.tsx"],"sourcesContent":["import {ReactElement, ReactNodeArray} from 'react';\nimport Formats from '../core/Formats';\nimport TranslationValues, {\n RichTranslationValues\n} from '../core/TranslationValues';\nimport MessageKeys from '../core/utils/MessageKeys';\nimport NamespaceKeys from '../core/utils/NamespaceKeys';\nimport NestedKeyOf from '../core/utils/NestedKeyOf';\nimport NestedValueOf from '../core/utils/NestedValueOf';\nimport useIntlContext from './useIntlContext';\nimport useTranslationsImpl from './useTranslationsImpl';\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 useTranslations<\n NestedKey extends NamespaceKeys<\n IntlMessages,\n NestedKeyOf<IntlMessages>\n > = never\n>(\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?: RichTranslationValues,\n formats?: Partial<Formats>\n ): string | ReactElement | ReactNodeArray;\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 const context = useIntlContext();\n const messages = context.messages as IntlMessages;\n\n // We have to wrap the actual hook 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 useTranslationsImpl<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >(\n {'!': messages},\n // @ts-ignore\n namespace ? `!.${namespace}` : '!',\n '!'\n );\n}\n"],"names":["useTranslations","namespace","context","useIntlContext","messages","useTranslationsImpl"],"mappings":";;;AAYA;;;;;;;AAOG;;AACqB,SAAAA,eAAA,CAMtBC,SANsB,EAMD;AA6DrB,EAAMC,IAAAA,OAAO,GAAGC,cAAc,EAA9B,CAAA;AACA,EAAA,IAAMC,QAAQ,GAAGF,OAAO,CAACE,QAAzB,CA9DqB;AAiErB;AACA;;AACA,EAAA,OAAOC,mBAAmB,CAIxB;AAAC,IAAKD,GAAAA,EAAAA,QAAAA;AAAN,GAJwB;AAMxBH,EAAAA,SAAS,GAAQA,IAAAA,GAAAA,SAAR,GAAsB,GANP,EAOxB,GAPwB,CAA1B,CAAA;AASD;;;;"}
@@ -0,0 +1,25 @@
1
+ import { useMemo } from 'react';
2
+ import createIntl from '../core/use-intl.esm3.js';
3
+ import useIntlContext from './use-intl.esm8.js';
4
+
5
+ function useIntl() {
6
+ var _useIntlContext = useIntlContext(),
7
+ formats = _useIntlContext.formats,
8
+ locale = _useIntlContext.locale,
9
+ globalNow = _useIntlContext.now,
10
+ onError = _useIntlContext.onError,
11
+ timeZone = _useIntlContext.timeZone;
12
+
13
+ return useMemo(function () {
14
+ return createIntl({
15
+ formats: formats,
16
+ locale: locale,
17
+ now: globalNow,
18
+ onError: onError,
19
+ timeZone: timeZone
20
+ });
21
+ }, [formats, globalNow, locale, onError, timeZone]);
22
+ }
23
+
24
+ export { useIntl as default };
25
+ //# sourceMappingURL=use-intl.esm3.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-intl.esm3.js","sources":["../../src/react/useIntl.tsx"],"sourcesContent":["import {useMemo} from 'react';\nimport createIntl from '../core/createIntl';\nimport useIntlContext from './useIntlContext';\n\nexport default function useIntl() {\n const {formats, locale, now: globalNow, onError, timeZone} = useIntlContext();\n\n return useMemo(\n () =>\n createIntl({\n formats,\n locale,\n now: globalNow,\n onError,\n timeZone\n }),\n [formats, globalNow, locale, onError, timeZone]\n );\n}\n"],"names":["useIntl","useIntlContext","formats","locale","globalNow","now","onError","timeZone","useMemo","createIntl"],"mappings":";;;;AAIc,SAAUA,OAAV,GAAiB;AAC7B,EAAA,IAAA,eAAA,GAA6DC,cAAc,EAA3E;AAAA,MAAOC,OAAP,mBAAOA,OAAP;AAAA,MAAgBC,MAAhB,mBAAgBA,MAAhB;AAAA,MAA6BC,SAA7B,mBAAwBC,GAAxB;AAAA,MAAwCC,OAAxC,mBAAwCA,OAAxC;AAAA,MAAiDC,QAAjD,mBAAiDA,QAAjD,CAAA;;AAEA,EAAA,OAAOC,OAAO,CACZ,YAAA;AAAA,IAAA,OACEC,UAAU,CAAC;AACTP,MAAAA,OAAO,EAAPA,OADS;AAETC,MAAAA,MAAM,EAANA,MAFS;AAGTE,MAAAA,GAAG,EAAED,SAHI;AAITE,MAAAA,OAAO,EAAPA,OAJS;AAKTC,MAAAA,QAAQ,EAARA,QAAAA;AALS,KAAD,CADZ,CAAA;AAAA,GADY,EASZ,CAACL,OAAD,EAAUE,SAAV,EAAqBD,MAArB,EAA6BG,OAA7B,EAAsCC,QAAtC,CATY,CAAd,CAAA;AAWD;;;;"}
@@ -1,8 +1,8 @@
1
- import useIntlContext from './use-intl.esm11.js';
1
+ import useIntlContext from './use-intl.esm8.js';
2
2
 
3
3
  function useLocale() {
4
4
  return useIntlContext().locale;
5
5
  }
6
6
 
7
7
  export { useLocale as default };
8
- //# sourceMappingURL=use-intl.esm5.js.map
8
+ //# sourceMappingURL=use-intl.esm4.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-intl.esm4.js","sources":["../../src/react/useLocale.tsx"],"sourcesContent":["import useIntlContext from './useIntlContext';\n\nexport default function useLocale() {\n return useIntlContext().locale;\n}\n"],"names":["useLocale","useIntlContext","locale"],"mappings":";;AAEc,SAAUA,SAAV,GAAmB;AAC/B,EAAOC,OAAAA,cAAc,GAAGC,MAAxB,CAAA;AACD;;;;"}
@@ -1,8 +1,8 @@
1
- import useIntlContext from './use-intl.esm11.js';
1
+ import useIntlContext from './use-intl.esm8.js';
2
2
 
3
3
  function useTimeZone() {
4
4
  return useIntlContext().timeZone;
5
5
  }
6
6
 
7
7
  export { useTimeZone as default };
8
- //# sourceMappingURL=use-intl.esm7.js.map
8
+ //# sourceMappingURL=use-intl.esm5.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-intl.esm5.js","sources":["../../src/react/useTimeZone.tsx"],"sourcesContent":["import useIntlContext from './useIntlContext';\n\nexport default function useTimeZone() {\n return useIntlContext().timeZone;\n}\n"],"names":["useTimeZone","useIntlContext","timeZone"],"mappings":";;AAEc,SAAUA,WAAV,GAAqB;AACjC,EAAOC,OAAAA,cAAc,GAAGC,QAAxB,CAAA;AACD;;;;"}
@@ -1,5 +1,5 @@
1
1
  import { useState, useEffect } from 'react';
2
- import useIntlContext from './use-intl.esm11.js';
2
+ import useIntlContext from './use-intl.esm8.js';
3
3
 
4
4
  function getNow() {
5
5
  return new Date();
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-intl.esm6.js","sources":["../../src/react/useNow.tsx"],"sourcesContent":["import {useState, useEffect} from 'react';\nimport useIntlContext from './useIntlContext';\n\ntype Options = {\n updateInterval?: number;\n};\n\nfunction getNow() {\n return new Date();\n}\n\n/**\n * Reading the current date via `new Date()` in components should be avoided, as\n * it causes components to be impure and can lead to flaky tests. Instead, this\n * hook can be used.\n *\n * By default, it returns the time when the component mounts. If `updateInterval`\n * is specified, the value will be updated based on the interval.\n *\n * You can however also return a static value from this hook, if you\n * configure the `now` parameter on the context provider. Note however,\n * that if `updateInterval` is configured in this case, the component\n * will initialize with the global value, but will afterwards update\n * continuously based on the interval.\n *\n * For unit tests, this can be mocked to a constant value. For end-to-end\n * testing, an environment parameter can be passed to the `now` parameter\n * of the provider to mock this to a static value.\n */\nexport default function useNow(options?: Options) {\n const updateInterval = options?.updateInterval;\n\n const {now: globalNow} = useIntlContext();\n const [now, setNow] = useState(globalNow || getNow());\n\n useEffect(() => {\n if (!updateInterval) return;\n\n const intervalId = setInterval(() => {\n setNow(getNow());\n }, updateInterval);\n\n return () => {\n clearInterval(intervalId);\n };\n }, [globalNow, updateInterval]);\n\n return now;\n}\n"],"names":["getNow","Date","useNow","options","updateInterval","useIntlContext","globalNow","now","useState","setNow","useEffect","intervalId","setInterval","clearInterval"],"mappings":";;;AAOA,SAASA,MAAT,GAAe;AACb,EAAO,OAAA,IAAIC,IAAJ,EAAP,CAAA;AACD,CAAA;AAED;;;;;;;;;;;;;;;;;AAiBG;;;AACqB,SAAAC,MAAA,CAAOC,OAAP,EAAwB;AAC9C,EAAA,IAAMC,cAAc,GAAGD,OAAH,IAAGA,IAAAA,GAAAA,KAAAA,CAAAA,GAAAA,OAAO,CAAEC,cAAhC,CAAA;;AAEA,EAAA,IAAA,eAAA,GAAyBC,cAAc,EAAvC;AAAA,MAAYC,SAAZ,mBAAOC,GAAP,CAAA;;AACA,EAAA,IAAA,SAAA,GAAsBC,QAAQ,CAACF,SAAS,IAAIN,MAAM,EAApB,CAA9B;AAAA,MAAOO,GAAP,GAAA,SAAA,CAAA,CAAA,CAAA;AAAA,MAAYE,MAAZ,GAAA,SAAA,CAAA,CAAA,CAAA,CAAA;;AAEAC,EAAAA,SAAS,CAAC,YAAK;AACb,IAAI,IAAA,CAACN,cAAL,EAAqB,OAAA;AAErB,IAAA,IAAMO,UAAU,GAAGC,WAAW,CAAC,YAAK;AAClCH,MAAAA,MAAM,CAACT,MAAM,EAAP,CAAN,CAAA;AACD,KAF6B,EAE3BI,cAF2B,CAA9B,CAAA;AAIA,IAAA,OAAO,YAAK;AACVS,MAAAA,aAAa,CAACF,UAAD,CAAb,CAAA;AACD,KAFD,CAAA;AAGD,GAVQ,EAUN,CAACL,SAAD,EAAYF,cAAZ,CAVM,CAAT,CAAA;AAYA,EAAA,OAAOG,GAAP,CAAA;AACD;;;;"}
@@ -3,4 +3,4 @@ import { createContext } from 'react';
3
3
  var IntlContext = /*#__PURE__*/createContext(undefined);
4
4
 
5
5
  export { IntlContext as default };
6
- //# sourceMappingURL=use-intl.esm10.js.map
6
+ //# sourceMappingURL=use-intl.esm7.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-intl.esm7.js","sources":["../../src/react/IntlContext.tsx"],"sourcesContent":["import {createContext} from 'react';\nimport AbstractIntlMessages from '../core/AbstractIntlMessages';\nimport Formats from '../core/Formats';\nimport IntlError from '../core/IntlError';\nimport {RichTranslationValues} from '../core/TranslationValues';\n\nexport type IntlContextShape = {\n messages?: AbstractIntlMessages;\n locale: string;\n formats?: Partial<Formats>;\n timeZone?: string;\n onError(error: IntlError): void;\n getMessageFallback(info: {\n error: IntlError;\n key: string;\n namespace?: string;\n }): string;\n now?: Date;\n defaultTranslationValues?: RichTranslationValues;\n};\n\nconst IntlContext = createContext<IntlContextShape | undefined>(undefined);\n\nexport default IntlContext;\n"],"names":["IntlContext","createContext","undefined"],"mappings":";;AAqBA,IAAMA,WAAW,gBAAGC,aAAa,CAA+BC,SAA/B;;;;"}
@@ -1,5 +1,5 @@
1
1
  import { useContext } from 'react';
2
- import IntlContext from './use-intl.esm10.js';
2
+ import IntlContext from './use-intl.esm7.js';
3
3
 
4
4
  function useIntlContext() {
5
5
  var context = useContext(IntlContext);
@@ -12,4 +12,4 @@ function useIntlContext() {
12
12
  }
13
13
 
14
14
  export { useIntlContext as default };
15
- //# sourceMappingURL=use-intl.esm11.js.map
15
+ //# sourceMappingURL=use-intl.esm8.js.map
@@ -0,0 +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;;;;"}
@@ -0,0 +1,44 @@
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';
5
+
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.
15
+
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 };
44
+ //# sourceMappingURL=use-intl.esm9.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-intl.esm9.js","sources":["../../src/react/useTranslationsImpl.tsx"],"sourcesContent":["import {IntlMessageFormat} from 'intl-messageformat';\nimport {useMemo, useRef} from 'react';\nimport AbstractIntlMessages from '../core/AbstractIntlMessages';\nimport createBaseTranslator, {\n getMessagesOrError\n} from '../core/createBaseTranslator';\nimport resolveNamespace from '../core/resolveNamespace';\nimport NestedKeyOf from '../core/utils/NestedKeyOf';\nimport useIntlContext from './useIntlContext';\n\nexport default function useTranslationsImpl<\n Messages extends AbstractIntlMessages,\n NestedKey extends NestedKeyOf<Messages>\n>(allMessages: Messages, namespace: NestedKey, namespacePrefix: string) {\n const {\n defaultTranslationValues,\n formats: globalFormats,\n getMessageFallback,\n locale,\n onError,\n timeZone\n } = useIntlContext();\n\n // The `namespacePrefix` is part of the type system.\n // See the comment in the hook invocation.\n allMessages = allMessages[namespacePrefix] as Messages;\n namespace = resolveNamespace(namespace, namespacePrefix) as NestedKey;\n\n const cachedFormatsByLocaleRef = useRef<\n Record<string, Record<string, IntlMessageFormat>>\n >({});\n\n const messagesOrError = useMemo(\n () => getMessagesOrError({messages: allMessages, namespace, onError}),\n [allMessages, namespace, onError]\n );\n\n const translate = useMemo(\n () =>\n createBaseTranslator({\n cachedFormatsByLocale: cachedFormatsByLocaleRef.current,\n getMessageFallback,\n messagesOrError,\n defaultTranslationValues,\n namespace,\n onError,\n formats: globalFormats,\n locale,\n timeZone\n }),\n [\n getMessageFallback,\n messagesOrError,\n defaultTranslationValues,\n namespace,\n onError,\n globalFormats,\n locale,\n timeZone\n ]\n );\n\n return translate;\n}\n"],"names":["useTranslationsImpl","allMessages","namespace","namespacePrefix","useIntlContext","defaultTranslationValues","globalFormats","formats","getMessageFallback","locale","onError","timeZone","resolveNamespace","cachedFormatsByLocaleRef","useRef","messagesOrError","useMemo","getMessagesOrError","messages","translate","createBaseTranslator","cachedFormatsByLocale","current"],"mappings":";;;;;AAUwB,SAAAA,mBAAA,CAGtBC,WAHsB,EAGCC,SAHD,EAGuBC,eAHvB,EAG8C;AACpE,EAAA,IAAA,eAAA,GAOIC,cAAc,EAPlB;AAAA,MACEC,wBADF,mBACEA,wBADF;AAAA,MAEWC,aAFX,mBAEEC,OAFF;AAAA,MAGEC,kBAHF,mBAGEA,kBAHF;AAAA,MAIEC,MAJF,mBAIEA,MAJF;AAAA,MAKEC,OALF,mBAKEA,OALF;AAAA,MAMEC,QANF,GAAA,eAAA,CAMEA,QANF,CADoE;AAWpE;;;AACAV,EAAAA,WAAW,GAAGA,WAAW,CAACE,eAAD,CAAzB,CAAA;AACAD,EAAAA,SAAS,GAAGU,gBAAgB,CAACV,SAAD,EAAYC,eAAZ,CAA5B,CAAA;AAEA,EAAA,IAAMU,wBAAwB,GAAGC,MAAM,CAErC,EAFqC,CAAvC,CAAA;AAIA,EAAMC,IAAAA,eAAe,GAAGC,OAAO,CAC7B,YAAA;AAAA,IAAA,OAAMC,kBAAkB,CAAC;AAACC,MAAAA,QAAQ,EAAEjB,WAAX;AAAwBC,MAAAA,SAAS,EAATA,SAAxB;AAAmCQ,MAAAA,OAAO,EAAPA,OAAAA;AAAnC,KAAD,CAAxB,CAAA;AAAA,GAD6B,EAE7B,CAACT,WAAD,EAAcC,SAAd,EAAyBQ,OAAzB,CAF6B,CAA/B,CAAA;AAKA,EAAMS,IAAAA,SAAS,GAAGH,OAAO,CACvB,YAAA;AAAA,IAAA,OACEI,oBAAoB,CAAC;AACnBC,MAAAA,qBAAqB,EAAER,wBAAwB,CAACS,OAD7B;AAEnBd,MAAAA,kBAAkB,EAAlBA,kBAFmB;AAGnBO,MAAAA,eAAe,EAAfA,eAHmB;AAInBV,MAAAA,wBAAwB,EAAxBA,wBAJmB;AAKnBH,MAAAA,SAAS,EAATA,SALmB;AAMnBQ,MAAAA,OAAO,EAAPA,OANmB;AAOnBH,MAAAA,OAAO,EAAED,aAPU;AAQnBG,MAAAA,MAAM,EAANA,MARmB;AASnBE,MAAAA,QAAQ,EAARA,QAAAA;AATmB,KAAD,CADtB,CAAA;AAAA,GADuB,EAavB,CACEH,kBADF,EAEEO,eAFF,EAGEV,wBAHF,EAIEH,SAJF,EAKEQ,OALF,EAMEJ,aANF,EAOEG,MAPF,EAQEE,QARF,CAbuB,CAAzB,CAAA;AAyBA,EAAA,OAAOQ,SAAP,CAAA;AACD;;;;"}
@@ -0,0 +1,5 @@
1
+ export default function useIntl(): {
2
+ formatDateTime: (value: number | Date, formatOrOptions?: string | import("../core/DateTimeFormatOptions").default | undefined) => string;
3
+ formatNumber: (value: number, formatOrOptions?: string | import("@formatjs/ecma402-abstract").NumberFormatOptions | undefined) => string;
4
+ formatRelativeTime: (date: number | Date, now?: number | Date | undefined) => string;
5
+ };
File without changes
File without changes