use-intl 2.6.0 → 2.7.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.
@@ -3,6 +3,7 @@ export declare enum IntlErrorCode {
3
3
  MISSING_FORMAT = "MISSING_FORMAT",
4
4
  INSUFFICIENT_PATH = "INSUFFICIENT_PATH",
5
5
  INVALID_MESSAGE = "INVALID_MESSAGE",
6
+ INVALID_KEY = "INVALID_KEY",
6
7
  FORMATTING_ERROR = "FORMATTING_ERROR"
7
8
  }
8
9
  export default class IntlError extends Error {
@@ -43,5 +43,5 @@ declare type Props = {
43
43
  * Defaults will be overidden by locally provided values. */
44
44
  defaultTranslationValues?: RichTranslationValues;
45
45
  };
46
- export default function IntlProvider({ children, onError, getMessageFallback, ...contextValues }: Props): JSX.Element;
46
+ export default function IntlProvider({ children, onError, getMessageFallback, messages, ...contextValues }: Props): JSX.Element;
47
47
  export {};
@@ -135,36 +135,6 @@ function _objectWithoutPropertiesLoose(source, excluded) {
135
135
 
136
136
  var IntlContext = /*#__PURE__*/React.createContext(undefined);
137
137
 
138
- var _excluded = ["children", "onError", "getMessageFallback"];
139
-
140
- function defaultGetMessageFallback(_ref) {
141
- var key = _ref.key,
142
- namespace = _ref.namespace;
143
- return [namespace, key].filter(function (part) {
144
- return part != null;
145
- }).join('.');
146
- }
147
-
148
- function defaultOnError(error) {
149
- console.error(error);
150
- }
151
-
152
- function IntlProvider(_ref2) {
153
- var children = _ref2.children,
154
- _ref2$onError = _ref2.onError,
155
- onError = _ref2$onError === void 0 ? defaultOnError : _ref2$onError,
156
- _ref2$getMessageFallb = _ref2.getMessageFallback,
157
- getMessageFallback = _ref2$getMessageFallb === void 0 ? defaultGetMessageFallback : _ref2$getMessageFallb,
158
- contextValues = _objectWithoutPropertiesLoose(_ref2, _excluded);
159
-
160
- return React__default["default"].createElement(IntlContext.Provider, {
161
- value: _extends({}, contextValues, {
162
- onError: onError,
163
- getMessageFallback: getMessageFallback
164
- })
165
- }, children);
166
- }
167
-
168
138
  exports.IntlErrorCode = void 0;
169
139
 
170
140
  (function (IntlErrorCode) {
@@ -172,6 +142,7 @@ exports.IntlErrorCode = void 0;
172
142
  IntlErrorCode["MISSING_FORMAT"] = "MISSING_FORMAT";
173
143
  IntlErrorCode["INSUFFICIENT_PATH"] = "INSUFFICIENT_PATH";
174
144
  IntlErrorCode["INVALID_MESSAGE"] = "INVALID_MESSAGE";
145
+ IntlErrorCode["INVALID_KEY"] = "INVALID_KEY";
175
146
  IntlErrorCode["FORMATTING_ERROR"] = "FORMATTING_ERROR";
176
147
  })(exports.IntlErrorCode || (exports.IntlErrorCode = {}));
177
148
 
@@ -202,6 +173,75 @@ var IntlError = /*#__PURE__*/function (_Error) {
202
173
  return IntlError;
203
174
  }( /*#__PURE__*/_wrapNativeSuper(Error));
204
175
 
176
+ function validateMessagesSegment(messages, invalidKeyLabels, parentPath) {
177
+ Object.entries(messages).forEach(function (_ref) {
178
+ var key = _ref[0],
179
+ messageOrMessages = _ref[1];
180
+
181
+ if (key.includes('.')) {
182
+ var keyLabel = key;
183
+ if (parentPath) keyLabel += " (at " + parentPath + ")";
184
+ invalidKeyLabels.push(keyLabel);
185
+ }
186
+
187
+ if (typeof messageOrMessages === 'object') {
188
+ validateMessagesSegment(messageOrMessages, invalidKeyLabels, [parentPath, key].filter(function (part) {
189
+ return part != null;
190
+ }).join('.'));
191
+ }
192
+ });
193
+ }
194
+
195
+ function validateMessages(messages, onError) {
196
+ var invalidKeyLabels = [];
197
+ validateMessagesSegment(messages, invalidKeyLabels);
198
+
199
+ if (invalidKeyLabels.length > 0) {
200
+ onError(new IntlError(exports.IntlErrorCode.INVALID_KEY, "Namespace keys can not contain the character \".\" as this is used to express nesting. Please remove it or replace it with another character.\n\nInvalid " + (invalidKeyLabels.length === 1 ? 'key' : 'keys') + ": " + invalidKeyLabels.join(', ')));
201
+ }
202
+ }
203
+
204
+ var _excluded = ["children", "onError", "getMessageFallback", "messages"];
205
+
206
+ function defaultGetMessageFallback(_ref) {
207
+ var key = _ref.key,
208
+ namespace = _ref.namespace;
209
+ return [namespace, key].filter(function (part) {
210
+ return part != null;
211
+ }).join('.');
212
+ }
213
+
214
+ function defaultOnError(error) {
215
+ console.error(error);
216
+ }
217
+
218
+ function IntlProvider(_ref2) {
219
+ var children = _ref2.children,
220
+ _ref2$onError = _ref2.onError,
221
+ onError = _ref2$onError === void 0 ? defaultOnError : _ref2$onError,
222
+ _ref2$getMessageFallb = _ref2.getMessageFallback,
223
+ getMessageFallback = _ref2$getMessageFallb === void 0 ? defaultGetMessageFallback : _ref2$getMessageFallb,
224
+ messages = _ref2.messages,
225
+ contextValues = _objectWithoutPropertiesLoose(_ref2, _excluded);
226
+
227
+ {
228
+ // eslint-disable-next-line react-hooks/rules-of-hooks
229
+ React.useEffect(function () {
230
+ if (messages) {
231
+ validateMessages(messages, onError);
232
+ }
233
+ }, [messages, onError]);
234
+ }
235
+
236
+ return React__default["default"].createElement(IntlContext.Provider, {
237
+ value: _extends({}, contextValues, {
238
+ messages: messages,
239
+ onError: onError,
240
+ getMessageFallback: getMessageFallback
241
+ })
242
+ }, children);
243
+ }
244
+
205
245
  function useIntlContext() {
206
246
  var context = React.useContext(IntlContext);
207
247
 
@@ -1 +1 @@
1
- {"version":3,"file":"use-intl.cjs.development.js","sources":["../src/IntlContext.tsx","../src/IntlProvider.tsx","../src/IntlError.tsx","../src/useIntlContext.tsx","../src/convertFormatsToIntlMessageFormat.tsx","../src/useTranslationsImpl.tsx","../src/useTranslations.tsx","../src/useIntl.tsx","../src/useLocale.tsx","../src/useNow.tsx","../src/useTimeZone.tsx"],"sourcesContent":["import {createContext} from 'react';\nimport AbstractIntlMessages from './AbstractIntlMessages';\nimport Formats from './Formats';\nimport IntlError from './IntlError';\nimport {RichTranslationValues} from './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","import React, {ReactNode} from 'react';\nimport AbstractIntlMessages from './AbstractIntlMessages';\nimport Formats from './Formats';\nimport IntlContext from './IntlContext';\nimport {RichTranslationValues} from './TranslationValues';\nimport {IntlError} from '.';\n\ntype Props = {\n /** All messages that will be available in your components. */\n messages?: AbstractIntlMessages;\n /** A valid Unicode locale tag (e.g. \"en\" or \"en-GB\"). */\n locale: string;\n /** Global formats can be provided to achieve consistent\n * formatting across components. */\n formats?: Partial<Formats>;\n /** 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`. */\n timeZone?: string;\n /** This callback will be invoked when an error is encountered during\n * resolving a message or formatting it. This defaults to `console.error` to\n * keep your app running. You can customize the handling by taking\n * `error.code` into account. */\n onError?(error: IntlError): void;\n /** Will be called when a message couldn't be resolved or formatting it led to\n * an error. This defaults to `${namespace}.${key}` You can use this to\n * customize what will be rendered in this case. */\n getMessageFallback?(info: {\n namespace?: string;\n key: string;\n error: IntlError;\n }): string;\n /** All components that use the provided hooks should be within this tree. */\n children: ReactNode;\n /**\n * Providing this value will have two effects:\n * 1. It will be used as the default for the `now` argument of\n * `useIntl().formatRelativeTime` if no explicit value is provided.\n * 2. It will be returned as a static value from the `useNow` hook. Note\n * however that when `updateInterval` is configured on the `useNow` hook,\n * the global `now` value will only be used for the initial render, but\n * afterwards the current date will be returned continuously.\n */\n now?: Date;\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};\n\nfunction defaultGetMessageFallback({\n key,\n namespace\n}: {\n key: string;\n namespace?: string;\n}) {\n return [namespace, key].filter((part) => part != null).join('.');\n}\n\nfunction defaultOnError(error: IntlError) {\n console.error(error);\n}\n\nexport default function IntlProvider({\n children,\n onError = defaultOnError,\n getMessageFallback = defaultGetMessageFallback,\n ...contextValues\n}: Props) {\n return (\n <IntlContext.Provider\n value={{...contextValues, onError, getMessageFallback}}\n >\n {children}\n </IntlContext.Provider>\n );\n}\n","export enum IntlErrorCode {\n MISSING_MESSAGE = 'MISSING_MESSAGE',\n MISSING_FORMAT = 'MISSING_FORMAT',\n INSUFFICIENT_PATH = 'INSUFFICIENT_PATH',\n INVALID_MESSAGE = 'INVALID_MESSAGE',\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","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","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","import {IntlMessageFormat} from 'intl-messageformat';\nimport {\n cloneElement,\n isValidElement,\n ReactElement,\n ReactNode,\n ReactNodeArray,\n useMemo,\n useRef\n} from 'react';\nimport AbstractIntlMessages from './AbstractIntlMessages';\nimport Formats from './Formats';\nimport IntlError, {IntlErrorCode} from './IntlError';\nimport TranslationValues, {RichTranslationValues} from './TranslationValues';\nimport convertFormatsToIntlMessageFormat from './convertFormatsToIntlMessageFormat';\nimport useIntlContext from './useIntlContext';\nimport MessageKeys from './utils/MessageKeys';\nimport NestedKeyOf from './utils/NestedKeyOf';\nimport NestedValueOf from './utils/NestedValueOf';\n\nfunction resolvePath(\n messages: AbstractIntlMessages | undefined,\n idPath: 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 idPath.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 \\`${idPath}\\` 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 = (children: ReactNode) => {\n const result = value(children);\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 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 = (\n namespace === namespacePrefix\n ? undefined\n : namespace.slice((namespacePrefix + '.').length)\n ) as NestedKey;\n\n const cachedFormatsByLocaleRef = useRef<\n Record<string, Record<string, IntlMessageFormat>>\n >({});\n\n const messagesOrError = useMemo(() => {\n try {\n if (!allMessages) {\n throw new Error(\n __DEV__ ? `No messages were configured on the provider.` : undefined\n );\n }\n\n const retrievedMessages = namespace\n ? resolvePath(allMessages, namespace)\n : allMessages;\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 }, [allMessages, namespace, onError]);\n\n const translate = useMemo(() => {\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 const cachedFormatsByLocale = cachedFormatsByLocaleRef.current;\n\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]\n .filter((part) => part != null)\n .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[locale]) {\n cachedFormatsByLocale[locale] = {};\n }\n cachedFormatsByLocale[locale][cacheKey] = messageFormat;\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 message = translateBaseFn(key, values, formats);\n\n if (typeof message !== '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 message;\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 onError,\n getMessageFallback,\n namespace,\n messagesOrError,\n locale,\n globalFormats,\n timeZone,\n defaultTranslationValues\n ]);\n\n return translate;\n}\n","import {ReactElement, ReactNodeArray} from 'react';\nimport Formats from './Formats';\nimport IntlError, {IntlErrorCode} from './IntlError';\nimport TranslationValues, {RichTranslationValues} from './TranslationValues';\nimport useIntlContext from './useIntlContext';\nimport useTranslationsImpl from './useTranslationsImpl';\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 useTranslations<\n NestedKey extends NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>>\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 NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>> extends NestedKey\n ? '!'\n : `!.${NestedKey}`\n >,\n NestedKeyOf<\n NestedValueOf<\n {'!': IntlMessages},\n NamespaceKeys<\n IntlMessages,\n NestedKeyOf<IntlMessages>\n > extends NestedKey\n ? '!'\n : `!.${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 NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>> extends NestedKey\n ? '!'\n : `!.${NestedKey}`\n >,\n NestedKeyOf<\n NestedValueOf<\n {'!': IntlMessages},\n NamespaceKeys<\n IntlMessages,\n NestedKeyOf<IntlMessages>\n > extends NestedKey\n ? '!'\n : `!.${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 NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>> extends NestedKey\n ? '!'\n : `!.${NestedKey}`\n >,\n NestedKeyOf<\n NestedValueOf<\n {'!': IntlMessages},\n NamespaceKeys<\n IntlMessages,\n NestedKeyOf<IntlMessages>\n > extends NestedKey\n ? '!'\n : `!.${NestedKey}`\n >\n >\n >\n >(\n key: TargetKey\n ): any;\n} {\n const context = useIntlContext();\n\n const messages = context.messages as IntlMessages;\n if (!messages) {\n const intlError = new IntlError(\n IntlErrorCode.MISSING_MESSAGE,\n __DEV__ ? `No messages were configured on the provider.` : undefined\n );\n context.onError(intlError);\n throw intlError;\n }\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, but we have to use some.\n return useTranslationsImpl<\n {'!': IntlMessages},\n NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>> extends NestedKey\n ? '!'\n : `!.${NestedKey}`\n >(\n {'!': messages},\n // @ts-ignore\n namespace ? `!.${namespace}` : '!',\n '!'\n );\n}\n","import DateTimeFormatOptions from './DateTimeFormatOptions';\nimport IntlError, {IntlErrorCode} from './IntlError';\nimport NumberFormatOptions from './NumberFormatOptions';\nimport useIntlContext from './useIntlContext';\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\nexport default function useIntl() {\n const {formats, locale, now: globalNow, onError, timeZone} = useIntlContext();\n\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 __DEV__\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 formatDateTime(\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 formatNumber(\n value: number,\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 formatRelativeTime(\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 __DEV__\n ? `The \\`now\\` parameter wasn't provided to \\`formatRelativeTime\\` 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 return {formatDateTime, formatNumber, formatRelativeTime};\n}\n","import useIntlContext from './useIntlContext';\n\nexport default function useLocale() {\n return useIntlContext().locale;\n}\n","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","import useIntlContext from './useIntlContext';\n\nexport default function useTimeZone() {\n return useIntlContext().timeZone;\n}\n"],"names":["IntlContext","createContext","undefined","defaultGetMessageFallback","key","namespace","filter","part","join","defaultOnError","error","console","IntlProvider","children","onError","getMessageFallback","contextValues","React","Provider","value","IntlErrorCode","IntlError","code","originalMessage","message","Error","useIntlContext","context","useContext","setTimeZoneInFormats","formats","timeZone","Object","keys","reduce","acc","convertFormatsToIntlMessageFormat","formatsWithTimeZone","dateTime","date","time","resolvePath","messages","idPath","split","forEach","next","prepareTranslationValues","values","length","transformedValues","index","transformed","result","isValidElement","cloneElement","useTranslationsImpl","allMessages","namespacePrefix","defaultTranslationValues","globalFormats","locale","slice","cachedFormatsByLocaleRef","useRef","messagesOrError","useMemo","retrievedMessages","intlError","MISSING_MESSAGE","translate","getFallbackFromErrorAndNotify","translateBaseFn","cachedFormatsByLocale","current","cacheKey","messageFormat","INSUFFICIENT_PATH","IntlMessageFormat","INVALID_MESSAGE","formattedMessage","format","Array","isArray","String","FORMATTING_ERROR","translateFn","rich","raw","useTranslations","MINUTE","HOUR","DAY","WEEK","MONTH","YEAR","getRelativeTimeFormatConfig","seconds","absValue","Math","abs","unit","round","useIntl","globalNow","now","resolveFormatOrOptions","typeFormats","formatOrOptions","options","formatName","MISSING_FORMAT","getFormattedValue","formatter","formatDateTime","Intl","DateTimeFormat","formatNumber","number","NumberFormat","formatRelativeTime","dateDate","Date","nowDate","getTime","RelativeTimeFormat","numeric","useLocale","getNow","useNow","updateInterval","useState","setNow","useEffect","intervalId","setInterval","clearInterval","useTimeZone"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqBA,IAAMA,WAAW,gBAAGC,mBAAa,CAA+BC,SAA/B,CAAjC;;;;AC2BA,SAASC,yBAAT,CAMC,IAAA,EAAA;AAAA,EALCC,IAAAA,GAKD,QALCA,GAKD;AAAA,MAJC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,CAAN,CAAA;AACD,KAF6B,EAE3BE,cAF2B,CAA9B,CAAA;AAIA,IAAA,OAAO,YAAK;AACVM,MAAAA,aAAa,CAACF,UAAD,CAAb,CAAA;AACD,KAFD,CAAA;AAGD,GAVQ,EAUN,CAAC9B,SAAD,EAAY0B,cAAZ,CAVM,CAAT,CAAA;AAYA,EAAA,OAAOzB,GAAP,CAAA;AACD;;AC9Ca,SAAUgC,WAAV,GAAqB;AACjC,EAAO/G,OAAAA,cAAc,GAAGK,QAAxB,CAAA;AACD;;;;;;;;;;"}
1
+ {"version":3,"file":"use-intl.cjs.development.js","sources":["../src/IntlContext.tsx","../src/IntlError.tsx","../src/validateMessages.tsx","../src/IntlProvider.tsx","../src/useIntlContext.tsx","../src/convertFormatsToIntlMessageFormat.tsx","../src/useTranslationsImpl.tsx","../src/useTranslations.tsx","../src/useIntl.tsx","../src/useLocale.tsx","../src/useNow.tsx","../src/useTimeZone.tsx"],"sourcesContent":["import {createContext} from 'react';\nimport AbstractIntlMessages from './AbstractIntlMessages';\nimport Formats from './Formats';\nimport IntlError from './IntlError';\nimport {RichTranslationValues} from './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","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","import AbstractIntlMessages from './AbstractIntlMessages';\nimport IntlError, {IntlErrorCode} from './IntlError';\n\nfunction validateMessagesSegment(\n messages: AbstractIntlMessages,\n invalidKeyLabels: Array<string>,\n parentPath?: string\n) {\n Object.entries(messages).forEach(([key, messageOrMessages]) => {\n if (key.includes('.')) {\n let keyLabel = key;\n if (parentPath) keyLabel += ` (at ${parentPath})`;\n invalidKeyLabels.push(keyLabel);\n }\n if (typeof messageOrMessages === 'object') {\n validateMessagesSegment(\n messageOrMessages,\n invalidKeyLabels,\n [parentPath, key].filter((part) => part != null).join('.')\n );\n }\n });\n}\n\nexport default function validateMessages(\n messages: AbstractIntlMessages,\n onError: (error: IntlError) => void\n) {\n const invalidKeyLabels: Array<string> = [];\n validateMessagesSegment(messages, invalidKeyLabels);\n\n if (invalidKeyLabels.length > 0) {\n onError(\n new IntlError(\n IntlErrorCode.INVALID_KEY,\n `Namespace keys can not contain the character \".\" as this is used to express nesting. Please remove it or replace it with another character.\\n\\nInvalid ${\n invalidKeyLabels.length === 1 ? 'key' : 'keys'\n }: ${invalidKeyLabels.join(', ')}`\n )\n );\n }\n}\n","import React, {ReactNode, useEffect} from 'react';\nimport AbstractIntlMessages from './AbstractIntlMessages';\nimport Formats from './Formats';\nimport IntlContext from './IntlContext';\nimport {RichTranslationValues} from './TranslationValues';\nimport validateMessages from './validateMessages';\nimport {IntlError} from '.';\n\ntype Props = {\n /** All messages that will be available in your components. */\n messages?: AbstractIntlMessages;\n /** A valid Unicode locale tag (e.g. \"en\" or \"en-GB\"). */\n locale: string;\n /** Global formats can be provided to achieve consistent\n * formatting across components. */\n formats?: Partial<Formats>;\n /** 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`. */\n timeZone?: string;\n /** This callback will be invoked when an error is encountered during\n * resolving a message or formatting it. This defaults to `console.error` to\n * keep your app running. You can customize the handling by taking\n * `error.code` into account. */\n onError?(error: IntlError): void;\n /** Will be called when a message couldn't be resolved or formatting it led to\n * an error. This defaults to `${namespace}.${key}` You can use this to\n * customize what will be rendered in this case. */\n getMessageFallback?(info: {\n namespace?: string;\n key: string;\n error: IntlError;\n }): string;\n /** All components that use the provided hooks should be within this tree. */\n children: ReactNode;\n /**\n * Providing this value will have two effects:\n * 1. It will be used as the default for the `now` argument of\n * `useIntl().formatRelativeTime` if no explicit value is provided.\n * 2. It will be returned as a static value from the `useNow` hook. Note\n * however that when `updateInterval` is configured on the `useNow` hook,\n * the global `now` value will only be used for the initial render, but\n * afterwards the current date will be returned continuously.\n */\n now?: Date;\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};\n\nfunction defaultGetMessageFallback({\n key,\n namespace\n}: {\n key: string;\n namespace?: string;\n}) {\n return [namespace, key].filter((part) => part != null).join('.');\n}\n\nfunction defaultOnError(error: IntlError) {\n console.error(error);\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","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","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","import {IntlMessageFormat} from 'intl-messageformat';\nimport {\n cloneElement,\n isValidElement,\n ReactElement,\n ReactNode,\n ReactNodeArray,\n useMemo,\n useRef\n} from 'react';\nimport AbstractIntlMessages from './AbstractIntlMessages';\nimport Formats from './Formats';\nimport IntlError, {IntlErrorCode} from './IntlError';\nimport TranslationValues, {RichTranslationValues} from './TranslationValues';\nimport convertFormatsToIntlMessageFormat from './convertFormatsToIntlMessageFormat';\nimport useIntlContext from './useIntlContext';\nimport MessageKeys from './utils/MessageKeys';\nimport NestedKeyOf from './utils/NestedKeyOf';\nimport NestedValueOf from './utils/NestedValueOf';\n\nfunction resolvePath(\n messages: AbstractIntlMessages | undefined,\n idPath: 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 idPath.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 \\`${idPath}\\` 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 = (children: ReactNode) => {\n const result = value(children);\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 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 = (\n namespace === namespacePrefix\n ? undefined\n : namespace.slice((namespacePrefix + '.').length)\n ) as NestedKey;\n\n const cachedFormatsByLocaleRef = useRef<\n Record<string, Record<string, IntlMessageFormat>>\n >({});\n\n const messagesOrError = useMemo(() => {\n try {\n if (!allMessages) {\n throw new Error(\n __DEV__ ? `No messages were configured on the provider.` : undefined\n );\n }\n\n const retrievedMessages = namespace\n ? resolvePath(allMessages, namespace)\n : allMessages;\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 }, [allMessages, namespace, onError]);\n\n const translate = useMemo(() => {\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 const cachedFormatsByLocale = cachedFormatsByLocaleRef.current;\n\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]\n .filter((part) => part != null)\n .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[locale]) {\n cachedFormatsByLocale[locale] = {};\n }\n cachedFormatsByLocale[locale][cacheKey] = messageFormat;\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 message = translateBaseFn(key, values, formats);\n\n if (typeof message !== '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 message;\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 onError,\n getMessageFallback,\n namespace,\n messagesOrError,\n locale,\n globalFormats,\n timeZone,\n defaultTranslationValues\n ]);\n\n return translate;\n}\n","import {ReactElement, ReactNodeArray} from 'react';\nimport Formats from './Formats';\nimport IntlError, {IntlErrorCode} from './IntlError';\nimport TranslationValues, {RichTranslationValues} from './TranslationValues';\nimport useIntlContext from './useIntlContext';\nimport useTranslationsImpl from './useTranslationsImpl';\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 useTranslations<\n NestedKey extends NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>>\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 NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>> extends NestedKey\n ? '!'\n : `!.${NestedKey}`\n >,\n NestedKeyOf<\n NestedValueOf<\n {'!': IntlMessages},\n NamespaceKeys<\n IntlMessages,\n NestedKeyOf<IntlMessages>\n > extends NestedKey\n ? '!'\n : `!.${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 NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>> extends NestedKey\n ? '!'\n : `!.${NestedKey}`\n >,\n NestedKeyOf<\n NestedValueOf<\n {'!': IntlMessages},\n NamespaceKeys<\n IntlMessages,\n NestedKeyOf<IntlMessages>\n > extends NestedKey\n ? '!'\n : `!.${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 NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>> extends NestedKey\n ? '!'\n : `!.${NestedKey}`\n >,\n NestedKeyOf<\n NestedValueOf<\n {'!': IntlMessages},\n NamespaceKeys<\n IntlMessages,\n NestedKeyOf<IntlMessages>\n > extends NestedKey\n ? '!'\n : `!.${NestedKey}`\n >\n >\n >\n >(\n key: TargetKey\n ): any;\n} {\n const context = useIntlContext();\n\n const messages = context.messages as IntlMessages;\n if (!messages) {\n const intlError = new IntlError(\n IntlErrorCode.MISSING_MESSAGE,\n __DEV__ ? `No messages were configured on the provider.` : undefined\n );\n context.onError(intlError);\n throw intlError;\n }\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, but we have to use some.\n return useTranslationsImpl<\n {'!': IntlMessages},\n NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>> extends NestedKey\n ? '!'\n : `!.${NestedKey}`\n >(\n {'!': messages},\n // @ts-ignore\n namespace ? `!.${namespace}` : '!',\n '!'\n );\n}\n","import DateTimeFormatOptions from './DateTimeFormatOptions';\nimport IntlError, {IntlErrorCode} from './IntlError';\nimport NumberFormatOptions from './NumberFormatOptions';\nimport useIntlContext from './useIntlContext';\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\nexport default function useIntl() {\n const {formats, locale, now: globalNow, onError, timeZone} = useIntlContext();\n\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 __DEV__\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 formatDateTime(\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 formatNumber(\n value: number,\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 formatRelativeTime(\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 __DEV__\n ? `The \\`now\\` parameter wasn't provided to \\`formatRelativeTime\\` 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 return {formatDateTime, formatNumber, formatRelativeTime};\n}\n","import useIntlContext from './useIntlContext';\n\nexport default function useLocale() {\n return useIntlContext().locale;\n}\n","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","import useIntlContext from './useIntlContext';\n\nexport default function useTimeZone() {\n return useIntlContext().timeZone;\n}\n"],"names":["IntlContext","createContext","undefined","IntlErrorCode","IntlError","code","originalMessage","message","Error","validateMessagesSegment","messages","invalidKeyLabels","parentPath","Object","entries","forEach","key","messageOrMessages","includes","keyLabel","push","filter","part","join","validateMessages","onError","length","INVALID_KEY","defaultGetMessageFallback","namespace","defaultOnError","error","console","IntlProvider","children","getMessageFallback","contextValues","useEffect","React","Provider","value","useIntlContext","context","useContext","setTimeZoneInFormats","formats","timeZone","keys","reduce","acc","convertFormatsToIntlMessageFormat","formatsWithTimeZone","dateTime","date","time","resolvePath","idPath","split","next","prepareTranslationValues","values","transformedValues","index","transformed","result","isValidElement","cloneElement","useTranslationsImpl","allMessages","namespacePrefix","defaultTranslationValues","globalFormats","locale","slice","cachedFormatsByLocaleRef","useRef","messagesOrError","useMemo","retrievedMessages","intlError","MISSING_MESSAGE","translate","getFallbackFromErrorAndNotify","translateBaseFn","cachedFormatsByLocale","current","cacheKey","messageFormat","INSUFFICIENT_PATH","IntlMessageFormat","INVALID_MESSAGE","formattedMessage","format","Array","isArray","String","FORMATTING_ERROR","translateFn","rich","raw","useTranslations","MINUTE","HOUR","DAY","WEEK","MONTH","YEAR","getRelativeTimeFormatConfig","seconds","absValue","Math","abs","unit","round","useIntl","globalNow","now","resolveFormatOrOptions","typeFormats","formatOrOptions","options","formatName","MISSING_FORMAT","getFormattedValue","formatter","formatDateTime","Intl","DateTimeFormat","formatNumber","number","NumberFormat","formatRelativeTime","dateDate","Date","nowDate","getTime","RelativeTimeFormat","numeric","useLocale","getNow","useNow","updateInterval","useState","setNow","intervalId","setInterval","clearInterval","useTimeZone"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqBA,IAAMA,WAAW,gBAAGC,mBAAa,CAA+BC,SAA/B,CAAjC;;ACrBYC,+BAAZ;;AAAA,CAAA,UAAYA,aAAZ,EAAyB;AACvBA,EAAAA,aAAA,CAAA,iBAAA,CAAA,GAAA,iBAAA,CAAA;AACAA,EAAAA,aAAA,CAAA,gBAAA,CAAA,GAAA,gBAAA,CAAA;AACAA,EAAAA,aAAA,CAAA,mBAAA,CAAA,GAAA,mBAAA,CAAA;AACAA,EAAAA,aAAA,CAAA,iBAAA,CAAA,GAAA,iBAAA,CAAA;AACAA,EAAAA,aAAA,CAAA,aAAA,CAAA,GAAA,aAAA,CAAA;AACAA,EAAAA,aAAA,CAAA,kBAAA,CAAA,GAAA,kBAAA,CAAA;AACD,CAPD,EAAYA,qBAAa,KAAbA,qBAAa,GAOxB,EAPwB,CAAzB,CAAA,CAAA;;IASqBC;;;AAInB,EAAYC,SAAAA,SAAAA,CAAAA,IAAZ,EAAiCC,eAAjC,EAAyD;AAAA,IAAA,IAAA,KAAA,CAAA;;AACvD,IAAIC,IAAAA,OAAO,GAAWF,IAAtB,CAAA;;AACA,IAAA,IAAIC,eAAJ,EAAqB;AACnBC,MAAAA,OAAO,IAAI,IAAA,GAAOD,eAAlB,CAAA;AACD,KAAA;;AACD,IAAA,KAAA,GAAA,MAAA,CAAA,IAAA,CAAA,IAAA,EAAMC,OAAN,CAAA,IAAA,IAA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D,EAAY0B,cAAZ,CAVM,CAAT,CAAA;AAYA,EAAA,OAAOzB,GAAP,CAAA;AACD;;AC9Ca,SAAU+B,WAAV,GAAqB;AACjC,EAAO1G,OAAAA,cAAc,GAAGK,QAAxB,CAAA;AACD;;;;;;;;;;"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var r=require("react"),e=require("intl-messageformat");function t(r){return r&&"object"==typeof r&&"default"in r?r:{default:r}}var n=t(r);function o(){return o=Object.assign||function(r){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(r[n]=t[n])}return r},o.apply(this,arguments)}function u(r){return u=Object.setPrototypeOf?Object.getPrototypeOf:function(r){return r.__proto__||Object.getPrototypeOf(r)},u(r)}function i(r,e){return i=Object.setPrototypeOf||function(r,e){return r.__proto__=e,r},i(r,e)}function a(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(r){return!1}}function c(r,e,t){return c=a()?Reflect.construct:function(r,e,t){var n=[null];n.push.apply(n,e);var o=new(Function.bind.apply(r,n));return t&&i(o,t.prototype),o},c.apply(null,arguments)}function f(r){var e="function"==typeof Map?new Map:void 0;return f=function(r){if(null===r||-1===Function.toString.call(r).indexOf("[native code]"))return r;if("function"!=typeof r)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(r))return e.get(r);e.set(r,t)}function t(){return c(r,arguments,u(this).constructor)}return t.prototype=Object.create(r.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),i(t,r)},f(r)}var l,s=r.createContext(void 0),v=["children","onError","getMessageFallback"];function d(r){return[r.namespace,r.key].filter((function(r){return null!=r})).join(".")}function p(r){console.error(r)}exports.IntlErrorCode=void 0,(l=exports.IntlErrorCode||(exports.IntlErrorCode={})).MISSING_MESSAGE="MISSING_MESSAGE",l.MISSING_FORMAT="MISSING_FORMAT",l.INSUFFICIENT_PATH="INSUFFICIENT_PATH",l.INVALID_MESSAGE="INVALID_MESSAGE",l.FORMATTING_ERROR="FORMATTING_ERROR";var E=function(r){var e,t;function n(e,t){var n,o=e;return t&&(o+=": "+t),(n=r.call(this,o)||this).code=void 0,n.originalMessage=void 0,n.code=e,t&&(n.originalMessage=t),n}return t=r,(e=n).prototype=Object.create(t.prototype),e.prototype.constructor=e,i(e,t),n}(f(Error));function I(){var e=r.useContext(s);if(!e)throw new Error(void 0);return e}function m(r,e){return r?Object.keys(r).reduce((function(t,n){return t[n]=o({timeZone:e},r[n]),t}),{}):r}function y(r,e,t){if(!r)throw new Error(void 0);var n=r;return e.split(".").forEach((function(r){var e=n[r];if(null==r||null==e)throw new Error(void 0);n=e})),n}function S(){return new Date}exports.IntlError=E,exports.IntlProvider=function(r){var e=r.children,t=r.onError,u=void 0===t?p:t,i=r.getMessageFallback,a=void 0===i?d:i,c=function(r,e){if(null==r)return{};var t,n,o={},u=Object.keys(r);for(n=0;n<u.length;n++)e.indexOf(t=u[n])>=0||(o[t]=r[t]);return o}(r,v);return n.default.createElement(s.Provider,{value:o({},c,{onError:u,getMessageFallback:a})},e)},exports.useIntl=function(){var r=I(),e=r.formats,t=r.locale,n=r.now,u=r.onError,i=r.timeZone;function a(r,e,t,n){var o;try{o=function(r,e){var t;if("string"==typeof e){if(!(t=null==r?void 0:r[e])){var n=new E(exports.IntlErrorCode.MISSING_FORMAT,void 0);throw u(n),n}}else t=e;return t}(t,e)}catch(e){return String(r)}try{return n(o)}catch(e){return u(new E(exports.IntlErrorCode.FORMATTING_ERROR,e.message)),String(r)}}return{formatDateTime:function(r,n){return a(r,n,null==e?void 0:e.dateTime,(function(e){var n;return!i||null!=(n=e)&&n.timeZone||(e=o({},e,{timeZone:i})),new Intl.DateTimeFormat(t,e).format(r)}))},formatNumber:function(r,n){return a(r,n,null==e?void 0:e.number,(function(e){return new Intl.NumberFormat(t,e).format(r)}))},formatRelativeTime:function(r,e){try{if(!e){if(!n)throw new Error(void 0);e=n}var o=r instanceof Date?r:new Date(r),i=e instanceof Date?e:new Date(e),a=function(r){var e,t,n=Math.abs(r);return n<60?(t="second",e=Math.round(r)):n<3600?(t="minute",e=Math.round(r/60)):n<86400?(t="hour",e=Math.round(r/3600)):n<604800?(t="day",e=Math.round(r/86400)):n<2628e3?(t="week",e=Math.round(r/604800)):n<31536e3?(t="month",e=Math.round(r/2628e3)):(t="year",e=Math.round(r/31536e3)),{value:e,unit:t}}((o.getTime()-i.getTime())/1e3),c=a.unit,f=a.value;return new Intl.RelativeTimeFormat(t,{numeric:"auto"}).format(f,c)}catch(e){return u(new E(exports.IntlErrorCode.FORMATTING_ERROR,e.message)),String(r)}}}},exports.useLocale=function(){return I().locale},exports.useNow=function(e){var t=null==e?void 0:e.updateInterval,n=I().now,o=r.useState(n||S()),u=o[0],i=o[1];return r.useEffect((function(){if(t){var r=setInterval((function(){i(S())}),t);return function(){clearInterval(r)}}}),[n,t]),u},exports.useTimeZone=function(){return I().timeZone},exports.useTranslations=function(t){var n=I(),u=n.messages;if(!u){var i=new E(exports.IntlErrorCode.MISSING_MESSAGE,void 0);throw n.onError(i),i}return function(t,n,u){var i=I(),a=i.defaultTranslationValues,c=i.formats,f=i.getMessageFallback,l=i.locale,s=i.onError,v=i.timeZone;t=t["!"],n="!"===n?void 0:n.slice("!.".length);var d=r.useRef({}),p=r.useMemo((function(){try{if(!t)throw new Error(void 0);var r=n?y(t,n):t;if(!r)throw new Error(void 0);return r}catch(r){var e=new E(exports.IntlErrorCode.MISSING_MESSAGE,r.message);return s(e),e}}),[t,n,s]);return r.useMemo((function(){function t(r,e,t){var o=new E(e,t);return s(o),f({error:o,key:r,namespace:n})}function u(u,i,s){var I,S=d.current;if(p instanceof E)return f({error:p,key:u,namespace:n});var h,M=p,g=[n,u].filter((function(r){return null!=r})).join(".");if(null!=(I=S[l])&&I[g])h=S[l][g];else{var w;try{w=y(M,u)}catch(r){return t(u,exports.IntlErrorCode.MISSING_MESSAGE,r.message)}if("object"==typeof w)return t(u,exports.IntlErrorCode.INSUFFICIENT_PATH,void 0);try{h=new e.IntlMessageFormat(w,l,function(r,e){var t=e?o({},r,{dateTime:m(r.dateTime,e)}):r;return o({},t,{date:null==t?void 0:t.dateTime,time:null==t?void 0:t.dateTime})}(o({},c,s),v))}catch(r){return t(u,exports.IntlErrorCode.INVALID_MESSAGE,r.message)}S[l]||(S[l]={}),S[l][g]=h}try{var O=h.format(function(e){if(0!==Object.keys(e).length){var t={};return Object.keys(e).forEach((function(n){var o=0,u=e[n];t[n]="function"==typeof u?function(e){var t=u(e);return r.isValidElement(t)?r.cloneElement(t,{key:n+o++}):t}:u})),t}}(o({},a,i)));if(null==O)throw new Error(void 0);return r.isValidElement(O)||Array.isArray(O)||"string"==typeof O?O:String(O)}catch(r){return t(u,exports.IntlErrorCode.FORMATTING_ERROR,r.message)}}function i(r,e,n){var o=u(r,e,n);return"string"!=typeof o?t(r,exports.IntlErrorCode.INVALID_MESSAGE,void 0):o}return i.rich=u,i.raw=function(r){if(p instanceof E)return f({error:p,key:r,namespace:n});var e=p;try{return y(e,r)}catch(e){return t(r,exports.IntlErrorCode.MISSING_MESSAGE,e.message)}},i}),[s,f,n,p,l,c,v,a])}({"!":u},t?"!."+t:"!")};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var r=require("react"),e=require("intl-messageformat");function t(r){return r&&"object"==typeof r&&"default"in r?r:{default:r}}var n=t(r);function o(){return o=Object.assign||function(r){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(r[n]=t[n])}return r},o.apply(this,arguments)}function u(r){return u=Object.setPrototypeOf?Object.getPrototypeOf:function(r){return r.__proto__||Object.getPrototypeOf(r)},u(r)}function i(r,e){return i=Object.setPrototypeOf||function(r,e){return r.__proto__=e,r},i(r,e)}function a(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(r){return!1}}function c(r,e,t){return c=a()?Reflect.construct:function(r,e,t){var n=[null];n.push.apply(n,e);var o=new(Function.bind.apply(r,n));return t&&i(o,t.prototype),o},c.apply(null,arguments)}function f(r){var e="function"==typeof Map?new Map:void 0;return f=function(r){if(null===r||-1===Function.toString.call(r).indexOf("[native code]"))return r;if("function"!=typeof r)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(r))return e.get(r);e.set(r,t)}function t(){return c(r,arguments,u(this).constructor)}return t.prototype=Object.create(r.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),i(t,r)},f(r)}var l,s=r.createContext(void 0);exports.IntlErrorCode=void 0,(l=exports.IntlErrorCode||(exports.IntlErrorCode={})).MISSING_MESSAGE="MISSING_MESSAGE",l.MISSING_FORMAT="MISSING_FORMAT",l.INSUFFICIENT_PATH="INSUFFICIENT_PATH",l.INVALID_MESSAGE="INVALID_MESSAGE",l.INVALID_KEY="INVALID_KEY",l.FORMATTING_ERROR="FORMATTING_ERROR";var v=function(r){var e,t;function n(e,t){var n,o=e;return t&&(o+=": "+t),(n=r.call(this,o)||this).code=void 0,n.originalMessage=void 0,n.code=e,t&&(n.originalMessage=t),n}return t=r,(e=n).prototype=Object.create(t.prototype),e.prototype.constructor=e,i(e,t),n}(f(Error)),d=["children","onError","getMessageFallback","messages"];function p(r){return[r.namespace,r.key].filter((function(r){return null!=r})).join(".")}function I(r){console.error(r)}function E(){var e=r.useContext(s);if(!e)throw new Error(void 0);return e}function m(r,e){return r?Object.keys(r).reduce((function(t,n){return t[n]=o({timeZone:e},r[n]),t}),{}):r}function y(r,e,t){if(!r)throw new Error(void 0);var n=r;return e.split(".").forEach((function(r){var e=n[r];if(null==r||null==e)throw new Error(void 0);n=e})),n}function S(){return new Date}exports.IntlError=v,exports.IntlProvider=function(r){var e=r.children,t=r.onError,u=void 0===t?I:t,i=r.getMessageFallback,a=void 0===i?p:i,c=r.messages,f=function(r,e){if(null==r)return{};var t,n,o={},u=Object.keys(r);for(n=0;n<u.length;n++)e.indexOf(t=u[n])>=0||(o[t]=r[t]);return o}(r,d);return n.default.createElement(s.Provider,{value:o({},f,{messages:c,onError:u,getMessageFallback:a})},e)},exports.useIntl=function(){var r=E(),e=r.formats,t=r.locale,n=r.now,u=r.onError,i=r.timeZone;function a(r,e,t,n){var o;try{o=function(r,e){var t;if("string"==typeof e){if(!(t=null==r?void 0:r[e])){var n=new v(exports.IntlErrorCode.MISSING_FORMAT,void 0);throw u(n),n}}else t=e;return t}(t,e)}catch(e){return String(r)}try{return n(o)}catch(e){return u(new v(exports.IntlErrorCode.FORMATTING_ERROR,e.message)),String(r)}}return{formatDateTime:function(r,n){return a(r,n,null==e?void 0:e.dateTime,(function(e){var n;return!i||null!=(n=e)&&n.timeZone||(e=o({},e,{timeZone:i})),new Intl.DateTimeFormat(t,e).format(r)}))},formatNumber:function(r,n){return a(r,n,null==e?void 0:e.number,(function(e){return new Intl.NumberFormat(t,e).format(r)}))},formatRelativeTime:function(r,e){try{if(!e){if(!n)throw new Error(void 0);e=n}var o=r instanceof Date?r:new Date(r),i=e instanceof Date?e:new Date(e),a=function(r){var e,t,n=Math.abs(r);return n<60?(t="second",e=Math.round(r)):n<3600?(t="minute",e=Math.round(r/60)):n<86400?(t="hour",e=Math.round(r/3600)):n<604800?(t="day",e=Math.round(r/86400)):n<2628e3?(t="week",e=Math.round(r/604800)):n<31536e3?(t="month",e=Math.round(r/2628e3)):(t="year",e=Math.round(r/31536e3)),{value:e,unit:t}}((o.getTime()-i.getTime())/1e3),c=a.unit,f=a.value;return new Intl.RelativeTimeFormat(t,{numeric:"auto"}).format(f,c)}catch(e){return u(new v(exports.IntlErrorCode.FORMATTING_ERROR,e.message)),String(r)}}}},exports.useLocale=function(){return E().locale},exports.useNow=function(e){var t=null==e?void 0:e.updateInterval,n=E().now,o=r.useState(n||S()),u=o[0],i=o[1];return r.useEffect((function(){if(t){var r=setInterval((function(){i(S())}),t);return function(){clearInterval(r)}}}),[n,t]),u},exports.useTimeZone=function(){return E().timeZone},exports.useTranslations=function(t){var n=E(),u=n.messages;if(!u){var i=new v(exports.IntlErrorCode.MISSING_MESSAGE,void 0);throw n.onError(i),i}return function(t,n,u){var i=E(),a=i.defaultTranslationValues,c=i.formats,f=i.getMessageFallback,l=i.locale,s=i.onError,d=i.timeZone;t=t["!"],n="!"===n?void 0:n.slice("!.".length);var p=r.useRef({}),I=r.useMemo((function(){try{if(!t)throw new Error(void 0);var r=n?y(t,n):t;if(!r)throw new Error(void 0);return r}catch(r){var e=new v(exports.IntlErrorCode.MISSING_MESSAGE,r.message);return s(e),e}}),[t,n,s]);return r.useMemo((function(){function t(r,e,t){var o=new v(e,t);return s(o),f({error:o,key:r,namespace:n})}function u(u,i,s){var E,S=p.current;if(I instanceof v)return f({error:I,key:u,namespace:n});var h,M=I,g=[n,u].filter((function(r){return null!=r})).join(".");if(null!=(E=S[l])&&E[g])h=S[l][g];else{var w;try{w=y(M,u)}catch(r){return t(u,exports.IntlErrorCode.MISSING_MESSAGE,r.message)}if("object"==typeof w)return t(u,exports.IntlErrorCode.INSUFFICIENT_PATH,void 0);try{h=new e.IntlMessageFormat(w,l,function(r,e){var t=e?o({},r,{dateTime:m(r.dateTime,e)}):r;return o({},t,{date:null==t?void 0:t.dateTime,time:null==t?void 0:t.dateTime})}(o({},c,s),d))}catch(r){return t(u,exports.IntlErrorCode.INVALID_MESSAGE,r.message)}S[l]||(S[l]={}),S[l][g]=h}try{var O=h.format(function(e){if(0!==Object.keys(e).length){var t={};return Object.keys(e).forEach((function(n){var o=0,u=e[n];t[n]="function"==typeof u?function(e){var t=u(e);return r.isValidElement(t)?r.cloneElement(t,{key:n+o++}):t}:u})),t}}(o({},a,i)));if(null==O)throw new Error(void 0);return r.isValidElement(O)||Array.isArray(O)||"string"==typeof O?O:String(O)}catch(r){return t(u,exports.IntlErrorCode.FORMATTING_ERROR,r.message)}}function i(r,e,n){var o=u(r,e,n);return"string"!=typeof o?t(r,exports.IntlErrorCode.INVALID_MESSAGE,void 0):o}return i.rich=u,i.raw=function(r){if(I instanceof v)return f({error:I,key:r,namespace:n});var e=I;try{return y(e,r)}catch(e){return t(r,exports.IntlErrorCode.MISSING_MESSAGE,e.message)}},i}),[s,f,n,I,l,c,d,a])}({"!":u},t?"!."+t:"!")};
2
2
  //# sourceMappingURL=use-intl.cjs.production.min.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-intl.cjs.production.min.js","sources":["../src/IntlContext.tsx","../src/IntlError.tsx","../src/IntlProvider.tsx","../src/useIntlContext.tsx","../src/convertFormatsToIntlMessageFormat.tsx","../src/useTranslationsImpl.tsx","../src/useNow.tsx","../src/useIntl.tsx","../src/useLocale.tsx","../src/useTimeZone.tsx","../src/useTranslations.tsx"],"sourcesContent":["import {createContext} from 'react';\nimport AbstractIntlMessages from './AbstractIntlMessages';\nimport Formats from './Formats';\nimport IntlError from './IntlError';\nimport {RichTranslationValues} from './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","export enum IntlErrorCode {\n MISSING_MESSAGE = 'MISSING_MESSAGE',\n MISSING_FORMAT = 'MISSING_FORMAT',\n INSUFFICIENT_PATH = 'INSUFFICIENT_PATH',\n INVALID_MESSAGE = 'INVALID_MESSAGE',\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","import React, {ReactNode} from 'react';\nimport AbstractIntlMessages from './AbstractIntlMessages';\nimport Formats from './Formats';\nimport IntlContext from './IntlContext';\nimport {RichTranslationValues} from './TranslationValues';\nimport {IntlError} from '.';\n\ntype Props = {\n /** All messages that will be available in your components. */\n messages?: AbstractIntlMessages;\n /** A valid Unicode locale tag (e.g. \"en\" or \"en-GB\"). */\n locale: string;\n /** Global formats can be provided to achieve consistent\n * formatting across components. */\n formats?: Partial<Formats>;\n /** 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`. */\n timeZone?: string;\n /** This callback will be invoked when an error is encountered during\n * resolving a message or formatting it. This defaults to `console.error` to\n * keep your app running. You can customize the handling by taking\n * `error.code` into account. */\n onError?(error: IntlError): void;\n /** Will be called when a message couldn't be resolved or formatting it led to\n * an error. This defaults to `${namespace}.${key}` You can use this to\n * customize what will be rendered in this case. */\n getMessageFallback?(info: {\n namespace?: string;\n key: string;\n error: IntlError;\n }): string;\n /** All components that use the provided hooks should be within this tree. */\n children: ReactNode;\n /**\n * Providing this value will have two effects:\n * 1. It will be used as the default for the `now` argument of\n * `useIntl().formatRelativeTime` if no explicit value is provided.\n * 2. It will be returned as a static value from the `useNow` hook. Note\n * however that when `updateInterval` is configured on the `useNow` hook,\n * the global `now` value will only be used for the initial render, but\n * afterwards the current date will be returned continuously.\n */\n now?: Date;\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};\n\nfunction defaultGetMessageFallback({\n key,\n namespace\n}: {\n key: string;\n namespace?: string;\n}) {\n return [namespace, key].filter((part) => part != null).join('.');\n}\n\nfunction defaultOnError(error: IntlError) {\n console.error(error);\n}\n\nexport default function IntlProvider({\n children,\n onError = defaultOnError,\n getMessageFallback = defaultGetMessageFallback,\n ...contextValues\n}: Props) {\n return (\n <IntlContext.Provider\n value={{...contextValues, onError, getMessageFallback}}\n >\n {children}\n </IntlContext.Provider>\n );\n}\n","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","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","import {IntlMessageFormat} from 'intl-messageformat';\nimport {\n cloneElement,\n isValidElement,\n ReactElement,\n ReactNode,\n ReactNodeArray,\n useMemo,\n useRef\n} from 'react';\nimport AbstractIntlMessages from './AbstractIntlMessages';\nimport Formats from './Formats';\nimport IntlError, {IntlErrorCode} from './IntlError';\nimport TranslationValues, {RichTranslationValues} from './TranslationValues';\nimport convertFormatsToIntlMessageFormat from './convertFormatsToIntlMessageFormat';\nimport useIntlContext from './useIntlContext';\nimport MessageKeys from './utils/MessageKeys';\nimport NestedKeyOf from './utils/NestedKeyOf';\nimport NestedValueOf from './utils/NestedValueOf';\n\nfunction resolvePath(\n messages: AbstractIntlMessages | undefined,\n idPath: 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 idPath.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 \\`${idPath}\\` 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 = (children: ReactNode) => {\n const result = value(children);\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 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 = (\n namespace === namespacePrefix\n ? undefined\n : namespace.slice((namespacePrefix + '.').length)\n ) as NestedKey;\n\n const cachedFormatsByLocaleRef = useRef<\n Record<string, Record<string, IntlMessageFormat>>\n >({});\n\n const messagesOrError = useMemo(() => {\n try {\n if (!allMessages) {\n throw new Error(\n __DEV__ ? `No messages were configured on the provider.` : undefined\n );\n }\n\n const retrievedMessages = namespace\n ? resolvePath(allMessages, namespace)\n : allMessages;\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 }, [allMessages, namespace, onError]);\n\n const translate = useMemo(() => {\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 const cachedFormatsByLocale = cachedFormatsByLocaleRef.current;\n\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]\n .filter((part) => part != null)\n .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[locale]) {\n cachedFormatsByLocale[locale] = {};\n }\n cachedFormatsByLocale[locale][cacheKey] = messageFormat;\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 message = translateBaseFn(key, values, formats);\n\n if (typeof message !== '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 message;\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 onError,\n getMessageFallback,\n namespace,\n messagesOrError,\n locale,\n globalFormats,\n timeZone,\n defaultTranslationValues\n ]);\n\n return translate;\n}\n","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","import DateTimeFormatOptions from './DateTimeFormatOptions';\nimport IntlError, {IntlErrorCode} from './IntlError';\nimport NumberFormatOptions from './NumberFormatOptions';\nimport useIntlContext from './useIntlContext';\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\nexport default function useIntl() {\n const {formats, locale, now: globalNow, onError, timeZone} = useIntlContext();\n\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 __DEV__\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 formatDateTime(\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 formatNumber(\n value: number,\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 formatRelativeTime(\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 __DEV__\n ? `The \\`now\\` parameter wasn't provided to \\`formatRelativeTime\\` 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 return {formatDateTime, formatNumber, formatRelativeTime};\n}\n","import useIntlContext from './useIntlContext';\n\nexport default function useLocale() {\n return useIntlContext().locale;\n}\n","import useIntlContext from './useIntlContext';\n\nexport default function useTimeZone() {\n return useIntlContext().timeZone;\n}\n","import {ReactElement, ReactNodeArray} from 'react';\nimport Formats from './Formats';\nimport IntlError, {IntlErrorCode} from './IntlError';\nimport TranslationValues, {RichTranslationValues} from './TranslationValues';\nimport useIntlContext from './useIntlContext';\nimport useTranslationsImpl from './useTranslationsImpl';\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 useTranslations<\n NestedKey extends NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>>\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 NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>> extends NestedKey\n ? '!'\n : `!.${NestedKey}`\n >,\n NestedKeyOf<\n NestedValueOf<\n {'!': IntlMessages},\n NamespaceKeys<\n IntlMessages,\n NestedKeyOf<IntlMessages>\n > extends NestedKey\n ? '!'\n : `!.${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 NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>> extends NestedKey\n ? '!'\n : `!.${NestedKey}`\n >,\n NestedKeyOf<\n NestedValueOf<\n {'!': IntlMessages},\n NamespaceKeys<\n IntlMessages,\n NestedKeyOf<IntlMessages>\n > extends NestedKey\n ? '!'\n : `!.${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 NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>> extends NestedKey\n ? '!'\n : `!.${NestedKey}`\n >,\n NestedKeyOf<\n NestedValueOf<\n {'!': IntlMessages},\n NamespaceKeys<\n IntlMessages,\n NestedKeyOf<IntlMessages>\n > extends NestedKey\n ? '!'\n : `!.${NestedKey}`\n >\n >\n >\n >(\n key: TargetKey\n ): any;\n} {\n const context = useIntlContext();\n\n const messages = context.messages as IntlMessages;\n if (!messages) {\n const intlError = new IntlError(\n IntlErrorCode.MISSING_MESSAGE,\n __DEV__ ? `No messages were configured on the provider.` : undefined\n );\n context.onError(intlError);\n throw intlError;\n }\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, but we have to use some.\n return useTranslationsImpl<\n {'!': IntlMessages},\n NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>> extends NestedKey\n ? '!'\n : `!.${NestedKey}`\n >(\n {'!': messages},\n // @ts-ignore\n namespace ? `!.${namespace}` : '!',\n '!'\n );\n}\n"],"names":["IntlErrorCode","IntlContext","createContext","undefined","defaultGetMessageFallback","_ref","namespace","key","filter","part","join","defaultOnError","error","console","IntlError","code","originalMessage","_this","message","_Error","call","this","Error","useIntlContext","context","useContext","setTimeZoneInFormats","formats","timeZone","Object","keys","reduce","acc","_extends","resolvePath","messages","idPath","split","forEach","next","getNow","Date","_ref2","children","_ref2$onError","onError","_ref2$getMessageFallb","getMessageFallback","contextValues","_objectWithoutPropertiesLoose","_excluded","React","Provider","value","_useIntlContext","locale","globalNow","now","getFormattedValue","formatOrOptions","typeFormats","formatter","options","MISSING_FORMAT","resolveFormatOrOptions","String","FORMATTING_ERROR","formatDateTime","dateTime","_options","Intl","DateTimeFormat","format","formatNumber","number","NumberFormat","formatRelativeTime","date","dateDate","nowDate","getRelativeTimeFormatConfig","seconds","unit","absValue","Math","abs","round","MINUTE","HOUR","DAY","getTime","RelativeTimeFormat","numeric","updateInterval","_useState","useState","setNow","useEffect","intervalId","setInterval","clearInterval","intlError","MISSING_MESSAGE","allMessages","namespacePrefix","defaultTranslationValues","globalFormats","slice","length","cachedFormatsByLocaleRef","useRef","messagesOrError","useMemo","retrievedMessages","getFallbackFromErrorAndNotify","translateBaseFn","values","_cachedFormatsByLocal","cachedFormatsByLocale","current","messageFormat","cacheKey","INSUFFICIENT_PATH","IntlMessageFormat","formatsWithTimeZone","time","convertFormatsToIntlMessageFormat","INVALID_MESSAGE","formattedMessage","transformedValues","index","result","isValidElement","cloneElement","prepareTranslationValues","Array","isArray","translateFn","rich","raw","useTranslationsImpl"],"mappings":"+hDAqBA,ICrBYA,EDqBNC,EAAcC,EAAaA,mBAA+BC,iDE2BhE,SAASC,EAMRC,GACQ,MAAA,GALPC,YADAC,KAMwBC,QAAO,SAACC,GAASA,OAAQ,MAARA,KAAcC,KAAK,KAG9D,SAASC,EAAeC,GACtBC,QAAQD,MAAMA,GD3DJZ,QAAZA,mBAAA,GAAYA,EAAAA,wBAAAA,QAAAA,cAMX,KALC,gBAAA,kBACAA,EAAA,eAAA,iBACAA,EAAA,kBAAA,oBACAA,EAAA,gBAAA,kBACAA,EAAA,iBAAA,uBAGmBc,sBAIPC,SAAAA,EAAAA,EAAqBC,GAAwB,IAAAC,EACnDC,EAAkBH,EADiC,OAEnDC,IACFE,GAAW,KAAOF,IAEpBC,EAAAE,EAAAC,KAAAC,KAAMH,IAANG,MARcN,UAGyC,EAAAE,EAFzCD,qBAEyC,EAOlDD,EAAAA,KAAOA,EACRC,IACGA,EAAAA,gBAAkBA,GAT8BC,8FAJpBK,QELzB,SAAUC,IACtB,IAAMC,EAAUC,aAAWxB,GAEvB,IAACuB,EACH,MAAM,IAAIF,WAGJnB,GAIR,OAAO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AAOiC,EAAmB,CACxBnC,MAAOmG,EACPxG,IAAAA,EACAD,UAAAA,IAGE6B,IAAAA,EAAW4E,EAEb,IACF,OAAO7E,EAAYC,EAAU5B,GAC7B,MAAOK,GACAsG,OAAAA,EACL3G,EACAP,QAAAA,cAAcsG,gBACb1F,EAAgBM,WAKhBuH,IACN,CACD5F,EACAE,EACAzC,EACAyG,EACAxD,EACAmD,EACA9E,EACA6E,IK5MKmC,CAML,CAAMzG,IAAAA,GAEN7B,EAAiBA,KAAAA,EAAc"}
1
+ {"version":3,"file":"use-intl.cjs.production.min.js","sources":["../src/IntlContext.tsx","../src/IntlError.tsx","../src/IntlProvider.tsx","../src/useIntlContext.tsx","../src/convertFormatsToIntlMessageFormat.tsx","../src/useTranslationsImpl.tsx","../src/useNow.tsx","../src/useIntl.tsx","../src/useLocale.tsx","../src/useTimeZone.tsx","../src/useTranslations.tsx"],"sourcesContent":["import {createContext} from 'react';\nimport AbstractIntlMessages from './AbstractIntlMessages';\nimport Formats from './Formats';\nimport IntlError from './IntlError';\nimport {RichTranslationValues} from './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","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","import React, {ReactNode, useEffect} from 'react';\nimport AbstractIntlMessages from './AbstractIntlMessages';\nimport Formats from './Formats';\nimport IntlContext from './IntlContext';\nimport {RichTranslationValues} from './TranslationValues';\nimport validateMessages from './validateMessages';\nimport {IntlError} from '.';\n\ntype Props = {\n /** All messages that will be available in your components. */\n messages?: AbstractIntlMessages;\n /** A valid Unicode locale tag (e.g. \"en\" or \"en-GB\"). */\n locale: string;\n /** Global formats can be provided to achieve consistent\n * formatting across components. */\n formats?: Partial<Formats>;\n /** 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`. */\n timeZone?: string;\n /** This callback will be invoked when an error is encountered during\n * resolving a message or formatting it. This defaults to `console.error` to\n * keep your app running. You can customize the handling by taking\n * `error.code` into account. */\n onError?(error: IntlError): void;\n /** Will be called when a message couldn't be resolved or formatting it led to\n * an error. This defaults to `${namespace}.${key}` You can use this to\n * customize what will be rendered in this case. */\n getMessageFallback?(info: {\n namespace?: string;\n key: string;\n error: IntlError;\n }): string;\n /** All components that use the provided hooks should be within this tree. */\n children: ReactNode;\n /**\n * Providing this value will have two effects:\n * 1. It will be used as the default for the `now` argument of\n * `useIntl().formatRelativeTime` if no explicit value is provided.\n * 2. It will be returned as a static value from the `useNow` hook. Note\n * however that when `updateInterval` is configured on the `useNow` hook,\n * the global `now` value will only be used for the initial render, but\n * afterwards the current date will be returned continuously.\n */\n now?: Date;\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};\n\nfunction defaultGetMessageFallback({\n key,\n namespace\n}: {\n key: string;\n namespace?: string;\n}) {\n return [namespace, key].filter((part) => part != null).join('.');\n}\n\nfunction defaultOnError(error: IntlError) {\n console.error(error);\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","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","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","import {IntlMessageFormat} from 'intl-messageformat';\nimport {\n cloneElement,\n isValidElement,\n ReactElement,\n ReactNode,\n ReactNodeArray,\n useMemo,\n useRef\n} from 'react';\nimport AbstractIntlMessages from './AbstractIntlMessages';\nimport Formats from './Formats';\nimport IntlError, {IntlErrorCode} from './IntlError';\nimport TranslationValues, {RichTranslationValues} from './TranslationValues';\nimport convertFormatsToIntlMessageFormat from './convertFormatsToIntlMessageFormat';\nimport useIntlContext from './useIntlContext';\nimport MessageKeys from './utils/MessageKeys';\nimport NestedKeyOf from './utils/NestedKeyOf';\nimport NestedValueOf from './utils/NestedValueOf';\n\nfunction resolvePath(\n messages: AbstractIntlMessages | undefined,\n idPath: 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 idPath.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 \\`${idPath}\\` 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 = (children: ReactNode) => {\n const result = value(children);\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 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 = (\n namespace === namespacePrefix\n ? undefined\n : namespace.slice((namespacePrefix + '.').length)\n ) as NestedKey;\n\n const cachedFormatsByLocaleRef = useRef<\n Record<string, Record<string, IntlMessageFormat>>\n >({});\n\n const messagesOrError = useMemo(() => {\n try {\n if (!allMessages) {\n throw new Error(\n __DEV__ ? `No messages were configured on the provider.` : undefined\n );\n }\n\n const retrievedMessages = namespace\n ? resolvePath(allMessages, namespace)\n : allMessages;\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 }, [allMessages, namespace, onError]);\n\n const translate = useMemo(() => {\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 const cachedFormatsByLocale = cachedFormatsByLocaleRef.current;\n\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]\n .filter((part) => part != null)\n .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[locale]) {\n cachedFormatsByLocale[locale] = {};\n }\n cachedFormatsByLocale[locale][cacheKey] = messageFormat;\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 message = translateBaseFn(key, values, formats);\n\n if (typeof message !== '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 message;\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 onError,\n getMessageFallback,\n namespace,\n messagesOrError,\n locale,\n globalFormats,\n timeZone,\n defaultTranslationValues\n ]);\n\n return translate;\n}\n","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","import DateTimeFormatOptions from './DateTimeFormatOptions';\nimport IntlError, {IntlErrorCode} from './IntlError';\nimport NumberFormatOptions from './NumberFormatOptions';\nimport useIntlContext from './useIntlContext';\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\nexport default function useIntl() {\n const {formats, locale, now: globalNow, onError, timeZone} = useIntlContext();\n\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 __DEV__\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 formatDateTime(\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 formatNumber(\n value: number,\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 formatRelativeTime(\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 __DEV__\n ? `The \\`now\\` parameter wasn't provided to \\`formatRelativeTime\\` 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 return {formatDateTime, formatNumber, formatRelativeTime};\n}\n","import useIntlContext from './useIntlContext';\n\nexport default function useLocale() {\n return useIntlContext().locale;\n}\n","import useIntlContext from './useIntlContext';\n\nexport default function useTimeZone() {\n return useIntlContext().timeZone;\n}\n","import {ReactElement, ReactNodeArray} from 'react';\nimport Formats from './Formats';\nimport IntlError, {IntlErrorCode} from './IntlError';\nimport TranslationValues, {RichTranslationValues} from './TranslationValues';\nimport useIntlContext from './useIntlContext';\nimport useTranslationsImpl from './useTranslationsImpl';\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 useTranslations<\n NestedKey extends NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>>\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 NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>> extends NestedKey\n ? '!'\n : `!.${NestedKey}`\n >,\n NestedKeyOf<\n NestedValueOf<\n {'!': IntlMessages},\n NamespaceKeys<\n IntlMessages,\n NestedKeyOf<IntlMessages>\n > extends NestedKey\n ? '!'\n : `!.${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 NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>> extends NestedKey\n ? '!'\n : `!.${NestedKey}`\n >,\n NestedKeyOf<\n NestedValueOf<\n {'!': IntlMessages},\n NamespaceKeys<\n IntlMessages,\n NestedKeyOf<IntlMessages>\n > extends NestedKey\n ? '!'\n : `!.${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 NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>> extends NestedKey\n ? '!'\n : `!.${NestedKey}`\n >,\n NestedKeyOf<\n NestedValueOf<\n {'!': IntlMessages},\n NamespaceKeys<\n IntlMessages,\n NestedKeyOf<IntlMessages>\n > extends NestedKey\n ? '!'\n : `!.${NestedKey}`\n >\n >\n >\n >(\n key: TargetKey\n ): any;\n} {\n const context = useIntlContext();\n\n const messages = context.messages as IntlMessages;\n if (!messages) {\n const intlError = new IntlError(\n IntlErrorCode.MISSING_MESSAGE,\n __DEV__ ? `No messages were configured on the provider.` : undefined\n );\n context.onError(intlError);\n throw intlError;\n }\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, but we have to use some.\n return useTranslationsImpl<\n {'!': IntlMessages},\n NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>> extends NestedKey\n ? '!'\n : `!.${NestedKey}`\n >(\n {'!': messages},\n // @ts-ignore\n namespace ? `!.${namespace}` : '!',\n '!'\n );\n}\n"],"names":["IntlErrorCode","IntlContext","createContext","undefined","IntlError","code","originalMessage","_this","message","_Error","call","this","Error","defaultGetMessageFallback","_ref","namespace","key","filter","part","join","defaultOnError","error","console","useIntlContext","context","useContext","setTimeZoneInFormats","formats","timeZone","Object","keys","reduce","acc","_extends","resolvePath","messages","idPath","split","forEach","next","getNow","Date","_ref2","children","_ref2$onError","onError","_ref2$getMessageFallb","getMessageFallback","contextValues","_objectWithoutPropertiesLoose","_excluded","React","Provider","value","_useIntlContext","locale","globalNow","now","getFormattedValue","formatOrOptions","typeFormats","formatter","options","MISSING_FORMAT","resolveFormatOrOptions","String","FORMATTING_ERROR","formatDateTime","dateTime","_options","Intl","DateTimeFormat","format","formatNumber","number","NumberFormat","formatRelativeTime","date","dateDate","nowDate","getRelativeTimeFormatConfig","seconds","unit","absValue","Math","abs","round","MINUTE","HOUR","DAY","getTime","RelativeTimeFormat","numeric","updateInterval","_useState","useState","setNow","useEffect","intervalId","setInterval","clearInterval","intlError","MISSING_MESSAGE","allMessages","namespacePrefix","defaultTranslationValues","globalFormats","slice","length","cachedFormatsByLocaleRef","useRef","messagesOrError","useMemo","retrievedMessages","getFallbackFromErrorAndNotify","translateBaseFn","values","_cachedFormatsByLocal","cachedFormatsByLocale","current","messageFormat","cacheKey","INSUFFICIENT_PATH","IntlMessageFormat","formatsWithTimeZone","time","convertFormatsToIntlMessageFormat","INVALID_MESSAGE","formattedMessage","transformedValues","index","result","isValidElement","cloneElement","prepareTranslationValues","Array","isArray","translateFn","rich","raw","useTranslationsImpl"],"mappings":"+hDAqBA,ICrBYA,EDqBNC,EAAcC,EAAaA,mBAA+BC,GCrBpDH,QAAZA,mBAAA,GAAYA,EAAAA,wBAAAA,QAAAA,cAOX,KANC,gBAAA,kBACAA,EAAA,eAAA,iBACAA,EAAA,kBAAA,oBACAA,EAAA,gBAAA,kBACAA,EAAA,YAAA,cACAA,EAAA,iBAAA,uBAGmBI,sBAIPC,SAAAA,EAAAA,EAAqBC,GAAwB,IAAAC,EACnDC,EAAkBH,EADiC,OAEnDC,IACFE,GAAW,KAAOF,IAEpBC,EAAAE,EAAAC,KAAAC,KAAMH,IAANG,MARcN,UAGyC,EAAAE,EAFzCD,qBAEyC,EAOlDD,EAAAA,KAAOA,EACRC,IACGA,EAAAA,gBAAkBA,GAT8BC,8FAJpBK,iECwCvC,SAASC,EAMRC,GACQ,MAAA,GALPC,YADAC,KAMwBC,QAAO,SAACC,GAASA,OAAQ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KoG,EAAQzF,GAE7C,MAAuB,iBAAZnB,EACF0G,EACLlG,EACAhB,QAAaA,cAAC+H,qBAKV5H,GAIDK,EA8BT,OA3BAiI,EAAYC,KAAOvB,EAEnBsB,EAAYE,IAAM,SAEhB3H,GAEI+F,GAAAA,aAA2B3G,EAE7B,OAAO2C,EAAmB,CACxB1B,MAAO0F,EACP/F,IAAAA,EACAD,UAAAA,IAGEoB,IAAAA,EAAW4E,EAEb,IACF,OAAO7E,EAAYC,EAAUnB,GAC7B,MAAOK,GACA6F,OAAAA,EACLlG,EACAhB,QAAAA,cAAcsG,gBACbjF,EAAgBb,WAKhBiI,IACN,CACD5F,EACAE,EACAhC,EACAgG,EACAxD,EACAmD,EACA9E,EACA6E,IK5MKmC,CAML,CAAMzG,IAAAA,GAENpB,EAAiBA,KAAAA,EAAc"}
@@ -1,4 +1,4 @@
1
- import React, { createContext, useContext, useRef, useMemo, isValidElement, cloneElement, useState, useEffect } from 'react';
1
+ import React, { createContext, useEffect, useContext, useRef, useMemo, isValidElement, cloneElement, useState } from 'react';
2
2
  import { IntlMessageFormat } from 'intl-messageformat';
3
3
 
4
4
  function _extends() {
@@ -127,36 +127,6 @@ function _objectWithoutPropertiesLoose(source, excluded) {
127
127
 
128
128
  var IntlContext = /*#__PURE__*/createContext(undefined);
129
129
 
130
- var _excluded = ["children", "onError", "getMessageFallback"];
131
-
132
- function defaultGetMessageFallback(_ref) {
133
- var key = _ref.key,
134
- namespace = _ref.namespace;
135
- return [namespace, key].filter(function (part) {
136
- return part != null;
137
- }).join('.');
138
- }
139
-
140
- function defaultOnError(error) {
141
- console.error(error);
142
- }
143
-
144
- function IntlProvider(_ref2) {
145
- var children = _ref2.children,
146
- _ref2$onError = _ref2.onError,
147
- onError = _ref2$onError === void 0 ? defaultOnError : _ref2$onError,
148
- _ref2$getMessageFallb = _ref2.getMessageFallback,
149
- getMessageFallback = _ref2$getMessageFallb === void 0 ? defaultGetMessageFallback : _ref2$getMessageFallb,
150
- contextValues = _objectWithoutPropertiesLoose(_ref2, _excluded);
151
-
152
- return React.createElement(IntlContext.Provider, {
153
- value: _extends({}, contextValues, {
154
- onError: onError,
155
- getMessageFallback: getMessageFallback
156
- })
157
- }, children);
158
- }
159
-
160
130
  var IntlErrorCode;
161
131
 
162
132
  (function (IntlErrorCode) {
@@ -164,6 +134,7 @@ var IntlErrorCode;
164
134
  IntlErrorCode["MISSING_FORMAT"] = "MISSING_FORMAT";
165
135
  IntlErrorCode["INSUFFICIENT_PATH"] = "INSUFFICIENT_PATH";
166
136
  IntlErrorCode["INVALID_MESSAGE"] = "INVALID_MESSAGE";
137
+ IntlErrorCode["INVALID_KEY"] = "INVALID_KEY";
167
138
  IntlErrorCode["FORMATTING_ERROR"] = "FORMATTING_ERROR";
168
139
  })(IntlErrorCode || (IntlErrorCode = {}));
169
140
 
@@ -194,6 +165,75 @@ var IntlError = /*#__PURE__*/function (_Error) {
194
165
  return IntlError;
195
166
  }( /*#__PURE__*/_wrapNativeSuper(Error));
196
167
 
168
+ function validateMessagesSegment(messages, invalidKeyLabels, parentPath) {
169
+ Object.entries(messages).forEach(function (_ref) {
170
+ var key = _ref[0],
171
+ messageOrMessages = _ref[1];
172
+
173
+ if (key.includes('.')) {
174
+ var keyLabel = key;
175
+ if (parentPath) keyLabel += " (at " + parentPath + ")";
176
+ invalidKeyLabels.push(keyLabel);
177
+ }
178
+
179
+ if (typeof messageOrMessages === 'object') {
180
+ validateMessagesSegment(messageOrMessages, invalidKeyLabels, [parentPath, key].filter(function (part) {
181
+ return part != null;
182
+ }).join('.'));
183
+ }
184
+ });
185
+ }
186
+
187
+ function validateMessages(messages, onError) {
188
+ var invalidKeyLabels = [];
189
+ validateMessagesSegment(messages, invalidKeyLabels);
190
+
191
+ if (invalidKeyLabels.length > 0) {
192
+ onError(new IntlError(IntlErrorCode.INVALID_KEY, "Namespace keys can not contain the character \".\" as this is used to express nesting. Please remove it or replace it with another character.\n\nInvalid " + (invalidKeyLabels.length === 1 ? 'key' : 'keys') + ": " + invalidKeyLabels.join(', ')));
193
+ }
194
+ }
195
+
196
+ var _excluded = ["children", "onError", "getMessageFallback", "messages"];
197
+
198
+ function defaultGetMessageFallback(_ref) {
199
+ var key = _ref.key,
200
+ namespace = _ref.namespace;
201
+ return [namespace, key].filter(function (part) {
202
+ return part != null;
203
+ }).join('.');
204
+ }
205
+
206
+ function defaultOnError(error) {
207
+ console.error(error);
208
+ }
209
+
210
+ function IntlProvider(_ref2) {
211
+ var children = _ref2.children,
212
+ _ref2$onError = _ref2.onError,
213
+ onError = _ref2$onError === void 0 ? defaultOnError : _ref2$onError,
214
+ _ref2$getMessageFallb = _ref2.getMessageFallback,
215
+ getMessageFallback = _ref2$getMessageFallb === void 0 ? defaultGetMessageFallback : _ref2$getMessageFallb,
216
+ messages = _ref2.messages,
217
+ contextValues = _objectWithoutPropertiesLoose(_ref2, _excluded);
218
+
219
+ if (process.env.NODE_ENV !== "production") {
220
+ // eslint-disable-next-line react-hooks/rules-of-hooks
221
+ useEffect(function () {
222
+ if (messages) {
223
+ validateMessages(messages, onError);
224
+ }
225
+ }, [messages, onError]);
226
+ }
227
+
228
+ return React.createElement(IntlContext.Provider, {
229
+ value: _extends({}, contextValues, {
230
+ messages: messages,
231
+ onError: onError,
232
+ getMessageFallback: getMessageFallback
233
+ })
234
+ }, children);
235
+ }
236
+
197
237
  function useIntlContext() {
198
238
  var context = useContext(IntlContext);
199
239
 
@@ -1 +1 @@
1
- {"version":3,"file":"use-intl.esm.js","sources":["../src/IntlContext.tsx","../src/IntlProvider.tsx","../src/IntlError.tsx","../src/useIntlContext.tsx","../src/convertFormatsToIntlMessageFormat.tsx","../src/useTranslationsImpl.tsx","../src/useTranslations.tsx","../src/useIntl.tsx","../src/useLocale.tsx","../src/useNow.tsx","../src/useTimeZone.tsx"],"sourcesContent":["import {createContext} from 'react';\nimport AbstractIntlMessages from './AbstractIntlMessages';\nimport Formats from './Formats';\nimport IntlError from './IntlError';\nimport {RichTranslationValues} from './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","import React, {ReactNode} from 'react';\nimport AbstractIntlMessages from './AbstractIntlMessages';\nimport Formats from './Formats';\nimport IntlContext from './IntlContext';\nimport {RichTranslationValues} from './TranslationValues';\nimport {IntlError} from '.';\n\ntype Props = {\n /** All messages that will be available in your components. */\n messages?: AbstractIntlMessages;\n /** A valid Unicode locale tag (e.g. \"en\" or \"en-GB\"). */\n locale: string;\n /** Global formats can be provided to achieve consistent\n * formatting across components. */\n formats?: Partial<Formats>;\n /** 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`. */\n timeZone?: string;\n /** This callback will be invoked when an error is encountered during\n * resolving a message or formatting it. This defaults to `console.error` to\n * keep your app running. You can customize the handling by taking\n * `error.code` into account. */\n onError?(error: IntlError): void;\n /** Will be called when a message couldn't be resolved or formatting it led to\n * an error. This defaults to `${namespace}.${key}` You can use this to\n * customize what will be rendered in this case. */\n getMessageFallback?(info: {\n namespace?: string;\n key: string;\n error: IntlError;\n }): string;\n /** All components that use the provided hooks should be within this tree. */\n children: ReactNode;\n /**\n * Providing this value will have two effects:\n * 1. It will be used as the default for the `now` argument of\n * `useIntl().formatRelativeTime` if no explicit value is provided.\n * 2. It will be returned as a static value from the `useNow` hook. Note\n * however that when `updateInterval` is configured on the `useNow` hook,\n * the global `now` value will only be used for the initial render, but\n * afterwards the current date will be returned continuously.\n */\n now?: Date;\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};\n\nfunction defaultGetMessageFallback({\n key,\n namespace\n}: {\n key: string;\n namespace?: string;\n}) {\n return [namespace, key].filter((part) => part != null).join('.');\n}\n\nfunction defaultOnError(error: IntlError) {\n console.error(error);\n}\n\nexport default function IntlProvider({\n children,\n onError = defaultOnError,\n getMessageFallback = defaultGetMessageFallback,\n ...contextValues\n}: Props) {\n return (\n <IntlContext.Provider\n value={{...contextValues, onError, getMessageFallback}}\n >\n {children}\n </IntlContext.Provider>\n );\n}\n","export enum IntlErrorCode {\n MISSING_MESSAGE = 'MISSING_MESSAGE',\n MISSING_FORMAT = 'MISSING_FORMAT',\n INSUFFICIENT_PATH = 'INSUFFICIENT_PATH',\n INVALID_MESSAGE = 'INVALID_MESSAGE',\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","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","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","import {IntlMessageFormat} from 'intl-messageformat';\nimport {\n cloneElement,\n isValidElement,\n ReactElement,\n ReactNode,\n ReactNodeArray,\n useMemo,\n useRef\n} from 'react';\nimport AbstractIntlMessages from './AbstractIntlMessages';\nimport Formats from './Formats';\nimport IntlError, {IntlErrorCode} from './IntlError';\nimport TranslationValues, {RichTranslationValues} from './TranslationValues';\nimport convertFormatsToIntlMessageFormat from './convertFormatsToIntlMessageFormat';\nimport useIntlContext from './useIntlContext';\nimport MessageKeys from './utils/MessageKeys';\nimport NestedKeyOf from './utils/NestedKeyOf';\nimport NestedValueOf from './utils/NestedValueOf';\n\nfunction resolvePath(\n messages: AbstractIntlMessages | undefined,\n idPath: 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 idPath.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 \\`${idPath}\\` 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 = (children: ReactNode) => {\n const result = value(children);\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 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 = (\n namespace === namespacePrefix\n ? undefined\n : namespace.slice((namespacePrefix + '.').length)\n ) as NestedKey;\n\n const cachedFormatsByLocaleRef = useRef<\n Record<string, Record<string, IntlMessageFormat>>\n >({});\n\n const messagesOrError = useMemo(() => {\n try {\n if (!allMessages) {\n throw new Error(\n __DEV__ ? `No messages were configured on the provider.` : undefined\n );\n }\n\n const retrievedMessages = namespace\n ? resolvePath(allMessages, namespace)\n : allMessages;\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 }, [allMessages, namespace, onError]);\n\n const translate = useMemo(() => {\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 const cachedFormatsByLocale = cachedFormatsByLocaleRef.current;\n\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]\n .filter((part) => part != null)\n .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[locale]) {\n cachedFormatsByLocale[locale] = {};\n }\n cachedFormatsByLocale[locale][cacheKey] = messageFormat;\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 message = translateBaseFn(key, values, formats);\n\n if (typeof message !== '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 message;\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 onError,\n getMessageFallback,\n namespace,\n messagesOrError,\n locale,\n globalFormats,\n timeZone,\n defaultTranslationValues\n ]);\n\n return translate;\n}\n","import {ReactElement, ReactNodeArray} from 'react';\nimport Formats from './Formats';\nimport IntlError, {IntlErrorCode} from './IntlError';\nimport TranslationValues, {RichTranslationValues} from './TranslationValues';\nimport useIntlContext from './useIntlContext';\nimport useTranslationsImpl from './useTranslationsImpl';\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 useTranslations<\n NestedKey extends NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>>\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 NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>> extends NestedKey\n ? '!'\n : `!.${NestedKey}`\n >,\n NestedKeyOf<\n NestedValueOf<\n {'!': IntlMessages},\n NamespaceKeys<\n IntlMessages,\n NestedKeyOf<IntlMessages>\n > extends NestedKey\n ? '!'\n : `!.${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 NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>> extends NestedKey\n ? '!'\n : `!.${NestedKey}`\n >,\n NestedKeyOf<\n NestedValueOf<\n {'!': IntlMessages},\n NamespaceKeys<\n IntlMessages,\n NestedKeyOf<IntlMessages>\n > extends NestedKey\n ? '!'\n : `!.${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 NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>> extends NestedKey\n ? '!'\n : `!.${NestedKey}`\n >,\n NestedKeyOf<\n NestedValueOf<\n {'!': IntlMessages},\n NamespaceKeys<\n IntlMessages,\n NestedKeyOf<IntlMessages>\n > extends NestedKey\n ? '!'\n : `!.${NestedKey}`\n >\n >\n >\n >(\n key: TargetKey\n ): any;\n} {\n const context = useIntlContext();\n\n const messages = context.messages as IntlMessages;\n if (!messages) {\n const intlError = new IntlError(\n IntlErrorCode.MISSING_MESSAGE,\n __DEV__ ? `No messages were configured on the provider.` : undefined\n );\n context.onError(intlError);\n throw intlError;\n }\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, but we have to use some.\n return useTranslationsImpl<\n {'!': IntlMessages},\n NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>> extends NestedKey\n ? '!'\n : `!.${NestedKey}`\n >(\n {'!': messages},\n // @ts-ignore\n namespace ? `!.${namespace}` : '!',\n '!'\n );\n}\n","import DateTimeFormatOptions from './DateTimeFormatOptions';\nimport IntlError, {IntlErrorCode} from './IntlError';\nimport NumberFormatOptions from './NumberFormatOptions';\nimport useIntlContext from './useIntlContext';\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\nexport default function useIntl() {\n const {formats, locale, now: globalNow, onError, timeZone} = useIntlContext();\n\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 __DEV__\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 formatDateTime(\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 formatNumber(\n value: number,\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 formatRelativeTime(\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 __DEV__\n ? `The \\`now\\` parameter wasn't provided to \\`formatRelativeTime\\` 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 return {formatDateTime, formatNumber, formatRelativeTime};\n}\n","import useIntlContext from './useIntlContext';\n\nexport default function useLocale() {\n return useIntlContext().locale;\n}\n","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","import useIntlContext from './useIntlContext';\n\nexport default function useTimeZone() {\n return useIntlContext().timeZone;\n}\n"],"names":["IntlContext","createContext","undefined","defaultGetMessageFallback","key","namespace","filter","part","join","defaultOnError","error","console","IntlProvider","children","onError","getMessageFallback","contextValues","React","Provider","value","IntlErrorCode","IntlError","code","originalMessage","message","Error","useIntlContext","context","useContext","setTimeZoneInFormats","formats","timeZone","Object","keys","reduce","acc","convertFormatsToIntlMessageFormat","formatsWithTimeZone","dateTime","date","time","resolvePath","messages","idPath","split","forEach","next","prepareTranslationValues","values","length","transformedValues","index","transformed","result","isValidElement","cloneElement","useTranslationsImpl","allMessages","namespacePrefix","defaultTranslationValues","globalFormats","locale","slice","cachedFormatsByLocaleRef","useRef","messagesOrError","useMemo","retrievedMessages","intlError","MISSING_MESSAGE","translate","getFallbackFromErrorAndNotify","translateBaseFn","cachedFormatsByLocale","current","cacheKey","messageFormat","INSUFFICIENT_PATH","IntlMessageFormat","INVALID_MESSAGE","formattedMessage","format","Array","isArray","String","FORMATTING_ERROR","translateFn","rich","raw","useTranslations","MINUTE","HOUR","DAY","WEEK","MONTH","YEAR","getRelativeTimeFormatConfig","seconds","absValue","Math","abs","unit","round","useIntl","globalNow","now","resolveFormatOrOptions","typeFormats","formatOrOptions","options","formatName","MISSING_FORMAT","getFormattedValue","formatter","formatDateTime","Intl","DateTimeFormat","formatNumber","number","NumberFormat","formatRelativeTime","dateDate","Date","nowDate","getTime","RelativeTimeFormat","numeric","useLocale","getNow","useNow","updateInterval","useState","setNow","useEffect","intervalId","setInterval","clearInterval","useTimeZone"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqBA,IAAMA,WAAW,gBAAGC,aAAa,CAA+BC,SAA/B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AO,CAAEqB,cAAhC,CAAA;;AAEA,EAAA,IAAA,eAAA,GAAyBxG,cAAc,EAAvC;AAAA,MAAY8E,SAAZ,mBAAOC,GAAP,CAAA;;AACA,EAAA,IAAA,SAAA,GAAsB0B,QAAQ,CAAC3B,SAAS,IAAIwB,MAAM,EAApB,CAA9B;AAAA,MAAOvB,GAAP,GAAA,SAAA,CAAA,CAAA,CAAA;AAAA,MAAY2B,MAAZ,GAAA,SAAA,CAAA,CAAA,CAAA,CAAA;;AAEAC,EAAAA,SAAS,CAAC,YAAK;AACb,IAAI,IAAA,CAACH,cAAL,EAAqB,OAAA;AAErB,IAAA,IAAMI,UAAU,GAAGC,WAAW,CAAC,YAAK;AAClCH,MAAAA,MAAM,CAACJ,MAAM,EAAP,CAAN,CAAA;AACD,KAF6B,EAE3BE,cAF2B,CAA9B,CAAA;AAIA,IAAA,OAAO,YAAK;AACVM,MAAAA,aAAa,CAACF,UAAD,CAAb,CAAA;AACD,KAFD,CAAA;AAGD,GAVQ,EAUN,CAAC9B,SAAD,EAAY0B,cAAZ,CAVM,CAAT,CAAA;AAYA,EAAA,OAAOzB,GAAP,CAAA;AACD;;AC9Ca,SAAUgC,WAAV,GAAqB;AACjC,EAAO/G,OAAAA,cAAc,GAAGK,QAAxB,CAAA;AACD;;;;"}
1
+ {"version":3,"file":"use-intl.esm.js","sources":["../src/IntlContext.tsx","../src/IntlError.tsx","../src/validateMessages.tsx","../src/IntlProvider.tsx","../src/useIntlContext.tsx","../src/convertFormatsToIntlMessageFormat.tsx","../src/useTranslationsImpl.tsx","../src/useTranslations.tsx","../src/useIntl.tsx","../src/useLocale.tsx","../src/useNow.tsx","../src/useTimeZone.tsx"],"sourcesContent":["import {createContext} from 'react';\nimport AbstractIntlMessages from './AbstractIntlMessages';\nimport Formats from './Formats';\nimport IntlError from './IntlError';\nimport {RichTranslationValues} from './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","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","import AbstractIntlMessages from './AbstractIntlMessages';\nimport IntlError, {IntlErrorCode} from './IntlError';\n\nfunction validateMessagesSegment(\n messages: AbstractIntlMessages,\n invalidKeyLabels: Array<string>,\n parentPath?: string\n) {\n Object.entries(messages).forEach(([key, messageOrMessages]) => {\n if (key.includes('.')) {\n let keyLabel = key;\n if (parentPath) keyLabel += ` (at ${parentPath})`;\n invalidKeyLabels.push(keyLabel);\n }\n if (typeof messageOrMessages === 'object') {\n validateMessagesSegment(\n messageOrMessages,\n invalidKeyLabels,\n [parentPath, key].filter((part) => part != null).join('.')\n );\n }\n });\n}\n\nexport default function validateMessages(\n messages: AbstractIntlMessages,\n onError: (error: IntlError) => void\n) {\n const invalidKeyLabels: Array<string> = [];\n validateMessagesSegment(messages, invalidKeyLabels);\n\n if (invalidKeyLabels.length > 0) {\n onError(\n new IntlError(\n IntlErrorCode.INVALID_KEY,\n `Namespace keys can not contain the character \".\" as this is used to express nesting. Please remove it or replace it with another character.\\n\\nInvalid ${\n invalidKeyLabels.length === 1 ? 'key' : 'keys'\n }: ${invalidKeyLabels.join(', ')}`\n )\n );\n }\n}\n","import React, {ReactNode, useEffect} from 'react';\nimport AbstractIntlMessages from './AbstractIntlMessages';\nimport Formats from './Formats';\nimport IntlContext from './IntlContext';\nimport {RichTranslationValues} from './TranslationValues';\nimport validateMessages from './validateMessages';\nimport {IntlError} from '.';\n\ntype Props = {\n /** All messages that will be available in your components. */\n messages?: AbstractIntlMessages;\n /** A valid Unicode locale tag (e.g. \"en\" or \"en-GB\"). */\n locale: string;\n /** Global formats can be provided to achieve consistent\n * formatting across components. */\n formats?: Partial<Formats>;\n /** 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`. */\n timeZone?: string;\n /** This callback will be invoked when an error is encountered during\n * resolving a message or formatting it. This defaults to `console.error` to\n * keep your app running. You can customize the handling by taking\n * `error.code` into account. */\n onError?(error: IntlError): void;\n /** Will be called when a message couldn't be resolved or formatting it led to\n * an error. This defaults to `${namespace}.${key}` You can use this to\n * customize what will be rendered in this case. */\n getMessageFallback?(info: {\n namespace?: string;\n key: string;\n error: IntlError;\n }): string;\n /** All components that use the provided hooks should be within this tree. */\n children: ReactNode;\n /**\n * Providing this value will have two effects:\n * 1. It will be used as the default for the `now` argument of\n * `useIntl().formatRelativeTime` if no explicit value is provided.\n * 2. It will be returned as a static value from the `useNow` hook. Note\n * however that when `updateInterval` is configured on the `useNow` hook,\n * the global `now` value will only be used for the initial render, but\n * afterwards the current date will be returned continuously.\n */\n now?: Date;\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};\n\nfunction defaultGetMessageFallback({\n key,\n namespace\n}: {\n key: string;\n namespace?: string;\n}) {\n return [namespace, key].filter((part) => part != null).join('.');\n}\n\nfunction defaultOnError(error: IntlError) {\n console.error(error);\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","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","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","import {IntlMessageFormat} from 'intl-messageformat';\nimport {\n cloneElement,\n isValidElement,\n ReactElement,\n ReactNode,\n ReactNodeArray,\n useMemo,\n useRef\n} from 'react';\nimport AbstractIntlMessages from './AbstractIntlMessages';\nimport Formats from './Formats';\nimport IntlError, {IntlErrorCode} from './IntlError';\nimport TranslationValues, {RichTranslationValues} from './TranslationValues';\nimport convertFormatsToIntlMessageFormat from './convertFormatsToIntlMessageFormat';\nimport useIntlContext from './useIntlContext';\nimport MessageKeys from './utils/MessageKeys';\nimport NestedKeyOf from './utils/NestedKeyOf';\nimport NestedValueOf from './utils/NestedValueOf';\n\nfunction resolvePath(\n messages: AbstractIntlMessages | undefined,\n idPath: 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 idPath.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 \\`${idPath}\\` 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 = (children: ReactNode) => {\n const result = value(children);\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 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 = (\n namespace === namespacePrefix\n ? undefined\n : namespace.slice((namespacePrefix + '.').length)\n ) as NestedKey;\n\n const cachedFormatsByLocaleRef = useRef<\n Record<string, Record<string, IntlMessageFormat>>\n >({});\n\n const messagesOrError = useMemo(() => {\n try {\n if (!allMessages) {\n throw new Error(\n __DEV__ ? `No messages were configured on the provider.` : undefined\n );\n }\n\n const retrievedMessages = namespace\n ? resolvePath(allMessages, namespace)\n : allMessages;\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 }, [allMessages, namespace, onError]);\n\n const translate = useMemo(() => {\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 const cachedFormatsByLocale = cachedFormatsByLocaleRef.current;\n\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]\n .filter((part) => part != null)\n .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[locale]) {\n cachedFormatsByLocale[locale] = {};\n }\n cachedFormatsByLocale[locale][cacheKey] = messageFormat;\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 message = translateBaseFn(key, values, formats);\n\n if (typeof message !== '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 message;\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 onError,\n getMessageFallback,\n namespace,\n messagesOrError,\n locale,\n globalFormats,\n timeZone,\n defaultTranslationValues\n ]);\n\n return translate;\n}\n","import {ReactElement, ReactNodeArray} from 'react';\nimport Formats from './Formats';\nimport IntlError, {IntlErrorCode} from './IntlError';\nimport TranslationValues, {RichTranslationValues} from './TranslationValues';\nimport useIntlContext from './useIntlContext';\nimport useTranslationsImpl from './useTranslationsImpl';\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 useTranslations<\n NestedKey extends NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>>\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 NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>> extends NestedKey\n ? '!'\n : `!.${NestedKey}`\n >,\n NestedKeyOf<\n NestedValueOf<\n {'!': IntlMessages},\n NamespaceKeys<\n IntlMessages,\n NestedKeyOf<IntlMessages>\n > extends NestedKey\n ? '!'\n : `!.${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 NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>> extends NestedKey\n ? '!'\n : `!.${NestedKey}`\n >,\n NestedKeyOf<\n NestedValueOf<\n {'!': IntlMessages},\n NamespaceKeys<\n IntlMessages,\n NestedKeyOf<IntlMessages>\n > extends NestedKey\n ? '!'\n : `!.${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 NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>> extends NestedKey\n ? '!'\n : `!.${NestedKey}`\n >,\n NestedKeyOf<\n NestedValueOf<\n {'!': IntlMessages},\n NamespaceKeys<\n IntlMessages,\n NestedKeyOf<IntlMessages>\n > extends NestedKey\n ? '!'\n : `!.${NestedKey}`\n >\n >\n >\n >(\n key: TargetKey\n ): any;\n} {\n const context = useIntlContext();\n\n const messages = context.messages as IntlMessages;\n if (!messages) {\n const intlError = new IntlError(\n IntlErrorCode.MISSING_MESSAGE,\n __DEV__ ? `No messages were configured on the provider.` : undefined\n );\n context.onError(intlError);\n throw intlError;\n }\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, but we have to use some.\n return useTranslationsImpl<\n {'!': IntlMessages},\n NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>> extends NestedKey\n ? '!'\n : `!.${NestedKey}`\n >(\n {'!': messages},\n // @ts-ignore\n namespace ? `!.${namespace}` : '!',\n '!'\n );\n}\n","import DateTimeFormatOptions from './DateTimeFormatOptions';\nimport IntlError, {IntlErrorCode} from './IntlError';\nimport NumberFormatOptions from './NumberFormatOptions';\nimport useIntlContext from './useIntlContext';\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\nexport default function useIntl() {\n const {formats, locale, now: globalNow, onError, timeZone} = useIntlContext();\n\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 __DEV__\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 formatDateTime(\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 formatNumber(\n value: number,\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 formatRelativeTime(\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 __DEV__\n ? `The \\`now\\` parameter wasn't provided to \\`formatRelativeTime\\` 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 return {formatDateTime, formatNumber, formatRelativeTime};\n}\n","import useIntlContext from './useIntlContext';\n\nexport default function useLocale() {\n return useIntlContext().locale;\n}\n","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","import useIntlContext from './useIntlContext';\n\nexport default function useTimeZone() {\n return useIntlContext().timeZone;\n}\n"],"names":["IntlContext","createContext","undefined","IntlErrorCode","IntlError","code","originalMessage","message","Error","validateMessagesSegment","messages","invalidKeyLabels","parentPath","Object","entries","forEach","key","messageOrMessages","includes","keyLabel","push","filter","part","join","validateMessages","onError","length","INVALID_KEY","defaultGetMessageFallback","namespace","defaultOnError","error","console","IntlProvider","children","getMessageFallback","contextValues","useEffect","React","Provider","value","useIntlContext","context","useContext","setTimeZoneInFormats","formats","timeZone","keys","reduce","acc","convertFormatsToIntlMessageFormat","formatsWithTimeZone","dateTime","date","time","resolvePath","idPath","split","next","prepareTranslationValues","values","transformedValues","index","transformed","result","isValidElement","cloneElement","useTranslationsImpl","allMessages","namespacePrefix","defaultTranslationValues","globalFormats","locale","slice","cachedFormatsByLocaleRef","useRef","messagesOrError","useMemo","retrievedMessages","intlError","MISSING_MESSAGE","translate","getFallbackFromErrorAndNotify","translateBaseFn","cachedFormatsByLocale","current","cacheKey","messageFormat","INSUFFICIENT_PATH","IntlMessageFormat","INVALID_MESSAGE","formattedMessage","format","Array","isArray","String","FORMATTING_ERROR","translateFn","rich","raw","useTranslations","MINUTE","HOUR","DAY","WEEK","MONTH","YEAR","getRelativeTimeFormatConfig","seconds","absValue","Math","abs","unit","round","useIntl","globalNow","now","resolveFormatOrOptions","typeFormats","formatOrOptions","options","formatName","MISSING_FORMAT","getFormattedValue","formatter","formatDateTime","Intl","DateTimeFormat","formatNumber","number","NumberFormat","formatRelativeTime","dateDate","Date","nowDate","getTime","RelativeTimeFormat","numeric","useLocale","getNow","useNow","updateInterval","useState","setNow","intervalId","setInterval","clearInterval","useTimeZone"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqBA,IAAMA,WAAW,gBAAGC,aAAa,CAA+BC,SAA/B,CAAjC;;ICrBYC,cAAZ;;AAAA,CAAA,UAAYA,aAAZ,EAAyB;AACvBA,EAAAA,aAAA,CAAA,iBAAA,CAAA,GAAA,iBAAA,CAAA;AACAA,EAAAA,aAAA,CAAA,gBAAA,CAAA,GAAA,gBAAA,CAAA;AACAA,EAAAA,aAAA,CAAA,mBAAA,CAAA,GAAA,mBAAA,CAAA;AACAA,EAAAA,aAAA,CAAA,iBAAA,CAAA,GAAA,iBAAA,CAAA;AACAA,EAAAA,aAAA,CAAA,aAAA,CAAA,GAAA,aAAA,CAAA;AACAA,EAAAA,aAA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MAAT,GAAe;AACb,EAAO,OAAA,IAAIN,IAAJ,EAAP,CAAA;AACD,CAAA;AAED;;;;;;;;;;;;;;;;;AAiBG;;;AACqB,SAAAO,MAAA,CAAOpB,OAAP,EAAwB;AAC9C,EAAA,IAAMqB,cAAc,GAAGrB,OAAH,IAAGA,IAAAA,GAAAA,KAAAA,CAAAA,GAAAA,OAAO,CAAEqB,cAAhC,CAAA;;AAEA,EAAA,IAAA,eAAA,GAAyBpG,cAAc,EAAvC;AAAA,MAAY0E,SAAZ,mBAAOC,GAAP,CAAA;;AACA,EAAA,IAAA,SAAA,GAAsB0B,QAAQ,CAAC3B,SAAS,IAAIwB,MAAM,EAApB,CAA9B;AAAA,MAAOvB,GAAP,GAAA,SAAA,CAAA,CAAA,CAAA;AAAA,MAAY2B,MAAZ,GAAA,SAAA,CAAA,CAAA,CAAA,CAAA;;AAEA1G,EAAAA,SAAS,CAAC,YAAK;AACb,IAAI,IAAA,CAACwG,cAAL,EAAqB,OAAA;AAErB,IAAA,IAAMG,UAAU,GAAGC,WAAW,CAAC,YAAK;AAClCF,MAAAA,MAAM,CAACJ,MAAM,EAAP,CAAN,CAAA;AACD,KAF6B,EAE3BE,cAF2B,CAA9B,CAAA;AAIA,IAAA,OAAO,YAAK;AACVK,MAAAA,aAAa,CAACF,UAAD,CAAb,CAAA;AACD,KAFD,CAAA;AAGD,GAVQ,EAUN,CAAC7B,SAAD,EAAY0B,cAAZ,CAVM,CAAT,CAAA;AAYA,EAAA,OAAOzB,GAAP,CAAA;AACD;;AC9Ca,SAAU+B,WAAV,GAAqB;AACjC,EAAO1G,OAAAA,cAAc,GAAGK,QAAxB,CAAA;AACD;;;;"}
@@ -0,0 +1,3 @@
1
+ import AbstractIntlMessages from './AbstractIntlMessages';
2
+ import IntlError from './IntlError';
3
+ export default function validateMessages(messages: AbstractIntlMessages, onError: (error: IntlError) => void): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "use-intl",
3
- "version": "2.6.0",
3
+ "version": "2.7.0",
4
4
  "sideEffects": false,
5
5
  "author": "Jan Amann <jan@amann.me>",
6
6
  "description": "Minimal, but complete solution for managing internationalization in React apps.",
@@ -59,5 +59,5 @@
59
59
  "engines": {
60
60
  "node": ">=10"
61
61
  },
62
- "gitHead": "3306b37d702db366464da11fc5b836a02f21d14c"
62
+ "gitHead": "36b019fbc9c58d69a9aa7b14076b0aad0e4d9c16"
63
63
  }
package/src/IntlError.tsx CHANGED
@@ -3,6 +3,7 @@ export enum IntlErrorCode {
3
3
  MISSING_FORMAT = 'MISSING_FORMAT',
4
4
  INSUFFICIENT_PATH = 'INSUFFICIENT_PATH',
5
5
  INVALID_MESSAGE = 'INVALID_MESSAGE',
6
+ INVALID_KEY = 'INVALID_KEY',
6
7
  FORMATTING_ERROR = 'FORMATTING_ERROR'
7
8
  }
8
9
 
@@ -1,8 +1,9 @@
1
- import React, {ReactNode} from 'react';
1
+ import React, {ReactNode, useEffect} from 'react';
2
2
  import AbstractIntlMessages from './AbstractIntlMessages';
3
3
  import Formats from './Formats';
4
4
  import IntlContext from './IntlContext';
5
5
  import {RichTranslationValues} from './TranslationValues';
6
+ import validateMessages from './validateMessages';
6
7
  import {IntlError} from '.';
7
8
 
8
9
  type Props = {
@@ -64,11 +65,21 @@ export default function IntlProvider({
64
65
  children,
65
66
  onError = defaultOnError,
66
67
  getMessageFallback = defaultGetMessageFallback,
68
+ messages,
67
69
  ...contextValues
68
70
  }: Props) {
71
+ if (__DEV__) {
72
+ // eslint-disable-next-line react-hooks/rules-of-hooks
73
+ useEffect(() => {
74
+ if (messages) {
75
+ validateMessages(messages, onError);
76
+ }
77
+ }, [messages, onError]);
78
+ }
79
+
69
80
  return (
70
81
  <IntlContext.Provider
71
- value={{...contextValues, onError, getMessageFallback}}
82
+ value={{...contextValues, messages, onError, getMessageFallback}}
72
83
  >
73
84
  {children}
74
85
  </IntlContext.Provider>
@@ -0,0 +1,42 @@
1
+ import AbstractIntlMessages from './AbstractIntlMessages';
2
+ import IntlError, {IntlErrorCode} from './IntlError';
3
+
4
+ function validateMessagesSegment(
5
+ messages: AbstractIntlMessages,
6
+ invalidKeyLabels: Array<string>,
7
+ parentPath?: string
8
+ ) {
9
+ Object.entries(messages).forEach(([key, messageOrMessages]) => {
10
+ if (key.includes('.')) {
11
+ let keyLabel = key;
12
+ if (parentPath) keyLabel += ` (at ${parentPath})`;
13
+ invalidKeyLabels.push(keyLabel);
14
+ }
15
+ if (typeof messageOrMessages === 'object') {
16
+ validateMessagesSegment(
17
+ messageOrMessages,
18
+ invalidKeyLabels,
19
+ [parentPath, key].filter((part) => part != null).join('.')
20
+ );
21
+ }
22
+ });
23
+ }
24
+
25
+ export default function validateMessages(
26
+ messages: AbstractIntlMessages,
27
+ onError: (error: IntlError) => void
28
+ ) {
29
+ const invalidKeyLabels: Array<string> = [];
30
+ validateMessagesSegment(messages, invalidKeyLabels);
31
+
32
+ if (invalidKeyLabels.length > 0) {
33
+ onError(
34
+ new IntlError(
35
+ IntlErrorCode.INVALID_KEY,
36
+ `Namespace keys can not contain the character "." as this is used to express nesting. Please remove it or replace it with another character.\n\nInvalid ${
37
+ invalidKeyLabels.length === 1 ? 'key' : 'keys'
38
+ }: ${invalidKeyLabels.join(', ')}`
39
+ )
40
+ );
41
+ }
42
+ }