use-intl 4.0.0-beta-5b218d4 → 4.0.0-beta-c40c5c9

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, d as createCache, b as createIntlFormatters, f as defaultGetMessageFallback, g as defaultOnError } from './initializeConfig-DNjOIggo.js';
2
- export { I as IntlError, a as IntlErrorCode, c as createFormatter, i as initializeConfig } from './initializeConfig-DNjOIggo.js';
1
+ import { r as resolveNamespace, e as createBaseTranslator, d as createCache, b as createIntlFormatters, f as defaultGetMessageFallback, g as defaultOnError } from './initializeConfig-PNba6rGQ.js';
2
+ export { I as IntlError, a as IntlErrorCode, c as createFormatter, i as initializeConfig } from './initializeConfig-PNba6rGQ.js';
3
3
 
4
4
 
5
5
 
@@ -1,4 +1,4 @@
1
- export { I as IntlError, a as IntlErrorCode, d as _createCache, b as _createIntlFormatters, c as createFormatter, i as initializeConfig } from './initializeConfig-DNjOIggo.js';
1
+ export { I as IntlError, a as IntlErrorCode, d as _createCache, b as _createIntlFormatters, c as createFormatter, i as initializeConfig } from './initializeConfig-PNba6rGQ.js';
2
2
  export { createTranslator, hasLocale } from './core.js';
3
3
  export { IntlProvider, useFormatter, useLocale, useMessages, useNow, useTimeZone, useTranslations } from './react.js';
4
4
 
