use-intl 3.6.0 → 3.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -54,7 +54,7 @@ export default function UserProfile({user}) {
54
54
  2. Add the provider
55
55
 
56
56
  ```jsx
57
- import {IntlProvider} from 'use-intl';
57
+ import {IntlProvider, useTranslations} from 'use-intl';
58
58
 
59
59
  // You can get the messages from anywhere you like. You can also
60
60
  // fetch them from within a component and then render the provider
@@ -79,7 +79,7 @@ function App({user}) {
79
79
  }
80
80
  ```
81
81
 
82
- Have a look at [the minimal setup example](https://codesandbox.io/s/use-intl-cra-example-13w917?file=/src/Root.tsx) to explore a working app.
82
+ Have a look at [the minimal setup example](https://github.com/amannn/next-intl/tree/main/examples/example-use-intl) to explore a working app.
83
83
 
84
84
  ## Usage
85
85
 
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var initializeConfig = require('./initializeConfig-c503e215.js');
6
- var createFormatter = require('./createFormatter-4ce6f6c8.js');
6
+ var createFormatter = require('./createFormatter-81d7e598.js');
7
7
  require('intl-messageformat');
8
8
  require('react');
9
9
 
@@ -358,6 +358,20 @@ function createFormatter(_ref) {
358
358
  onError = initializeConfig.defaultOnError,
359
359
  timeZone: globalTimeZone
360
360
  } = _ref;
361
+ function applyTimeZone(options) {
362
+ var _options;
363
+ if (!((_options = options) !== null && _options !== void 0 && _options.timeZone)) {
364
+ if (globalTimeZone) {
365
+ options = {
366
+ ...options,
367
+ timeZone: globalTimeZone
368
+ };
369
+ } else {
370
+ onError(new initializeConfig.IntlError(initializeConfig.IntlErrorCode.ENVIRONMENT_FALLBACK, "The `timeZone` parameter wasn't provided and there is no global default configured. Consider adding a global default to avoid markup mismatches caused by environment differences. Learn more: https://next-intl-docs.vercel.app/docs/configuration#time-zone" ));
371
+ }
372
+ }
373
+ return options;
374
+ }
361
375
  function resolveFormatOrOptions(typeFormats, formatOrOptions) {
362
376
  let options;
363
377
  if (typeof formatOrOptions === 'string') {
@@ -393,20 +407,21 @@ function createFormatter(_ref) {
393
407
  * Otherwise the user time zone will be used. */
394
408
  formatOrOptions) {
395
409
  return getFormattedValue(formatOrOptions, formats === null || formats === void 0 ? void 0 : formats.dateTime, options => {
396
- var _options;
397
- if (!((_options = options) !== null && _options !== void 0 && _options.timeZone)) {
398
- if (globalTimeZone) {
399
- options = {
400
- ...options,
401
- timeZone: globalTimeZone
402
- };
403
- } else {
404
- onError(new initializeConfig.IntlError(initializeConfig.IntlErrorCode.ENVIRONMENT_FALLBACK, "The `timeZone` parameter wasn't provided and there is no global default configured. Consider adding a global default to avoid markup mismatches caused by environment differences. Learn more: https://next-intl-docs.vercel.app/docs/configuration#time-zone" ));
405
- }
406
- }
410
+ options = applyTimeZone(options);
407
411
  return new Intl.DateTimeFormat(locale, options).format(value);
408
412
  }, () => String(value));
409
413
  }
414
+ function dateTimeRange( /** If a number is supplied, this is interpreted as a UTC timestamp. */
415
+ start, /** If a number is supplied, this is interpreted as a UTC timestamp. */
416
+ end,
417
+ /** If a time zone is supplied, the values are converted to that time zone.
418
+ * Otherwise the user time zone will be used. */
419
+ formatOrOptions) {
420
+ return getFormattedValue(formatOrOptions, formats === null || formats === void 0 ? void 0 : formats.dateTime, options => {
421
+ options = applyTimeZone(options);
422
+ return new Intl.DateTimeFormat(locale, options).formatRange(start, end);
423
+ }, () => [dateTime(start), dateTime(end)].join(' – '));
424
+ }
410
425
  function number(value, formatOrOptions) {
411
426
  return getFormattedValue(formatOrOptions, formats === null || formats === void 0 ? void 0 : formats.number, options => new Intl.NumberFormat(locale, options).format(value), () => String(value));
412
427
  }
@@ -486,7 +501,8 @@ function createFormatter(_ref) {
486
501
  dateTime,
487
502
  number,
488
503
  relativeTime,
489
- list
504
+ list,
505
+ dateTimeRange
490
506
  };
491
507
  }
492
508
 
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var initializeConfig = require('./initializeConfig-c503e215.js');
6
6
  var core = require('./core.js');
7
- var createFormatter = require('./createFormatter-4ce6f6c8.js');
7
+ var createFormatter = require('./createFormatter-81d7e598.js');
8
8
  var _IntlProvider = require('./_IntlProvider.js');
9
9
  var react = require('./react.js');
10
10
  var _useLocale = require('./_useLocale-321e619f.js');
@@ -5,7 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var _IntlProvider = require('./_IntlProvider.js');
6
6
  var _useLocale = require('./_useLocale-321e619f.js');
7
7
  var React = require('react');
8
- var createFormatter = require('./createFormatter-4ce6f6c8.js');
8
+ var createFormatter = require('./createFormatter-81d7e598.js');
9
9
  var initializeConfig = require('./initializeConfig-c503e215.js');
10
10
  require('./IntlContext-b5cc6be8.js');
11
11
  require('intl-messageformat');
package/dist/esm/core.js CHANGED
@@ -1 +1 @@
1
- import{b as e,d as r}from"./initializeConfig-8268c3a9.js";export{I as IntlError,a as IntlErrorCode,i as initializeConfig}from"./initializeConfig-8268c3a9.js";import{r as s,a as t}from"./createFormatter-57e6b76d.js";export{c as createFormatter}from"./createFormatter-57e6b76d.js";import"intl-messageformat";import"react";function o(a){let{getMessageFallback:o=e,messages:n,namespace:i,onError:m=r,...c}=a;return function(e,a){let{getMessageFallback:r,messages:o,namespace:n,onError:i,...m}=e;return o=o[a],n=s(n,a),t({...m,onError:i,getMessageFallback:r,messages:o,namespace:n})}({...c,onError:m,getMessageFallback:o,messages:{"!":n},namespace:i?"!.".concat(i):"!"},"!")}export{o as createTranslator};
1
+ import{b as e,d as r}from"./initializeConfig-8268c3a9.js";export{I as IntlError,a as IntlErrorCode,i as initializeConfig}from"./initializeConfig-8268c3a9.js";import{r as s,a as t}from"./createFormatter-16a5cf3e.js";export{c as createFormatter}from"./createFormatter-16a5cf3e.js";import"intl-messageformat";import"react";function o(a){let{getMessageFallback:o=e,messages:n,namespace:i,onError:m=r,...c}=a;return function(e,a){let{getMessageFallback:r,messages:o,namespace:n,onError:i,...m}=e;return o=o[a],n=s(n,a),t({...m,onError:i,getMessageFallback:r,messages:o,namespace:n})}({...c,onError:m,getMessageFallback:o,messages:{"!":n},namespace:i?"!.".concat(i):"!"},"!")}export{o as createTranslator};
@@ -1 +1 @@
1
- import e from"intl-messageformat";import{isValidElement as t,cloneElement as n}from"react";import{I as r,a as o,j as a,d as s,b as i}from"./initializeConfig-8268c3a9.js";function c(e,t){return e?Object.keys(e).reduce(((n,r)=>(n[r]={timeZone:t,...e[r]},n)),{}):e}function u(e,t,n,r){const o=a(r,n);if(!t)throw new Error("No messages available at `".concat(r,"`."));let s=t;return n.split(".").forEach((t=>{const n=s[t];if(null==t||null==n)throw new Error("Could not resolve `".concat(o,"` in messages for locale `").concat(e,"`."));s=n})),s}function l(l){const m=function(e,t,n){let a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:s;try{if(!t)throw new Error("No messages were configured on the provider.");const r=n?u(e,t,n):t;if(!r)throw new Error("No messages for namespace `".concat(n,"` found."));return r}catch(e){const t=new r(o.MISSING_MESSAGE,e.message);return a(t),t}}(l.locale,l.messages,l.namespace,l.onError);return function(s){let{defaultTranslationValues:l,formats:m,getMessageFallback:f=i,locale:d,messageFormatCache:g,messagesOrError:p,namespace:h,onError:w,timeZone:y}=s;function v(e,t,n){const o=new r(t,n);return w(o),f({error:o,key:e,namespace:h})}function E(s,i,w){if(p instanceof r)return f({error:p,key:s,namespace:h});const E=p;let I;try{I=u(d,E,s,h)}catch(e){return v(s,o.MISSING_MESSAGE,e.message)}const S=a(d,h,s,String(I));let T;if(null!=g&&g.has(S))T=g.get(S);else{if("object"==typeof I){let e,t;return Array.isArray(I)?(e=o.INVALID_MESSAGE,t="Message at `".concat(a(h,s),"` resolved to an array, but only strings are supported. See https://next-intl-docs.vercel.app/docs/usage/messages#arrays-of-messages")):(e=o.INSUFFICIENT_PATH,t="Message at `".concat(a(h,s),"` resolved to an object, but only strings are supported. Use a `.` to retrieve nested messages. See https://next-intl-docs.vercel.app/docs/usage/messages#structuring-messages")),v(s,e,t)}const t=function(e,t){if(t)return;const n=e.replace(/'([{}])/gi,"$1");return/<|{/.test(n)?void 0:n}(I,i);if(t)return t;try{T=new e(I,d,function(t,n){const r=n?{...t,dateTime:c(t.dateTime,n)}:t,o=e.formats.date,a=n?c(o,n):o,s=e.formats.time,i=n?c(s,n):s;return{...r,date:{...a,...null==r?void 0:r.dateTime},time:{...i,...null==r?void 0:r.dateTime}}}({...m,...w},y),{formatters:{getNumberFormat:(e,t)=>new Intl.NumberFormat(e,t),getDateTimeFormat:(e,t)=>new Intl.DateTimeFormat(e,{timeZone:y,...t}),getPluralRules:(e,t)=>new Intl.PluralRules(e,t)}})}catch(e){const t=e;return v(s,o.INVALID_MESSAGE,t.message+("originalMessage"in t?" (".concat(t.originalMessage,")"):""))}null==g||g.set(S,T)}try{const e=T.format(function(e){if(0===Object.keys(e).length)return;const r={};return Object.keys(e).forEach((o=>{let a=0;const s=e[o];let i;i="function"==typeof s?e=>{const r=s(e);return t(r)?n(r,{key:o+a++}):r}:s,r[o]=i})),r}({...l,...i}));if(null==e)throw new Error("Unable to format `".concat(s,"` in ").concat(h?"namespace `".concat(h,"`"):"messages"));return t(e)||Array.isArray(e)||"string"==typeof e?e:String(e)}catch(e){return v(s,o.FORMATTING_ERROR,e.message)}}function I(e,t,n){const r=E(e,t,n);return"string"!=typeof r?v(e,o.INVALID_MESSAGE,"The message `".concat(e,"` in ").concat(h?"namespace `".concat(h,"`"):"messages"," didn't resolve to a string. If you want to format rich text, use `t.rich` instead.")):r}return I.rich=E,I.markup=(e,t,n)=>{const a=E(e,t,n);if("string"!=typeof a){const t=new r(o.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>`})");return w(t),f({error:t,key:e,namespace:h})}return a},I.raw=e=>{if(p instanceof r)return f({error:p,key:e,namespace:h});const t=p;try{return u(d,t,e,h)}catch(t){return v(e,o.MISSING_MESSAGE,t.message)}},I}({...l,messagesOrError:m})}function m(e,t){return e===t?void 0:e.slice((t+".").length)}const f=60,d=60*f,g=24*d,p=7*g,h=g*(365/12),w=3*h,y=365*g,v={second:1,seconds:1,minute:f,minutes:f,hour:d,hours:d,day:g,days:g,week:p,weeks:p,month:h,months:h,quarter:w,quarters:w,year:y,years:y};function E(e){let{formats:t,locale:n,now:a,onError:i=s,timeZone:c}=e;function u(e,t,n,a){let s;try{s=function(e,t){let n;if("string"==typeof t){const a=t;if(n=null==e?void 0:e[a],!n){const e=new r(o.MISSING_FORMAT,"Format `".concat(a,"` is not available. You can configure it on the provider or provide custom options."));throw i(e),e}}else n=t;return n}(t,e)}catch(e){return a()}try{return n(s)}catch(e){return i(new r(o.FORMATTING_ERROR,e.message)),a()}}function l(e){return e instanceof Date||"number"==typeof e?new Date(e):void 0!==(null==e?void 0:e.now)?new Date(e.now):a||(i(new r(o.ENVIRONMENT_FALLBACK,"The `now` parameter wasn't provided and there is no global default configured. Consider adding a global default to avoid markup mismatches caused by environment differences. Learn more: https://next-intl-docs.vercel.app/docs/configuration#now")),new Date)}return{dateTime:function(e,a){return u(a,null==t?void 0:t.dateTime,(t=>{var a;return null!==(a=t)&&void 0!==a&&a.timeZone||(c?t={...t,timeZone:c}:i(new r(o.ENVIRONMENT_FALLBACK,"The `timeZone` parameter wasn't provided and there is no global default configured. Consider adding a global default to avoid markup mismatches caused by environment differences. Learn more: https://next-intl-docs.vercel.app/docs/configuration#time-zone"))),new Intl.DateTimeFormat(n,t).format(e)}),(()=>String(e)))},number:function(e,r){return u(r,null==t?void 0:t.number,(t=>new Intl.NumberFormat(n,t).format(e)),(()=>String(e)))},relativeTime:function(e,t){try{const r=new Date(e),o=l(t),a=(r.getTime()-o.getTime())/1e3,s="number"==typeof t||t instanceof Date||void 0===(null==t?void 0:t.unit)?function(e){const t=Math.abs(e);return t<f?"second":t<d?"minute":t<g?"hour":t<p?"day":t<h?"week":t<y?"month":"year"}(a):t.unit,i=function(e,t){return Math.round(e/v[t])}(a,s);return new Intl.RelativeTimeFormat(n,{numeric:"second"===s?"auto":"always"}).format(i,s)}catch(t){return i(new r(o.FORMATTING_ERROR,t.message)),String(e)}},list:function(e,r){const o=[],a=new Map;let s=0;for(const t of e){let e;"object"==typeof t?(e=String(s),a.set(e,t)):e=String(t),o.push(e),s++}return u(r,null==t?void 0:t.list,(e=>{const t=new Intl.ListFormat(n,e).formatToParts(o).map((e=>"literal"===e.type?e.value:a.get(e.value)||e.value));return a.size>0?t:t.join("")}),(()=>String(e)))}}}export{l as a,E as c,m as r};
1
+ import e from"intl-messageformat";import{isValidElement as t,cloneElement as n}from"react";import{I as r,a as o,j as a,d as s,b as i}from"./initializeConfig-8268c3a9.js";function c(e,t){return e?Object.keys(e).reduce(((n,r)=>(n[r]={timeZone:t,...e[r]},n)),{}):e}function u(e,t,n,r){const o=a(r,n);if(!t)throw new Error("No messages available at `".concat(r,"`."));let s=t;return n.split(".").forEach((t=>{const n=s[t];if(null==t||null==n)throw new Error("Could not resolve `".concat(o,"` in messages for locale `").concat(e,"`."));s=n})),s}function l(l){const m=function(e,t,n){let a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:s;try{if(!t)throw new Error("No messages were configured on the provider.");const r=n?u(e,t,n):t;if(!r)throw new Error("No messages for namespace `".concat(n,"` found."));return r}catch(e){const t=new r(o.MISSING_MESSAGE,e.message);return a(t),t}}(l.locale,l.messages,l.namespace,l.onError);return function(s){let{defaultTranslationValues:l,formats:m,getMessageFallback:f=i,locale:d,messageFormatCache:g,messagesOrError:p,namespace:h,onError:w,timeZone:y}=s;function v(e,t,n){const o=new r(t,n);return w(o),f({error:o,key:e,namespace:h})}function E(s,i,w){if(p instanceof r)return f({error:p,key:s,namespace:h});const E=p;let T;try{T=u(d,E,s,h)}catch(e){return v(s,o.MISSING_MESSAGE,e.message)}const I=a(d,h,s,String(T));let S;if(null!=g&&g.has(I))S=g.get(I);else{if("object"==typeof T){let e,t;return Array.isArray(T)?(e=o.INVALID_MESSAGE,t="Message at `".concat(a(h,s),"` resolved to an array, but only strings are supported. See https://next-intl-docs.vercel.app/docs/usage/messages#arrays-of-messages")):(e=o.INSUFFICIENT_PATH,t="Message at `".concat(a(h,s),"` resolved to an object, but only strings are supported. Use a `.` to retrieve nested messages. See https://next-intl-docs.vercel.app/docs/usage/messages#structuring-messages")),v(s,e,t)}const t=function(e,t){if(t)return;const n=e.replace(/'([{}])/gi,"$1");return/<|{/.test(n)?void 0:n}(T,i);if(t)return t;try{S=new e(T,d,function(t,n){const r=n?{...t,dateTime:c(t.dateTime,n)}:t,o=e.formats.date,a=n?c(o,n):o,s=e.formats.time,i=n?c(s,n):s;return{...r,date:{...a,...null==r?void 0:r.dateTime},time:{...i,...null==r?void 0:r.dateTime}}}({...m,...w},y),{formatters:{getNumberFormat:(e,t)=>new Intl.NumberFormat(e,t),getDateTimeFormat:(e,t)=>new Intl.DateTimeFormat(e,{timeZone:y,...t}),getPluralRules:(e,t)=>new Intl.PluralRules(e,t)}})}catch(e){const t=e;return v(s,o.INVALID_MESSAGE,t.message+("originalMessage"in t?" (".concat(t.originalMessage,")"):""))}null==g||g.set(I,S)}try{const e=S.format(function(e){if(0===Object.keys(e).length)return;const r={};return Object.keys(e).forEach((o=>{let a=0;const s=e[o];let i;i="function"==typeof s?e=>{const r=s(e);return t(r)?n(r,{key:o+a++}):r}:s,r[o]=i})),r}({...l,...i}));if(null==e)throw new Error("Unable to format `".concat(s,"` in ").concat(h?"namespace `".concat(h,"`"):"messages"));return t(e)||Array.isArray(e)||"string"==typeof e?e:String(e)}catch(e){return v(s,o.FORMATTING_ERROR,e.message)}}function T(e,t,n){const r=E(e,t,n);return"string"!=typeof r?v(e,o.INVALID_MESSAGE,"The message `".concat(e,"` in ").concat(h?"namespace `".concat(h,"`"):"messages"," didn't resolve to a string. If you want to format rich text, use `t.rich` instead.")):r}return T.rich=E,T.markup=(e,t,n)=>{const a=E(e,t,n);if("string"!=typeof a){const t=new r(o.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>`})");return w(t),f({error:t,key:e,namespace:h})}return a},T.raw=e=>{if(p instanceof r)return f({error:p,key:e,namespace:h});const t=p;try{return u(d,t,e,h)}catch(t){return v(e,o.MISSING_MESSAGE,t.message)}},T}({...l,messagesOrError:m})}function m(e,t){return e===t?void 0:e.slice((t+".").length)}const f=60,d=60*f,g=24*d,p=7*g,h=g*(365/12),w=3*h,y=365*g,v={second:1,seconds:1,minute:f,minutes:f,hour:d,hours:d,day:g,days:g,week:p,weeks:p,month:h,months:h,quarter:w,quarters:w,year:y,years:y};function E(e){let{formats:t,locale:n,now:a,onError:i=s,timeZone:c}=e;function u(e){var t;return null!==(t=e)&&void 0!==t&&t.timeZone||(c?e={...e,timeZone:c}:i(new r(o.ENVIRONMENT_FALLBACK,"The `timeZone` parameter wasn't provided and there is no global default configured. Consider adding a global default to avoid markup mismatches caused by environment differences. Learn more: https://next-intl-docs.vercel.app/docs/configuration#time-zone"))),e}function l(e,t,n,a){let s;try{s=function(e,t){let n;if("string"==typeof t){const a=t;if(n=null==e?void 0:e[a],!n){const e=new r(o.MISSING_FORMAT,"Format `".concat(a,"` is not available. You can configure it on the provider or provide custom options."));throw i(e),e}}else n=t;return n}(t,e)}catch(e){return a()}try{return n(s)}catch(e){return i(new r(o.FORMATTING_ERROR,e.message)),a()}}function m(e,r){return l(r,null==t?void 0:t.dateTime,(t=>(t=u(t),new Intl.DateTimeFormat(n,t).format(e))),(()=>String(e)))}function w(e){return e instanceof Date||"number"==typeof e?new Date(e):void 0!==(null==e?void 0:e.now)?new Date(e.now):a||(i(new r(o.ENVIRONMENT_FALLBACK,"The `now` parameter wasn't provided and there is no global default configured. Consider adding a global default to avoid markup mismatches caused by environment differences. Learn more: https://next-intl-docs.vercel.app/docs/configuration#now")),new Date)}return{dateTime:m,number:function(e,r){return l(r,null==t?void 0:t.number,(t=>new Intl.NumberFormat(n,t).format(e)),(()=>String(e)))},relativeTime:function(e,t){try{const r=new Date(e),o=w(t),a=(r.getTime()-o.getTime())/1e3,s="number"==typeof t||t instanceof Date||void 0===(null==t?void 0:t.unit)?function(e){const t=Math.abs(e);return t<f?"second":t<d?"minute":t<g?"hour":t<p?"day":t<h?"week":t<y?"month":"year"}(a):t.unit,i=function(e,t){return Math.round(e/v[t])}(a,s);return new Intl.RelativeTimeFormat(n,{numeric:"second"===s?"auto":"always"}).format(i,s)}catch(t){return i(new r(o.FORMATTING_ERROR,t.message)),String(e)}},list:function(e,r){const o=[],a=new Map;let s=0;for(const t of e){let e;"object"==typeof t?(e=String(s),a.set(e,t)):e=String(t),o.push(e),s++}return l(r,null==t?void 0:t.list,(e=>{const t=new Intl.ListFormat(n,e).formatToParts(o).map((e=>"literal"===e.type?e.value:a.get(e.value)||e.value));return a.size>0?t:t.join("")}),(()=>String(e)))},dateTimeRange:function(e,r,o){return l(o,null==t?void 0:t.dateTime,(t=>(t=u(t),new Intl.DateTimeFormat(n,t).formatRange(e,r))),(()=>[m(e),m(r)].join(" – ")))}}}export{l as a,E as c,m as r};
package/dist/esm/index.js CHANGED
@@ -1 +1 @@
1
- export{I as IntlError,a as IntlErrorCode,i as initializeConfig}from"./initializeConfig-8268c3a9.js";export{createTranslator}from"./core.js";export{c as createFormatter}from"./createFormatter-57e6b76d.js";export{IntlProvider}from"./_IntlProvider.js";export{useFormatter,useMessages,useNow,useTimeZone,useTranslations}from"./react.js";export{u as useLocale}from"./_useLocale-65297b4e.js";import"intl-messageformat";import"react";import"./IntlContext-b1dc6cbd.js";
1
+ export{I as IntlError,a as IntlErrorCode,i as initializeConfig}from"./initializeConfig-8268c3a9.js";export{createTranslator}from"./core.js";export{c as createFormatter}from"./createFormatter-16a5cf3e.js";export{IntlProvider}from"./_IntlProvider.js";export{useFormatter,useMessages,useNow,useTimeZone,useTranslations}from"./react.js";export{u as useLocale}from"./_useLocale-65297b4e.js";import"intl-messageformat";import"react";import"./IntlContext-b1dc6cbd.js";
package/dist/esm/react.js CHANGED
@@ -1 +1 @@
1
- export{IntlProvider}from"./_IntlProvider.js";import{a as e}from"./_useLocale-65297b4e.js";export{u as useLocale}from"./_useLocale-65297b4e.js";import{useMemo as o,useState as t,useEffect as n}from"react";import{r,a,c as s}from"./createFormatter-57e6b76d.js";import{I as i,a as c}from"./initializeConfig-8268c3a9.js";import"./IntlContext-b1dc6cbd.js";import"intl-messageformat";let l=!1;const m="undefined"==typeof window;function f(t){return function(t,n,s){const{defaultTranslationValues:u,formats:f,getMessageFallback:d,locale:g,messageFormatCache:p,onError:v,timeZone:h}=e();return t=t[s],n=r(n,s),h||l||!m||(l=!0,v(new i(c.ENVIRONMENT_FALLBACK,"There is no `timeZone` configured, this can lead to markup mismatches caused by environment differences. Consider adding a global default: https://next-intl-docs.vercel.app/docs/configuration#time-zone"))),o((()=>a({messageFormatCache:p,getMessageFallback:d,messages:t,defaultTranslationValues:u,namespace:n,onError:v,formats:f,locale:g,timeZone:h})),[p,d,t,n,v,u,f,g,h])}({"!":e().messages},t?"!.".concat(t):"!","!")}function d(){return new Date}function g(o){const r=null==o?void 0:o.updateInterval,{now:a}=e(),[s,i]=t(a||d());return n((()=>{if(!r)return;const e=setInterval((()=>{i(d())}),r);return()=>{clearInterval(e)}}),[a,r]),s}function p(){return e().timeZone}function v(){const o=e();if(!o.messages)throw new Error("No messages found. Have you configured them correctly? See https://next-intl-docs.vercel.app/docs/configuration#messages");return o.messages}function h(){const{formats:t,locale:n,now:r,onError:a,timeZone:i}=e();return o((()=>s({formats:t,locale:n,now:r,onError:a,timeZone:i})),[t,r,n,a,i])}export{h as useFormatter,v as useMessages,g as useNow,p as useTimeZone,f as useTranslations};
1
+ export{IntlProvider}from"./_IntlProvider.js";import{a as e}from"./_useLocale-65297b4e.js";export{u as useLocale}from"./_useLocale-65297b4e.js";import{useMemo as o,useState as t,useEffect as n}from"react";import{r,a,c as s}from"./createFormatter-16a5cf3e.js";import{I as i,a as c}from"./initializeConfig-8268c3a9.js";import"./IntlContext-b1dc6cbd.js";import"intl-messageformat";let l=!1;const m="undefined"==typeof window;function f(t){return function(t,n,s){const{defaultTranslationValues:u,formats:f,getMessageFallback:d,locale:g,messageFormatCache:p,onError:v,timeZone:h}=e();return t=t[s],n=r(n,s),h||l||!m||(l=!0,v(new i(c.ENVIRONMENT_FALLBACK,"There is no `timeZone` configured, this can lead to markup mismatches caused by environment differences. Consider adding a global default: https://next-intl-docs.vercel.app/docs/configuration#time-zone"))),o((()=>a({messageFormatCache:p,getMessageFallback:d,messages:t,defaultTranslationValues:u,namespace:n,onError:v,formats:f,locale:g,timeZone:h})),[p,d,t,n,v,u,f,g,h])}({"!":e().messages},t?"!.".concat(t):"!","!")}function d(){return new Date}function g(o){const r=null==o?void 0:o.updateInterval,{now:a}=e(),[s,i]=t(a||d());return n((()=>{if(!r)return;const e=setInterval((()=>{i(d())}),r);return()=>{clearInterval(e)}}),[a,r]),s}function p(){return e().timeZone}function v(){const o=e();if(!o.messages)throw new Error("No messages found. Have you configured them correctly? See https://next-intl-docs.vercel.app/docs/configuration#messages");return o.messages}function h(){const{formats:t,locale:n,now:r,onError:a,timeZone:i}=e();return o((()=>s({formats:t,locale:n,now:r,onError:a,timeZone:i})),[t,r,n,a,i])}export{h as useFormatter,v as useMessages,g as useNow,p as useTimeZone,f as useTranslations};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./createFormatter-f65f393d.js"),r=require("./initializeConfig-63bc7f90.js");require("intl-messageformat"),require("react"),exports.IntlError=e.IntlError,exports.IntlErrorCode=e.IntlErrorCode,exports.createFormatter=e.createFormatter,exports.initializeConfig=r.initializeConfig,exports.createTranslator=function(a){let{getMessageFallback:t=r.defaultGetMessageFallback,messages:s,namespace:o,onError:n=r.defaultOnError,...l}=a;return function(r,a){let{getMessageFallback:t,messages:s,namespace:o,onError:n,...l}=r;return s=s[a],o=e.resolveNamespace(o,a),e.createBaseTranslator({...l,onError:n,getMessageFallback:t,messages:s,namespace:o})}({...l,onError:n,getMessageFallback:t,messages:{"!":s},namespace:o?"!.".concat(o):"!"},"!")};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./createFormatter-488f80ec.js"),r=require("./initializeConfig-63bc7f90.js");require("intl-messageformat"),require("react"),exports.IntlError=e.IntlError,exports.IntlErrorCode=e.IntlErrorCode,exports.createFormatter=e.createFormatter,exports.initializeConfig=r.initializeConfig,exports.createTranslator=function(a){let{getMessageFallback:t=r.defaultGetMessageFallback,messages:s,namespace:o,onError:n=r.defaultOnError,...l}=a;return function(r,a){let{getMessageFallback:t,messages:s,namespace:o,onError:n,...l}=r;return s=s[a],o=e.resolveNamespace(o,a),e.createBaseTranslator({...l,onError:n,getMessageFallback:t,messages:s,namespace:o})}({...l,onError:n,getMessageFallback:t,messages:{"!":s},namespace:o?"!.".concat(o):"!"},"!")};
@@ -0,0 +1 @@
1
+ "use strict";var e=require("intl-messageformat"),t=require("react"),r=require("./initializeConfig-63bc7f90.js");function n(e){return e&&e.__esModule?e:{default:e}}var o=n(e);function i(e,t,r){return(t=function(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:String(t)}(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}let a=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}({});class u extends Error{constructor(e,t){let r=e;t&&(r+=": "+t),super(r),i(this,"code",void 0),i(this,"originalMessage",void 0),this.code=e,t&&(this.originalMessage=t)}}function s(e,t){return e?Object.keys(e).reduce(((r,n)=>(r[n]={timeZone:t,...e[n]},r)),{}):e}function l(e,t,n,o){const i=r.joinPath(o,n);if(!t)throw new Error(i);let a=t;return n.split(".").forEach((t=>{const r=a[t];if(null==t||null==r)throw new Error(i+" (".concat(e,")"));a=r})),a}const c=60,m=60*c,f=24*m,d=7*f,E=f*(365/12),I=3*E,g=365*f,S={second:1,seconds:1,minute:c,minutes:c,hour:m,hours:m,day:f,days:f,week:d,weeks:d,month:E,months:E,quarter:I,quarters:I,year:g,years:g};exports.IntlError=u,exports.IntlErrorCode=a,exports.createBaseTranslator=function(e){const n=function(e,t,n){let o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:r.defaultOnError;try{if(!t)throw new Error(void 0);const r=n?l(e,t,n):t;if(!r)throw new Error(n);return r}catch(e){const t=new u(a.MISSING_MESSAGE,e.message);return o(t),t}}(e.locale,e.messages,e.namespace,e.onError);return function(e){let{defaultTranslationValues:n,formats:i,getMessageFallback:c=r.defaultGetMessageFallback,locale:m,messageFormatCache:f,messagesOrError:d,namespace:E,onError:I,timeZone:g}=e;function S(e,t,r){const n=new u(t,r);return I(n),c({error:n,key:e,namespace:E})}function T(e,I,T){if(d instanceof u)return c({error:d,key:e,namespace:E});const w=d;let y;try{y=l(m,w,e,E)}catch(t){return S(e,a.MISSING_MESSAGE,t.message)}const N=r.joinPath(m,E,e,String(y));let v;if(null!=f&&f.has(N))v=f.get(N);else{if("object"==typeof y){let t,r;return t=Array.isArray(y)?a.INVALID_MESSAGE:a.INSUFFICIENT_PATH,S(e,t,r)}const t=function(e,t){if(t)return;const r=e.replace(/'([{}])/gi,"$1");return/<|{/.test(r)?void 0:r}(y,I);if(t)return t;try{v=new o.default(y,m,function(e,t){const r=t?{...e,dateTime:s(e.dateTime,t)}:e,n=o.default.formats.date,i=t?s(n,t):n,a=o.default.formats.time,u=t?s(a,t):a;return{...r,date:{...i,...null==r?void 0:r.dateTime},time:{...u,...null==r?void 0:r.dateTime}}}({...i,...T},g),{formatters:{getNumberFormat:(e,t)=>new Intl.NumberFormat(e,t),getDateTimeFormat:(e,t)=>new Intl.DateTimeFormat(e,{timeZone:g,...t}),getPluralRules:(e,t)=>new Intl.PluralRules(e,t)}})}catch(t){const r=t;return S(e,a.INVALID_MESSAGE,r.message)}null==f||f.set(N,v)}try{const e=v.format(function(e){if(0===Object.keys(e).length)return;const r={};return Object.keys(e).forEach((n=>{let o=0;const i=e[n];let a;a="function"==typeof i?e=>{const r=i(e);return t.isValidElement(r)?t.cloneElement(r,{key:n+o++}):r}:i,r[n]=a})),r}({...n,...I}));if(null==e)throw new Error(void 0);return t.isValidElement(e)||Array.isArray(e)||"string"==typeof e?e:String(e)}catch(t){return S(e,a.FORMATTING_ERROR,t.message)}}function w(e,t,r){const n=T(e,t,r);return"string"!=typeof n?S(e,a.INVALID_MESSAGE,void 0):n}return w.rich=T,w.markup=(e,t,r)=>{const n=T(e,t,r);if("string"!=typeof n){const t=new u(a.FORMATTING_ERROR,void 0);return I(t),c({error:t,key:e,namespace:E})}return n},w.raw=e=>{if(d instanceof u)return c({error:d,key:e,namespace:E});const t=d;try{return l(m,t,e,E)}catch(t){return S(e,a.MISSING_MESSAGE,t.message)}},w}({...e,messagesOrError:n})},exports.createFormatter=function(e){let{formats:t,locale:n,now:o,onError:i=r.defaultOnError,timeZone:s}=e;function l(e){var t;return null!==(t=e)&&void 0!==t&&t.timeZone||(s?e={...e,timeZone:s}:i(new u(a.ENVIRONMENT_FALLBACK,void 0))),e}function I(e,t,r,n){let o;try{o=function(e,t){let r;if("string"==typeof t){if(r=null==e?void 0:e[t],!r){const e=new u(a.MISSING_FORMAT,void 0);throw i(e),e}}else r=t;return r}(t,e)}catch(e){return n()}try{return r(o)}catch(e){return i(new u(a.FORMATTING_ERROR,e.message)),n()}}function T(e,r){return I(r,null==t?void 0:t.dateTime,(t=>(t=l(t),new Intl.DateTimeFormat(n,t).format(e))),(()=>String(e)))}function w(e){return e instanceof Date||"number"==typeof e?new Date(e):void 0!==(null==e?void 0:e.now)?new Date(e.now):o||(i(new u(a.ENVIRONMENT_FALLBACK,void 0)),new Date)}return{dateTime:T,number:function(e,r){return I(r,null==t?void 0:t.number,(t=>new Intl.NumberFormat(n,t).format(e)),(()=>String(e)))},relativeTime:function(e,t){try{const r=new Date(e),o=w(t),i=(r.getTime()-o.getTime())/1e3,a="number"==typeof t||t instanceof Date||void 0===(null==t?void 0:t.unit)?function(e){const t=Math.abs(e);return t<c?"second":t<m?"minute":t<f?"hour":t<d?"day":t<E?"week":t<g?"month":"year"}(i):t.unit,u=function(e,t){return Math.round(e/S[t])}(i,a);return new Intl.RelativeTimeFormat(n,{numeric:"second"===a?"auto":"always"}).format(u,a)}catch(t){return i(new u(a.FORMATTING_ERROR,t.message)),String(e)}},list:function(e,r){const o=[],i=new Map;let a=0;for(const t of e){let e;"object"==typeof t?(e=String(a),i.set(e,t)):e=String(t),o.push(e),a++}return I(r,null==t?void 0:t.list,(e=>{const t=new Intl.ListFormat(n,e).formatToParts(o).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,r,o){return I(o,null==t?void 0:t.dateTime,(t=>(t=l(t),new Intl.DateTimeFormat(n,t).formatRange(e,r))),(()=>[T(e),T(r)].join(" – ")))}}},exports.resolveNamespace=function(e,t){return e===t?void 0:e.slice((t+".").length)};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./createFormatter-f65f393d.js"),r=require("./core.js"),t=require("./initializeConfig-63bc7f90.js"),s=require("./_IntlProvider.js"),o=require("./react.js"),i=require("./_useLocale-8e23751a.js");require("intl-messageformat"),require("react"),require("./IntlContext-381f3ce4.js"),exports.IntlError=e.IntlError,exports.IntlErrorCode=e.IntlErrorCode,exports.createFormatter=e.createFormatter,exports.createTranslator=r.createTranslator,exports.initializeConfig=t.initializeConfig,exports.IntlProvider=s.IntlProvider,exports.useFormatter=o.useFormatter,exports.useMessages=o.useMessages,exports.useNow=o.useNow,exports.useTimeZone=o.useTimeZone,exports.useTranslations=o.useTranslations,exports.useLocale=i.useLocale;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./createFormatter-488f80ec.js"),r=require("./core.js"),t=require("./initializeConfig-63bc7f90.js"),s=require("./_IntlProvider.js"),o=require("./react.js"),i=require("./_useLocale-8e23751a.js");require("intl-messageformat"),require("react"),require("./IntlContext-381f3ce4.js"),exports.IntlError=e.IntlError,exports.IntlErrorCode=e.IntlErrorCode,exports.createFormatter=e.createFormatter,exports.createTranslator=r.createTranslator,exports.initializeConfig=t.initializeConfig,exports.IntlProvider=s.IntlProvider,exports.useFormatter=o.useFormatter,exports.useMessages=o.useMessages,exports.useNow=o.useNow,exports.useTimeZone=o.useTimeZone,exports.useTranslations=o.useTranslations,exports.useLocale=i.useLocale;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./_IntlProvider.js"),t=require("./_useLocale-8e23751a.js"),r=require("react"),o=require("./createFormatter-f65f393d.js");require("./initializeConfig-63bc7f90.js"),require("./IntlContext-381f3ce4.js"),require("intl-messageformat");let n=!1;const s="undefined"==typeof window;function a(){return new Date}exports.IntlProvider=e.IntlProvider,exports.useLocale=t.useLocale,exports.useFormatter=function(){const{formats:e,locale:n,now:s,onError:a,timeZone:u}=t.useIntlContext();return r.useMemo((()=>o.createFormatter({formats:e,locale:n,now:s,onError:a,timeZone:u})),[e,s,n,a,u])},exports.useMessages=function(){const e=t.useIntlContext();if(!e.messages)throw new Error(void 0);return e.messages},exports.useNow=function(e){const o=null==e?void 0:e.updateInterval,{now:n}=t.useIntlContext(),[s,u]=r.useState(n||a());return r.useEffect((()=>{if(!o)return;const e=setInterval((()=>{u(a())}),o);return()=>{clearInterval(e)}}),[n,o]),s},exports.useTimeZone=function(){return t.useIntlContext().timeZone},exports.useTranslations=function(e){return function(e,a,u){const{defaultTranslationValues:l,formats:i,getMessageFallback:c,locale:m,messageFormatCache:f,onError:I,timeZone:d}=t.useIntlContext();return e=e[u],a=o.resolveNamespace(a,u),d||n||!s||(n=!0,I(new o.IntlError(o.IntlErrorCode.ENVIRONMENT_FALLBACK,void 0))),r.useMemo((()=>o.createBaseTranslator({messageFormatCache:f,getMessageFallback:c,messages:e,defaultTranslationValues:l,namespace:a,onError:I,formats:i,locale:m,timeZone:d})),[f,c,e,a,I,l,i,m,d])}({"!":t.useIntlContext().messages},e?"!.".concat(e):"!","!")};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./_IntlProvider.js"),t=require("./_useLocale-8e23751a.js"),r=require("react"),o=require("./createFormatter-488f80ec.js");require("./initializeConfig-63bc7f90.js"),require("./IntlContext-381f3ce4.js"),require("intl-messageformat");let n=!1;const s="undefined"==typeof window;function a(){return new Date}exports.IntlProvider=e.IntlProvider,exports.useLocale=t.useLocale,exports.useFormatter=function(){const{formats:e,locale:n,now:s,onError:a,timeZone:u}=t.useIntlContext();return r.useMemo((()=>o.createFormatter({formats:e,locale:n,now:s,onError:a,timeZone:u})),[e,s,n,a,u])},exports.useMessages=function(){const e=t.useIntlContext();if(!e.messages)throw new Error(void 0);return e.messages},exports.useNow=function(e){const o=null==e?void 0:e.updateInterval,{now:n}=t.useIntlContext(),[s,u]=r.useState(n||a());return r.useEffect((()=>{if(!o)return;const e=setInterval((()=>{u(a())}),o);return()=>{clearInterval(e)}}),[n,o]),s},exports.useTimeZone=function(){return t.useIntlContext().timeZone},exports.useTranslations=function(e){return function(e,a,u){const{defaultTranslationValues:l,formats:i,getMessageFallback:c,locale:m,messageFormatCache:f,onError:I,timeZone:d}=t.useIntlContext();return e=e[u],a=o.resolveNamespace(a,u),d||n||!s||(n=!0,I(new o.IntlError(o.IntlErrorCode.ENVIRONMENT_FALLBACK,void 0))),r.useMemo((()=>o.createBaseTranslator({messageFormatCache:f,getMessageFallback:c,messages:e,defaultTranslationValues:l,namespace:a,onError:I,formats:i,locale:m,timeZone:d})),[f,c,e,a,I,l,i,m,d])}({"!":t.useIntlContext().messages},e?"!.".concat(e):"!","!")};
@@ -17,5 +17,6 @@ export default function createFormatter({ formats, locale, now: globalNow, onErr
17
17
  number: (value: number | bigint, formatOrOptions?: string | NumberFormatOptions) => string;
18
18
  relativeTime: (date: number | Date, nowOrOptions?: RelativeTimeFormatOptions['now'] | RelativeTimeFormatOptions) => string;
19
19
  list: <Value extends string | ReactElement<any, string | import("react").JSXElementConstructor<any>>>(value: Iterable<Value>, formatOrOptions?: string | Intl.ListFormatOptions) => Value extends string ? string : Iterable<ReactElement<any, string | import("react").JSXElementConstructor<any>>>;
20
+ dateTimeRange: (start: Date | number, end: Date | number, formatOrOptions?: string | DateTimeFormatOptions) => string;
20
21
  };
21
22
  export {};
@@ -4,4 +4,5 @@ export default function useFormatter(): {
4
4
  number: (value: number | bigint, formatOrOptions?: string | import("@formatjs/ecma402-abstract/types/number").NumberFormatOptions | undefined) => string;
5
5
  relativeTime: (date: number | Date, nowOrOptions?: number | Date | import("../core/RelativeTimeFormatOptions").default | undefined) => string;
6
6
  list: <Value extends string | import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>>(value: Iterable<Value>, formatOrOptions?: string | Intl.ListFormatOptions | undefined) => Value extends string ? string : Iterable<import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>>;
7
+ dateTimeRange: (start: number | Date, end: number | Date, formatOrOptions?: string | import("../core/DateTimeFormatOptions").default | undefined) => string;
7
8
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "use-intl",
3
- "version": "3.6.0",
3
+ "version": "3.8.0",
4
4
  "sideEffects": false,
5
5
  "author": "Jan Amann <jan@amann.work>",
6
6
  "description": "Minimal, but complete solution for managing internationalization in React apps.",
@@ -90,8 +90,8 @@
90
90
  "size-limit": [
91
91
  {
92
92
  "path": "dist/production/index.js",
93
- "limit": "12.5 kB"
93
+ "limit": "12.565 kB"
94
94
  }
95
95
  ],
96
- "gitHead": "5cb950652a74f5bb1675d747d1140ec2e2f04f8a"
96
+ "gitHead": "5cc264ddd769a57ea09440f25c26325c142d0c25"
97
97
  }
@@ -1 +0,0 @@
1
- "use strict";var e=require("intl-messageformat"),t=require("react"),r=require("./initializeConfig-63bc7f90.js");function n(e){return e&&e.__esModule?e:{default:e}}var o=n(e);function i(e,t,r){return(t=function(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:String(t)}(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}let a=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}({});class s extends Error{constructor(e,t){let r=e;t&&(r+=": "+t),super(r),i(this,"code",void 0),i(this,"originalMessage",void 0),this.code=e,t&&(this.originalMessage=t)}}function u(e,t){return e?Object.keys(e).reduce(((r,n)=>(r[n]={timeZone:t,...e[n]},r)),{}):e}function l(e,t,n,o){const i=r.joinPath(o,n);if(!t)throw new Error(i);let a=t;return n.split(".").forEach((t=>{const r=a[t];if(null==t||null==r)throw new Error(i+" (".concat(e,")"));a=r})),a}const c=60,f=60*c,m=24*f,E=7*m,d=m*(365/12),I=3*d,S=365*m,g={second:1,seconds:1,minute:c,minutes:c,hour:f,hours:f,day:m,days:m,week:E,weeks:E,month:d,months:d,quarter:I,quarters:I,year:S,years:S};exports.IntlError=s,exports.IntlErrorCode=a,exports.createBaseTranslator=function(e){const n=function(e,t,n){let o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:r.defaultOnError;try{if(!t)throw new Error(void 0);const r=n?l(e,t,n):t;if(!r)throw new Error(n);return r}catch(e){const t=new s(a.MISSING_MESSAGE,e.message);return o(t),t}}(e.locale,e.messages,e.namespace,e.onError);return function(e){let{defaultTranslationValues:n,formats:i,getMessageFallback:c=r.defaultGetMessageFallback,locale:f,messageFormatCache:m,messagesOrError:E,namespace:d,onError:I,timeZone:S}=e;function g(e,t,r){const n=new s(t,r);return I(n),c({error:n,key:e,namespace:d})}function y(e,I,y){if(E instanceof s)return c({error:E,key:e,namespace:d});const N=E;let w;try{w=l(f,N,e,d)}catch(t){return g(e,a.MISSING_MESSAGE,t.message)}const T=r.joinPath(f,d,e,String(w));let v;if(null!=m&&m.has(T))v=m.get(T);else{if("object"==typeof w){let t,r;return t=Array.isArray(w)?a.INVALID_MESSAGE:a.INSUFFICIENT_PATH,g(e,t,r)}const t=function(e,t){if(t)return;const r=e.replace(/'([{}])/gi,"$1");return/<|{/.test(r)?void 0:r}(w,I);if(t)return t;try{v=new o.default(w,f,function(e,t){const r=t?{...e,dateTime:u(e.dateTime,t)}:e,n=o.default.formats.date,i=t?u(n,t):n,a=o.default.formats.time,s=t?u(a,t):a;return{...r,date:{...i,...null==r?void 0:r.dateTime},time:{...s,...null==r?void 0:r.dateTime}}}({...i,...y},S),{formatters:{getNumberFormat:(e,t)=>new Intl.NumberFormat(e,t),getDateTimeFormat:(e,t)=>new Intl.DateTimeFormat(e,{timeZone:S,...t}),getPluralRules:(e,t)=>new Intl.PluralRules(e,t)}})}catch(t){const r=t;return g(e,a.INVALID_MESSAGE,r.message)}null==m||m.set(T,v)}try{const e=v.format(function(e){if(0===Object.keys(e).length)return;const r={};return Object.keys(e).forEach((n=>{let o=0;const i=e[n];let a;a="function"==typeof i?e=>{const r=i(e);return t.isValidElement(r)?t.cloneElement(r,{key:n+o++}):r}:i,r[n]=a})),r}({...n,...I}));if(null==e)throw new Error(void 0);return t.isValidElement(e)||Array.isArray(e)||"string"==typeof e?e:String(e)}catch(t){return g(e,a.FORMATTING_ERROR,t.message)}}function N(e,t,r){const n=y(e,t,r);return"string"!=typeof n?g(e,a.INVALID_MESSAGE,void 0):n}return N.rich=y,N.markup=(e,t,r)=>{const n=y(e,t,r);if("string"!=typeof n){const t=new s(a.FORMATTING_ERROR,void 0);return I(t),c({error:t,key:e,namespace:d})}return n},N.raw=e=>{if(E instanceof s)return c({error:E,key:e,namespace:d});const t=E;try{return l(f,t,e,d)}catch(t){return g(e,a.MISSING_MESSAGE,t.message)}},N}({...e,messagesOrError:n})},exports.createFormatter=function(e){let{formats:t,locale:n,now:o,onError:i=r.defaultOnError,timeZone:u}=e;function l(e,t,r,n){let o;try{o=function(e,t){let r;if("string"==typeof t){if(r=null==e?void 0:e[t],!r){const e=new s(a.MISSING_FORMAT,void 0);throw i(e),e}}else r=t;return r}(t,e)}catch(e){return n()}try{return r(o)}catch(e){return i(new s(a.FORMATTING_ERROR,e.message)),n()}}function I(e){return e instanceof Date||"number"==typeof e?new Date(e):void 0!==(null==e?void 0:e.now)?new Date(e.now):o||(i(new s(a.ENVIRONMENT_FALLBACK,void 0)),new Date)}return{dateTime:function(e,r){return l(r,null==t?void 0:t.dateTime,(t=>{var r;return null!==(r=t)&&void 0!==r&&r.timeZone||(u?t={...t,timeZone:u}:i(new s(a.ENVIRONMENT_FALLBACK,void 0))),new Intl.DateTimeFormat(n,t).format(e)}),(()=>String(e)))},number:function(e,r){return l(r,null==t?void 0:t.number,(t=>new Intl.NumberFormat(n,t).format(e)),(()=>String(e)))},relativeTime:function(e,t){try{const r=new Date(e),o=I(t),i=(r.getTime()-o.getTime())/1e3,a="number"==typeof t||t instanceof Date||void 0===(null==t?void 0:t.unit)?function(e){const t=Math.abs(e);return t<c?"second":t<f?"minute":t<m?"hour":t<E?"day":t<d?"week":t<S?"month":"year"}(i):t.unit,s=function(e,t){return Math.round(e/g[t])}(i,a);return new Intl.RelativeTimeFormat(n,{numeric:"second"===a?"auto":"always"}).format(s,a)}catch(t){return i(new s(a.FORMATTING_ERROR,t.message)),String(e)}},list:function(e,r){const o=[],i=new Map;let a=0;for(const t of e){let e;"object"==typeof t?(e=String(a),i.set(e,t)):e=String(t),o.push(e),a++}return l(r,null==t?void 0:t.list,(e=>{const t=new Intl.ListFormat(n,e).formatToParts(o).map((e=>"literal"===e.type?e.value:i.get(e.value)||e.value));return i.size>0?t:t.join("")}),(()=>String(e)))}}},exports.resolveNamespace=function(e,t){return e===t?void 0:e.slice((t+".").length)};