use-intl 4.4.0 → 4.5.1

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.
@@ -1,5 +1,5 @@
1
- import { r as resolveNamespace, e as createBaseTranslator, f as defaultGetMessageFallback, b as createIntlFormatters, d as createCache, g as defaultOnError } from './initializeConfig-z8OlpM94.js';
2
- export { I as IntlError, a as IntlErrorCode, c as createFormatter, i as initializeConfig } from './initializeConfig-z8OlpM94.js';
1
+ import { r as resolveNamespace, e as createBaseTranslator, f as defaultGetMessageFallback, b as createIntlFormatters, d as createCache, g as defaultOnError } from './initializeConfig-CIDVMS2E.js';
2
+ export { I as IntlError, a as IntlErrorCode, c as createFormatter, i as initializeConfig } from './initializeConfig-CIDVMS2E.js';
3
3
 
4
4
 
5
5
 
@@ -23,6 +23,10 @@ function createTranslatorImpl({
23
23
  // This type is slightly more loose than `AbstractIntlMessages`
24
24
  // in order to avoid a type error.
25
25
 
26
+ /**
27
+ * @private Not intended for direct use.
28
+ */
29
+
26
30
  /**
27
31
  * Translates messages from the given namespace by using the ICU syntax.
28
32
  * See https://formatjs.io/docs/core-concepts/icu-syntax.
@@ -1,6 +1,6 @@
1
- export { I as IntlError, a as IntlErrorCode, d as _createCache, b as _createIntlFormatters, c as createFormatter, i as initializeConfig } from './initializeConfig-z8OlpM94.js';
1
+ export { I as IntlError, a as IntlErrorCode, d as _createCache, b as _createIntlFormatters, c as createFormatter, i as initializeConfig } from './initializeConfig-CIDVMS2E.js';
2
2
  export { createTranslator, hasLocale } from './core.js';
3
- export { IntlProvider, useFormatter, useLocale, useMessages, useNow, useTimeZone, useTranslations } from './react.js';
3
+ export { IntlProvider, _useExtracted, useFormatter, useLocale, useMessages, useNow, useTimeZone, useTranslations } from './react.js';
4
4
 
5
5
 
6
6
 
@@ -186,7 +186,7 @@ function prepareTranslationValues(values) {
186
186
  });
187
187
  return transformedValues;
188
188
  }
189
- function getMessagesOrError(locale, messages, namespace, onError = defaultOnError) {
189
+ function getMessagesOrError(locale, messages, namespace) {
190
190
  try {
191
191
  if (!messages) {
192
192
  throw new Error(`No messages were configured.` );
@@ -200,7 +200,6 @@ function getMessagesOrError(locale, messages, namespace, onError = defaultOnErro
200
200
  return retrievedMessages;
201
201
  } catch (error) {
202
202
  const intlError = new IntlError(IntlErrorCode.MISSING_MESSAGE, error.message);
203
- onError(intlError);
204
203
  return intlError;
205
204
  }
206
205
  }
@@ -217,7 +216,7 @@ function getPlainMessage(candidate, values) {
217
216
  );
218
217
  }
219
218
  function createBaseTranslator(config) {
220
- const messagesOrError = getMessagesOrError(config.locale, config.messages, config.namespace, config.onError);
219
+ const messagesOrError = getMessagesOrError(config.locale, config.messages, config.namespace);
221
220
  return createBaseTranslatorImpl({
222
221
  ...config,
223
222
  messagesOrError
@@ -235,10 +234,10 @@ function createBaseTranslatorImpl({
235
234
  timeZone
236
235
  }) {
237
236
  const hasMessagesError = messagesOrError instanceof IntlError;
238
- function getFallbackFromErrorAndNotify(key, code, message) {
237
+ function getFallbackFromErrorAndNotify(key, code, message, fallback) {
239
238
  const error = new IntlError(code, message);
240
239
  onError(error);
241
- return getMessageFallback({
240
+ return fallback ?? getMessageFallback({
242
241
  error,
243
242
  key,
244
243
  namespace
@@ -247,21 +246,31 @@ function createBaseTranslatorImpl({
247
246
  function translateBaseFn(/** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */
248
247
  key, /** Key value pairs for values to interpolate into the message. */
249
248
  values, /** Provide custom formats for numbers, dates and times. */
250
- formats) {
251
- if (hasMessagesError) {
252
- // We have already warned about this during render
253
- return getMessageFallback({
254
- error: messagesOrError,
255
- key,
256
- namespace
257
- });
258
- }
259
- const messages = messagesOrError;
249
+ formats, _fallback) {
250
+ const fallback = _fallback;
260
251
  let message;
261
- try {
262
- message = resolvePath(locale, messages, key, namespace);
263
- } catch (error) {
264
- return getFallbackFromErrorAndNotify(key, IntlErrorCode.MISSING_MESSAGE, error.message);
252
+ if (hasMessagesError) {
253
+ if (fallback) {
254
+ message = fallback;
255
+ } else {
256
+ onError(messagesOrError);
257
+ return getMessageFallback({
258
+ error: messagesOrError,
259
+ key,
260
+ namespace
261
+ });
262
+ }
263
+ } else {
264
+ const messages = messagesOrError;
265
+ try {
266
+ message = resolvePath(locale, messages, key, namespace);
267
+ } catch (error) {
268
+ if (fallback) {
269
+ message = fallback;
270
+ } else {
271
+ return getFallbackFromErrorAndNotify(key, IntlErrorCode.MISSING_MESSAGE, error.message, fallback);
272
+ }
273
+ }
265
274
  }
266
275
  if (typeof message === 'object') {
267
276
  let code, errorMessage;
@@ -304,7 +313,7 @@ function createBaseTranslatorImpl({
304
313
  });
305
314
  } catch (error) {
306
315
  const thrownError = error;
307
- return getFallbackFromErrorAndNotify(key, IntlErrorCode.INVALID_MESSAGE, thrownError.message + ('originalMessage' in thrownError ? ` (${thrownError.originalMessage})` : '') );
316
+ return getFallbackFromErrorAndNotify(key, IntlErrorCode.INVALID_MESSAGE, thrownError.message + ('originalMessage' in thrownError ? ` (${thrownError.originalMessage})` : '') , fallback);
308
317
  }
309
318
  try {
310
319
  const formattedMessage = messageFormat.format(
@@ -322,14 +331,14 @@ function createBaseTranslatorImpl({
322
331
  // Arrays of React elements
323
332
  Array.isArray(formattedMessage) || typeof formattedMessage === 'string' ? formattedMessage : String(formattedMessage);
324
333
  } catch (error) {
325
- return getFallbackFromErrorAndNotify(key, IntlErrorCode.FORMATTING_ERROR, error.message);
334
+ return getFallbackFromErrorAndNotify(key, IntlErrorCode.FORMATTING_ERROR, error.message, fallback);
326
335
  }
327
336
  }
328
337
  function translateFn(/** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */
329
338
  key, /** Key value pairs for values to interpolate into the message. */
330
- values, /** Provide custom formats for numbers, dates and times. */
331
- formats) {
332
- const result = translateBaseFn(key, values, formats);
339
+ values, /** Custom formats for numbers, dates and times. */
340
+ formats, _fallback) {
341
+ const result = translateBaseFn(key, values, formats, _fallback);
333
342
  if (typeof result !== 'string') {
334
343
  return getFallbackFromErrorAndNotify(key, 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.` );
335
344
  }
@@ -338,11 +347,11 @@ function createBaseTranslatorImpl({
338
347
  translateFn.rich = translateBaseFn;
339
348
 
340
349
  // Augment `translateBaseFn` to return plain strings
341
- translateFn.markup = (key, values, formats) => {
350
+ translateFn.markup = (key, values, formats, _fallback) => {
342
351
  const result = translateBaseFn(key,
343
352
  // @ts-expect-error -- `MarkupTranslationValues` is practically a sub type
344
353
  // of `RichTranslationValues` but TypeScript isn't smart enough here.
345
- values, formats);
354
+ values, formats, _fallback);
346
355
  if (typeof result !== 'string') {
347
356
  const error = new IntlError(IntlErrorCode.FORMATTING_ERROR, "`t.markup` only accepts functions for formatting that receive and return strings.\n\nE.g. t.markup('markup', {b: (chunks) => `<b>${chunks}</b>`})");
348
357
  onError(error);
@@ -356,7 +365,7 @@ function createBaseTranslatorImpl({
356
365
  };
357
366
  translateFn.raw = key => {
358
367
  if (hasMessagesError) {
359
- // We have already warned about this during render
368
+ onError(messagesOrError);
360
369
  return getMessageFallback({
361
370
  error: messagesOrError,
362
371
  key,
@@ -1,5 +1,5 @@
1
1
  import { createContext, useContext, useMemo, useState, useEffect } from 'react';
2
- import { d as createCache, b as createIntlFormatters, i as initializeConfig, r as resolveNamespace, I as IntlError, a as IntlErrorCode, e as createBaseTranslator, c as createFormatter } from './initializeConfig-z8OlpM94.js';
2
+ import { d as createCache, b as createIntlFormatters, i as initializeConfig, r as resolveNamespace, I as IntlError, a as IntlErrorCode, e as createBaseTranslator, c as createFormatter } from './initializeConfig-CIDVMS2E.js';
3
3
  import { jsx } from 'react/jsx-runtime';
4
4
 
5
5
 
@@ -181,4 +181,50 @@ function useFormatter() {
181
181
  }), [formats, formatters, globalNow, locale, onError, timeZone]);
182
182
  }
183
183
 
184
- export { IntlProvider, useFormatter, useLocale, useMessages, useNow, useTimeZone, useTranslations };
184
+ function getArgs(messageOrParams, ...rest) {
185
+ let message, values, formats;
186
+ if (typeof messageOrParams === 'string') {
187
+ message = messageOrParams;
188
+ values = rest[0];
189
+ formats = rest[1];
190
+ } else {
191
+ message = messageOrParams.message;
192
+ values = messageOrParams.values;
193
+ formats = messageOrParams.formats;
194
+ // `description` is is not used at runtime
195
+ }
196
+ // @ts-expect-error -- Secret fallback parameter
197
+ return [undefined,
198
+ // Always use fallback if not compiled
199
+ values, formats, message ];
200
+ }
201
+
202
+ // Note: This API is usually compiled into `useTranslations`,
203
+ // but there is some fallback handling which allows this hook
204
+ // to still work when not being compiled.
205
+ //
206
+ // This is relevant for:
207
+ // - Isolated environments like tests, Storybook, etc.
208
+ // - Fallbacks in case an extracted message is not yet available
209
+ function useExtracted(namespace) {
210
+ const t = useTranslations(namespace);
211
+ function translateFn(...params) {
212
+ // @ts-expect-error -- Passing `undefined` as an ID is secretly allowed here
213
+ return t(...getArgs(...params));
214
+ }
215
+ translateFn.rich = (...params) =>
216
+ // @ts-expect-error -- Passing `undefined` as an ID is secretly allowed here
217
+ t.rich(...getArgs(...params));
218
+ translateFn.markup = (...params) =>
219
+ // @ts-expect-error -- Passing `undefined` as an ID is secretly allowed here
220
+ t.markup(...getArgs(...params));
221
+ translateFn.has = function translateHasFn(
222
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
223
+ message) {
224
+ // Not really something better we can do here
225
+ return true;
226
+ };
227
+ return translateFn;
228
+ }
229
+
230
+ export { IntlProvider, useExtracted as _useExtracted, useFormatter, useLocale, useMessages, useNow, useTimeZone, useTranslations };
@@ -1 +1 @@
1
- import{r as e,e as s,f as r,b as t,d as o,g as n}from"./initializeConfig-JxT5lzW-.js";export{I as IntlError,a as IntlErrorCode,c as createFormatter,i as initializeConfig}from"./initializeConfig-JxT5lzW-.js";function m({_cache:a=o(),_formatters:i=t(a),getMessageFallback:m=r,messages:c,namespace:f,onError:g=n,...l}){return function({messages:a,namespace:r,...t},o){return a=a[o],r=e(r,o),s({...t,messages:a,namespace:r})}({...l,onError:g,cache:a,formatters:i,getMessageFallback:m,messages:{"!":c},namespace:f?`!.${f}`:"!"},"!")}function f(e,a){return e.includes(a)}export{o as _createCache,t as _createIntlFormatters,m as createTranslator,f as hasLocale};
1
+ import{r as e,e as s,f as r,b as t,d as o,g as n}from"./initializeConfig-CzP0yD8_.js";export{I as IntlError,a as IntlErrorCode,c as createFormatter,i as initializeConfig}from"./initializeConfig-CzP0yD8_.js";function m({_cache:a=o(),_formatters:i=t(a),getMessageFallback:m=r,messages:c,namespace:f,onError:g=n,...l}){return function({messages:a,namespace:r,...t},o){return a=a[o],r=e(r,o),s({...t,messages:a,namespace:r})}({...l,onError:g,cache:a,formatters:i,getMessageFallback:m,messages:{"!":c},namespace:f?`!.${f}`:"!"},"!")}function f(e,a){return e.includes(a)}export{o as _createCache,t as _createIntlFormatters,m as createTranslator,f as hasLocale};
@@ -1 +1 @@
1
- export{I as IntlError,a as IntlErrorCode,d as _createCache,b as _createIntlFormatters,c as createFormatter,i as initializeConfig}from"./initializeConfig-JxT5lzW-.js";export{createTranslator,hasLocale}from"./core.js";export{IntlProvider,useFormatter,useLocale,useMessages,useNow,useTimeZone,useTranslations}from"./react.js";
1
+ export{I as IntlError,a as IntlErrorCode,d as _createCache,b as _createIntlFormatters,c as createFormatter,i as initializeConfig}from"./initializeConfig-CzP0yD8_.js";export{createTranslator,hasLocale}from"./core.js";export{IntlProvider,_useExtracted,useFormatter,useLocale,useMessages,useNow,useTimeZone,useTranslations}from"./react.js";
@@ -0,0 +1 @@
1
+ import{IntlMessageFormat as e}from"intl-messageformat";import{isValidElement as t,cloneElement as r}from"react";import{memoize as n,strategies as o}from"@formatjs/fast-memoize";class a extends Error{constructor(e,t){let r=e;t&&(r+=": "+t),super(r),this.code=e,t&&(this.originalMessage=t)}}var s=function(e){return e.MISSING_MESSAGE="MISSING_MESSAGE",e.MISSING_FORMAT="MISSING_FORMAT",e.ENVIRONMENT_FALLBACK="ENVIRONMENT_FALLBACK",e.INSUFFICIENT_PATH="INSUFFICIENT_PATH",e.INVALID_MESSAGE="INVALID_MESSAGE",e.INVALID_KEY="INVALID_KEY",e.FORMATTING_ERROR="FORMATTING_ERROR",e}(s||{});function i(...e){return e.filter(Boolean).join(".")}function u(e){return i(e.namespace,e.key)}function c(e){console.error(e)}function m(){return{dateTime:{},number:{},message:{},relativeTime:{},pluralRules:{},list:{},displayNames:{}}}function f(e,t){return n(e,{cache:(r=t,{create:()=>({get:e=>r[e],set(e,t){r[e]=t}})}),strategy:o.variadic});var r}function l(e,t){return f(((...t)=>new e(...t)),t)}function g(e){return{getDateTimeFormat:l(Intl.DateTimeFormat,e.dateTime),getNumberFormat:l(Intl.NumberFormat,e.number),getPluralRules:l(Intl.PluralRules,e.pluralRules),getRelativeTimeFormat:l(Intl.RelativeTimeFormat,e.relativeTime),getListFormat:l(Intl.ListFormat,e.list),getDisplayNames:l(Intl.DisplayNames,e.displayNames)}}function I(e,t,r,n){const o=i(n,r);if(!t)throw new Error(o);let a=t;return r.split(".").forEach((t=>{const r=a[t];if(null==t||null==r)throw new Error(o+` (${e})`);a=r})),a}function E(n){const o=function(e,t,r){try{if(!t)throw new Error(void 0);const n=r?I(e,t,r):t;if(!n)throw new Error(r);return n}catch(e){return new a(s.MISSING_MESSAGE,e.message)}}(n.locale,n.messages,n.namespace);return function({cache:n,formats:o,formatters:i,getMessageFallback:c=u,locale:m,messagesOrError:l,namespace:g,onError:E,timeZone:S}){const T=l instanceof a;function N(e,t,r,n){const o=new a(t,r);return E(o),n??c({error:o,key:e,namespace:g})}function y(a,u,y,A){const M=A;let F,R;if(T){if(!M)return E(l),c({error:l,key:a,namespace:g});F=M}else{const e=l;try{F=I(m,e,a,g)}catch(e){if(!M)return N(a,s.MISSING_MESSAGE,e.message,M);F=M}}if("object"==typeof F){let e,t;return e=Array.isArray(F)?s.INVALID_MESSAGE:s.INSUFFICIENT_PATH,N(a,e,t)}const d=function(e,t){return t||/'[{}]/.test(e)?void 0:e}(F,u);if(d)return d;i.getMessageFormat||(i.getMessageFormat=function(t,r){return f(((...t)=>new e(t[0],t[1],t[2],{formatters:r,...t[3]})),t.message)}(n,i));try{R=i.getMessageFormat(F,m,function(t,r,n){const o=e.formats.date,a=e.formats.time,s={...t?.dateTime,...r?.dateTime},i={date:{...o,...s},time:{...a,...s},number:{...t?.number,...r?.number}};return n&&["date","time"].forEach((e=>{const t=i[e];for(const[e,r]of Object.entries(t))t[e]={timeZone:n,...r}})),i}(o,y,S),{formatters:{...i,getDateTimeFormat:(e,t)=>i.getDateTimeFormat(e,{timeZone:S,...t})}})}catch(e){const t=e;return N(a,s.INVALID_MESSAGE,t.message,M)}try{const e=R.format(u?function(e){const n={};return Object.keys(e).forEach((o=>{let a=0;const s=e[o];let i;i="function"==typeof s?e=>{const n=s(e);return t(n)?r(n,{key:o+a++}):n}:s,n[o]=i})),n}(u):u);if(null==e)throw new Error(void 0);return t(e)||Array.isArray(e)||"string"==typeof e?e:String(e)}catch(e){return N(a,s.FORMATTING_ERROR,e.message,M)}}function A(e,t,r,n){const o=y(e,t,r,n);return"string"!=typeof o?N(e,s.INVALID_MESSAGE,void 0):o}return A.rich=y,A.markup=(e,t,r,n)=>y(e,t,r,n),A.raw=e=>{if(T)return E(l),c({error:l,key:e,namespace:g});const t=l;try{return I(m,t,e,g)}catch(t){return N(e,s.MISSING_MESSAGE,t.message)}},A.has=e=>{if(T)return!1;try{return I(m,l,e,g),!0}catch{return!1}},A}({...n,messagesOrError:o})}function S(e,t){return e===t?void 0:e.slice((t+".").length)}const T=3600,N=86400,y=7*N,A=2628e3,M=7884e3,F=365*N,R={second:1,seconds:1,minute:60,minutes:60,hour:T,hours:T,day:N,days:N,week:y,weeks:y,month:A,months:A,quarter:M,quarters:M,year:F,years:F};function d(e){const{_cache:t=m(),_formatters:r=g(t),formats:n,locale:o,onError:i=c,timeZone:u}=e;function f(e){return e?.timeZone||(u?e={...e,timeZone:u}:i(new a(s.ENVIRONMENT_FALLBACK,void 0))),e}function l(e,t,r,n,o){let u;try{u=function(e,t,r){let n;if("string"==typeof t){const r=t;if(n=e?.[r],!n){const e=new a(s.MISSING_FORMAT,void 0);throw i(e),e}}else n=t;return r&&(n={...n,...r}),n}(r,e,t)}catch{return o()}try{return n(u)}catch(e){return i(new a(s.FORMATTING_ERROR,e.message)),o()}}function I(e,t,a){return l(t,a,n?.dateTime,(t=>(t=f(t),r.getDateTimeFormat(o,t).format(e))),(()=>String(e)))}function E(){return e.now?e.now:(i(new a(s.ENVIRONMENT_FALLBACK,void 0)),new Date)}return{dateTime:I,number:function(e,t,a){return l(t,a,n?.number,(t=>r.getNumberFormat(o,t).format(e)),(()=>String(e)))},relativeTime:function(e,t){try{let n,a;const s={};t instanceof Date||"number"==typeof t?n=new Date(t):t&&(n=null!=t.now?new Date(t.now):E(),a=t.unit,s.style=t.style,s.numberingSystem=t.numberingSystem),n||(n=E());const i=(new Date(e).getTime()-n.getTime())/1e3;a||(a=function(e){const t=Math.abs(e);return t<60?"second":t<T?"minute":t<N?"hour":t<y?"day":t<A?"week":t<F?"month":"year"}(i)),s.numeric="second"===a?"auto":"always";const u=function(e,t){return Math.round(e/R[t])}(i,a);return r.getRelativeTimeFormat(o,s).format(u,a)}catch(t){return i(new a(s.FORMATTING_ERROR,t.message)),String(e)}},list:function(e,t,a){const s=[],i=new Map;let u=0;for(const t of e){let e;"object"==typeof t?(e=String(u),i.set(e,t)):e=String(t),s.push(e),u++}return l(t,a,n?.list,(e=>{const t=r.getListFormat(o,e).formatToParts(s).map((e=>"literal"===e.type?e.value:i.get(e.value)||e.value));return i.size>0?t:t.join("")}),(()=>String(e)))},dateTimeRange:function(e,t,a,s){return l(a,s,n?.dateTime,(n=>(n=f(n),r.getDateTimeFormat(o,n).formatRange(e,t))),(()=>[I(e),I(t)].join(" – ")))}}}function h({formats:e,getMessageFallback:t,messages:r,onError:n,...o}){return{...o,formats:e||void 0,messages:r||void 0,onError:n||c,getMessageFallback:t||u}}export{a as I,s as a,g as b,d as c,m as d,E as e,u as f,c as g,h as i,S as r};
@@ -1 +1 @@
1
- import{createContext as e,useContext as r,useMemo as o,useState as t,useEffect as n}from"react";import{d as a,b as s,i as c,r as i,I as m,a as f,e as l,c as u}from"./initializeConfig-JxT5lzW-.js";import{jsx as g}from"react/jsx-runtime";const d=e(void 0);function w({children:e,formats:t,getMessageFallback:n,locale:i,messages:m,now:f,onError:l,timeZone:u}){const w=r(d),v=o((()=>w?.cache||a()),[i,w?.cache]),E=o((()=>w?.formatters||s(v)),[v,w?.formatters]),h=o((()=>({...c({locale:i,formats:void 0===t?w?.formats:t,getMessageFallback:n||w?.getMessageFallback,messages:void 0===m?w?.messages:m,now:f||w?.now,onError:l||w?.onError,timeZone:u||w?.timeZone}),formatters:E,cache:v})),[v,t,E,n,i,m,f,l,w,u]);return g(d.Provider,{value:h,children:e})}function v(){const e=r(d);if(!e)throw new Error(void 0);return e}let E=!1;const h="undefined"==typeof window;function p(e){return function(e,r,t){const{cache:n,formats:a,formatters:s,getMessageFallback:c,locale:u,onError:g,timeZone:d}=v(),w=e[t],p=i(r,t);return d||E||!h||(E=!0,g(new m(f.ENVIRONMENT_FALLBACK,void 0))),o((()=>l({cache:n,formatters:s,getMessageFallback:c,messages:w,namespace:p,onError:g,formats:a,locale:u,timeZone:d})),[n,s,c,w,p,g,a,u,d])}({"!":v().messages},e?`!.${e}`:"!","!")}function Z(){return v().locale}function b(){return new Date}function F(e){const r=e?.updateInterval,{now:o}=v(),[a,s]=t(o||b());return n((()=>{if(!r)return;const e=setInterval((()=>{s(b())}),r);return()=>{clearInterval(e)}}),[o,r]),null==r&&o?o:a}function M(){return v().timeZone}function k(){const e=v();if(!e.messages)throw new Error(void 0);return e.messages}function I(){const{formats:e,formatters:r,locale:t,now:n,onError:a,timeZone:s}=v();return o((()=>u({formats:e,locale:t,now:n,onError:a,timeZone:s,_formatters:r})),[e,r,n,t,a,s])}export{w as IntlProvider,I as useFormatter,Z as useLocale,k as useMessages,F as useNow,M as useTimeZone,p as useTranslations};
1
+ import{createContext as e,useContext as r,useMemo as t,useState as o,useEffect as n}from"react";import{d as a,b as s,i as c,r as i,I as m,a as f,e as u,c as l}from"./initializeConfig-CzP0yD8_.js";import{jsx as g}from"react/jsx-runtime";const d=e(void 0);function v({children:e,formats:o,getMessageFallback:n,locale:i,messages:m,now:f,onError:u,timeZone:l}){const v=r(d),w=t((()=>v?.cache||a()),[i,v?.cache]),h=t((()=>v?.formatters||s(w)),[w,v?.formatters]),p=t((()=>({...c({locale:i,formats:void 0===o?v?.formats:o,getMessageFallback:n||v?.getMessageFallback,messages:void 0===m?v?.messages:m,now:f||v?.now,onError:u||v?.onError,timeZone:l||v?.timeZone}),formatters:h,cache:w})),[w,o,h,n,i,m,f,u,v,l]);return g(d.Provider,{value:p,children:e})}function w(){const e=r(d);if(!e)throw new Error(void 0);return e}let h=!1;const p="undefined"==typeof window;function E(e){return function(e,r,o){const{cache:n,formats:a,formatters:s,getMessageFallback:c,locale:l,onError:g,timeZone:d}=w(),v=e[o],E=i(r,o);return d||h||!p||(h=!0,g(new m(f.ENVIRONMENT_FALLBACK,void 0))),t((()=>u({cache:n,formatters:s,getMessageFallback:c,messages:v,namespace:E,onError:g,formats:a,locale:l,timeZone:d})),[n,s,c,v,E,g,a,l,d])}({"!":w().messages},e?`!.${e}`:"!","!")}function Z(){return w().locale}function k(){return new Date}function b(e){const r=e?.updateInterval,{now:t}=w(),[a,s]=o(t||k());return n((()=>{if(!r)return;const e=setInterval((()=>{s(k())}),r);return()=>{clearInterval(e)}}),[t,r]),null==r&&t?t:a}function F(){return w().timeZone}function M(){const e=w();if(!e.messages)throw new Error(void 0);return e.messages}function I(){const{formats:e,formatters:r,locale:o,now:n,onError:a,timeZone:s}=w();return t((()=>l({formats:e,locale:o,now:n,onError:a,timeZone:s,_formatters:r})),[e,r,n,o,a,s])}function j(e,...r){let t,o;return"string"==typeof e?(t=r[0],o=r[1]):(t=e.values,o=e.formats),[void 0,t,o,void 0]}function x(e){const r=E(e);function t(...e){return r(...j(...e))}return t.rich=(...e)=>r.rich(...j(...e)),t.markup=(...e)=>r.markup(...j(...e)),t.has=function(e){return!0},t}export{v as IntlProvider,x as _useExtracted,I as useFormatter,Z as useLocale,M as useMessages,b as useNow,F as useTimeZone,E as useTranslations};
@@ -13,9 +13,9 @@ export type CreateBaseTranslatorProps<Messages> = InitializedIntlConfig & {
13
13
  messagesOrError: Messages | IntlError;
14
14
  };
15
15
  export default function createBaseTranslator<Messages extends AbstractIntlMessages, NestedKey extends NestedKeyOf<Messages>>(config: Omit<CreateBaseTranslatorProps<Messages>, 'messagesOrError'>): {
16
- <TargetKey extends MessageKeys<NestedValueOf<Messages, NestedKey>, NestedKeyOf<NestedValueOf<Messages, NestedKey>>>>(key: TargetKey, values?: TranslationValues, formats?: Formats): string;
17
- rich: (key: string, values?: RichTranslationValues, formats?: Formats) => ReactNode;
18
- markup(key: Parameters<(key: string, values?: RichTranslationValues, formats?: Formats) => ReactNode>[0], values: MarkupTranslationValues, formats?: Parameters<(key: string, values?: RichTranslationValues, formats?: Formats) => ReactNode>[2]): string;
16
+ <TargetKey extends MessageKeys<NestedValueOf<Messages, NestedKey>, NestedKeyOf<NestedValueOf<Messages, NestedKey>>>>(key: TargetKey, values?: TranslationValues, formats?: Formats, _fallback?: never): string;
17
+ rich: (key: string, values?: RichTranslationValues, formats?: Formats, _fallback?: never) => ReactNode;
18
+ markup(key: Parameters<(key: string, values?: RichTranslationValues, formats?: Formats, _fallback?: never) => ReactNode>[0], values: MarkupTranslationValues, formats?: Parameters<(key: string, values?: RichTranslationValues, formats?: Formats, _fallback?: never) => ReactNode>[2], _fallback?: never): string;
19
19
  raw(key: string): any;
20
20
  has(key: string): boolean;
21
21
  };
@@ -13,7 +13,7 @@ type ICUArgsWithTags<MessageString extends string, TagsFn extends RichTagsFuncti
13
13
  ICUDateArgument: Date;
14
14
  }> & ([TagsFn] extends [never] ? {} : ICUTags<MessageString, TagsFn>);
15
15
  type OnlyOptional<T> = Partial<T> extends T ? true : false;
16
- type TranslateArgs<Value extends string, TagsFn extends RichTagsFunction | MarkupTagsFunction = never> = string extends Value ? [
16
+ export type TranslateArgs<Value extends string, TagsFn extends RichTagsFunction | MarkupTagsFunction = never> = string extends Value ? [
17
17
  values?: Record<string, TranslationValues[string] | TagsFn>,
18
18
  formats?: Formats
19
19
  ] : (Value extends any ? (key: ICUArgsWithTags<Value, TagsFn>) => void : never) extends (key: infer Args) => void ? OnlyOptional<Args> extends true ? [values?: undefined, formats?: Formats] : [values: Prettify<Args>, formats?: Formats] : never;
@@ -30,6 +30,16 @@ type NamespacedMessageKeys<TranslatorMessages extends IntlMessages, Namespace ex
30
30
  type NamespacedValue<TranslatorMessages extends IntlMessages, Namespace extends NamespaceKeys<TranslatorMessages, NestedKeyOf<TranslatorMessages>>, TargetKey extends NamespacedMessageKeys<TranslatorMessages, Namespace>> = NestedValueOf<TranslatorMessages, [
31
31
  Namespace
32
32
  ] extends [never] ? TargetKey : `${Namespace}.${TargetKey}`>;
33
+ /**
34
+ * @private Not intended for direct use.
35
+ */
36
+ export type Translator<TranslatorMessages extends IntlMessages = IntlMessages, Namespace extends NamespaceKeys<TranslatorMessages, NestedKeyOf<TranslatorMessages>> = never> = {
37
+ <TargetKey extends NamespacedMessageKeys<TranslatorMessages, Namespace>>(key: TargetKey, ...args: TranslateArgs<NamespacedValue<TranslatorMessages, Namespace, TargetKey>>): string;
38
+ rich<TargetKey extends NamespacedMessageKeys<TranslatorMessages, Namespace>>(key: TargetKey, ...args: TranslateArgs<NamespacedValue<TranslatorMessages, Namespace, TargetKey>, RichTagsFunction>): ReactNode;
39
+ markup<TargetKey extends NamespacedMessageKeys<TranslatorMessages, Namespace>>(key: TargetKey, ...args: TranslateArgs<NamespacedValue<TranslatorMessages, Namespace, TargetKey>, MarkupTagsFunction>): string;
40
+ raw<TargetKey extends NamespacedMessageKeys<TranslatorMessages, Namespace>>(key: TargetKey): any;
41
+ has<TargetKey extends NamespacedMessageKeys<TranslatorMessages, Namespace>>(key: TargetKey): boolean;
42
+ };
33
43
  /**
34
44
  * Translates messages from the given namespace by using the ICU syntax.
35
45
  * See https://formatjs.io/docs/core-concepts/icu-syntax.
@@ -45,11 +55,5 @@ export default function createTranslator<const TranslatorMessages extends IntlMe
45
55
  _formatters?: Formatters;
46
56
  /** @private */
47
57
  _cache?: IntlCache;
48
- }): {
49
- <TargetKey extends NamespacedMessageKeys<TranslatorMessages, Namespace>>(key: TargetKey, ...args: TranslateArgs<NamespacedValue<TranslatorMessages, Namespace, TargetKey>>): string;
50
- rich<TargetKey extends NamespacedMessageKeys<TranslatorMessages, Namespace>>(key: TargetKey, ...args: TranslateArgs<NamespacedValue<TranslatorMessages, Namespace, TargetKey>, RichTagsFunction>): ReactNode;
51
- markup<TargetKey extends NamespacedMessageKeys<TranslatorMessages, Namespace>>(key: TargetKey, ...args: TranslateArgs<NamespacedValue<TranslatorMessages, Namespace, TargetKey>, MarkupTagsFunction>): string;
52
- raw<TargetKey extends NamespacedMessageKeys<TranslatorMessages, Namespace>>(key: TargetKey): any;
53
- has<TargetKey extends NamespacedMessageKeys<TranslatorMessages, Namespace>>(key: TargetKey): boolean;
54
- };
58
+ }): Translator<TranslatorMessages, Namespace>;
55
59
  export {};
@@ -9,9 +9,9 @@ export type CreateTranslatorImplProps<Messages> = Omit<InitializedIntlConfig, 'm
9
9
  cache: IntlCache;
10
10
  };
11
11
  export default function createTranslatorImpl<Messages extends AbstractIntlMessages, NestedKey extends NestedKeyOf<Messages>>({ messages, namespace, ...rest }: CreateTranslatorImplProps<Messages>, namespacePrefix: string): {
12
- <TargetKey extends import("./MessageKeys.js").MessageKeys<import("./MessageKeys.js").NestedValueOf<Messages, NestedKey>, NestedKeyOf<import("./MessageKeys.js").NestedValueOf<Messages, NestedKey>>>>(key: TargetKey, values?: import("./TranslationValues.js").TranslationValues, formats?: import("./Formats.js").default): string;
13
- rich: (key: string, values?: import("./TranslationValues.js").RichTranslationValues, formats?: import("./Formats.js").default) => import("react").ReactNode;
14
- markup(key: Parameters<(key: string, values?: import("./TranslationValues.js").RichTranslationValues, formats?: import("./Formats.js").default) => import("react").ReactNode>[0], values: import("./TranslationValues.js").MarkupTranslationValues, formats?: Parameters<(key: string, values?: import("./TranslationValues.js").RichTranslationValues, formats?: import("./Formats.js").default) => import("react").ReactNode>[2]): string;
12
+ <TargetKey extends import("./MessageKeys.js").MessageKeys<import("./MessageKeys.js").NestedValueOf<Messages, NestedKey>, NestedKeyOf<import("./MessageKeys.js").NestedValueOf<Messages, NestedKey>>>>(key: TargetKey, values?: import("./TranslationValues.js").TranslationValues, formats?: import("./Formats.js").default, _fallback?: never): string;
13
+ rich: (key: string, values?: import("./TranslationValues.js").RichTranslationValues, formats?: import("./Formats.js").default, _fallback?: never) => import("react").ReactNode;
14
+ markup(key: Parameters<(key: string, values?: import("./TranslationValues.js").RichTranslationValues, formats?: import("./Formats.js").default, _fallback?: never) => import("react").ReactNode>[0], values: import("./TranslationValues.js").MarkupTranslationValues, formats?: Parameters<(key: string, values?: import("./TranslationValues.js").RichTranslationValues, formats?: import("./Formats.js").default, _fallback?: never) => import("react").ReactNode>[2], _fallback?: never): string;
15
15
  raw(key: string): any;
16
16
  has(key: string): boolean;
17
17
  };
@@ -18,3 +18,5 @@ export type { default as RelativeTimeFormatOptions } from './RelativeTimeFormatO
18
18
  export type { default as Timezone } from './TimeZone.js';
19
19
  export type { default as ICUArgs } from './ICUArgs.js';
20
20
  export type { default as ICUTags } from './ICUTags.js';
21
+ /** @private -- Only for type portability */
22
+ export type { Translator as _Translator } from './createTranslator.js';
@@ -5,3 +5,5 @@ export { default as useNow } from './useNow.js';
5
5
  export { default as useTimeZone } from './useTimeZone.js';
6
6
  export { default as useMessages } from './useMessages.js';
7
7
  export { default as useFormatter } from './useFormatter.js';
8
+ /** @private -- Only for usage in `next-intl` currently */
9
+ export { default as _useExtracted } from './useExtracted.js';
@@ -0,0 +1,42 @@
1
+ import type { ReactNode } from 'react';
2
+ import type { MarkupTagsFunction, RichTagsFunction } from '../core/TranslationValues.js';
3
+ import type { TranslateArgs } from '../core/createTranslator.js';
4
+ type TranslateArgsObject<Value extends string, TagsFn extends RichTagsFunction | MarkupTagsFunction = never> = TranslateArgs<Value, TagsFn> extends readonly [any?, any?] ? undefined extends TranslateArgs<Value, TagsFn>[0] ? {
5
+ values?: TranslateArgs<Value, TagsFn>[0];
6
+ formats?: TranslateArgs<Value, TagsFn>[1];
7
+ } : {
8
+ values: TranslateArgs<Value, TagsFn>[0];
9
+ formats?: TranslateArgs<Value, TagsFn>[1];
10
+ } : never;
11
+ export default function useExtracted(namespace?: string): {
12
+ <Message extends string>(message: Message, ...[values, formats]: TranslateArgs<Message>): string;
13
+ <Message extends string>(params: {
14
+ id?: string;
15
+ /** Inline ICU message in the source locale. */
16
+ message: Message;
17
+ /** Description for translators and tooling. */
18
+ description?: string;
19
+ } & TranslateArgsObject<Message>): string;
20
+ rich: {
21
+ <Message extends string>(message: Message, ...[values, formats]: TranslateArgs<Message, RichTagsFunction>): ReactNode;
22
+ <Message extends string>(params: {
23
+ id?: string;
24
+ /** Inline ICU message in the source locale. */
25
+ message: Message;
26
+ /** Description for translators and tooling. */
27
+ description?: string;
28
+ } & TranslateArgsObject<Message, RichTagsFunction>): ReactNode;
29
+ };
30
+ markup: {
31
+ <Message extends string>(message: Message, ...[values, formats]: TranslateArgs<Message, MarkupTagsFunction>): string;
32
+ <Message extends string>(params: {
33
+ id?: string;
34
+ /** Inline ICU message in the source locale. */
35
+ message: Message;
36
+ /** Description for translators and tooling. */
37
+ description?: string;
38
+ } & TranslateArgsObject<Message, MarkupTagsFunction>): string;
39
+ };
40
+ has<Message extends string>(message: Message): boolean;
41
+ };
42
+ export {};
@@ -1,9 +1,9 @@
1
1
  import type AbstractIntlMessages from '../core/AbstractIntlMessages.js';
2
2
  import type { NestedKeyOf } from '../core/MessageKeys.js';
3
3
  export default function useTranslationsImpl<Messages extends AbstractIntlMessages, NestedKey extends NestedKeyOf<Messages>>(allMessagesPrefixed: Messages, namespacePrefixed: NestedKey, namespacePrefix: string): {
4
- <TargetKey extends unknown>(key: TargetKey, values?: import("../core.js").TranslationValues, formats?: import("../core.js").Formats): string;
5
- rich: (key: string, values?: import("../core.js").RichTranslationValues, formats?: import("../core.js").Formats) => import("react").ReactNode;
6
- markup(key: Parameters<(key: string, values?: import("../core.js").RichTranslationValues, formats?: import("../core.js").Formats) => import("react").ReactNode>[0], values: import("../core.js").MarkupTranslationValues, formats?: Parameters<(key: string, values?: import("../core.js").RichTranslationValues, formats?: import("../core.js").Formats) => import("react").ReactNode>[2]): string;
4
+ <TargetKey extends unknown>(key: TargetKey, values?: import("../core.js").TranslationValues, formats?: import("../core.js").Formats, _fallback?: never): string;
5
+ rich: (key: string, values?: import("../core.js").RichTranslationValues, formats?: import("../core.js").Formats, _fallback?: never) => import("react").ReactNode;
6
+ markup(key: Parameters<(key: string, values?: import("../core.js").RichTranslationValues, formats?: import("../core.js").Formats, _fallback?: never) => import("react").ReactNode>[0], values: import("../core.js").MarkupTranslationValues, formats?: Parameters<(key: string, values?: import("../core.js").RichTranslationValues, formats?: import("../core.js").Formats, _fallback?: never) => import("react").ReactNode>[2], _fallback?: never): string;
7
7
  raw(key: string): any;
8
8
  has(key: string): boolean;
9
9
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "use-intl",
3
- "version": "4.4.0",
3
+ "version": "4.5.1",
4
4
  "sideEffects": false,
5
5
  "author": "Jan Amann <jan@amann.work>",
6
6
  "description": "Internationalization (i18n) for React",
@@ -8,7 +8,7 @@
8
8
  "homepage": "https://next-intl.dev",
9
9
  "repository": {
10
10
  "type": "git",
11
- "url": "https://github.com/amannn/next-intl/tree/main/packages/use-intl"
11
+ "url": "git+https://github.com/amannn/next-intl.git"
12
12
  },
13
13
  "scripts": {
14
14
  "build": "rm -rf dist && rollup -c",
@@ -64,5 +64,5 @@
64
64
  "peerDependencies": {
65
65
  "react": "^17.0.0 || ^18.0.0 || >=19.0.0-rc <19.0.0 || ^19.0.0"
66
66
  },
67
- "gitHead": "bc09e3c77a2776af7124259a9166e80d44f9b651"
67
+ "gitHead": "7b3475d6299109a61fc30324d32175a37bfc16c9"
68
68
  }
@@ -1 +0,0 @@
1
- import{IntlMessageFormat as e}from"intl-messageformat";import{isValidElement as t,cloneElement as r}from"react";import{memoize as n,strategies as o}from"@formatjs/fast-memoize";class a extends Error{constructor(e,t){let r=e;t&&(r+=": "+t),super(r),this.code=e,t&&(this.originalMessage=t)}}var s=function(e){return e.MISSING_MESSAGE="MISSING_MESSAGE",e.MISSING_FORMAT="MISSING_FORMAT",e.ENVIRONMENT_FALLBACK="ENVIRONMENT_FALLBACK",e.INSUFFICIENT_PATH="INSUFFICIENT_PATH",e.INVALID_MESSAGE="INVALID_MESSAGE",e.INVALID_KEY="INVALID_KEY",e.FORMATTING_ERROR="FORMATTING_ERROR",e}(s||{});function i(...e){return e.filter(Boolean).join(".")}function u(e){return i(e.namespace,e.key)}function c(e){console.error(e)}function m(){return{dateTime:{},number:{},message:{},relativeTime:{},pluralRules:{},list:{},displayNames:{}}}function f(e,t){return n(e,{cache:(r=t,{create:()=>({get:e=>r[e],set(e,t){r[e]=t}})}),strategy:o.variadic});var r}function l(e,t){return f(((...t)=>new e(...t)),t)}function g(e){return{getDateTimeFormat:l(Intl.DateTimeFormat,e.dateTime),getNumberFormat:l(Intl.NumberFormat,e.number),getPluralRules:l(Intl.PluralRules,e.pluralRules),getRelativeTimeFormat:l(Intl.RelativeTimeFormat,e.relativeTime),getListFormat:l(Intl.ListFormat,e.list),getDisplayNames:l(Intl.DisplayNames,e.displayNames)}}function I(e,t,r,n){const o=i(n,r);if(!t)throw new Error(o);let a=t;return r.split(".").forEach((t=>{const r=a[t];if(null==t||null==r)throw new Error(o+` (${e})`);a=r})),a}function E(n){const o=function(e,t,r,n=c){try{if(!t)throw new Error(void 0);const n=r?I(e,t,r):t;if(!n)throw new Error(r);return n}catch(e){const t=new a(s.MISSING_MESSAGE,e.message);return n(t),t}}(n.locale,n.messages,n.namespace,n.onError);return function({cache:n,formats:o,formatters:i,getMessageFallback:c=u,locale:m,messagesOrError:l,namespace:g,onError:E,timeZone:S}){const T=l instanceof a;function N(e,t,r){const n=new a(t,r);return E(n),c({error:n,key:e,namespace:g})}function y(a,u,E){if(T)return c({error:l,key:a,namespace:g});const y=l;let A,M;try{A=I(m,y,a,g)}catch(e){return N(a,s.MISSING_MESSAGE,e.message)}if("object"==typeof A){let e,t;return e=Array.isArray(A)?s.INVALID_MESSAGE:s.INSUFFICIENT_PATH,N(a,e,t)}const F=function(e,t){return t||/'[{}]/.test(e)?void 0:e}(A,u);if(F)return F;i.getMessageFormat||(i.getMessageFormat=function(t,r){return f(((...t)=>new e(t[0],t[1],t[2],{formatters:r,...t[3]})),t.message)}(n,i));try{M=i.getMessageFormat(A,m,function(t,r,n){const o=e.formats.date,a=e.formats.time,s={...t?.dateTime,...r?.dateTime},i={date:{...o,...s},time:{...a,...s},number:{...t?.number,...r?.number}};return n&&["date","time"].forEach((e=>{const t=i[e];for(const[e,r]of Object.entries(t))t[e]={timeZone:n,...r}})),i}(o,E,S),{formatters:{...i,getDateTimeFormat:(e,t)=>i.getDateTimeFormat(e,{timeZone:S,...t})}})}catch(e){const t=e;return N(a,s.INVALID_MESSAGE,t.message)}try{const e=M.format(u?function(e){const n={};return Object.keys(e).forEach((o=>{let a=0;const s=e[o];let i;i="function"==typeof s?e=>{const n=s(e);return t(n)?r(n,{key:o+a++}):n}:s,n[o]=i})),n}(u):u);if(null==e)throw new Error(void 0);return t(e)||Array.isArray(e)||"string"==typeof e?e:String(e)}catch(e){return N(a,s.FORMATTING_ERROR,e.message)}}function A(e,t,r){const n=y(e,t,r);return"string"!=typeof n?N(e,s.INVALID_MESSAGE,void 0):n}return A.rich=y,A.markup=(e,t,r)=>y(e,t,r),A.raw=e=>{if(T)return c({error:l,key:e,namespace:g});const t=l;try{return I(m,t,e,g)}catch(t){return N(e,s.MISSING_MESSAGE,t.message)}},A.has=e=>{if(T)return!1;try{return I(m,l,e,g),!0}catch{return!1}},A}({...n,messagesOrError:o})}function S(e,t){return e===t?void 0:e.slice((t+".").length)}const T=3600,N=86400,y=7*N,A=2628e3,M=7884e3,F=365*N,R={second:1,seconds:1,minute:60,minutes:60,hour:T,hours:T,day:N,days:N,week:y,weeks:y,month:A,months:A,quarter:M,quarters:M,year:F,years:F};function d(e){const{_cache:t=m(),_formatters:r=g(t),formats:n,locale:o,onError:i=c,timeZone:u}=e;function f(e){return e?.timeZone||(u?e={...e,timeZone:u}:i(new a(s.ENVIRONMENT_FALLBACK,void 0))),e}function l(e,t,r,n,o){let u;try{u=function(e,t,r){let n;if("string"==typeof t){const r=t;if(n=e?.[r],!n){const e=new a(s.MISSING_FORMAT,void 0);throw i(e),e}}else n=t;return r&&(n={...n,...r}),n}(r,e,t)}catch{return o()}try{return n(u)}catch(e){return i(new a(s.FORMATTING_ERROR,e.message)),o()}}function I(e,t,a){return l(t,a,n?.dateTime,(t=>(t=f(t),r.getDateTimeFormat(o,t).format(e))),(()=>String(e)))}function E(){return e.now?e.now:(i(new a(s.ENVIRONMENT_FALLBACK,void 0)),new Date)}return{dateTime:I,number:function(e,t,a){return l(t,a,n?.number,(t=>r.getNumberFormat(o,t).format(e)),(()=>String(e)))},relativeTime:function(e,t){try{let n,a;const s={};t instanceof Date||"number"==typeof t?n=new Date(t):t&&(n=null!=t.now?new Date(t.now):E(),a=t.unit,s.style=t.style,s.numberingSystem=t.numberingSystem),n||(n=E());const i=(new Date(e).getTime()-n.getTime())/1e3;a||(a=function(e){const t=Math.abs(e);return t<60?"second":t<T?"minute":t<N?"hour":t<y?"day":t<A?"week":t<F?"month":"year"}(i)),s.numeric="second"===a?"auto":"always";const u=function(e,t){return Math.round(e/R[t])}(i,a);return r.getRelativeTimeFormat(o,s).format(u,a)}catch(t){return i(new a(s.FORMATTING_ERROR,t.message)),String(e)}},list:function(e,t,a){const s=[],i=new Map;let u=0;for(const t of e){let e;"object"==typeof t?(e=String(u),i.set(e,t)):e=String(t),s.push(e),u++}return l(t,a,n?.list,(e=>{const t=r.getListFormat(o,e).formatToParts(s).map((e=>"literal"===e.type?e.value:i.get(e.value)||e.value));return i.size>0?t:t.join("")}),(()=>String(e)))},dateTimeRange:function(e,t,a,s){return l(a,s,n?.dateTime,(n=>(n=f(n),r.getDateTimeFormat(o,n).formatRange(e,t))),(()=>[I(e),I(t)].join(" – ")))}}}function h({formats:e,getMessageFallback:t,messages:r,onError:n,...o}){return{...o,formats:e||void 0,messages:r||void 0,onError:n||c,getMessageFallback:t||u}}export{a as I,s as a,g as b,d as c,m as d,E as e,u as f,c as g,h as i,S as r};