@@ -669,6 +669,7 @@ const output = Object.entries(input).reduce(
669
669
  * Enhances the incoming props with defaults.
670
670
  */
671
671
  function initializeConfig({
672
+ formats,
672
673
  getMessageFallback,
673
674
  messages,
674
675
  onError,
@@ -683,7 +684,8 @@ function initializeConfig({
683
684
  }
684
685
  return {
685
686
  ...rest,
686
- messages,
687
+ formats: formats || undefined,
688
+ messages: messages || undefined,
687
689
  onError: finalOnError,
688
690
  getMessageFallback: finalGetMessageFallback
689
691
  };
@@ -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-DNjOIggo.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-PNba6rGQ.js';
3
3
  import { jsx } from 'react/jsx-runtime';
4
4
 
5
5
 
@@ -38,9 +38,9 @@ function IntlProvider({
38
38
  ...initializeConfig({
39
39
  locale,
40
40
  // (required by provider)
41
- formats: formats || prevContext?.formats,
41
+ formats: formats === undefined ? prevContext?.formats : formats,
42
42
  getMessageFallback: getMessageFallback || prevContext?.getMessageFallback,
43
- messages: messages || prevContext?.messages,
43
+ messages: messages === undefined ? prevContext?.messages : messages,
44
44
  now: now || prevContext?.now,
45
45
  onError: onError || prevContext?.onError,
46
46
  timeZone: timeZone || prevContext?.timeZone
@@ -1 +1 @@
1
- import{r as e,e as s,d as r,b as t,f as o,g as n}from"./initializeConfig-BE7tJS3N.js";export{I as IntlError,a as IntlErrorCode,c as createFormatter,i as initializeConfig}from"./initializeConfig-BE7tJS3N.js";function m({_cache:a=r(),_formatters:i=t(a),getMessageFallback:m=o,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{r as _createCache,t as _createIntlFormatters,m as createTranslator,f as hasLocale};
1
+ import{r as e,e as s,d as r,b as t,f as o,g as n}from"./initializeConfig-C-a_U8o2.js";export{I as IntlError,a as IntlErrorCode,c as createFormatter,i as initializeConfig}from"./initializeConfig-C-a_U8o2.js";function m({_cache:a=r(),_formatters:i=t(a),getMessageFallback:m=o,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{r 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-BE7tJS3N.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-C-a_U8o2.js";export{createTranslator,hasLocale}from"./core.js";export{IntlProvider,useFormatter,useLocale,useMessages,useNow,useTimeZone,useTranslations}from"./react.js";
@@ -1 +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,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?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 h(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){let o;try{o=function(e,t){let r;if("string"==typeof t){const n=t;if(r=e?.[n],!r){const e=new a(s.MISSING_FORMAT,void 0);throw i(e),e}}else r=t;return r}(t,e)}catch{return n()}try{return r(o)}catch(e){return i(new a(s.FORMATTING_ERROR,e.message)),n()}}function I(e,t){return l(t,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){return l(t,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){const a=[],s=new Map;let i=0;for(const t of e){let e;"object"==typeof t?(e=String(i),s.set(e,t)):e=String(t),a.push(e),i++}return l(t,n?.list,(e=>{const t=r.getListFormat(o,e).formatToParts(a).map((e=>"literal"===e.type?e.value:s.get(e.value)||e.value));return s.size>0?t:t.join("")}),(()=>String(e)))},dateTimeRange:function(e,t,a){return l(a,n?.dateTime,(n=>(n=f(n),r.getDateTimeFormat(o,n).formatRange(e,t))),(()=>[I(e),I(t)].join(" – ")))}}}function w({getMessageFallback:e,messages:t,onError:r,...n}){return{...n,messages:t,onError:r||c,getMessageFallback:e||u}}export{a as I,s as a,g as b,h as c,m as d,E as e,u as f,c as g,w as i,S as r};
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?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){let o;try{o=function(e,t){let r;if("string"==typeof t){const n=t;if(r=e?.[n],!r){const e=new a(s.MISSING_FORMAT,void 0);throw i(e),e}}else r=t;return r}(t,e)}catch{return n()}try{return r(o)}catch(e){return i(new a(s.FORMATTING_ERROR,e.message)),n()}}function I(e,t){return l(t,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){return l(t,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){const a=[],s=new Map;let i=0;for(const t of e){let e;"object"==typeof t?(e=String(i),s.set(e,t)):e=String(t),a.push(e),i++}return l(t,n?.list,(e=>{const t=r.getListFormat(o,e).formatToParts(a).map((e=>"literal"===e.type?e.value:s.get(e.value)||e.value));return s.size>0?t:t.join("")}),(()=>String(e)))},dateTimeRange:function(e,t,a){return l(a,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-BE7tJS3N.js";import{jsx as g}from"react/jsx-runtime";const w=e(void 0);function d({children:e,formats:t,getMessageFallback:n,locale:i,messages:m,now:f,onError:l,timeZone:u}){const d=r(w),E=o((()=>d?.cache||a()),[i,d?.cache]),h=o((()=>d?.formatters||s(E)),[E,d?.formatters]),p=o((()=>({...c({locale:i,formats:t||d?.formats,getMessageFallback:n||d?.getMessageFallback,messages:m||d?.messages,now:f||d?.now,onError:l||d?.onError,timeZone:u||d?.timeZone}),formatters:h,cache:E})),[E,t,h,n,i,m,f,l,d,u]);return g(w.Provider,{value:p,children:e})}function E(){const e=r(w);if(!e)throw new Error(void 0);return e}let h=!1;const p="undefined"==typeof window;function v(e){return function(e,r,t){const{cache:n,formats:a,formatters:s,getMessageFallback:c,locale:u,onError:g,timeZone:w}=E(),d=e[t],v=i(r,t);return w||h||!p||(h=!0,g(new m(f.ENVIRONMENT_FALLBACK,void 0))),o((()=>l({cache:n,formatters:s,getMessageFallback:c,messages:d,namespace:v,onError:g,formats:a,locale:u,timeZone:w})),[n,s,c,d,v,g,a,u,w])}({"!":E().messages},e?`!.${e}`:"!","!")}function Z(){return E().locale}function b(){return new Date}function F(e){const r=e?.updateInterval,{now:o}=E(),[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 E().timeZone}function k(){const e=E();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}=E();return o((()=>u({formats:e,locale:t,now:n,onError:a,timeZone:s,_formatters:r})),[e,r,n,t,a,s])}export{d as IntlProvider,I as useFormatter,Z as useLocale,k as useMessages,F as useNow,M as useTimeZone,v as useTranslations};
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-C-a_U8o2.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,17 +1,17 @@
1
- import type AbstractIntlMessages from './AbstractIntlMessages.js';
2
- import type { Locale } from './AppConfig.js';
1
+ import type { Locale, Messages } from './AppConfig.js';
3
2
  import type Formats from './Formats.js';
4
3
  import type IntlError from './IntlError.js';
5
4
  import type TimeZone from './TimeZone.js';
5
+ import type { DeepPartial } from './types.js';
6
6
  /**
7
7
  * Should be used for entry points that configure the library.
8
8
  */
9
- type IntlConfig<Messages extends AbstractIntlMessages = AbstractIntlMessages> = {
9
+ type IntlConfig = {
10
10
  /** A valid Unicode locale tag (e.g. "en" or "en-GB"). */
11
11
  locale: Locale;
12
12
  /** Global formats can be provided to achieve consistent
13
13
  * formatting across components. */
14
- formats?: Formats;
14
+ formats?: Formats | null;
15
15
  /** 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`. */
16
16
  timeZone?: TimeZone;
17
17
  /** This callback will be invoked when an error is encountered during
@@ -38,14 +38,17 @@ type IntlConfig<Messages extends AbstractIntlMessages = AbstractIntlMessages> =
38
38
  */
39
39
  now?: Date;
40
40
  /** All messages that will be available. */
41
- messages?: Messages;
41
+ messages?: DeepPartial<Messages> | null;
42
42
  };
43
+ /**
43
44
  /**
44
45
  * A stricter set of the configuration that should be used internally
45
46
  * once defaults are assigned to `IntlConfiguration`.
46
47
  */
47
- export type InitializedIntlConfig<Messages extends AbstractIntlMessages = AbstractIntlMessages> = IntlConfig<Messages> & {
48
- onError: NonNullable<IntlConfig<Messages>['onError']>;
49
- getMessageFallback: NonNullable<IntlConfig<Messages>['getMessageFallback']>;
48
+ export type InitializedIntlConfig = Omit<IntlConfig, 'formats' | 'messages' | 'onError' | 'getMessageFallback'> & {
49
+ formats?: NonNullable<IntlConfig['formats']>;
50
+ messages?: NonNullable<IntlConfig['messages']>;
51
+ onError: NonNullable<IntlConfig['onError']>;
52
+ getMessageFallback: NonNullable<IntlConfig['getMessageFallback']>;
50
53
  };
51
54
  export default IntlConfig;
@@ -38,7 +38,7 @@ type NamespacedValue<TranslatorMessages extends IntlMessages, Namespace extends
38
38
  * The namespace can also indicate nesting by using a dot
39
39
  * (e.g. `namespace.Component`).
40
40
  */
41
- export default function createTranslator<const TranslatorMessages extends IntlMessages, const Namespace extends NamespaceKeys<TranslatorMessages, NestedKeyOf<TranslatorMessages>> = never>({ _cache, _formatters, getMessageFallback, messages, namespace, onError, ...rest }: Omit<IntlConfig<TranslatorMessages>, 'messages'> & {
41
+ export default function createTranslator<const TranslatorMessages extends IntlMessages, const Namespace extends NamespaceKeys<TranslatorMessages, NestedKeyOf<TranslatorMessages>> = never>({ _cache, _formatters, getMessageFallback, messages, namespace, onError, ...rest }: Omit<IntlConfig, 'messages'> & {
42
42
  messages?: TranslatorMessages;
43
43
  namespace?: Namespace;
44
44
  /** @private */
@@ -2,8 +2,9 @@ import type IntlConfig from './IntlConfig.js';
2
2
  /**
3
3
  * Enhances the incoming props with defaults.
4
4
  */
5
- export default function initializeConfig<Props extends IntlConfig>({ getMessageFallback, messages, onError, ...rest }: Props): Omit<Props, "onError" | "getMessageFallback" | "messages"> & {
6
- messages: import("./AbstractIntlMessages.js").default | undefined;
5
+ export default function initializeConfig<Props extends IntlConfig>({ formats, getMessageFallback, messages, onError, ...rest }: Props): Omit<Props, "formats" | "messages" | "onError" | "getMessageFallback"> & {
6
+ formats: NonNullable<IntlConfig["formats"]> | undefined;
7
+ messages: NonNullable<IntlConfig["messages"]> | undefined;
7
8
  onError: (error: import("./IntlError.js").default) => void;
8
9
  getMessageFallback: (info: {
9
10
  error: import("./IntlError.js").default;
@@ -1,3 +1,6 @@
1
1
  export type Prettify<T> = {
2
2
  [K in keyof T]: T[K];
3
3
  } & {};
4
+ export type DeepPartial<Type> = {
5
+ [Key in keyof Type]?: Type[Key] extends object ? DeepPartial<Type[Key]> : Type[Key];
6
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "use-intl",
3
- "version": "4.0.0-beta-5b218d4",
3
+ "version": "4.0.0-beta-c40c5c9",
4
4
  "sideEffects": false,
5
5
  "author": "Jan Amann <jan@amann.work>",
6
6
  "description": "Internationalization (i18n) for React",
@@ -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": "1ea3a6b31662c37c0dcd2800ada448ece5cd0641"
67
+ "gitHead": "2d8a449b1dbc4f02e75aa616f9943daeb60228c1"
68
68
  }