use-intl 1.5.1 → 2.0.2

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.
@@ -311,7 +311,7 @@ function useTranslations(namespace) {
311
311
  }
312
312
  }, [allMessages, namespace, onError]);
313
313
  var translate = React.useMemo(function () {
314
- function getFallbackFromError(key, code, message) {
314
+ function getFallbackFromErrorAndNotify(key, code, message) {
315
315
  var error = new IntlError(code, message);
316
316
  onError(error);
317
317
  return getMessageFallback({
@@ -321,7 +321,7 @@ function useTranslations(namespace) {
321
321
  });
322
322
  }
323
323
 
324
- function translateFn(
324
+ function translateBaseFn(
325
325
  /** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */
326
326
  key,
327
327
  /** Key value pairs for values to interpolate into the message. */
@@ -342,52 +342,75 @@ function useTranslations(namespace) {
342
342
  }
343
343
 
344
344
  var messages = messagesOrError;
345
+ var cacheKey = [namespace, key].filter(function (part) {
346
+ return part != null;
347
+ }).join('.');
345
348
  var messageFormat;
346
349
 
347
- if ((_cachedFormatsByLocal = cachedFormatsByLocale[locale]) != null && _cachedFormatsByLocal[key]) {
348
- messageFormat = cachedFormatsByLocale[locale][key];
350
+ if ((_cachedFormatsByLocal = cachedFormatsByLocale[locale]) != null && _cachedFormatsByLocal[cacheKey]) {
351
+ messageFormat = cachedFormatsByLocale[locale][cacheKey];
349
352
  } else {
350
353
  var message;
351
354
 
352
355
  try {
353
356
  message = resolvePath(messages, key, namespace);
354
357
  } catch (error) {
355
- return getFallbackFromError(key, exports.IntlErrorCode.MISSING_MESSAGE, error.message);
358
+ return getFallbackFromErrorAndNotify(key, exports.IntlErrorCode.MISSING_MESSAGE, error.message);
356
359
  }
357
360
 
358
361
  if (typeof message === 'object') {
359
- return getFallbackFromError(key, exports.IntlErrorCode.INSUFFICIENT_PATH, "Insufficient path specified for `" + key + "` in `" + namespace + "`." );
362
+ return getFallbackFromErrorAndNotify(key, exports.IntlErrorCode.INSUFFICIENT_PATH, "Insufficient path specified for `" + key + "` in `" + (namespace ? "`" + namespace + "`" : 'messages') + "`." );
360
363
  }
361
364
 
362
365
  try {
363
366
  messageFormat = new IntlMessageFormat(message, locale, convertFormatsToIntlMessageFormat(_extends({}, globalFormats, formats), timeZone));
364
367
  } catch (error) {
365
- return getFallbackFromError(key, exports.IntlErrorCode.INVALID_MESSAGE, error.message);
368
+ return getFallbackFromErrorAndNotify(key, exports.IntlErrorCode.INVALID_MESSAGE, error.message);
366
369
  }
367
370
 
368
371
  if (!cachedFormatsByLocale[locale]) {
369
372
  cachedFormatsByLocale[locale] = {};
370
373
  }
371
374
 
372
- cachedFormatsByLocale[locale][key] = messageFormat;
375
+ cachedFormatsByLocale[locale][cacheKey] = messageFormat;
373
376
  }
374
377
 
375
378
  try {
376
379
  var formattedMessage = messageFormat.format(prepareTranslationValues(values));
377
380
 
378
381
  if (formattedMessage == null) {
379
- throw new Error("development" !== "production" ? "Unable to format " + [namespace, key].join('.') : undefined);
382
+ throw new Error("development" !== "production" ? "Unable to format `" + key + "` in " + (namespace ? "namespace `" + namespace + "`" : 'messages') : undefined);
380
383
  } // Limit the function signature to return strings or React elements
381
384
 
382
385
 
383
386
  return React.isValidElement(formattedMessage) || // Arrays of React elements
384
387
  Array.isArray(formattedMessage) || typeof formattedMessage === 'string' ? formattedMessage : String(formattedMessage);
385
388
  } catch (error) {
386
- return getFallbackFromError(key, exports.IntlErrorCode.FORMATTING_ERROR, error.message);
389
+ return getFallbackFromErrorAndNotify(key, exports.IntlErrorCode.FORMATTING_ERROR, error.message);
387
390
  }
388
391
  }
389
392
 
390
- translateFn.raw = function (key) {
393
+ function translateFn(
394
+ /** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */
395
+ key,
396
+ /** Key value pairs for values to interpolate into the message. */
397
+ values,
398
+ /** Provide custom formats for numbers, dates and times. */
399
+ formats) {
400
+ var message = translateBaseFn(key, values, formats);
401
+
402
+ if (typeof message !== 'string') {
403
+ return getFallbackFromErrorAndNotify(key, exports.IntlErrorCode.INVALID_MESSAGE, "The message `" + key + "` in " + (namespace ? "namespace `" + namespace + "`" : 'messages') + " didn't resolve to a string. If you want to format rich text, use `t.rich` instead." );
404
+ }
405
+
406
+ return message;
407
+ }
408
+
409
+ translateFn.rich = translateBaseFn;
410
+
411
+ translateFn.raw = function (
412
+ /** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */
413
+ key) {
391
414
  if (messagesOrError instanceof IntlError) {
392
415
  // We have already warned about this during render
393
416
  return getMessageFallback({
@@ -402,7 +425,7 @@ function useTranslations(namespace) {
402
425
  try {
403
426
  return resolvePath(messages, key, namespace);
404
427
  } catch (error) {
405
- return getFallbackFromError(key, exports.IntlErrorCode.MISSING_MESSAGE, error.message);
428
+ return getFallbackFromErrorAndNotify(key, exports.IntlErrorCode.MISSING_MESSAGE, error.message);
406
429
  }
407
430
  };
408
431
 
@@ -1 +1 @@
1
- {"version":3,"file":"use-intl.cjs.development.js","sources":["../src/IntlContext.tsx","../src/IntlProvider.tsx","../src/IntlError.tsx","../src/convertFormatsToIntlMessageFormat.tsx","../src/useIntlContext.tsx","../src/useTranslations.tsx","../src/useIntl.tsx","../src/useNow.tsx"],"sourcesContent":["import {createContext} from 'react';\nimport Formats from './Formats';\nimport IntlError from './IntlError';\nimport IntlMessages from './IntlMessages';\n\nexport type IntlContextShape = {\n messages?: IntlMessages;\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};\n\nconst IntlContext = createContext<IntlContextShape | undefined>(undefined);\n\nexport default IntlContext;\n","import React, {ReactNode} from 'react';\nimport Formats from './Formats';\nimport IntlContext from './IntlContext';\nimport IntlMessages from './IntlMessages';\nimport {IntlError} from '.';\n\ntype Props = {\n /** All messages that will be available in your components. */\n messages?: IntlMessages;\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};\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 {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 {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 IntlMessageFormat from 'intl-messageformat';\nimport {\n cloneElement,\n isValidElement,\n ReactElement,\n ReactNode,\n ReactNodeArray,\n useMemo,\n useRef\n} from 'react';\nimport Formats from './Formats';\nimport IntlError, {IntlErrorCode} from './IntlError';\nimport IntlMessages from './IntlMessages';\nimport TranslationValues from './TranslationValues';\nimport convertFormatsToIntlMessageFormat from './convertFormatsToIntlMessageFormat';\nimport useIntlContext from './useIntlContext';\n\nfunction resolvePath(\n messages: IntlMessages | 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?: TranslationValues) {\n if (!values) return values;\n\n // Workaround for https://github.com/formatjs/formatjs/issues/1467\n const transformedValues: TranslationValues = {};\n Object.keys(values).forEach((key) => {\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, {\n key: result.key || key + String(children)\n })\n : result;\n };\n } else {\n transformed = value;\n }\n\n transformedValues[key] = transformed;\n });\n\n return transformedValues;\n}\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(namespace?: string) {\n const {\n formats: globalFormats,\n getMessageFallback,\n locale,\n messages: allMessages,\n onError,\n timeZone\n } = useIntlContext();\n\n const cachedFormatsByLocaleRef = useRef<\n Record<string, Record<string, IntlMessageFormat>>\n >({});\n\n const messagesOrError = useMemo(() => {\n try {\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.message\n );\n onError(intlError);\n return intlError;\n }\n }, [allMessages, namespace, onError]);\n\n const translate = useMemo(() => {\n function getFallbackFromError(\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 translateFn(\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?: TranslationValues,\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 let messageFormat;\n if (cachedFormatsByLocale[locale]?.[key]) {\n messageFormat = cachedFormatsByLocale[locale][key];\n } else {\n let message;\n try {\n message = resolvePath(messages, key, namespace);\n } catch (error) {\n return getFallbackFromError(\n key,\n IntlErrorCode.MISSING_MESSAGE,\n error.message\n );\n }\n\n if (typeof message === 'object') {\n return getFallbackFromError(\n key,\n IntlErrorCode.INSUFFICIENT_PATH,\n __DEV__\n ? `Insufficient path specified for \\`${key}\\` in \\`${namespace}\\`.`\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 getFallbackFromError(\n key,\n IntlErrorCode.INVALID_MESSAGE,\n error.message\n );\n }\n\n if (!cachedFormatsByLocale[locale]) {\n cachedFormatsByLocale[locale] = {};\n }\n cachedFormatsByLocale[locale][key] = messageFormat;\n }\n\n try {\n const formattedMessage = messageFormat.format(\n prepareTranslationValues(values)\n );\n\n if (formattedMessage == null) {\n throw new Error(\n __DEV__\n ? `Unable to format ${[namespace, key].join('.')}`\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 getFallbackFromError(\n key,\n IntlErrorCode.FORMATTING_ERROR,\n error.message\n );\n }\n }\n\n translateFn.raw = (key: string): 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 getFallbackFromError(\n key,\n IntlErrorCode.MISSING_MESSAGE,\n error.message\n );\n }\n };\n\n return translateFn;\n }, [\n getMessageFallback,\n globalFormats,\n locale,\n messagesOrError,\n namespace,\n onError,\n timeZone\n ]);\n\n return translate;\n}\n","import DateTimeFormatOptions from './DateTimeFormatOptions';\nimport IntlError, {IntlErrorCode} from './IntlError';\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(new IntlError(IntlErrorCode.FORMATTING_ERROR, error.message));\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 | Intl.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(new IntlError(IntlErrorCode.FORMATTING_ERROR, error.message));\n return String(date);\n }\n }\n\n return {formatDateTime, formatNumber, formatRelativeTime};\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"],"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","setTimeZoneInFormats","formats","timeZone","Object","keys","reduce","acc","convertFormatsToIntlMessageFormat","formatsWithTimeZone","dateTime","date","time","useIntlContext","context","useContext","resolvePath","messages","idPath","split","forEach","next","prepareTranslationValues","values","transformedValues","transformed","result","isValidElement","cloneElement","String","useTranslations","globalFormats","locale","allMessages","cachedFormatsByLocaleRef","useRef","messagesOrError","useMemo","retrievedMessages","intlError","MISSING_MESSAGE","translate","getFallbackFromError","translateFn","cachedFormatsByLocale","current","messageFormat","INSUFFICIENT_PATH","IntlMessageFormat","INVALID_MESSAGE","formattedMessage","format","Array","isArray","FORMATTING_ERROR","raw","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","getNow","useNow","updateInterval","useState","setNow","useEffect","intervalId","setInterval","clearInterval"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmBA,IAAMA,WAAW,gBAAGC,mBAAa,CAA+BC,SAA/B,CAAjC;;ACwBA,SAASC,yBAAT;MACEC,WAAAA;MACAC,iBAAAA;AAKA,SAAO,CAACA,SAAD,EAAYD,GAAZ,EAAiBE,MAAjB,CAAwB,UAACC,IAAD;AAAA,WAAUA,IAAI,IAAI,IAAlB;AAAA,GAAxB,EAAgDC,IAAhD,CAAqD,GAArD,CAAP;AACD;;AAED,SAASC,cAAT,CAAwBC,KAAxB;AACEC,EAAAA,OAAO,CAACD,KAAR,CAAcA,K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":["../src/IntlContext.tsx","../src/IntlProvider.tsx","../src/IntlError.tsx","../src/convertFormatsToIntlMessageFormat.tsx","../src/useIntlContext.tsx","../src/useTranslations.tsx","../src/useIntl.tsx","../src/useNow.tsx"],"sourcesContent":["import {createContext} from 'react';\nimport Formats from './Formats';\nimport IntlError from './IntlError';\nimport IntlMessages from './IntlMessages';\n\nexport type IntlContextShape = {\n messages?: IntlMessages;\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};\n\nconst IntlContext = createContext<IntlContextShape | undefined>(undefined);\n\nexport default IntlContext;\n","import React, {ReactNode} from 'react';\nimport Formats from './Formats';\nimport IntlContext from './IntlContext';\nimport IntlMessages from './IntlMessages';\nimport {IntlError} from '.';\n\ntype Props = {\n /** All messages that will be available in your components. */\n messages?: IntlMessages;\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};\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 {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 {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 IntlMessageFormat from 'intl-messageformat';\nimport {\n cloneElement,\n isValidElement,\n ReactElement,\n ReactNode,\n ReactNodeArray,\n useMemo,\n useRef\n} from 'react';\nimport Formats from './Formats';\nimport IntlError, {IntlErrorCode} from './IntlError';\nimport IntlMessages from './IntlMessages';\nimport TranslationValues from './TranslationValues';\nimport convertFormatsToIntlMessageFormat from './convertFormatsToIntlMessageFormat';\nimport useIntlContext from './useIntlContext';\n\nfunction resolvePath(\n messages: IntlMessages | 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?: TranslationValues) {\n if (!values) return values;\n\n // Workaround for https://github.com/formatjs/formatjs/issues/1467\n const transformedValues: TranslationValues = {};\n Object.keys(values).forEach((key) => {\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, {\n key: result.key || key + String(children)\n })\n : result;\n };\n } else {\n transformed = value;\n }\n\n transformedValues[key] = transformed;\n });\n\n return transformedValues;\n}\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(namespace?: string) {\n const {\n formats: globalFormats,\n getMessageFallback,\n locale,\n messages: allMessages,\n onError,\n timeZone\n } = useIntlContext();\n\n const cachedFormatsByLocaleRef = useRef<\n Record<string, Record<string, IntlMessageFormat>>\n >({});\n\n const messagesOrError = useMemo(() => {\n try {\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.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?: TranslationValues,\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.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.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 prepareTranslationValues(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.message\n );\n }\n }\n\n function translateFn(\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?: 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.message\n );\n }\n };\n\n return translateFn;\n }, [\n getMessageFallback,\n globalFormats,\n locale,\n messagesOrError,\n namespace,\n onError,\n timeZone\n ]);\n\n return translate;\n}\n","import DateTimeFormatOptions from './DateTimeFormatOptions';\nimport IntlError, {IntlErrorCode} from './IntlError';\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(new IntlError(IntlErrorCode.FORMATTING_ERROR, error.message));\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 | Intl.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(new IntlError(IntlErrorCode.FORMATTING_ERROR, error.message));\n return String(date);\n }\n }\n\n return {formatDateTime, formatNumber, formatRelativeTime};\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"],"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","setTimeZoneInFormats","formats","timeZone","Object","keys","reduce","acc","convertFormatsToIntlMessageFormat","formatsWithTimeZone","dateTime","date","time","useIntlContext","context","useContext","resolvePath","messages","idPath","split","forEach","next","prepareTranslationValues","values","transformedValues","transformed","result","isValidElement","cloneElement","String","useTranslations","globalFormats","locale","allMessages","cachedFormatsByLocaleRef","useRef","messagesOrError","useMemo","retrievedMessages","intlError","MISSING_MESSAGE","translate","getFallbackFromErrorAndNotify","translateBaseFn","cachedFormatsByLocale","current","cacheKey","messageFormat","INSUFFICIENT_PATH","IntlMessageFormat","INVALID_MESSAGE","formattedMessage","format","Array","isArray","FORMATTING_ERROR","translateFn","rich","raw","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","getNow","useNow","updateInterval","useState","setNow","useEffect","intervalId","setInterval","clearInterval"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmBA,IAAMA,WAAW,gBAAGC,mBAAa,CAA+BC,SAA/B,CAAjC;;ACwBA,SAASC,yBAAT;MACEC,WAAAA;MACAC,iBAAAA;AAKA,SAAO,CAACA,SAAD,EAAYD,GAAZ,EAAiBE,MAAjB,CAAwB,UAACC,IAAD;AAAA,WAAUA,IAAI,IAAI,IAAlB;AAAA,GAAxB,EAAgDC,IAAhD,CAAqD,GAArD,CAAP;AACD;;A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YAAY,EAAZA,YAAjB;AAA+BG,IAAAA,kBAAkB,EAAlBA;AAA/B,GAAP;AACD;;AC3JD,SAASO,MAAT;AACE,SAAO,IAAIL,IAAJ,EAAP;AACD;AAED;;;;;;;;;;;;;;;;;;;;AAkBA,SAAwBM,OAAOnB;AAC7B,MAAMoB,cAAc,GAAGpB,OAAH,oBAAGA,OAAO,CAAEoB,cAAhC;;wBAEyBrF,cAAc;MAA3B4D,4BAALC;;kBACeyB,cAAQ,CAAC1B,SAAS,IAAIuB,MAAM,EAApB;MAAvBtB;MAAK0B;;AAEZC,EAAAA,eAAS,CAAC;AACR,QAAI,CAACH,cAAL,EAAqB;AAErB,QAAMI,UAAU,GAAGC,WAAW,CAAC;AAC7BH,MAAAA,MAAM,CAACJ,MAAM,EAAP,CAAN;AACD,KAF6B,EAE3BE,cAF2B,CAA9B;AAIA,WAAO;AACLM,MAAAA,aAAa,CAACF,UAAD,CAAb;AACD,KAFD;AAGD,GAVQ,EAUN,CAAC7B,SAAD,EAAYyB,cAAZ,CAVM,CAAT;AAYA,SAAOxB,GAAP;AACD;;;;;;;;"}
@@ -1,2 +1,2 @@
1
- "use strict";function r(r){return r&&"object"==typeof r&&"default"in r?r.default:r}Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=r(e),n=r(require("intl-messageformat"));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}).apply(this,arguments)}function u(r){return(u=Object.setPrototypeOf?Object.getPrototypeOf:function(r){return r.__proto__||Object.getPrototypeOf(r)})(r)}function a(r,e){return(a=Object.setPrototypeOf||function(r,e){return r.__proto__=e,r})(r,e)}function i(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(r){return!1}}function c(r,e,t){return(c=i()?Reflect.construct:function(r,e,t){var n=[null];n.push.apply(n,e);var o=new(Function.bind.apply(r,n));return t&&a(o,t.prototype),o}).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}}),a(t,r)})(r)}var l,s=e.createContext(void 0);function p(r){return[r.namespace,r.key].filter((function(r){return null!=r})).join(".")}function v(r){console.error(r)}(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 d=function(r){var e,t;function n(e,t){var n,o=e;return t&&(o+=": "+t),(n=r.call(this,o)||this).code=e,t&&(n.originalMessage=t),n}return t=r,(e=n).prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t,n}(f(Error));function m(r,e){return r?Object.keys(r).reduce((function(t,n){return t[n]=o({timeZone:e},r[n]),t}),{}):r}function E(){var r=e.useContext(s);if(!r)throw new Error(void 0);return r}function I(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 y(){return new Date}exports.IntlError=d,exports.IntlProvider=function(r){var e=r.children,n=r.onError,u=void 0===n?v:n,a=r.getMessageFallback,i=void 0===a?p:a,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,["children","onError","getMessageFallback"]);return t.createElement(s.Provider,{value:o({},c,{onError:u,getMessageFallback:i})},e)},exports.useIntl=function(){var r=E(),e=r.formats,t=r.locale,n=r.now,u=r.onError,a=r.timeZone;function i(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 d(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 d(exports.IntlErrorCode.FORMATTING_ERROR,e.message)),String(r)}}return{formatDateTime:function(r,n){return i(r,n,null==e?void 0:e.dateTime,(function(e){var n;return!a||null!=(n=e)&&n.timeZone||(e=o({},e,{timeZone:a})),new Intl.DateTimeFormat(t,e).format(r)}))},formatNumber:function(r,n){return i(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),a=e instanceof Date?e:new Date(e),i=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()-a.getTime())/1e3),c=i.unit,f=i.value;return new Intl.RelativeTimeFormat(t,{numeric:"auto"}).format(f,c)}catch(e){return u(new d(exports.IntlErrorCode.FORMATTING_ERROR,e.message)),String(r)}}}},exports.useNow=function(r){var t=null==r?void 0:r.updateInterval,n=E().now,o=e.useState(n||y()),u=o[0],a=o[1];return e.useEffect((function(){if(t){var r=setInterval((function(){a(y())}),t);return function(){clearInterval(r)}}}),[n,t]),u},exports.useTranslations=function(r){var t=E(),u=t.formats,a=t.getMessageFallback,i=t.locale,c=t.messages,f=t.onError,l=t.timeZone,s=e.useRef({}),p=e.useMemo((function(){try{var e=r?I(c,r):c;if(!e)throw new Error(void 0);return e}catch(r){var t=new d(exports.IntlErrorCode.MISSING_MESSAGE,r.message);return f(t),t}}),[c,r,f]);return e.useMemo((function(){function t(e,t,n){var o=new d(t,n);return f(o),a({error:o,key:e,namespace:r})}function c(c,f,v){var E,y=s.current;if(p instanceof d)return a({error:p,key:c,namespace:r});var S,h=p;if(null!=(E=y[i])&&E[c])S=y[i][c];else{var M;try{M=I(h,c)}catch(r){return t(c,exports.IntlErrorCode.MISSING_MESSAGE,r.message)}if("object"==typeof M)return t(c,exports.IntlErrorCode.INSUFFICIENT_PATH,void 0);try{S=new n(M,i,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({},u,v),l))}catch(r){return t(c,exports.IntlErrorCode.INVALID_MESSAGE,r.message)}y[i]||(y[i]={}),y[i][c]=S}try{var g=S.format(function(r){if(!r)return r;var t={};return Object.keys(r).forEach((function(n){var o=r[n];t[n]="function"==typeof o?function(r){var t=o(r);return e.isValidElement(t)?e.cloneElement(t,{key:t.key||n+String(r)}):t}:o})),t}(f));if(null==g)throw new Error(void 0);return e.isValidElement(g)||Array.isArray(g)||"string"==typeof g?g:String(g)}catch(r){return t(c,exports.IntlErrorCode.FORMATTING_ERROR,r.message)}}return c.raw=function(e){if(p instanceof d)return a({error:p,key:e,namespace:r});var n=p;try{return I(n,e)}catch(r){return t(e,exports.IntlErrorCode.MISSING_MESSAGE,r.message)}},c}),[a,u,i,p,r,f,l])};
1
+ "use strict";function r(r){return r&&"object"==typeof r&&"default"in r?r.default:r}Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=r(e),n=r(require("intl-messageformat"));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}).apply(this,arguments)}function u(r){return(u=Object.setPrototypeOf?Object.getPrototypeOf:function(r){return r.__proto__||Object.getPrototypeOf(r)})(r)}function i(r,e){return(i=Object.setPrototypeOf||function(r,e){return r.__proto__=e,r})(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 Date.prototype.toString.call(Reflect.construct(Date,[],(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}).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)})(r)}var l,s=e.createContext(void 0);function p(r){return[r.namespace,r.key].filter((function(r){return null!=r})).join(".")}function v(r){console.error(r)}(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 d=function(r){var e,t;function n(e,t){var n,o=e;return t&&(o+=": "+t),(n=r.call(this,o)||this).code=e,t&&(n.originalMessage=t),n}return t=r,(e=n).prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t,n}(f(Error));function E(r,e){return r?Object.keys(r).reduce((function(t,n){return t[n]=o({timeZone:e},r[n]),t}),{}):r}function I(){var r=e.useContext(s);if(!r)throw new Error(void 0);return r}function m(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 y(){return new Date}exports.IntlError=d,exports.IntlProvider=function(r){var e=r.children,n=r.onError,u=void 0===n?v:n,i=r.getMessageFallback,a=void 0===i?p: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,["children","onError","getMessageFallback"]);return t.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 d(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 d(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 d(exports.IntlErrorCode.FORMATTING_ERROR,e.message)),String(r)}}}},exports.useNow=function(r){var t=null==r?void 0:r.updateInterval,n=I().now,o=e.useState(n||y()),u=o[0],i=o[1];return e.useEffect((function(){if(t){var r=setInterval((function(){i(y())}),t);return function(){clearInterval(r)}}}),[n,t]),u},exports.useTranslations=function(r){var t=I(),u=t.formats,i=t.getMessageFallback,a=t.locale,c=t.messages,f=t.onError,l=t.timeZone,s=e.useRef({}),p=e.useMemo((function(){try{var e=r?m(c,r):c;if(!e)throw new Error(void 0);return e}catch(r){var t=new d(exports.IntlErrorCode.MISSING_MESSAGE,r.message);return f(t),t}}),[c,r,f]);return e.useMemo((function(){function t(e,t,n){var o=new d(t,n);return f(o),i({error:o,key:e,namespace:r})}function c(c,f,v){var I,y=s.current;if(p instanceof d)return i({error:p,key:c,namespace:r});var S,h=p,M=[r,c].filter((function(r){return null!=r})).join(".");if(null!=(I=y[a])&&I[M])S=y[a][M];else{var g;try{g=m(h,c)}catch(r){return t(c,exports.IntlErrorCode.MISSING_MESSAGE,r.message)}if("object"==typeof g)return t(c,exports.IntlErrorCode.INSUFFICIENT_PATH,void 0);try{S=new n(g,a,function(r,e){var t=e?o({},r,{dateTime:E(r.dateTime,e)}):r;return o({},t,{date:null==t?void 0:t.dateTime,time:null==t?void 0:t.dateTime})}(o({},u,v),l))}catch(r){return t(c,exports.IntlErrorCode.INVALID_MESSAGE,r.message)}y[a]||(y[a]={}),y[a][M]=S}try{var w=S.format(function(r){if(!r)return r;var t={};return Object.keys(r).forEach((function(n){var o=r[n];t[n]="function"==typeof o?function(r){var t=o(r);return e.isValidElement(t)?e.cloneElement(t,{key:t.key||n+String(r)}):t}:o})),t}(f));if(null==w)throw new Error(void 0);return e.isValidElement(w)||Array.isArray(w)||"string"==typeof w?w:String(w)}catch(r){return t(c,exports.IntlErrorCode.FORMATTING_ERROR,r.message)}}function v(r,e,n){var o=c(r,e,n);return"string"!=typeof o?t(r,exports.IntlErrorCode.INVALID_MESSAGE,void 0):o}return v.rich=c,v.raw=function(e){if(p instanceof d)return i({error:p,key:e,namespace:r});var n=p;try{return m(n,e)}catch(r){return t(e,exports.IntlErrorCode.MISSING_MESSAGE,r.message)}},v}),[i,u,a,p,r,f,l])};
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/convertFormatsToIntlMessageFormat.tsx","../src/useIntlContext.tsx","../src/useTranslations.tsx","../src/useNow.tsx","../src/useIntl.tsx"],"sourcesContent":["import {createContext} from 'react';\nimport Formats from './Formats';\nimport IntlError from './IntlError';\nimport IntlMessages from './IntlMessages';\n\nexport type IntlContextShape = {\n messages?: IntlMessages;\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};\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 Formats from './Formats';\nimport IntlContext from './IntlContext';\nimport IntlMessages from './IntlMessages';\nimport {IntlError} from '.';\n\ntype Props = {\n /** All messages that will be available in your components. */\n messages?: IntlMessages;\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};\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 {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 {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 IntlMessageFormat from 'intl-messageformat';\nimport {\n cloneElement,\n isValidElement,\n ReactElement,\n ReactNode,\n ReactNodeArray,\n useMemo,\n useRef\n} from 'react';\nimport Formats from './Formats';\nimport IntlError, {IntlErrorCode} from './IntlError';\nimport IntlMessages from './IntlMessages';\nimport TranslationValues from './TranslationValues';\nimport convertFormatsToIntlMessageFormat from './convertFormatsToIntlMessageFormat';\nimport useIntlContext from './useIntlContext';\n\nfunction resolvePath(\n messages: IntlMessages | 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?: TranslationValues) {\n if (!values) return values;\n\n // Workaround for https://github.com/formatjs/formatjs/issues/1467\n const transformedValues: TranslationValues = {};\n Object.keys(values).forEach((key) => {\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, {\n key: result.key || key + String(children)\n })\n : result;\n };\n } else {\n transformed = value;\n }\n\n transformedValues[key] = transformed;\n });\n\n return transformedValues;\n}\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(namespace?: string) {\n const {\n formats: globalFormats,\n getMessageFallback,\n locale,\n messages: allMessages,\n onError,\n timeZone\n } = useIntlContext();\n\n const cachedFormatsByLocaleRef = useRef<\n Record<string, Record<string, IntlMessageFormat>>\n >({});\n\n const messagesOrError = useMemo(() => {\n try {\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.message\n );\n onError(intlError);\n return intlError;\n }\n }, [allMessages, namespace, onError]);\n\n const translate = useMemo(() => {\n function getFallbackFromError(\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 translateFn(\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?: TranslationValues,\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 let messageFormat;\n if (cachedFormatsByLocale[locale]?.[key]) {\n messageFormat = cachedFormatsByLocale[locale][key];\n } else {\n let message;\n try {\n message = resolvePath(messages, key, namespace);\n } catch (error) {\n return getFallbackFromError(\n key,\n IntlErrorCode.MISSING_MESSAGE,\n error.message\n );\n }\n\n if (typeof message === 'object') {\n return getFallbackFromError(\n key,\n IntlErrorCode.INSUFFICIENT_PATH,\n __DEV__\n ? `Insufficient path specified for \\`${key}\\` in \\`${namespace}\\`.`\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 getFallbackFromError(\n key,\n IntlErrorCode.INVALID_MESSAGE,\n error.message\n );\n }\n\n if (!cachedFormatsByLocale[locale]) {\n cachedFormatsByLocale[locale] = {};\n }\n cachedFormatsByLocale[locale][key] = messageFormat;\n }\n\n try {\n const formattedMessage = messageFormat.format(\n prepareTranslationValues(values)\n );\n\n if (formattedMessage == null) {\n throw new Error(\n __DEV__\n ? `Unable to format ${[namespace, key].join('.')}`\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 getFallbackFromError(\n key,\n IntlErrorCode.FORMATTING_ERROR,\n error.message\n );\n }\n }\n\n translateFn.raw = (key: string): 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 getFallbackFromError(\n key,\n IntlErrorCode.MISSING_MESSAGE,\n error.message\n );\n }\n };\n\n return translateFn;\n }, [\n getMessageFallback,\n globalFormats,\n locale,\n messagesOrError,\n namespace,\n onError,\n timeZone\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 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(new IntlError(IntlErrorCode.FORMATTING_ERROR, error.message));\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 | Intl.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(new IntlError(IntlErrorCode.FORMATTING_ERROR, error.message));\n return String(date);\n }\n }\n\n return {formatDateTime, formatNumber, formatRelativeTime};\n}\n"],"names":["IntlErrorCode","IntlContext","createContext","undefined","defaultGetMessageFallback","namespace","key","filter","part","join","defaultOnError","error","console","IntlError","code","originalMessage","message","Error","setTimeZoneInFormats","formats","timeZone","Object","keys","reduce","acc","useIntlContext","context","useContext","resolvePath","messages","idPath","split","forEach","next","getNow","Date","children","onError","getMessageFallback","contextValues","React","Provider","value","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","seconds","unit","absValue","Math","abs","round","MINUTE","HOUR","DAY","getRelativeTimeFormatConfig","getTime","RelativeTimeFormat","numeric","updateInterval","useState","setNow","useEffect","intervalId","setInterval","clearInterval","globalFormats","allMessages","cachedFormatsByLocaleRef","useRef","messagesOrError","useMemo","retrievedMessages","intlError","MISSING_MESSAGE","getFallbackFromError","translateFn","values","cachedFormatsByLocale","current","messageFormat","_cachedFormatsByLocal","INSUFFICIENT_PATH","IntlMessageFormat","formatsWithTimeZone","time","convertFormatsToIntlMessageFormat","INVALID_MESSAGE","formattedMessage","transformedValues","result","isValidElement","cloneElement","prepareTranslationValues","Array","isArray","raw"],"mappings":"khDAmBA,ICnBYA,EDmBNC,EAAcC,qBAA4CC,GEwBhE,SAASC,WAOA,GALPC,YADAC,KAMwBC,QAAO,SAACC,UAAiB,MAARA,KAAcC,KAAK,KAG9D,SAASC,EAAeC,GACtBC,QAAQD,MAAMA,IDtDJX,EAAAA,wBAAAA,6DAEVA,kCACAA,wCACAA,oCACAA,0CAGmBa,iCAIPC,EAAqBC,SAC3BC,EAAkBF,SAClBC,IACFC,GAAW,KAAOD,kBAEdC,UAEDF,KAAOA,EACRC,MACGA,gBAAkBA,wGAbUE,QEJvC,SAASC,EACPC,EACAC,UAEKD,EAIEE,OAAOC,KAAKH,GAASI,QAC1B,SAACC,EAA4ClB,UAC3CkB,EAAIlB,MACFc,SAAAA,GACGD,EAAQb,IAENkB,IAET,IAZmBL,WCLCM,QAChBC,EAAUC,aAAW1B,OAEtByB,QACG,IAAIT,WAGJd,UAIDuB,WCGAE,EACPC,EACAC,EACAzB,OAEKwB,QACG,IAAIZ,WACiDd,OAIzDa,EAAUa,SAEdC,EAAOC,MAAM,KAAKC,SAAQ,SAACxB,OACnByB,EAAQjB,EAAgBR,MAElB,MAARA,GAAwB,MAARyB,QACZ,IAAIhB,WAKJd,GAIRa,EAAUiB,KAGLjB,WCvCAkB,WACA,IAAIC,8DJkDXC,IAAAA,aACAC,QAAAA,aAAU3B,QACV4B,mBAAAA,aAAqBlC,IAClBmC,2LAGDC,gBAACvC,EAAYwC,UACXC,WAAWH,GAAeF,QAAAA,EAASC,mBAAAA,KAElCF,oBKvBP,iBAC+DX,IAAtDN,IAAAA,QAASwB,IAAAA,OAAaC,IAAL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,UACAsF,EACL3F,EACAN,sBAAcsD,iBACd3C,EAAMK,iBAKZkF,EAAYoB,IAAM,SAAChH,MACbsF,aAA2B/E,SAEtByB,EAAmB,CACxB3B,MAAOiF,EACPtF,IAAAA,EACAD,UAAAA,QAGEwB,EAAW+D,aAGRhE,EAAYC,EAAUvB,GAC7B,MAAOK,UACAsF,EACL3F,EACAN,sBAAcgG,gBACdrF,EAAMK,WAKLkF,IACN,CACD5D,EACAkD,EACA7C,EACAiD,EACAvF,EACAgC,EACAjB"}
1
+ {"version":3,"file":"use-intl.cjs.production.min.js","sources":["../src/IntlContext.tsx","../src/IntlError.tsx","../src/IntlProvider.tsx","../src/convertFormatsToIntlMessageFormat.tsx","../src/useIntlContext.tsx","../src/useTranslations.tsx","../src/useNow.tsx","../src/useIntl.tsx"],"sourcesContent":["import {createContext} from 'react';\nimport Formats from './Formats';\nimport IntlError from './IntlError';\nimport IntlMessages from './IntlMessages';\n\nexport type IntlContextShape = {\n messages?: IntlMessages;\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};\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 Formats from './Formats';\nimport IntlContext from './IntlContext';\nimport IntlMessages from './IntlMessages';\nimport {IntlError} from '.';\n\ntype Props = {\n /** All messages that will be available in your components. */\n messages?: IntlMessages;\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};\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 {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 {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 IntlMessageFormat from 'intl-messageformat';\nimport {\n cloneElement,\n isValidElement,\n ReactElement,\n ReactNode,\n ReactNodeArray,\n useMemo,\n useRef\n} from 'react';\nimport Formats from './Formats';\nimport IntlError, {IntlErrorCode} from './IntlError';\nimport IntlMessages from './IntlMessages';\nimport TranslationValues from './TranslationValues';\nimport convertFormatsToIntlMessageFormat from './convertFormatsToIntlMessageFormat';\nimport useIntlContext from './useIntlContext';\n\nfunction resolvePath(\n messages: IntlMessages | 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?: TranslationValues) {\n if (!values) return values;\n\n // Workaround for https://github.com/formatjs/formatjs/issues/1467\n const transformedValues: TranslationValues = {};\n Object.keys(values).forEach((key) => {\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, {\n key: result.key || key + String(children)\n })\n : result;\n };\n } else {\n transformed = value;\n }\n\n transformedValues[key] = transformed;\n });\n\n return transformedValues;\n}\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(namespace?: string) {\n const {\n formats: globalFormats,\n getMessageFallback,\n locale,\n messages: allMessages,\n onError,\n timeZone\n } = useIntlContext();\n\n const cachedFormatsByLocaleRef = useRef<\n Record<string, Record<string, IntlMessageFormat>>\n >({});\n\n const messagesOrError = useMemo(() => {\n try {\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.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?: TranslationValues,\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.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.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 prepareTranslationValues(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.message\n );\n }\n }\n\n function translateFn(\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?: 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.message\n );\n }\n };\n\n return translateFn;\n }, [\n getMessageFallback,\n globalFormats,\n locale,\n messagesOrError,\n namespace,\n onError,\n timeZone\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 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(new IntlError(IntlErrorCode.FORMATTING_ERROR, error.message));\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 | Intl.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(new IntlError(IntlErrorCode.FORMATTING_ERROR, error.message));\n return String(date);\n }\n }\n\n return {formatDateTime, formatNumber, formatRelativeTime};\n}\n"],"names":["IntlErrorCode","IntlContext","createContext","undefined","defaultGetMessageFallback","namespace","key","filter","part","join","defaultOnError","error","console","IntlError","code","originalMessage","message","Error","setTimeZoneInFormats","formats","timeZone","Object","keys","reduce","acc","useIntlContext","context","useContext","resolvePath","messages","idPath","split","forEach","next","getNow","Date","children","onError","getMessageFallback","contextValues","React","Provider","value","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","seconds","unit","absValue","Math","abs","round","MINUTE","HOUR","DAY","getRelativeTimeFormatConfig","getTime","RelativeTimeFormat","numeric","updateInterval","useState","setNow","useEffect","intervalId","setInterval","clearInterval","globalFormats","allMessages","cachedFormatsByLocaleRef","useRef","messagesOrError","useMemo","retrievedMessages","intlError","MISSING_MESSAGE","getFallbackFromErrorAndNotify","translateBaseFn","values","cachedFormatsByLocale","current","messageFormat","cacheKey","_cachedFormatsByLocal","INSUFFICIENT_PATH","IntlMessageFormat","formatsWithTimeZone","time","convertFormatsToIntlMessageFormat","INVALID_MESSAGE","formattedMessage","transformedValues","result","isValidElement","cloneElement","prepareTranslationValues","Array","isArray","translateFn","rich","raw"],"mappings":"khDAmBA,ICnBYA,EDmBNC,EAAcC,qBAA4CC,GEwBhE,SAASC,WAOA,GALPC,YADAC,KAMwBC,QAAO,SAACC,UAAiB,MAARA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B,CACxB3B,MAAOiF,EACPtF,IAAAA,EACAD,UAAAA,QAGEwB,EAAW+D,aAGRhE,EAAYC,EAAUvB,GAC7B,MAAOK,UACAsF,EACL3F,EACAN,sBAAcgG,gBACdrF,EAAMK,WAKLuG,IACN,CACDjF,EACAkD,EACA7C,EACAiD,EACAvF,EACAgC,EACAjB"}
@@ -306,7 +306,7 @@ function useTranslations(namespace) {
306
306
  }
307
307
  }, [allMessages, namespace, onError]);
308
308
  var translate = useMemo(function () {
309
- function getFallbackFromError(key, code, message) {
309
+ function getFallbackFromErrorAndNotify(key, code, message) {
310
310
  var error = new IntlError(code, message);
311
311
  onError(error);
312
312
  return getMessageFallback({
@@ -316,7 +316,7 @@ function useTranslations(namespace) {
316
316
  });
317
317
  }
318
318
 
319
- function translateFn(
319
+ function translateBaseFn(
320
320
  /** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */
321
321
  key,
322
322
  /** Key value pairs for values to interpolate into the message. */
@@ -337,52 +337,75 @@ function useTranslations(namespace) {
337
337
  }
338
338
 
339
339
  var messages = messagesOrError;
340
+ var cacheKey = [namespace, key].filter(function (part) {
341
+ return part != null;
342
+ }).join('.');
340
343
  var messageFormat;
341
344
 
342
- if ((_cachedFormatsByLocal = cachedFormatsByLocale[locale]) != null && _cachedFormatsByLocal[key]) {
343
- messageFormat = cachedFormatsByLocale[locale][key];
345
+ if ((_cachedFormatsByLocal = cachedFormatsByLocale[locale]) != null && _cachedFormatsByLocal[cacheKey]) {
346
+ messageFormat = cachedFormatsByLocale[locale][cacheKey];
344
347
  } else {
345
348
  var message;
346
349
 
347
350
  try {
348
351
  message = resolvePath(messages, key, namespace);
349
352
  } catch (error) {
350
- return getFallbackFromError(key, IntlErrorCode.MISSING_MESSAGE, error.message);
353
+ return getFallbackFromErrorAndNotify(key, IntlErrorCode.MISSING_MESSAGE, error.message);
351
354
  }
352
355
 
353
356
  if (typeof message === 'object') {
354
- return getFallbackFromError(key, IntlErrorCode.INSUFFICIENT_PATH, process.env.NODE_ENV !== "production" ? "Insufficient path specified for `" + key + "` in `" + namespace + "`." : undefined);
357
+ return getFallbackFromErrorAndNotify(key, IntlErrorCode.INSUFFICIENT_PATH, process.env.NODE_ENV !== "production" ? "Insufficient path specified for `" + key + "` in `" + (namespace ? "`" + namespace + "`" : 'messages') + "`." : undefined);
355
358
  }
356
359
 
357
360
  try {
358
361
  messageFormat = new IntlMessageFormat(message, locale, convertFormatsToIntlMessageFormat(_extends({}, globalFormats, formats), timeZone));
359
362
  } catch (error) {
360
- return getFallbackFromError(key, IntlErrorCode.INVALID_MESSAGE, error.message);
363
+ return getFallbackFromErrorAndNotify(key, IntlErrorCode.INVALID_MESSAGE, error.message);
361
364
  }
362
365
 
363
366
  if (!cachedFormatsByLocale[locale]) {
364
367
  cachedFormatsByLocale[locale] = {};
365
368
  }
366
369
 
367
- cachedFormatsByLocale[locale][key] = messageFormat;
370
+ cachedFormatsByLocale[locale][cacheKey] = messageFormat;
368
371
  }
369
372
 
370
373
  try {
371
374
  var formattedMessage = messageFormat.format(prepareTranslationValues(values));
372
375
 
373
376
  if (formattedMessage == null) {
374
- throw new Error(process.env.NODE_ENV !== "production" ? "Unable to format " + [namespace, key].join('.') : undefined);
377
+ throw new Error(process.env.NODE_ENV !== "production" ? "Unable to format `" + key + "` in " + (namespace ? "namespace `" + namespace + "`" : 'messages') : undefined);
375
378
  } // Limit the function signature to return strings or React elements
376
379
 
377
380
 
378
381
  return isValidElement(formattedMessage) || // Arrays of React elements
379
382
  Array.isArray(formattedMessage) || typeof formattedMessage === 'string' ? formattedMessage : String(formattedMessage);
380
383
  } catch (error) {
381
- return getFallbackFromError(key, IntlErrorCode.FORMATTING_ERROR, error.message);
384
+ return getFallbackFromErrorAndNotify(key, IntlErrorCode.FORMATTING_ERROR, error.message);
382
385
  }
383
386
  }
384
387
 
385
- translateFn.raw = function (key) {
388
+ function translateFn(
389
+ /** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */
390
+ key,
391
+ /** Key value pairs for values to interpolate into the message. */
392
+ values,
393
+ /** Provide custom formats for numbers, dates and times. */
394
+ formats) {
395
+ var message = translateBaseFn(key, values, formats);
396
+
397
+ if (typeof message !== 'string') {
398
+ return getFallbackFromErrorAndNotify(key, IntlErrorCode.INVALID_MESSAGE, process.env.NODE_ENV !== "production" ? "The message `" + key + "` in " + (namespace ? "namespace `" + namespace + "`" : 'messages') + " didn't resolve to a string. If you want to format rich text, use `t.rich` instead." : undefined);
399
+ }
400
+
401
+ return message;
402
+ }
403
+
404
+ translateFn.rich = translateBaseFn;
405
+
406
+ translateFn.raw = function (
407
+ /** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */
408
+ key) {
386
409
  if (messagesOrError instanceof IntlError) {
387
410
  // We have already warned about this during render
388
411
  return getMessageFallback({
@@ -397,7 +420,7 @@ function useTranslations(namespace) {
397
420
  try {
398
421
  return resolvePath(messages, key, namespace);
399
422
  } catch (error) {
400
- return getFallbackFromError(key, IntlErrorCode.MISSING_MESSAGE, error.message);
423
+ return getFallbackFromErrorAndNotify(key, IntlErrorCode.MISSING_MESSAGE, error.message);
401
424
  }
402
425
  };
403
426
 
@@ -1 +1 @@
1
- {"version":3,"file":"use-intl.esm.js","sources":["../src/IntlContext.tsx","../src/IntlProvider.tsx","../src/IntlError.tsx","../src/convertFormatsToIntlMessageFormat.tsx","../src/useIntlContext.tsx","../src/useTranslations.tsx","../src/useIntl.tsx","../src/useNow.tsx"],"sourcesContent":["import {createContext} from 'react';\nimport Formats from './Formats';\nimport IntlError from './IntlError';\nimport IntlMessages from './IntlMessages';\n\nexport type IntlContextShape = {\n messages?: IntlMessages;\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};\n\nconst IntlContext = createContext<IntlContextShape | undefined>(undefined);\n\nexport default IntlContext;\n","import React, {ReactNode} from 'react';\nimport Formats from './Formats';\nimport IntlContext from './IntlContext';\nimport IntlMessages from './IntlMessages';\nimport {IntlError} from '.';\n\ntype Props = {\n /** All messages that will be available in your components. */\n messages?: IntlMessages;\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};\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 {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 {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 IntlMessageFormat from 'intl-messageformat';\nimport {\n cloneElement,\n isValidElement,\n ReactElement,\n ReactNode,\n ReactNodeArray,\n useMemo,\n useRef\n} from 'react';\nimport Formats from './Formats';\nimport IntlError, {IntlErrorCode} from './IntlError';\nimport IntlMessages from './IntlMessages';\nimport TranslationValues from './TranslationValues';\nimport convertFormatsToIntlMessageFormat from './convertFormatsToIntlMessageFormat';\nimport useIntlContext from './useIntlContext';\n\nfunction resolvePath(\n messages: IntlMessages | 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?: TranslationValues) {\n if (!values) return values;\n\n // Workaround for https://github.com/formatjs/formatjs/issues/1467\n const transformedValues: TranslationValues = {};\n Object.keys(values).forEach((key) => {\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, {\n key: result.key || key + String(children)\n })\n : result;\n };\n } else {\n transformed = value;\n }\n\n transformedValues[key] = transformed;\n });\n\n return transformedValues;\n}\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(namespace?: string) {\n const {\n formats: globalFormats,\n getMessageFallback,\n locale,\n messages: allMessages,\n onError,\n timeZone\n } = useIntlContext();\n\n const cachedFormatsByLocaleRef = useRef<\n Record<string, Record<string, IntlMessageFormat>>\n >({});\n\n const messagesOrError = useMemo(() => {\n try {\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.message\n );\n onError(intlError);\n return intlError;\n }\n }, [allMessages, namespace, onError]);\n\n const translate = useMemo(() => {\n function getFallbackFromError(\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 translateFn(\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?: TranslationValues,\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 let messageFormat;\n if (cachedFormatsByLocale[locale]?.[key]) {\n messageFormat = cachedFormatsByLocale[locale][key];\n } else {\n let message;\n try {\n message = resolvePath(messages, key, namespace);\n } catch (error) {\n return getFallbackFromError(\n key,\n IntlErrorCode.MISSING_MESSAGE,\n error.message\n );\n }\n\n if (typeof message === 'object') {\n return getFallbackFromError(\n key,\n IntlErrorCode.INSUFFICIENT_PATH,\n __DEV__\n ? `Insufficient path specified for \\`${key}\\` in \\`${namespace}\\`.`\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 getFallbackFromError(\n key,\n IntlErrorCode.INVALID_MESSAGE,\n error.message\n );\n }\n\n if (!cachedFormatsByLocale[locale]) {\n cachedFormatsByLocale[locale] = {};\n }\n cachedFormatsByLocale[locale][key] = messageFormat;\n }\n\n try {\n const formattedMessage = messageFormat.format(\n prepareTranslationValues(values)\n );\n\n if (formattedMessage == null) {\n throw new Error(\n __DEV__\n ? `Unable to format ${[namespace, key].join('.')}`\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 getFallbackFromError(\n key,\n IntlErrorCode.FORMATTING_ERROR,\n error.message\n );\n }\n }\n\n translateFn.raw = (key: string): 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 getFallbackFromError(\n key,\n IntlErrorCode.MISSING_MESSAGE,\n error.message\n );\n }\n };\n\n return translateFn;\n }, [\n getMessageFallback,\n globalFormats,\n locale,\n messagesOrError,\n namespace,\n onError,\n timeZone\n ]);\n\n return translate;\n}\n","import DateTimeFormatOptions from './DateTimeFormatOptions';\nimport IntlError, {IntlErrorCode} from './IntlError';\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(new IntlError(IntlErrorCode.FORMATTING_ERROR, error.message));\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 | Intl.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(new IntlError(IntlErrorCode.FORMATTING_ERROR, error.message));\n return String(date);\n }\n }\n\n return {formatDateTime, formatNumber, formatRelativeTime};\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"],"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","setTimeZoneInFormats","formats","timeZone","Object","keys","reduce","acc","convertFormatsToIntlMessageFormat","formatsWithTimeZone","dateTime","date","time","useIntlContext","context","useContext","resolvePath","messages","idPath","split","forEach","next","prepareTranslationValues","values","transformedValues","transformed","result","isValidElement","cloneElement","String","useTranslations","globalFormats","locale","allMessages","cachedFormatsByLocaleRef","useRef","messagesOrError","useMemo","retrievedMessages","intlError","MISSING_MESSAGE","translate","getFallbackFromError","translateFn","cachedFormatsByLocale","current","messageFormat","INSUFFICIENT_PATH","IntlMessageFormat","INVALID_MESSAGE","formattedMessage","format","Array","isArray","FORMATTING_ERROR","raw","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","getNow","useNow","updateInterval","useState","setNow","useEffect","intervalId","setInterval","clearInterval"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmBA,IAAMA,WAAW,gBAAGC,aAAa,CAA+BC,SAA/B,CAAjC;;ACwBA,SAASC,yBAAT;MACEC,WAAAA;MACAC,iBAAAA;AAKA,SAAO,CAACA,SAAD,EAAYD,GAAZ,EAAiBE,MAAjB,CAAwB,UAACC,IAAD;AAAA,W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;AAIA,WAAO;AACLM,MAAAA,aAAa,CAACF,UAAD,CAAb;AACD,KAFD;AAGD,GAVQ,EAUN,CAAC7B,SAAD,EAAYyB,cAAZ,CAVM,CAAT;AAYA,SAAOxB,GAAP;AACD;;;;"}
1
+ {"version":3,"file":"use-intl.esm.js","sources":["../src/IntlContext.tsx","../src/IntlProvider.tsx","../src/IntlError.tsx","../src/convertFormatsToIntlMessageFormat.tsx","../src/useIntlContext.tsx","../src/useTranslations.tsx","../src/useIntl.tsx","../src/useNow.tsx"],"sourcesContent":["import {createContext} from 'react';\nimport Formats from './Formats';\nimport IntlError from './IntlError';\nimport IntlMessages from './IntlMessages';\n\nexport type IntlContextShape = {\n messages?: IntlMessages;\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};\n\nconst IntlContext = createContext<IntlContextShape | undefined>(undefined);\n\nexport default IntlContext;\n","import React, {ReactNode} from 'react';\nimport Formats from './Formats';\nimport IntlContext from './IntlContext';\nimport IntlMessages from './IntlMessages';\nimport {IntlError} from '.';\n\ntype Props = {\n /** All messages that will be available in your components. */\n messages?: IntlMessages;\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};\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 {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 {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 IntlMessageFormat from 'intl-messageformat';\nimport {\n cloneElement,\n isValidElement,\n ReactElement,\n ReactNode,\n ReactNodeArray,\n useMemo,\n useRef\n} from 'react';\nimport Formats from './Formats';\nimport IntlError, {IntlErrorCode} from './IntlError';\nimport IntlMessages from './IntlMessages';\nimport TranslationValues from './TranslationValues';\nimport convertFormatsToIntlMessageFormat from './convertFormatsToIntlMessageFormat';\nimport useIntlContext from './useIntlContext';\n\nfunction resolvePath(\n messages: IntlMessages | 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?: TranslationValues) {\n if (!values) return values;\n\n // Workaround for https://github.com/formatjs/formatjs/issues/1467\n const transformedValues: TranslationValues = {};\n Object.keys(values).forEach((key) => {\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, {\n key: result.key || key + String(children)\n })\n : result;\n };\n } else {\n transformed = value;\n }\n\n transformedValues[key] = transformed;\n });\n\n return transformedValues;\n}\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(namespace?: string) {\n const {\n formats: globalFormats,\n getMessageFallback,\n locale,\n messages: allMessages,\n onError,\n timeZone\n } = useIntlContext();\n\n const cachedFormatsByLocaleRef = useRef<\n Record<string, Record<string, IntlMessageFormat>>\n >({});\n\n const messagesOrError = useMemo(() => {\n try {\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.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?: TranslationValues,\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.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.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 prepareTranslationValues(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.message\n );\n }\n }\n\n function translateFn(\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?: 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.message\n );\n }\n };\n\n return translateFn;\n }, [\n getMessageFallback,\n globalFormats,\n locale,\n messagesOrError,\n namespace,\n onError,\n timeZone\n ]);\n\n return translate;\n}\n","import DateTimeFormatOptions from './DateTimeFormatOptions';\nimport IntlError, {IntlErrorCode} from './IntlError';\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(new IntlError(IntlErrorCode.FORMATTING_ERROR, error.message));\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 | Intl.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(new IntlError(IntlErrorCode.FORMATTING_ERROR, error.message));\n return String(date);\n }\n }\n\n return {formatDateTime, formatNumber, formatRelativeTime};\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"],"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","setTimeZoneInFormats","formats","timeZone","Object","keys","reduce","acc","convertFormatsToIntlMessageFormat","formatsWithTimeZone","dateTime","date","time","useIntlContext","context","useContext","resolvePath","messages","idPath","split","forEach","next","prepareTranslationValues","values","transformedValues","transformed","result","isValidElement","cloneElement","String","useTranslations","globalFormats","locale","allMessages","cachedFormatsByLocaleRef","useRef","messagesOrError","useMemo","retrievedMessages","intlError","MISSING_MESSAGE","translate","getFallbackFromErrorAndNotify","translateBaseFn","cachedFormatsByLocale","current","cacheKey","messageFormat","INSUFFICIENT_PATH","IntlMessageFormat","INVALID_MESSAGE","formattedMessage","format","Array","isArray","FORMATTING_ERROR","translateFn","rich","raw","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","getNow","useNow","updateInterval","useState","setNow","useEffect","intervalId","setInterval","clearInterval"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmBA,IAAMA,WAAW,gBAAGC,aAAa,CAA+BC,SAA/B,CAAjC;;ACwBA,SAASC,yBAAT;MACEC,WAAAA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P,EAAc;AACdI,MAAAA,OAAO,CAAC,IAAIO,SAAJ,CAAcD,aAAa,CAAC4D,gBAA5B,EAA8CtE,KAAK,CAACc,OAApD,CAAD,CAAP;AACA,aAAO8B,MAAM,CAAClB,IAAD,CAAb;AACD;AACF;;AAED,SAAO;AAACwE,IAAAA,cAAc,EAAdA,cAAD;AAAiBG,IAAAA,YAAY,EAAZA,YAAjB;AAA+BG,IAAAA,kBAAkB,EAAlBA;AAA/B,GAAP;AACD;;AC3JD,SAASO,MAAT;AACE,SAAO,IAAIL,IAAJ,EAAP;AACD;AAED;;;;;;;;;;;;;;;;;;;;AAkBA,SAAwBM,OAAOnB;AAC7B,MAAMoB,cAAc,GAAGpB,OAAH,oBAAGA,OAAO,CAAEoB,cAAhC;;wBAEyBrF,cAAc;MAA3B4D,4BAALC;;kBACeyB,QAAQ,CAAC1B,SAAS,IAAIuB,MAAM,EAApB;MAAvBtB;MAAK0B;;AAEZC,EAAAA,SAAS,CAAC;AACR,QAAI,CAACH,cAAL,EAAqB;AAErB,QAAMI,UAAU,GAAGC,WAAW,CAAC;AAC7BH,MAAAA,MAAM,CAACJ,MAAM,EAAP,CAAN;AACD,KAF6B,EAE3BE,cAF2B,CAA9B;AAIA,WAAO;AACLM,MAAAA,aAAa,CAACF,UAAD,CAAb;AACD,KAFD;AAGD,GAVQ,EAUN,CAAC7B,SAAD,EAAYyB,cAAZ,CAVM,CAAT;AAYA,SAAOxB,GAAP;AACD;;;;"}
@@ -9,6 +9,7 @@ import Formats from './Formats';
9
9
  * (e.g. `namespace.Component`).
10
10
  */
11
11
  export default function useTranslations(namespace?: string): {
12
- (key: string, values?: Record<string, string | number | boolean | Date | ((children: ReactNode) => ReactNode) | null | undefined> | undefined, formats?: Partial<Formats> | undefined): string | ReactElement | ReactNodeArray;
12
+ (key: string, values?: Record<string, string | number | boolean | Date | ((children: ReactNode) => ReactNode) | null | undefined> | undefined, formats?: Partial<Formats> | undefined): string;
13
+ rich: (key: string, values?: Record<string, string | number | boolean | Date | ((children: ReactNode) => ReactNode) | null | undefined> | undefined, formats?: Partial<Formats> | undefined) => string | ReactElement | ReactNodeArray;
13
14
  raw(key: string): any;
14
15
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "use-intl",
3
- "version": "1.5.1",
3
+ "version": "2.0.2",
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.",
@@ -55,5 +55,5 @@
55
55
  "engines": {
56
56
  "node": ">=10"
57
57
  },
58
- "gitHead": "f3bbb7de303e0705d59a1997bb3f6d772d89bfa2"
58
+ "gitHead": "1185cfd2d0cf8d5a0faa5ed7fbd5696648b2e90c"
59
59
  }
@@ -124,7 +124,7 @@ export default function useTranslations(namespace?: string) {
124
124
  }, [allMessages, namespace, onError]);
125
125
 
126
126
  const translate = useMemo(() => {
127
- function getFallbackFromError(
127
+ function getFallbackFromErrorAndNotify(
128
128
  key: string,
129
129
  code: IntlErrorCode,
130
130
  message?: string
@@ -134,7 +134,7 @@ export default function useTranslations(namespace?: string) {
134
134
  return getMessageFallback({error, key, namespace});
135
135
  }
136
136
 
137
- function translateFn(
137
+ function translateBaseFn(
138
138
  /** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */
139
139
  key: string,
140
140
  /** Key value pairs for values to interpolate into the message. */
@@ -154,15 +154,19 @@ export default function useTranslations(namespace?: string) {
154
154
  }
155
155
  const messages = messagesOrError;
156
156
 
157
+ const cacheKey = [namespace, key]
158
+ .filter((part) => part != null)
159
+ .join('.');
160
+
157
161
  let messageFormat;
158
- if (cachedFormatsByLocale[locale]?.[key]) {
159
- messageFormat = cachedFormatsByLocale[locale][key];
162
+ if (cachedFormatsByLocale[locale]?.[cacheKey]) {
163
+ messageFormat = cachedFormatsByLocale[locale][cacheKey];
160
164
  } else {
161
165
  let message;
162
166
  try {
163
167
  message = resolvePath(messages, key, namespace);
164
168
  } catch (error) {
165
- return getFallbackFromError(
169
+ return getFallbackFromErrorAndNotify(
166
170
  key,
167
171
  IntlErrorCode.MISSING_MESSAGE,
168
172
  error.message
@@ -170,11 +174,13 @@ export default function useTranslations(namespace?: string) {
170
174
  }
171
175
 
172
176
  if (typeof message === 'object') {
173
- return getFallbackFromError(
177
+ return getFallbackFromErrorAndNotify(
174
178
  key,
175
179
  IntlErrorCode.INSUFFICIENT_PATH,
176
180
  __DEV__
177
- ? `Insufficient path specified for \`${key}\` in \`${namespace}\`.`
181
+ ? `Insufficient path specified for \`${key}\` in \`${
182
+ namespace ? `\`${namespace}\`` : 'messages'
183
+ }\`.`
178
184
  : undefined
179
185
  );
180
186
  }
@@ -189,7 +195,7 @@ export default function useTranslations(namespace?: string) {
189
195
  )
190
196
  );
191
197
  } catch (error) {
192
- return getFallbackFromError(
198
+ return getFallbackFromErrorAndNotify(
193
199
  key,
194
200
  IntlErrorCode.INVALID_MESSAGE,
195
201
  error.message
@@ -199,7 +205,7 @@ export default function useTranslations(namespace?: string) {
199
205
  if (!cachedFormatsByLocale[locale]) {
200
206
  cachedFormatsByLocale[locale] = {};
201
207
  }
202
- cachedFormatsByLocale[locale][key] = messageFormat;
208
+ cachedFormatsByLocale[locale][cacheKey] = messageFormat;
203
209
  }
204
210
 
205
211
  try {
@@ -210,7 +216,9 @@ export default function useTranslations(namespace?: string) {
210
216
  if (formattedMessage == null) {
211
217
  throw new Error(
212
218
  __DEV__
213
- ? `Unable to format ${[namespace, key].join('.')}`
219
+ ? `Unable to format \`${key}\` in ${
220
+ namespace ? `namespace \`${namespace}\`` : 'messages'
221
+ }`
214
222
  : undefined
215
223
  );
216
224
  }
@@ -223,7 +231,7 @@ export default function useTranslations(namespace?: string) {
223
231
  ? formattedMessage
224
232
  : String(formattedMessage);
225
233
  } catch (error) {
226
- return getFallbackFromError(
234
+ return getFallbackFromErrorAndNotify(
227
235
  key,
228
236
  IntlErrorCode.FORMATTING_ERROR,
229
237
  error.message
@@ -231,7 +239,37 @@ export default function useTranslations(namespace?: string) {
231
239
  }
232
240
  }
233
241
 
234
- translateFn.raw = (key: string): any => {
242
+ function translateFn(
243
+ /** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */
244
+ key: string,
245
+ /** Key value pairs for values to interpolate into the message. */
246
+ values?: TranslationValues,
247
+ /** Provide custom formats for numbers, dates and times. */
248
+ formats?: Partial<Formats>
249
+ ): string {
250
+ const message = translateBaseFn(key, values, formats);
251
+
252
+ if (typeof message !== 'string') {
253
+ return getFallbackFromErrorAndNotify(
254
+ key,
255
+ IntlErrorCode.INVALID_MESSAGE,
256
+ __DEV__
257
+ ? `The message \`${key}\` in ${
258
+ namespace ? `namespace \`${namespace}\`` : 'messages'
259
+ } didn't resolve to a string. If you want to format rich text, use \`t.rich\` instead.`
260
+ : undefined
261
+ );
262
+ }
263
+
264
+ return message;
265
+ }
266
+
267
+ translateFn.rich = translateBaseFn;
268
+
269
+ translateFn.raw = (
270
+ /** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */
271
+ key: string
272
+ ): any => {
235
273
  if (messagesOrError instanceof IntlError) {
236
274
  // We have already warned about this during render
237
275
  return getMessageFallback({
@@ -245,7 +283,7 @@ export default function useTranslations(namespace?: string) {
245
283
  try {
246
284
  return resolvePath(messages, key, namespace);
247
285
  } catch (error) {
248
- return getFallbackFromError(
286
+ return getFallbackFromErrorAndNotify(
249
287
  key,
250
288
  IntlErrorCode.MISSING_MESSAGE,
251
289
  error.message