use-intl 3.22.0-canary.0 → 3.22.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 +5 -5
- package/dist/development/_IntlProvider.js +1 -1
- package/dist/development/core.js +2 -2
- package/dist/development/{createFormatter-TZTkYRKI.js → createFormatter-D2v4ATzl.js} +13 -11
- package/dist/development/index.js +2 -2
- package/dist/development/{initializeConfig-o7L_y07P.js → initializeConfig-BhfMSHP7.js} +2 -2
- package/dist/development/react.js +2 -2
- package/dist/esm/core.js +1 -1
- package/dist/esm/createFormatter-zqPbsiYR.js +1 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/react.js +1 -1
- package/dist/production/core.js +1 -1
- package/dist/production/createFormatter-CZeYe_QF.js +1 -0
- package/dist/production/index.js +1 -1
- package/dist/production/react.js +1 -1
- package/dist/types/src/core/IntlConfig.d.ts +4 -1
- package/package.json +4 -3
- package/dist/esm/createFormatter-D1WNHqdE.js +0 -1
- package/dist/production/createFormatter-CTr0qKAI.js +0 -1
package/README.md
CHANGED
|
@@ -17,10 +17,10 @@ Internationalization (i18n) is an essential part of the user experience, therefo
|
|
|
17
17
|
```jsx
|
|
18
18
|
// UserProfile.tsx
|
|
19
19
|
import {useTranslations} from 'use-intl';
|
|
20
|
-
|
|
20
|
+
|
|
21
21
|
export default function UserProfile({user}) {
|
|
22
22
|
const t = useTranslations('UserProfile');
|
|
23
|
-
|
|
23
|
+
|
|
24
24
|
return (
|
|
25
25
|
<section>
|
|
26
26
|
<h1>{t('title', {firstName: user.firstName})}</h1>
|
|
@@ -56,11 +56,11 @@ export default function UserProfile({user}) {
|
|
|
56
56
|
import {IntlProvider, useTranslations} from 'use-intl';
|
|
57
57
|
|
|
58
58
|
// You can get the messages from anywhere you like. You can also
|
|
59
|
-
// fetch them from within a component and then render the provider
|
|
59
|
+
// fetch them from within a component and then render the provider
|
|
60
60
|
// along with your app once you have the messages.
|
|
61
61
|
const messages = {
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
App: {
|
|
63
|
+
hello: 'Hello {username}!'
|
|
64
64
|
}
|
|
65
65
|
};
|
|
66
66
|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var React = require('react');
|
|
6
|
-
var initializeConfig = require('./initializeConfig-
|
|
6
|
+
var initializeConfig = require('./initializeConfig-BhfMSHP7.js');
|
|
7
7
|
var IntlContext = require('./IntlContext-BKfsnzBx.js');
|
|
8
8
|
require('@formatjs/fast-memoize');
|
|
9
9
|
|
package/dist/development/core.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var initializeConfig = require('./initializeConfig-
|
|
6
|
-
var createFormatter = require('./createFormatter-
|
|
5
|
+
var initializeConfig = require('./initializeConfig-BhfMSHP7.js');
|
|
6
|
+
var createFormatter = require('./createFormatter-D2v4ATzl.js');
|
|
7
7
|
require('@formatjs/fast-memoize');
|
|
8
8
|
require('intl-messageformat');
|
|
9
9
|
require('react');
|
|
@@ -2,13 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
var IntlMessageFormat = require('intl-messageformat');
|
|
4
4
|
var React = require('react');
|
|
5
|
-
var initializeConfig = require('./initializeConfig-
|
|
5
|
+
var initializeConfig = require('./initializeConfig-BhfMSHP7.js');
|
|
6
6
|
|
|
7
7
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
8
8
|
|
|
9
9
|
var IntlMessageFormat__default = /*#__PURE__*/_interopDefault(IntlMessageFormat);
|
|
10
10
|
|
|
11
|
-
// eslint-disable-next-line import/no-named-as-default -- False positive
|
|
12
11
|
function setTimeZoneInFormats(formats, timeZone) {
|
|
13
12
|
if (!formats) return formats;
|
|
14
13
|
|
|
@@ -43,16 +42,15 @@ function convertFormatsToIntlMessageFormat(formats, timeZone) {
|
|
|
43
42
|
...formatsWithTimeZone,
|
|
44
43
|
date: {
|
|
45
44
|
...defaultDateFormats,
|
|
46
|
-
...
|
|
45
|
+
...formatsWithTimeZone.dateTime
|
|
47
46
|
},
|
|
48
47
|
time: {
|
|
49
48
|
...defaultTimeFormats,
|
|
50
|
-
...
|
|
49
|
+
...formatsWithTimeZone.dateTime
|
|
51
50
|
}
|
|
52
51
|
};
|
|
53
52
|
}
|
|
54
53
|
|
|
55
|
-
// eslint-disable-next-line import/no-named-as-default -- False positive
|
|
56
54
|
// Placed here for improved tree shaking. Somehow when this is placed in
|
|
57
55
|
// `formatters.tsx`, then it can't be shaken off from `next-intl`.
|
|
58
56
|
function createMessageFormatter(cache, intlFormatters) {
|
|
@@ -72,6 +70,8 @@ function resolvePath(locale, messages, key, namespace) {
|
|
|
72
70
|
let message = messages;
|
|
73
71
|
key.split('.').forEach(part => {
|
|
74
72
|
const next = message[part];
|
|
73
|
+
|
|
74
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
75
75
|
if (part == null || next == null) {
|
|
76
76
|
throw new Error("Could not resolve `".concat(fullKey, "` in messages for locale `").concat(locale, "`.") );
|
|
77
77
|
}
|
|
@@ -109,6 +109,8 @@ function getMessagesOrError(locale, messages, namespace) {
|
|
|
109
109
|
throw new Error("No messages were configured on the provider." );
|
|
110
110
|
}
|
|
111
111
|
const retrievedMessages = namespace ? resolvePath(locale, messages, namespace) : messages;
|
|
112
|
+
|
|
113
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
112
114
|
if (!retrievedMessages) {
|
|
113
115
|
throw new Error("No messages for namespace `".concat(namespace, "` found.") );
|
|
114
116
|
}
|
|
@@ -162,7 +164,7 @@ function createBaseTranslatorImpl(_ref) {
|
|
|
162
164
|
namespace
|
|
163
165
|
});
|
|
164
166
|
}
|
|
165
|
-
function translateBaseFn(
|
|
167
|
+
function translateBaseFn(/** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */
|
|
166
168
|
key, /** Key value pairs for values to interpolate into the message. */
|
|
167
169
|
values, /** Provide custom formats for numbers, dates and times. */
|
|
168
170
|
formats) {
|
|
@@ -249,7 +251,7 @@ function createBaseTranslatorImpl(_ref) {
|
|
|
249
251
|
return getFallbackFromErrorAndNotify(key, initializeConfig.IntlErrorCode.FORMATTING_ERROR, error.message);
|
|
250
252
|
}
|
|
251
253
|
}
|
|
252
|
-
function translateFn(
|
|
254
|
+
function translateFn(/** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */
|
|
253
255
|
key, /** Key value pairs for values to interpolate into the message. */
|
|
254
256
|
values, /** Provide custom formats for numbers, dates and times. */
|
|
255
257
|
formats) {
|
|
@@ -412,7 +414,7 @@ function createFormatter(_ref) {
|
|
|
412
414
|
let options;
|
|
413
415
|
try {
|
|
414
416
|
options = resolveFormatOrOptions(typeFormats, formatOrOptions);
|
|
415
|
-
} catch (
|
|
417
|
+
} catch (_unused) {
|
|
416
418
|
return getFallback();
|
|
417
419
|
}
|
|
418
420
|
try {
|
|
@@ -422,7 +424,7 @@ function createFormatter(_ref) {
|
|
|
422
424
|
return getFallback();
|
|
423
425
|
}
|
|
424
426
|
}
|
|
425
|
-
function dateTime(
|
|
427
|
+
function dateTime(/** If a number is supplied, this is interpreted as a UTC timestamp. */
|
|
426
428
|
value,
|
|
427
429
|
/** If a time zone is supplied, the `value` is converted to that time zone.
|
|
428
430
|
* Otherwise the user time zone will be used. */
|
|
@@ -432,7 +434,7 @@ function createFormatter(_ref) {
|
|
|
432
434
|
return formatters.getDateTimeFormat(locale, options).format(value);
|
|
433
435
|
}, () => String(value));
|
|
434
436
|
}
|
|
435
|
-
function dateTimeRange(
|
|
437
|
+
function dateTimeRange(/** If a number is supplied, this is interpreted as a UTC timestamp. */
|
|
436
438
|
start, /** If a number is supplied, this is interpreted as a UTC timestamp. */
|
|
437
439
|
end,
|
|
438
440
|
/** If a time zone is supplied, the values are converted to that time zone.
|
|
@@ -454,7 +456,7 @@ function createFormatter(_ref) {
|
|
|
454
456
|
return new Date();
|
|
455
457
|
}
|
|
456
458
|
}
|
|
457
|
-
function relativeTime(
|
|
459
|
+
function relativeTime(/** The date time that needs to be formatted. */
|
|
458
460
|
date, /** The reference point in time to which `date` will be formatted in relation to. */
|
|
459
461
|
nowOrOptions) {
|
|
460
462
|
try {
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var initializeConfig = require('./initializeConfig-
|
|
5
|
+
var initializeConfig = require('./initializeConfig-BhfMSHP7.js');
|
|
6
6
|
var core = require('./core.js');
|
|
7
|
-
var createFormatter = require('./createFormatter-
|
|
7
|
+
var createFormatter = require('./createFormatter-D2v4ATzl.js');
|
|
8
8
|
var _IntlProvider = require('./_IntlProvider.js');
|
|
9
9
|
var react = require('./react.js');
|
|
10
10
|
var _useLocale = require('./_useLocale-0Rl9uR82.js');
|
|
@@ -70,8 +70,6 @@ function defaultOnError(error) {
|
|
|
70
70
|
console.error(error);
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
// eslint-disable-next-line import/no-named-as-default -- False positive
|
|
74
|
-
|
|
75
73
|
function createCache() {
|
|
76
74
|
return {
|
|
77
75
|
dateTime: {},
|
|
@@ -136,6 +134,8 @@ function validateMessagesSegment(messages, invalidKeyLabels, parentPath) {
|
|
|
136
134
|
if (parentPath) keyLabel += " (at ".concat(parentPath, ")");
|
|
137
135
|
invalidKeyLabels.push(keyLabel);
|
|
138
136
|
}
|
|
137
|
+
|
|
138
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
139
139
|
if (messageOrMessages != null && typeof messageOrMessages === 'object') {
|
|
140
140
|
validateMessagesSegment(messageOrMessages, invalidKeyLabels, joinPath(parentPath, key));
|
|
141
141
|
}
|
|
@@ -5,8 +5,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var _IntlProvider = require('./_IntlProvider.js');
|
|
6
6
|
var _useLocale = require('./_useLocale-0Rl9uR82.js');
|
|
7
7
|
var React = require('react');
|
|
8
|
-
var createFormatter = require('./createFormatter-
|
|
9
|
-
var initializeConfig = require('./initializeConfig-
|
|
8
|
+
var createFormatter = require('./createFormatter-D2v4ATzl.js');
|
|
9
|
+
var initializeConfig = require('./initializeConfig-BhfMSHP7.js');
|
|
10
10
|
require('./IntlContext-BKfsnzBx.js');
|
|
11
11
|
require('intl-messageformat');
|
|
12
12
|
require('@formatjs/fast-memoize');
|
package/dist/esm/core.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{b as e,c as r,e as t,d as s}from"./initializeConfig-D2A8plWf.js";export{I as IntlError,a as IntlErrorCode,i as initializeConfig}from"./initializeConfig-D2A8plWf.js";import{r as o,a as m}from"./createFormatter-
|
|
1
|
+
import{b as e,c as r,e as t,d as s}from"./initializeConfig-D2A8plWf.js";export{I as IntlError,a as IntlErrorCode,i as initializeConfig}from"./initializeConfig-D2A8plWf.js";import{r as o,a as m}from"./createFormatter-zqPbsiYR.js";export{c as createFormatter}from"./createFormatter-zqPbsiYR.js";import"@formatjs/fast-memoize";import"intl-messageformat";import"react";function n(a){let{_cache:i=e(),_formatters:c=r(i),getMessageFallback:n=t,messages:f,namespace:l,onError:g=s,...p}=a;return function(e,a){let{messages:r,namespace:t,...s}=e;return r=r[a],t=o(t,a),m({...s,messages:r,namespace:t})}({...p,onError:g,cache:i,formatters:c,getMessageFallback:n,messages:{"!":f},namespace:l?"!.".concat(l):"!"},"!")}export{e as _createCache,r as _createIntlFormatters,n as createTranslator};
|
|
@@ -0,0 +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,e as i,m as c,b as u,c as m}from"./initializeConfig-D2A8plWf.js";function l(e,t){return e?Object.keys(e).reduce(((n,r)=>(n[r]={timeZone:t,...e[r]},n)),{}):e}function f(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 g(u){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?f(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}}(u.locale,u.messages,u.namespace,u.onError);return function(s){let{cache:u,defaultTranslationValues:m,formats:g,formatters:d,getMessageFallback:p=i,locale:h,messagesOrError:y,namespace:v,onError:w,timeZone:E}=s;const T=y instanceof r;function S(e,t,n){const o=new r(t,n);return w(o),p({error:o,key:e,namespace:v})}function b(r,s,i){if(T)return p({error:y,key:r,namespace:v});const w=y;let b,M;try{b=f(h,w,r,v)}catch(e){return S(r,o.MISSING_MESSAGE,e.message)}if("object"==typeof b){let e,t;return Array.isArray(b)?(e=o.INVALID_MESSAGE,t="Message at `".concat(a(v,r),"` 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(v,r),"` 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")),S(r,e,t)}const I=function(e,t){if(t)return;const n=e.replace(/'([{}])/gi,"$1");return/<|{/.test(n)?void 0:n}(b,s);if(I)return I;d.getMessageFormat||(d.getMessageFormat=function(t,n){const r=c((function(){return new e(arguments.length<=0?void 0:arguments[0],arguments.length<=1?void 0:arguments[1],arguments.length<=2?void 0:arguments[2],{formatters:n,...arguments.length<=3?void 0:arguments[3]})}),t.message);return r}(u,d));try{M=d.getMessageFormat(b,h,function(t,n){const r=n?{...t,dateTime:l(t.dateTime,n)}:t,o=e.formats.date,a=n?l(o,n):o,s=e.formats.time,i=n?l(s,n):s;return{...r,date:{...a,...r.dateTime},time:{...i,...r.dateTime}}}({...g,...i},E),{formatters:{...d,getDateTimeFormat:(e,t)=>d.getDateTimeFormat(e,{timeZone:E,...t})}})}catch(e){const t=e;return S(r,o.INVALID_MESSAGE,t.message+("originalMessage"in t?" (".concat(t.originalMessage,")"):""))}try{const e=M.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}({...m,...s}));if(null==e)throw new Error("Unable to format `".concat(r,"` in ").concat(v?"namespace `".concat(v,"`"):"messages"));return t(e)||Array.isArray(e)||"string"==typeof e?e:String(e)}catch(e){return S(r,o.FORMATTING_ERROR,e.message)}}function M(e,t,n){const r=b(e,t,n);return"string"!=typeof r?S(e,o.INVALID_MESSAGE,"The message `".concat(e,"` in ").concat(v?"namespace `".concat(v,"`"):"messages"," didn't resolve to a string. If you want to format rich text, use `t.rich` instead.")):r}return M.rich=b,M.markup=(e,t,n)=>{const a=b(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),p({error:t,key:e,namespace:v})}return a},M.raw=e=>{if(T)return p({error:y,key:e,namespace:v});const t=y;try{return f(h,t,e,v)}catch(t){return S(e,o.MISSING_MESSAGE,t.message)}},M.has=e=>{if(T)return!1;try{return f(h,y,e,v),!0}catch(e){return!1}},M}({...u,messagesOrError:m})}function d(e,t){return e===t?void 0:e.slice((t+".").length)}const p=60,h=60*p,y=24*h,v=7*y,w=y*(365/12),E=3*w,T=365*y,S={second:1,seconds:1,minute:p,minutes:p,hour:h,hours:h,day:y,days:y,week:v,weeks:v,month:w,months:w,quarter:E,quarters:E,year:T,years:T};function b(e){let{_cache:t=u(),_formatters:n=m(t),formats:a,locale:i,now:c,onError:l=s,timeZone:f}=e;function g(e){var t;return null!==(t=e)&&void 0!==t&&t.timeZone||(f?e={...e,timeZone:f}:l(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 d(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 l(e),e}}else n=t;return n}(t,e)}catch(e){return a()}try{return n(s)}catch(e){return l(new r(o.FORMATTING_ERROR,e.message)),a()}}function E(e,t){return d(t,null==a?void 0:a.dateTime,(t=>(t=g(t),n.getDateTimeFormat(i,t).format(e))),(()=>String(e)))}function b(){return c||(l(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:E,number:function(e,t){return d(t,null==a?void 0:a.number,(t=>n.getNumberFormat(i,t).format(e)),(()=>String(e)))},relativeTime:function(e,t){try{let r,o;const a={};t instanceof Date||"number"==typeof t?r=new Date(t):t&&(r=null!=t.now?new Date(t.now):b(),o=t.unit,a.style=t.style,a.numberingSystem=t.numberingSystem),r||(r=b());const s=(new Date(e).getTime()-r.getTime())/1e3;o||(o=function(e){const t=Math.abs(e);return t<p?"second":t<h?"minute":t<y?"hour":t<v?"day":t<w?"week":t<T?"month":"year"}(s)),a.numeric="second"===o?"auto":"always";const c=function(e,t){return Math.round(e/S[t])}(s,o);return n.getRelativeTimeFormat(i,a).format(c,o)}catch(t){return l(new r(o.FORMATTING_ERROR,t.message)),String(e)}},list:function(e,t){const r=[],o=new Map;let s=0;for(const t of e){let e;"object"==typeof t?(e=String(s),o.set(e,t)):e=String(t),r.push(e),s++}return d(t,null==a?void 0:a.list,(e=>{const t=n.getListFormat(i,e).formatToParts(r).map((e=>"literal"===e.type?e.value:o.get(e.value)||e.value));return o.size>0?t:t.join("")}),(()=>String(e)))},dateTimeRange:function(e,t,r){return d(r,null==a?void 0:a.dateTime,(r=>(r=g(r),n.getDateTimeFormat(i,r).formatRange(e,t))),(()=>[E(e),E(t)].join(" – ")))}}}export{g as a,b as c,d as r};
|
package/dist/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{I as IntlError,a as IntlErrorCode,b as _createCache,c as _createIntlFormatters,i as initializeConfig}from"./initializeConfig-D2A8plWf.js";export{createTranslator}from"./core.js";export{c as createFormatter}from"./createFormatter-
|
|
1
|
+
export{I as IntlError,a as IntlErrorCode,b as _createCache,c as _createIntlFormatters,i as initializeConfig}from"./initializeConfig-D2A8plWf.js";export{createTranslator}from"./core.js";export{c as createFormatter}from"./createFormatter-zqPbsiYR.js";export{IntlProvider}from"./_IntlProvider.js";export{useFormatter,useMessages,useNow,useTimeZone,useTranslations}from"./react.js";export{u as useLocale}from"./_useLocale-v-ZT5JoE.js";import"@formatjs/fast-memoize";import"intl-messageformat";import"react";import"./IntlContext-DoS4CDM3.js";
|
package/dist/esm/react.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{IntlProvider}from"./_IntlProvider.js";import{a as e}from"./_useLocale-v-ZT5JoE.js";export{u as useLocale}from"./_useLocale-v-ZT5JoE.js";import{useMemo as t,useState as o,useEffect as r}from"react";import{r as n,a,c as s}from"./createFormatter-
|
|
1
|
+
export{IntlProvider}from"./_IntlProvider.js";import{a as e}from"./_useLocale-v-ZT5JoE.js";export{u as useLocale}from"./_useLocale-v-ZT5JoE.js";import{useMemo as t,useState as o,useEffect as r}from"react";import{r as n,a,c as s}from"./createFormatter-zqPbsiYR.js";import{I as i,a as c}from"./initializeConfig-D2A8plWf.js";import"./IntlContext-DoS4CDM3.js";import"intl-messageformat";import"@formatjs/fast-memoize";let m=!1;const l="undefined"==typeof window;function f(o){return function(o,r,s){const{cache:f,defaultTranslationValues:u,formats:d,formatters:p,getMessageFallback:g,locale:v,onError:h,timeZone:w}=e(),I=o[s],j=n(r,s);return w||m||!l||(m=!0,h(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"))),t((()=>a({cache:f,formatters:p,getMessageFallback:g,messages:I,defaultTranslationValues:u,namespace:j,onError:h,formats:d,locale:v,timeZone:w})),[f,p,g,I,u,j,h,d,v,w])}({"!":e().messages},o?"!.".concat(o):"!","!")}function d(){return new Date}function p(t){const n=null==t?void 0:t.updateInterval,{now:a}=e(),[s,i]=o(a||d());return r((()=>{if(!n)return;const e=setInterval((()=>{i(d())}),n);return()=>{clearInterval(e)}}),[a,n]),null==n&&a?a:s}function g(){return e().timeZone}function v(){const t=e();if(!t.messages)throw new Error("No messages found. Have you configured them correctly? See https://next-intl-docs.vercel.app/docs/configuration#messages");return t.messages}function h(){const{formats:o,formatters:r,locale:n,now:a,onError:i,timeZone:c}=e();return t((()=>s({formats:o,locale:n,now:a,onError:i,timeZone:c,_formatters:r})),[o,r,a,n,i,c])}export{h as useFormatter,v as useMessages,p as useNow,g as useTimeZone,f as useTranslations};
|
package/dist/production/core.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./createFormatter-
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./createFormatter-CZeYe_QF.js"),r=require("./initializeConfig-AbYTngyP.js");require("intl-messageformat"),require("react"),require("@formatjs/fast-memoize"),exports.IntlError=e.IntlError,exports.IntlErrorCode=e.IntlErrorCode,exports.createFormatter=e.createFormatter,exports._createCache=r.createCache,exports._createIntlFormatters=r.createIntlFormatters,exports.initializeConfig=r.initializeConfig,exports.createTranslator=function(t){let{_cache:a=r.createCache(),_formatters:s=r.createIntlFormatters(a),getMessageFallback:o=r.defaultGetMessageFallback,messages:c,namespace:n,onError:i=r.defaultOnError,...l}=t;return function(r,t){let{messages:a,namespace:s,...o}=r;return a=a[t],s=e.resolveNamespace(s,t),e.createBaseTranslator({...o,messages:a,namespace:s})}({...l,onError:i,cache:a,formatters:s,getMessageFallback:o,messages:{"!":c},namespace:n?"!.".concat(n):"!"},"!")};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("intl-messageformat"),t=require("react"),r=require("./initializeConfig-AbYTngyP.js");function n(e){return e&&e.__esModule?e:{default:e}}var o=n(e);function a(e,t,r){return(t=function(e){var t=function(e,t){if("object"!=typeof e||!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:t+""}(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}let i=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),a(this,"code",void 0),a(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 c(e,t,n,o){const a=r.joinPath(o,n);if(!t)throw new Error(a);let i=t;return n.split(".").forEach((t=>{const r=i[t];if(null==t||null==r)throw new Error(a+" (".concat(e,")"));i=r})),i}const l=60,m=60*l,f=24*m,g=7*f,E=f*(365/12),d=3*E,I=365*f,S={second:1,seconds:1,minute:l,minutes:l,hour:m,hours:m,day:f,days:f,week:g,weeks:g,month:E,months:E,quarter:d,quarters:d,year:I,years:I};exports.IntlError=s,exports.IntlErrorCode=i,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?c(e,t,n):t;if(!r)throw new Error(n);return r}catch(e){const t=new s(i.MISSING_MESSAGE,e.message);return o(t),t}}(e.locale,e.messages,e.namespace,e.onError);return function(e){let{cache:n,defaultTranslationValues:a,formats:l,formatters:m,getMessageFallback:f=r.defaultGetMessageFallback,locale:g,messagesOrError:E,namespace:d,onError:I,timeZone:S}=e;const y=E instanceof s;function T(e,t,r){const n=new s(t,r);return I(n),f({error:n,key:e,namespace:d})}function h(e,s,I){if(y)return f({error:E,key:e,namespace:d});const h=E;let M,N;try{M=c(g,h,e,d)}catch(t){return T(e,i.MISSING_MESSAGE,t.message)}if("object"==typeof M){let t,r;return t=Array.isArray(M)?i.INVALID_MESSAGE:i.INSUFFICIENT_PATH,T(e,t,r)}const A=function(e,t){if(t)return;const r=e.replace(/'([{}])/gi,"$1");return/<|{/.test(r)?void 0:r}(M,s);if(A)return A;m.getMessageFormat||(m.getMessageFormat=function(e,t){const n=r.memoFn((function(){return new o.default(arguments.length<=0?void 0:arguments[0],arguments.length<=1?void 0:arguments[1],arguments.length<=2?void 0:arguments[2],{formatters:t,...arguments.length<=3?void 0:arguments[3]})}),e.message);return n}(n,m));try{N=m.getMessageFormat(M,g,function(e,t){const r=t?{...e,dateTime:u(e.dateTime,t)}:e,n=o.default.formats.date,a=t?u(n,t):n,i=o.default.formats.time,s=t?u(i,t):i;return{...r,date:{...a,...r.dateTime},time:{...s,...r.dateTime}}}({...l,...I},S),{formatters:{...m,getDateTimeFormat:(e,t)=>m.getDateTimeFormat(e,{timeZone:S,...t})}})}catch(t){const r=t;return T(e,i.INVALID_MESSAGE,r.message)}try{const e=N.format(function(e){if(0===Object.keys(e).length)return;const r={};return Object.keys(e).forEach((n=>{let o=0;const a=e[n];let i;i="function"==typeof a?e=>{const r=a(e);return t.isValidElement(r)?t.cloneElement(r,{key:n+o++}):r}:a,r[n]=i})),r}({...a,...s}));if(null==e)throw new Error(void 0);return t.isValidElement(e)||Array.isArray(e)||"string"==typeof e?e:String(e)}catch(t){return T(e,i.FORMATTING_ERROR,t.message)}}function M(e,t,r){const n=h(e,t,r);return"string"!=typeof n?T(e,i.INVALID_MESSAGE,void 0):n}return M.rich=h,M.markup=(e,t,r)=>{const n=h(e,t,r);if("string"!=typeof n){const t=new s(i.FORMATTING_ERROR,void 0);return I(t),f({error:t,key:e,namespace:d})}return n},M.raw=e=>{if(y)return f({error:E,key:e,namespace:d});const t=E;try{return c(g,t,e,d)}catch(t){return T(e,i.MISSING_MESSAGE,t.message)}},M.has=e=>{if(y)return!1;try{return c(g,E,e,d),!0}catch(e){return!1}},M}({...e,messagesOrError:n})},exports.createFormatter=function(e){let{_cache:t=r.createCache(),_formatters:n=r.createIntlFormatters(t),formats:o,locale:a,now:u,onError:c=r.defaultOnError,timeZone:d}=e;function y(e){var t;return null!==(t=e)&&void 0!==t&&t.timeZone||(d?e={...e,timeZone:d}:c(new s(i.ENVIRONMENT_FALLBACK,void 0))),e}function T(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(i.MISSING_FORMAT,void 0);throw c(e),e}}else r=t;return r}(t,e)}catch(e){return n()}try{return r(o)}catch(e){return c(new s(i.FORMATTING_ERROR,e.message)),n()}}function h(e,t){return T(t,null==o?void 0:o.dateTime,(t=>(t=y(t),n.getDateTimeFormat(a,t).format(e))),(()=>String(e)))}function M(){return u||(c(new s(i.ENVIRONMENT_FALLBACK,void 0)),new Date)}return{dateTime:h,number:function(e,t){return T(t,null==o?void 0:o.number,(t=>n.getNumberFormat(a,t).format(e)),(()=>String(e)))},relativeTime:function(e,t){try{let r,o;const i={};t instanceof Date||"number"==typeof t?r=new Date(t):t&&(r=null!=t.now?new Date(t.now):M(),o=t.unit,i.style=t.style,i.numberingSystem=t.numberingSystem),r||(r=M());const s=(new Date(e).getTime()-r.getTime())/1e3;o||(o=function(e){const t=Math.abs(e);return t<l?"second":t<m?"minute":t<f?"hour":t<g?"day":t<E?"week":t<I?"month":"year"}(s)),i.numeric="second"===o?"auto":"always";const u=function(e,t){return Math.round(e/S[t])}(s,o);return n.getRelativeTimeFormat(a,i).format(u,o)}catch(t){return c(new s(i.FORMATTING_ERROR,t.message)),String(e)}},list:function(e,t){const r=[],i=new Map;let s=0;for(const t of e){let e;"object"==typeof t?(e=String(s),i.set(e,t)):e=String(t),r.push(e),s++}return T(t,null==o?void 0:o.list,(e=>{const t=n.getListFormat(a,e).formatToParts(r).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,r){return T(r,null==o?void 0:o.dateTime,(r=>(r=y(r),n.getDateTimeFormat(a,r).formatRange(e,t))),(()=>[h(e),h(t)].join(" – ")))}}},exports.resolveNamespace=function(e,t){return e===t?void 0:e.slice((t+".").length)};
|
package/dist/production/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./createFormatter-
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./createFormatter-CZeYe_QF.js"),r=require("./core.js"),t=require("./initializeConfig-AbYTngyP.js"),s=require("./_IntlProvider.js"),o=require("./react.js"),a=require("./_useLocale-CpTrqBDt.js");require("intl-messageformat"),require("react"),require("@formatjs/fast-memoize"),require("./IntlContext-DcFt0tgW.js"),exports.IntlError=e.IntlError,exports.IntlErrorCode=e.IntlErrorCode,exports.createFormatter=e.createFormatter,exports.createTranslator=r.createTranslator,exports._createCache=t.createCache,exports._createIntlFormatters=t.createIntlFormatters,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=a.useLocale;
|
package/dist/production/react.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./_IntlProvider.js"),t=require("./_useLocale-CpTrqBDt.js"),r=require("react"),o=require("./createFormatter-
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./_IntlProvider.js"),t=require("./_useLocale-CpTrqBDt.js"),r=require("react"),o=require("./createFormatter-CZeYe_QF.js");require("./initializeConfig-AbYTngyP.js"),require("@formatjs/fast-memoize"),require("./IntlContext-DcFt0tgW.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,formatters:n,locale:s,now:a,onError:u,timeZone:l}=t.useIntlContext();return r.useMemo((()=>o.createFormatter({formats:e,locale:s,now:a,onError:u,timeZone:l,_formatters:n})),[e,n,a,s,u,l])},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]),null==o&&n?n:s},exports.useTimeZone=function(){return t.useIntlContext().timeZone},exports.useTranslations=function(e){return function(e,a,u){const{cache:l,defaultTranslationValues:i,formats:c,formatters:m,getMessageFallback:f,locale:I,onError:d,timeZone:x}=t.useIntlContext(),p=e[u],v=o.resolveNamespace(a,u);return x||n||!s||(n=!0,d(new o.IntlError(o.IntlErrorCode.ENVIRONMENT_FALLBACK,void 0))),r.useMemo((()=>o.createBaseTranslator({cache:l,formatters:m,getMessageFallback:f,messages:p,defaultTranslationValues:i,namespace:v,onError:d,formats:c,locale:I,timeZone:x})),[l,m,f,p,i,v,d,c,I,x])}({"!":t.useIntlContext().messages},e?"!.".concat(e):"!","!")};
|
|
@@ -41,7 +41,10 @@ type IntlConfig<Messages = AbstractIntlMessages> = {
|
|
|
41
41
|
messages?: Messages;
|
|
42
42
|
/** Global default values for translation values and rich text elements.
|
|
43
43
|
* Can be used for consistent usage or styling of rich text elements.
|
|
44
|
-
* Defaults will be overidden by locally provided values.
|
|
44
|
+
* Defaults will be overidden by locally provided values.
|
|
45
|
+
*
|
|
46
|
+
* @deprecated See https://next-intl-docs.vercel.app/docs/usage/messages#rich-text-reuse-tags
|
|
47
|
+
**/
|
|
45
48
|
defaultTranslationValues?: RichTranslationValues;
|
|
46
49
|
};
|
|
47
50
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "use-intl",
|
|
3
|
-
"version": "3.22.0
|
|
3
|
+
"version": "3.22.0",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"author": "Jan Amann <jan@amann.work>",
|
|
6
6
|
"description": "Internationalization (i18n) for React",
|
|
@@ -14,8 +14,9 @@
|
|
|
14
14
|
"build": "rm -rf dist && rollup -c",
|
|
15
15
|
"test": "TZ=Europe/Berlin vitest",
|
|
16
16
|
"lint": "pnpm run lint:source && pnpm run lint:package",
|
|
17
|
-
"lint:source": "eslint src test && tsc --noEmit",
|
|
17
|
+
"lint:source": "eslint src test && tsc --noEmit && pnpm run lint:prettier",
|
|
18
18
|
"lint:package": "publint && attw --pack",
|
|
19
|
+
"lint:prettier": "prettier src --check",
|
|
19
20
|
"prepublishOnly": "turbo build",
|
|
20
21
|
"size": "size-limit"
|
|
21
22
|
},
|
|
@@ -69,5 +70,5 @@
|
|
|
69
70
|
"peerDependencies": {
|
|
70
71
|
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
|
|
71
72
|
},
|
|
72
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "02bc1190dc993b202e50e52de75ee36d0172e3db"
|
|
73
74
|
}
|
|
@@ -1 +0,0 @@
|
|
|
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,e as i,m as c,b as u,c as m}from"./initializeConfig-D2A8plWf.js";function l(e,t){return e?Object.keys(e).reduce(((n,r)=>(n[r]={timeZone:t,...e[r]},n)),{}):e}function f(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 g(u){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?f(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}}(u.locale,u.messages,u.namespace,u.onError);return function(s){let{cache:u,defaultTranslationValues:m,formats:g,formatters:d,getMessageFallback:p=i,locale:h,messagesOrError:y,namespace:v,onError:w,timeZone:E}=s;const T=y instanceof r;function S(e,t,n){const o=new r(t,n);return w(o),p({error:o,key:e,namespace:v})}function b(r,s,i){if(T)return p({error:y,key:r,namespace:v});const w=y;let b,M;try{b=f(h,w,r,v)}catch(e){return S(r,o.MISSING_MESSAGE,e.message)}if("object"==typeof b){let e,t;return Array.isArray(b)?(e=o.INVALID_MESSAGE,t="Message at `".concat(a(v,r),"` 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(v,r),"` 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")),S(r,e,t)}const I=function(e,t){if(t)return;const n=e.replace(/'([{}])/gi,"$1");return/<|{/.test(n)?void 0:n}(b,s);if(I)return I;d.getMessageFormat||(d.getMessageFormat=function(t,n){const r=c((function(){return new e(arguments.length<=0?void 0:arguments[0],arguments.length<=1?void 0:arguments[1],arguments.length<=2?void 0:arguments[2],{formatters:n,...arguments.length<=3?void 0:arguments[3]})}),t.message);return r}(u,d));try{M=d.getMessageFormat(b,h,function(t,n){const r=n?{...t,dateTime:l(t.dateTime,n)}:t,o=e.formats.date,a=n?l(o,n):o,s=e.formats.time,i=n?l(s,n):s;return{...r,date:{...a,...null==r?void 0:r.dateTime},time:{...i,...null==r?void 0:r.dateTime}}}({...g,...i},E),{formatters:{...d,getDateTimeFormat:(e,t)=>d.getDateTimeFormat(e,{timeZone:E,...t})}})}catch(e){const t=e;return S(r,o.INVALID_MESSAGE,t.message+("originalMessage"in t?" (".concat(t.originalMessage,")"):""))}try{const e=M.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}({...m,...s}));if(null==e)throw new Error("Unable to format `".concat(r,"` in ").concat(v?"namespace `".concat(v,"`"):"messages"));return t(e)||Array.isArray(e)||"string"==typeof e?e:String(e)}catch(e){return S(r,o.FORMATTING_ERROR,e.message)}}function M(e,t,n){const r=b(e,t,n);return"string"!=typeof r?S(e,o.INVALID_MESSAGE,"The message `".concat(e,"` in ").concat(v?"namespace `".concat(v,"`"):"messages"," didn't resolve to a string. If you want to format rich text, use `t.rich` instead.")):r}return M.rich=b,M.markup=(e,t,n)=>{const a=b(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),p({error:t,key:e,namespace:v})}return a},M.raw=e=>{if(T)return p({error:y,key:e,namespace:v});const t=y;try{return f(h,t,e,v)}catch(t){return S(e,o.MISSING_MESSAGE,t.message)}},M.has=e=>{if(T)return!1;try{return f(h,y,e,v),!0}catch(e){return!1}},M}({...u,messagesOrError:m})}function d(e,t){return e===t?void 0:e.slice((t+".").length)}const p=60,h=60*p,y=24*h,v=7*y,w=y*(365/12),E=3*w,T=365*y,S={second:1,seconds:1,minute:p,minutes:p,hour:h,hours:h,day:y,days:y,week:v,weeks:v,month:w,months:w,quarter:E,quarters:E,year:T,years:T};function b(e){let{_cache:t=u(),_formatters:n=m(t),formats:a,locale:i,now:c,onError:l=s,timeZone:f}=e;function g(e){var t;return null!==(t=e)&&void 0!==t&&t.timeZone||(f?e={...e,timeZone:f}:l(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 d(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 l(e),e}}else n=t;return n}(t,e)}catch(e){return a()}try{return n(s)}catch(e){return l(new r(o.FORMATTING_ERROR,e.message)),a()}}function E(e,t){return d(t,null==a?void 0:a.dateTime,(t=>(t=g(t),n.getDateTimeFormat(i,t).format(e))),(()=>String(e)))}function b(){return c||(l(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:E,number:function(e,t){return d(t,null==a?void 0:a.number,(t=>n.getNumberFormat(i,t).format(e)),(()=>String(e)))},relativeTime:function(e,t){try{let r,o;const a={};t instanceof Date||"number"==typeof t?r=new Date(t):t&&(r=null!=t.now?new Date(t.now):b(),o=t.unit,a.style=t.style,a.numberingSystem=t.numberingSystem),r||(r=b());const s=(new Date(e).getTime()-r.getTime())/1e3;o||(o=function(e){const t=Math.abs(e);return t<p?"second":t<h?"minute":t<y?"hour":t<v?"day":t<w?"week":t<T?"month":"year"}(s)),a.numeric="second"===o?"auto":"always";const c=function(e,t){return Math.round(e/S[t])}(s,o);return n.getRelativeTimeFormat(i,a).format(c,o)}catch(t){return l(new r(o.FORMATTING_ERROR,t.message)),String(e)}},list:function(e,t){const r=[],o=new Map;let s=0;for(const t of e){let e;"object"==typeof t?(e=String(s),o.set(e,t)):e=String(t),r.push(e),s++}return d(t,null==a?void 0:a.list,(e=>{const t=n.getListFormat(i,e).formatToParts(r).map((e=>"literal"===e.type?e.value:o.get(e.value)||e.value));return o.size>0?t:t.join("")}),(()=>String(e)))},dateTimeRange:function(e,t,r){return d(r,null==a?void 0:a.dateTime,(r=>(r=g(r),n.getDateTimeFormat(i,r).formatRange(e,t))),(()=>[E(e),E(t)].join(" – ")))}}}export{g as a,b as c,d as r};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var e=require("intl-messageformat"),t=require("react"),r=require("./initializeConfig-AbYTngyP.js");function n(e){return e&&e.__esModule?e:{default:e}}var o=n(e);function a(e,t,r){return(t=function(e){var t=function(e,t){if("object"!=typeof e||!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:t+""}(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}let i=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),a(this,"code",void 0),a(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 c(e,t,n,o){const a=r.joinPath(o,n);if(!t)throw new Error(a);let i=t;return n.split(".").forEach((t=>{const r=i[t];if(null==t||null==r)throw new Error(a+" (".concat(e,")"));i=r})),i}const l=60,m=60*l,f=24*m,g=7*f,d=f*(365/12),E=3*d,I=365*f,S={second:1,seconds:1,minute:l,minutes:l,hour:m,hours:m,day:f,days:f,week:g,weeks:g,month:d,months:d,quarter:E,quarters:E,year:I,years:I};exports.IntlError=s,exports.IntlErrorCode=i,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?c(e,t,n):t;if(!r)throw new Error(n);return r}catch(e){const t=new s(i.MISSING_MESSAGE,e.message);return o(t),t}}(e.locale,e.messages,e.namespace,e.onError);return function(e){let{cache:n,defaultTranslationValues:a,formats:l,formatters:m,getMessageFallback:f=r.defaultGetMessageFallback,locale:g,messagesOrError:d,namespace:E,onError:I,timeZone:S}=e;const y=d instanceof s;function T(e,t,r){const n=new s(t,r);return I(n),f({error:n,key:e,namespace:E})}function h(e,s,I){if(y)return f({error:d,key:e,namespace:E});const h=d;let v,M;try{v=c(g,h,e,E)}catch(t){return T(e,i.MISSING_MESSAGE,t.message)}if("object"==typeof v){let t,r;return t=Array.isArray(v)?i.INVALID_MESSAGE:i.INSUFFICIENT_PATH,T(e,t,r)}const N=function(e,t){if(t)return;const r=e.replace(/'([{}])/gi,"$1");return/<|{/.test(r)?void 0:r}(v,s);if(N)return N;m.getMessageFormat||(m.getMessageFormat=function(e,t){const n=r.memoFn((function(){return new o.default(arguments.length<=0?void 0:arguments[0],arguments.length<=1?void 0:arguments[1],arguments.length<=2?void 0:arguments[2],{formatters:t,...arguments.length<=3?void 0:arguments[3]})}),e.message);return n}(n,m));try{M=m.getMessageFormat(v,g,function(e,t){const r=t?{...e,dateTime:u(e.dateTime,t)}:e,n=o.default.formats.date,a=t?u(n,t):n,i=o.default.formats.time,s=t?u(i,t):i;return{...r,date:{...a,...null==r?void 0:r.dateTime},time:{...s,...null==r?void 0:r.dateTime}}}({...l,...I},S),{formatters:{...m,getDateTimeFormat:(e,t)=>m.getDateTimeFormat(e,{timeZone:S,...t})}})}catch(t){const r=t;return T(e,i.INVALID_MESSAGE,r.message)}try{const e=M.format(function(e){if(0===Object.keys(e).length)return;const r={};return Object.keys(e).forEach((n=>{let o=0;const a=e[n];let i;i="function"==typeof a?e=>{const r=a(e);return t.isValidElement(r)?t.cloneElement(r,{key:n+o++}):r}:a,r[n]=i})),r}({...a,...s}));if(null==e)throw new Error(void 0);return t.isValidElement(e)||Array.isArray(e)||"string"==typeof e?e:String(e)}catch(t){return T(e,i.FORMATTING_ERROR,t.message)}}function v(e,t,r){const n=h(e,t,r);return"string"!=typeof n?T(e,i.INVALID_MESSAGE,void 0):n}return v.rich=h,v.markup=(e,t,r)=>{const n=h(e,t,r);if("string"!=typeof n){const t=new s(i.FORMATTING_ERROR,void 0);return I(t),f({error:t,key:e,namespace:E})}return n},v.raw=e=>{if(y)return f({error:d,key:e,namespace:E});const t=d;try{return c(g,t,e,E)}catch(t){return T(e,i.MISSING_MESSAGE,t.message)}},v.has=e=>{if(y)return!1;try{return c(g,d,e,E),!0}catch(e){return!1}},v}({...e,messagesOrError:n})},exports.createFormatter=function(e){let{_cache:t=r.createCache(),_formatters:n=r.createIntlFormatters(t),formats:o,locale:a,now:u,onError:c=r.defaultOnError,timeZone:E}=e;function y(e){var t;return null!==(t=e)&&void 0!==t&&t.timeZone||(E?e={...e,timeZone:E}:c(new s(i.ENVIRONMENT_FALLBACK,void 0))),e}function T(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(i.MISSING_FORMAT,void 0);throw c(e),e}}else r=t;return r}(t,e)}catch(e){return n()}try{return r(o)}catch(e){return c(new s(i.FORMATTING_ERROR,e.message)),n()}}function h(e,t){return T(t,null==o?void 0:o.dateTime,(t=>(t=y(t),n.getDateTimeFormat(a,t).format(e))),(()=>String(e)))}function v(){return u||(c(new s(i.ENVIRONMENT_FALLBACK,void 0)),new Date)}return{dateTime:h,number:function(e,t){return T(t,null==o?void 0:o.number,(t=>n.getNumberFormat(a,t).format(e)),(()=>String(e)))},relativeTime:function(e,t){try{let r,o;const i={};t instanceof Date||"number"==typeof t?r=new Date(t):t&&(r=null!=t.now?new Date(t.now):v(),o=t.unit,i.style=t.style,i.numberingSystem=t.numberingSystem),r||(r=v());const s=(new Date(e).getTime()-r.getTime())/1e3;o||(o=function(e){const t=Math.abs(e);return t<l?"second":t<m?"minute":t<f?"hour":t<g?"day":t<d?"week":t<I?"month":"year"}(s)),i.numeric="second"===o?"auto":"always";const u=function(e,t){return Math.round(e/S[t])}(s,o);return n.getRelativeTimeFormat(a,i).format(u,o)}catch(t){return c(new s(i.FORMATTING_ERROR,t.message)),String(e)}},list:function(e,t){const r=[],i=new Map;let s=0;for(const t of e){let e;"object"==typeof t?(e=String(s),i.set(e,t)):e=String(t),r.push(e),s++}return T(t,null==o?void 0:o.list,(e=>{const t=n.getListFormat(a,e).formatToParts(r).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,r){return T(r,null==o?void 0:o.dateTime,(r=>(r=y(r),n.getDateTimeFormat(a,r).formatRange(e,t))),(()=>[h(e),h(t)].join(" – ")))}}},exports.resolveNamespace=function(e,t){return e===t?void 0:e.slice((t+".").length)};
|