use-intl 3.0.0-beta.3 → 3.0.0-rc.5
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/dist/development/_IntlProvider.js +1 -1
- package/dist/development/core.js +6 -7
- package/dist/development/{createIntl-dfba4462.js → createFormatter-bcc5a49f.js} +67 -58
- package/dist/development/index.js +4 -6
- package/dist/development/{initializeConfig-cde42612.js → initializeConfig-0a0b87a7.js} +1 -0
- package/dist/development/react.js +16 -31
- package/dist/esm/_IntlProvider.js +1 -1
- package/dist/esm/core.js +1 -1
- package/dist/esm/createFormatter-cccbd794.js +1 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/initializeConfig-29e7ba4c.js +1 -0
- package/dist/esm/react.js +1 -1
- package/dist/production/core.js +1 -1
- package/dist/production/createFormatter-8c0b8eb2.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 +1 -1
- package/dist/types/src/core/IntlError.d.ts +1 -0
- package/dist/types/src/core/RelativeTimeFormatOptions.d.ts +5 -0
- package/dist/types/src/core/createFormatter.d.ts +3 -2
- package/dist/types/src/core/index.d.ts +0 -1
- package/dist/types/src/react/index.d.ts +0 -1
- package/dist/types/src/react/useFormatter.d.ts +1 -1
- package/dist/types/src/react/useMessages.d.ts +2 -1
- package/dist/types/src/react/useTranslationsImpl.d.ts +1 -1
- package/package.json +3 -3
- package/dist/esm/createIntl-164a7766.js +0 -1
- package/dist/esm/initializeConfig-c316f266.js +0 -1
- package/dist/production/createIntl-e408cd5c.js +0 -1
- package/dist/types/src/core/createIntl.d.ts +0 -7
- package/dist/types/src/react/getInitializedConfig.d.ts +0 -1
- package/dist/types/src/react/useIntl.d.ts +0 -6
- package/dist/types/test/core/createIntl.test.d.ts +0 -1
- package/dist/types/test/react/useIntl.test.d.ts +0 -1
|
@@ -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-0a0b87a7.js');
|
|
7
7
|
var IntlContext = require('./IntlContext-b5cc6be8.js');
|
|
8
8
|
|
|
9
9
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
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
|
|
5
|
+
var initializeConfig = require('./initializeConfig-0a0b87a7.js');
|
|
6
|
+
var createFormatter = require('./createFormatter-bcc5a49f.js');
|
|
7
7
|
require('intl-messageformat');
|
|
8
8
|
require('react');
|
|
9
9
|
|
|
@@ -18,8 +18,8 @@ function createTranslatorImpl(_ref, namespacePrefix) {
|
|
|
18
18
|
// The `namespacePrefix` is part of the type system.
|
|
19
19
|
// See the comment in the function invocation.
|
|
20
20
|
messages = messages[namespacePrefix];
|
|
21
|
-
namespace =
|
|
22
|
-
const translator =
|
|
21
|
+
namespace = createFormatter.resolveNamespace(namespace, namespacePrefix);
|
|
22
|
+
const translator = createFormatter.createBaseTranslator({
|
|
23
23
|
...rest,
|
|
24
24
|
onError,
|
|
25
25
|
getMessageFallback,
|
|
@@ -86,7 +86,6 @@ function createTranslator(_ref) {
|
|
|
86
86
|
exports.IntlError = initializeConfig.IntlError;
|
|
87
87
|
exports.IntlErrorCode = initializeConfig.IntlErrorCode;
|
|
88
88
|
exports.initializeConfig = initializeConfig.initializeConfig;
|
|
89
|
-
exports.createBaseTranslator =
|
|
90
|
-
exports.createFormatter =
|
|
91
|
-
exports.createIntl = createIntl.createIntl;
|
|
89
|
+
exports.createBaseTranslator = createFormatter.createBaseTranslator;
|
|
90
|
+
exports.createFormatter = createFormatter.createFormatter;
|
|
92
91
|
exports.createTranslator = createTranslator;
|
|
@@ -2,7 +2,7 @@
|
|
|
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-0a0b87a7.js');
|
|
6
6
|
|
|
7
7
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
8
8
|
|
|
@@ -272,45 +272,53 @@ function resolveNamespace(namespace, namespacePrefix) {
|
|
|
272
272
|
return namespace === namespacePrefix ? undefined : namespace.slice((namespacePrefix + '.').length);
|
|
273
273
|
}
|
|
274
274
|
|
|
275
|
-
const
|
|
275
|
+
const SECOND = 1;
|
|
276
|
+
const MINUTE = SECOND * 60;
|
|
276
277
|
const HOUR = MINUTE * 60;
|
|
277
278
|
const DAY = HOUR * 24;
|
|
278
279
|
const WEEK = DAY * 7;
|
|
279
280
|
const MONTH = DAY * (365 / 12); // Approximation
|
|
281
|
+
const QUARTER = MONTH * 3;
|
|
280
282
|
const YEAR = DAY * 365;
|
|
281
|
-
|
|
283
|
+
const UNIT_SECONDS = {
|
|
284
|
+
second: SECOND,
|
|
285
|
+
seconds: SECOND,
|
|
286
|
+
minute: MINUTE,
|
|
287
|
+
minutes: MINUTE,
|
|
288
|
+
hour: HOUR,
|
|
289
|
+
hours: HOUR,
|
|
290
|
+
day: DAY,
|
|
291
|
+
days: DAY,
|
|
292
|
+
week: WEEK,
|
|
293
|
+
weeks: WEEK,
|
|
294
|
+
month: MONTH,
|
|
295
|
+
months: MONTH,
|
|
296
|
+
quarter: QUARTER,
|
|
297
|
+
quarters: QUARTER,
|
|
298
|
+
year: YEAR,
|
|
299
|
+
years: YEAR
|
|
300
|
+
};
|
|
301
|
+
function resolveRelativeTimeUnit(seconds) {
|
|
282
302
|
const absValue = Math.abs(seconds);
|
|
283
|
-
let value, unit;
|
|
284
|
-
|
|
285
|
-
// We have to round the resulting values, as `Intl.RelativeTimeFormat`
|
|
286
|
-
// will include fractions like '2.1 hours ago'.
|
|
287
|
-
|
|
288
303
|
if (absValue < MINUTE) {
|
|
289
|
-
|
|
290
|
-
value = Math.round(seconds);
|
|
304
|
+
return 'second';
|
|
291
305
|
} else if (absValue < HOUR) {
|
|
292
|
-
|
|
293
|
-
value = Math.round(seconds / MINUTE);
|
|
306
|
+
return 'minute';
|
|
294
307
|
} else if (absValue < DAY) {
|
|
295
|
-
|
|
296
|
-
value = Math.round(seconds / HOUR);
|
|
308
|
+
return 'hour';
|
|
297
309
|
} else if (absValue < WEEK) {
|
|
298
|
-
|
|
299
|
-
value = Math.round(seconds / DAY);
|
|
310
|
+
return 'day';
|
|
300
311
|
} else if (absValue < MONTH) {
|
|
301
|
-
|
|
302
|
-
value = Math.round(seconds / WEEK);
|
|
312
|
+
return 'week';
|
|
303
313
|
} else if (absValue < YEAR) {
|
|
304
|
-
|
|
305
|
-
value = Math.round(seconds / MONTH);
|
|
306
|
-
} else {
|
|
307
|
-
unit = 'year';
|
|
308
|
-
value = Math.round(seconds / YEAR);
|
|
314
|
+
return 'month';
|
|
309
315
|
}
|
|
310
|
-
return
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
316
|
+
return 'year';
|
|
317
|
+
}
|
|
318
|
+
function calculateRelativeTimeValue(seconds, unit) {
|
|
319
|
+
// We have to round the resulting values, as `Intl.RelativeTimeFormat`
|
|
320
|
+
// will include fractions like '2.1 hours ago'.
|
|
321
|
+
return Math.round(seconds / UNIT_SECONDS[unit]);
|
|
314
322
|
}
|
|
315
323
|
function createFormatter(_ref) {
|
|
316
324
|
let {
|
|
@@ -318,7 +326,7 @@ function createFormatter(_ref) {
|
|
|
318
326
|
locale,
|
|
319
327
|
now: globalNow,
|
|
320
328
|
onError = initializeConfig.defaultOnError,
|
|
321
|
-
timeZone
|
|
329
|
+
timeZone: globalTimeZone
|
|
322
330
|
} = _ref;
|
|
323
331
|
function resolveFormatOrOptions(typeFormats, formatOrOptions) {
|
|
324
332
|
let options;
|
|
@@ -356,11 +364,15 @@ function createFormatter(_ref) {
|
|
|
356
364
|
formatOrOptions) {
|
|
357
365
|
return getFormattedValue(value, formatOrOptions, formats === null || formats === void 0 ? void 0 : formats.dateTime, options => {
|
|
358
366
|
var _options;
|
|
359
|
-
if (
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
367
|
+
if (!((_options = options) !== null && _options !== void 0 && _options.timeZone)) {
|
|
368
|
+
if (globalTimeZone) {
|
|
369
|
+
options = {
|
|
370
|
+
...options,
|
|
371
|
+
timeZone: globalTimeZone
|
|
372
|
+
};
|
|
373
|
+
} else {
|
|
374
|
+
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" ));
|
|
375
|
+
}
|
|
364
376
|
}
|
|
365
377
|
return new Intl.DateTimeFormat(locale, options).format(value);
|
|
366
378
|
});
|
|
@@ -368,24 +380,32 @@ function createFormatter(_ref) {
|
|
|
368
380
|
function number(value, formatOrOptions) {
|
|
369
381
|
return getFormattedValue(value, formatOrOptions, formats === null || formats === void 0 ? void 0 : formats.number, options => new Intl.NumberFormat(locale, options).format(value));
|
|
370
382
|
}
|
|
383
|
+
function getGlobalNow() {
|
|
384
|
+
if (globalNow) {
|
|
385
|
+
return globalNow;
|
|
386
|
+
} else {
|
|
387
|
+
onError(new initializeConfig.IntlError(initializeConfig.IntlErrorCode.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" ));
|
|
388
|
+
return new Date();
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
function extractNowDate(nowOrOptions) {
|
|
392
|
+
if (nowOrOptions instanceof Date || typeof nowOrOptions === 'number') {
|
|
393
|
+
return new Date(nowOrOptions);
|
|
394
|
+
}
|
|
395
|
+
if ((nowOrOptions === null || nowOrOptions === void 0 ? void 0 : nowOrOptions.now) !== undefined) {
|
|
396
|
+
return new Date(nowOrOptions.now);
|
|
397
|
+
}
|
|
398
|
+
return getGlobalNow();
|
|
399
|
+
}
|
|
371
400
|
function relativeTime( /** The date time that needs to be formatted. */
|
|
372
401
|
date, /** The reference point in time to which `date` will be formatted in relation to. */
|
|
373
|
-
|
|
402
|
+
nowOrOptions) {
|
|
374
403
|
try {
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
now = globalNow;
|
|
378
|
-
} else {
|
|
379
|
-
throw new Error("The `now` parameter wasn't provided and there was no global fallback configured on the provider." );
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
const dateDate = date instanceof Date ? date : new Date(date);
|
|
383
|
-
const nowDate = now instanceof Date ? now : new Date(now);
|
|
404
|
+
const dateDate = new Date(date);
|
|
405
|
+
const nowDate = extractNowDate(nowOrOptions);
|
|
384
406
|
const seconds = (dateDate.getTime() - nowDate.getTime()) / 1000;
|
|
385
|
-
const
|
|
386
|
-
|
|
387
|
-
value
|
|
388
|
-
} = getRelativeTimeFormatConfig(seconds);
|
|
407
|
+
const unit = typeof nowOrOptions === 'number' || nowOrOptions instanceof Date || (nowOrOptions === null || nowOrOptions === void 0 ? void 0 : nowOrOptions.unit) === undefined ? resolveRelativeTimeUnit(seconds) : nowOrOptions.unit;
|
|
408
|
+
const value = calculateRelativeTimeValue(seconds, unit);
|
|
389
409
|
return new Intl.RelativeTimeFormat(locale, {
|
|
390
410
|
numeric: 'auto'
|
|
391
411
|
}).format(value, unit);
|
|
@@ -405,17 +425,6 @@ function createFormatter(_ref) {
|
|
|
405
425
|
};
|
|
406
426
|
}
|
|
407
427
|
|
|
408
|
-
/** @deprecated Switch to `createFormatter` */
|
|
409
|
-
function createIntl() {
|
|
410
|
-
const formatter = createFormatter(...arguments);
|
|
411
|
-
return {
|
|
412
|
-
formatDateTime: formatter.dateTime,
|
|
413
|
-
formatNumber: formatter.number,
|
|
414
|
-
formatRelativeTime: formatter.relativeTime
|
|
415
|
-
};
|
|
416
|
-
}
|
|
417
|
-
|
|
418
428
|
exports.createBaseTranslator = createBaseTranslator;
|
|
419
429
|
exports.createFormatter = createFormatter;
|
|
420
|
-
exports.createIntl = createIntl;
|
|
421
430
|
exports.resolveNamespace = resolveNamespace;
|
|
@@ -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-0a0b87a7.js');
|
|
6
6
|
var core = require('./core.js');
|
|
7
|
-
var
|
|
7
|
+
var createFormatter = require('./createFormatter-bcc5a49f.js');
|
|
8
8
|
var _IntlProvider = require('./_IntlProvider.js');
|
|
9
9
|
var react = require('./react.js');
|
|
10
10
|
var _useLocale = require('./_useLocale-321e619f.js');
|
|
@@ -18,12 +18,10 @@ exports.IntlError = initializeConfig.IntlError;
|
|
|
18
18
|
exports.IntlErrorCode = initializeConfig.IntlErrorCode;
|
|
19
19
|
exports.initializeConfig = initializeConfig.initializeConfig;
|
|
20
20
|
exports.createTranslator = core.createTranslator;
|
|
21
|
-
exports.createBaseTranslator =
|
|
22
|
-
exports.createFormatter =
|
|
23
|
-
exports.createIntl = createIntl.createIntl;
|
|
21
|
+
exports.createBaseTranslator = createFormatter.createBaseTranslator;
|
|
22
|
+
exports.createFormatter = createFormatter.createFormatter;
|
|
24
23
|
exports.IntlProvider = _IntlProvider.IntlProvider;
|
|
25
24
|
exports.useFormatter = react.useFormatter;
|
|
26
|
-
exports.useIntl = react.useIntl;
|
|
27
25
|
exports.useMessages = react.useMessages;
|
|
28
26
|
exports.useNow = react.useNow;
|
|
29
27
|
exports.useTimeZone = react.useTimeZone;
|
|
@@ -32,6 +32,7 @@ function _toPropertyKey(arg) {
|
|
|
32
32
|
let IntlErrorCode = /*#__PURE__*/function (IntlErrorCode) {
|
|
33
33
|
IntlErrorCode["MISSING_MESSAGE"] = "MISSING_MESSAGE";
|
|
34
34
|
IntlErrorCode["MISSING_FORMAT"] = "MISSING_FORMAT";
|
|
35
|
+
IntlErrorCode["ENVIRONMENT_FALLBACK"] = "ENVIRONMENT_FALLBACK";
|
|
35
36
|
IntlErrorCode["INSUFFICIENT_PATH"] = "INSUFFICIENT_PATH";
|
|
36
37
|
IntlErrorCode["INVALID_MESSAGE"] = "INVALID_MESSAGE";
|
|
37
38
|
IntlErrorCode["INVALID_KEY"] = "INVALID_KEY";
|
|
@@ -5,11 +5,13 @@ 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
|
|
9
|
-
require('./initializeConfig-
|
|
8
|
+
var createFormatter = require('./createFormatter-bcc5a49f.js');
|
|
9
|
+
var initializeConfig = require('./initializeConfig-0a0b87a7.js');
|
|
10
10
|
require('./IntlContext-b5cc6be8.js');
|
|
11
11
|
require('intl-messageformat');
|
|
12
12
|
|
|
13
|
+
let hasWarnedForMissingTimezone = false;
|
|
14
|
+
const isServer = typeof window === 'undefined';
|
|
13
15
|
function useTranslationsImpl(allMessages, namespace, namespacePrefix) {
|
|
14
16
|
const {
|
|
15
17
|
defaultTranslationValues,
|
|
@@ -24,8 +26,12 @@ function useTranslationsImpl(allMessages, namespace, namespacePrefix) {
|
|
|
24
26
|
// The `namespacePrefix` is part of the type system.
|
|
25
27
|
// See the comment in the hook invocation.
|
|
26
28
|
allMessages = allMessages[namespacePrefix];
|
|
27
|
-
namespace =
|
|
28
|
-
|
|
29
|
+
namespace = createFormatter.resolveNamespace(namespace, namespacePrefix);
|
|
30
|
+
if (!timeZone && !hasWarnedForMissingTimezone && isServer) {
|
|
31
|
+
hasWarnedForMissingTimezone = true;
|
|
32
|
+
onError(new initializeConfig.IntlError(initializeConfig.IntlErrorCode.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" ));
|
|
33
|
+
}
|
|
34
|
+
const translate = React.useMemo(() => createFormatter.createBaseTranslator({
|
|
29
35
|
messageFormatCache,
|
|
30
36
|
getMessageFallback,
|
|
31
37
|
messages: allMessages,
|
|
@@ -106,7 +112,11 @@ function useTimeZone() {
|
|
|
106
112
|
}
|
|
107
113
|
|
|
108
114
|
function useMessages() {
|
|
109
|
-
|
|
115
|
+
const context = _useLocale.useIntlContext();
|
|
116
|
+
if (!context.messages) {
|
|
117
|
+
throw new Error('No messages found. Have you configured them correctly? See https://next-intl-docs.vercel.app/docs/configuration#messages' );
|
|
118
|
+
}
|
|
119
|
+
return context.messages;
|
|
110
120
|
}
|
|
111
121
|
|
|
112
122
|
function useFormatter() {
|
|
@@ -117,31 +127,7 @@ function useFormatter() {
|
|
|
117
127
|
onError,
|
|
118
128
|
timeZone
|
|
119
129
|
} = _useLocale.useIntlContext();
|
|
120
|
-
return React.useMemo(() =>
|
|
121
|
-
formats,
|
|
122
|
-
locale,
|
|
123
|
-
now: globalNow,
|
|
124
|
-
onError,
|
|
125
|
-
timeZone
|
|
126
|
-
}), [formats, globalNow, locale, onError, timeZone]);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
let hasWarned = false;
|
|
130
|
-
|
|
131
|
-
/** @deprecated Switch to `useFormatter` instead. */
|
|
132
|
-
function useIntl() {
|
|
133
|
-
const {
|
|
134
|
-
formats,
|
|
135
|
-
locale,
|
|
136
|
-
now: globalNow,
|
|
137
|
-
onError,
|
|
138
|
-
timeZone
|
|
139
|
-
} = _useLocale.useIntlContext();
|
|
140
|
-
if (!hasWarned) {
|
|
141
|
-
hasWarned = true;
|
|
142
|
-
console.warn('`useIntl()` is deprecated and will be removed in the next major version. Please switch to `useFormatter()`.');
|
|
143
|
-
}
|
|
144
|
-
return React.useMemo(() => createIntl.createIntl({
|
|
130
|
+
return React.useMemo(() => createFormatter.createFormatter({
|
|
145
131
|
formats,
|
|
146
132
|
locale,
|
|
147
133
|
now: globalNow,
|
|
@@ -153,7 +139,6 @@ function useIntl() {
|
|
|
153
139
|
exports.IntlProvider = _IntlProvider.IntlProvider;
|
|
154
140
|
exports.useLocale = _useLocale.useLocale;
|
|
155
141
|
exports.useFormatter = useFormatter;
|
|
156
|
-
exports.useIntl = useIntl;
|
|
157
142
|
exports.useMessages = useMessages;
|
|
158
143
|
exports.useNow = useNow;
|
|
159
144
|
exports.useTimeZone = useTimeZone;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("./initializeConfig-
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("./initializeConfig-29e7ba4c.js"),r=require("./IntlContext-381f3ce4.js");function i(e){return e&&e.__esModule?e:{default:e}}var n=i(e);exports.IntlProvider=function(i){let{children:a,...o}=i;const[u]=e.useState((()=>new Map));return n.default.createElement(r.IntlContext.Provider,{value:{...t.initializeConfig(o),messageFormatCache:u}},a)};
|
package/dist/esm/core.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./initializeConfig-
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./initializeConfig-29e7ba4c.js"),r=require("./createFormatter-cccbd794.js");require("intl-messageformat"),require("react"),exports.IntlError=e.IntlError,exports.IntlErrorCode=e.IntlErrorCode,exports.initializeConfig=e.initializeConfig,exports.createBaseTranslator=r.createBaseTranslator,exports.createFormatter=r.createFormatter,exports.createTranslator=function(t){let{getMessageFallback:a=e.defaultGetMessageFallback,messages:s,namespace:n,onError:o=e.defaultOnError,...c}=t;return function(t,a){let{getMessageFallback:s,messages:n,namespace:o,onError:c,...i}=t;n=n[a],o=r.resolveNamespace(o,a);const l=r.createBaseTranslator({...i,onError:c,getMessageFallback:s,messages:n,namespace:o}),g=l.rich;function u(){return l(...arguments)}return u.rich=(r,t,a)=>{const n=g(r,t,a);if("string"!=typeof n){const t=new e.IntlError(e.IntlErrorCode.FORMATTING_ERROR,"`createTranslator` only accepts functions for rich text formatting that receive and return strings.\n\nE.g. t.rich('rich', {b: (chunks) => `<b>${chunks}</b>`})");return c(t),s({error:t,key:r,namespace:o})}return n},u.raw=l.raw,u}({...c,onError:o,getMessageFallback:a,messages:{"!":s},namespace:n?"!.".concat(n):"!"},"!")};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("intl-messageformat"),r=require("react"),t=require("./initializeConfig-29e7ba4c.js");function n(e){return e&&e.__esModule?e:{default:e}}var o=n(e);function a(e,r){return e?Object.keys(e).reduce(((t,n)=>(t[n]={timeZone:r,...e[n]},t)),{}):e}function s(e,r,t){if(!e)throw new Error("No messages available at `".concat(t,"`."));let n=e;return r.split(".").forEach((e=>{const o=n[e];if(null==e||null==o)throw new Error("Could not resolve `".concat(r,"` in ").concat(t?"`".concat(t,"`"):"messages","."));n=o})),n}const i=60,c=60*i,u=24*c,l=7*u,m=u*(365/12),d=3*m,f=365*u,g={second:1,seconds:1,minute:i,minutes:i,hour:c,hours:c,day:u,days:u,week:l,weeks:l,month:m,months:m,quarter:d,quarters:d,year:f,years:f};exports.createBaseTranslator=function(e){const n=function(e){let{messages:r,namespace:n,onError:o=t.defaultOnError}=e;try{if(!r)throw new Error("No messages were configured on the provider.");const e=n?s(r,n):r;if(!e)throw new Error("No messages for namespace `".concat(n,"` found."));return e}catch(e){const r=new t.IntlError(t.IntlErrorCode.MISSING_MESSAGE,e.message);return o(r),r}}({messages:e.messages,namespace:e.namespace,onError:e.onError});return function(e){let{defaultTranslationValues:n,formats:i,getMessageFallback:c=t.defaultGetMessageFallback,locale:u,messageFormatCache:l,messagesOrError:m,namespace:d,onError:f,timeZone:g}=e;function E(e,r,n){const o=new t.IntlError(r,n);return f(o),c({error:o,key:e,namespace:d})}function p(e,f,p){if(m instanceof t.IntlError)return c({error:m,key:e,namespace:d});const I=m;let h;try{h=s(I,e,d)}catch(r){return E(e,t.IntlErrorCode.MISSING_MESSAGE,r.message)}function w(e){return e.filter((e=>null!=e)).join(".")}const v=w([u,d,e,String(h)]);let y;if(null!=l&&l.has(v))y=l.get(v);else{if("object"==typeof h){let r,n;return Array.isArray(h)?(r=t.IntlErrorCode.INVALID_MESSAGE,n="Message at `".concat(w([d,e]),"` resolved to an array, but only strings are supported. See https://next-intl-docs.vercel.app/docs/usage/messages#arrays-of-messages")):(r=t.IntlErrorCode.INSUFFICIENT_PATH,n="Message at `".concat(w([d,e]),"` 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")),E(e,r,n)}const r=function(e,r){if(r)return;const t=e.replace(/'([{}])/gi,"$1");return/<|{/.test(t)?void 0:t}(h,f);if(r)return r;try{y=new o.default(h,u,function(e,r){const t=r?{...e,dateTime:a(e.dateTime,r)}:e,n=o.default.formats.date,s=r?a(n,r):n,i=o.default.formats.time,c=r?a(i,r):i;return{...t,date:{...s,...null==t?void 0:t.dateTime},time:{...c,...null==t?void 0:t.dateTime}}}({...i,...p},g))}catch(r){return E(e,t.IntlErrorCode.INVALID_MESSAGE,r.message)}null==l||l.set(v,y)}try{const t=y.format(function(e){if(0===Object.keys(e).length)return;const t={};return Object.keys(e).forEach((n=>{let o=0;const a=e[n];let s;s="function"==typeof a?e=>{const t=a(e);return r.isValidElement(t)?r.cloneElement(t,{key:n+o++}):t}:a,t[n]=s})),t}({...n,...f}));if(null==t)throw new Error("Unable to format `".concat(e,"` in ").concat(d?"namespace `".concat(d,"`"):"messages"));return r.isValidElement(t)||Array.isArray(t)||"string"==typeof t?t:String(t)}catch(r){return E(e,t.IntlErrorCode.FORMATTING_ERROR,r.message)}}function I(e,r,n){const o=p(e,r,n);return"string"!=typeof o?E(e,t.IntlErrorCode.INVALID_MESSAGE,"The message `".concat(e,"` in ").concat(d?"namespace `".concat(d,"`"):"messages"," didn't resolve to a string. If you want to format rich text, use `t.rich` instead.")):o}return I.rich=p,I.raw=e=>{if(m instanceof t.IntlError)return c({error:m,key:e,namespace:d});const r=m;try{return s(r,e,d)}catch(r){return E(e,t.IntlErrorCode.MISSING_MESSAGE,r.message)}},I}({...e,messagesOrError:n})},exports.createFormatter=function(e){let{formats:r,locale:n,now:o,onError:a=t.defaultOnError,timeZone:s}=e;function d(e,r,n,o){let s;try{s=function(e,r){let n;if("string"==typeof r){const o=r;if(n=null==e?void 0:e[o],!n){const e=new t.IntlError(t.IntlErrorCode.MISSING_FORMAT,"Format `".concat(o,"` is not available. You can configure it on the provider or provide custom options."));throw a(e),e}}else n=r;return n}(n,r)}catch(r){return String(e)}try{return o(s)}catch(r){return a(new t.IntlError(t.IntlErrorCode.FORMATTING_ERROR,r.message)),String(e)}}function E(e){return e instanceof Date||"number"==typeof e?new Date(e):void 0!==(null==e?void 0:e.now)?new Date(e.now):o||(a(new t.IntlError(t.IntlErrorCode.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,o){return d(e,o,null==r?void 0:r.dateTime,(r=>{var o;return null!==(o=r)&&void 0!==o&&o.timeZone||(s?r={...r,timeZone:s}:a(new t.IntlError(t.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"))),new Intl.DateTimeFormat(n,r).format(e)}))},number:function(e,t){return d(e,t,null==r?void 0:r.number,(r=>new Intl.NumberFormat(n,r).format(e)))},relativeTime:function(e,r){try{const t=new Date(e),o=E(r),a=(t.getTime()-o.getTime())/1e3,s="number"==typeof r||r instanceof Date||void 0===(null==r?void 0:r.unit)?function(e){const r=Math.abs(e);return r<i?"second":r<c?"minute":r<u?"hour":r<l?"day":r<m?"week":r<f?"month":"year"}(a):r.unit,d=function(e,r){return Math.round(e/g[r])}(a,s);return new Intl.RelativeTimeFormat(n,{numeric:"auto"}).format(d,s)}catch(r){return a(new t.IntlError(t.IntlErrorCode.FORMATTING_ERROR,r.message)),String(e)}},list:function(e,t){return d(e,t,null==r?void 0:r.list,(r=>new Intl.ListFormat(n,r).format(e)))}}},exports.resolveNamespace=function(e,r){return e===r?void 0:e.slice((r+".").length)};
|
package/dist/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./initializeConfig-
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./initializeConfig-29e7ba4c.js"),r=require("./core.js"),t=require("./createFormatter-cccbd794.js"),s=require("./_IntlProvider.js"),o=require("./react.js"),a=require("./_useLocale-89b32eb9.js");require("intl-messageformat"),require("react"),require("./IntlContext-381f3ce4.js"),exports.IntlError=e.IntlError,exports.IntlErrorCode=e.IntlErrorCode,exports.initializeConfig=e.initializeConfig,exports.createTranslator=r.createTranslator,exports.createBaseTranslator=t.createBaseTranslator,exports.createFormatter=t.createFormatter,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;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";function e(e,n,t){return(n=function(e){var n=function(e,n){if("object"!=typeof e||null===e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var r=t.call(e,n||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===n?String:Number)(e)}(e,"string");return"symbol"==typeof n?n:String(n)}(n))in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}let n=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 t extends Error{constructor(n,t){let r=n;t&&(r+=": "+t),super(r),e(this,"code",void 0),e(this,"originalMessage",void 0),this.code=n,t&&(this.originalMessage=t)}}function r(e){return[e.namespace,e.key].filter((e=>null!=e)).join(".")}function o(e){console.error(e)}function i(e,n,t){Object.entries(e).forEach((e=>{let[r,o]=e;if(r.includes(".")){let e=r;t&&(e+=" (at ".concat(t,")")),n.push(e)}null!=o&&"object"==typeof o&&i(o,n,[t,r].filter((e=>null!=e)).join("."))}))}function s(e,r){const o=[];i(e,o),o.length>0&&r(new t(n.INVALID_KEY,'Namespace keys can not contain the character "." as this is used to express nesting. Please remove it or replace it with another character.\n\nInvalid '.concat(1===o.length?"key":"keys",": ").concat(o.join(", "),'\n\nIf you\'re migrating from a flat structure, you can convert your messages as follows:\n\nimport {set} from "lodash";\n\nconst input = {\n "one.one": "1.1",\n "one.two": "1.2",\n "two.one.one": "2.1.1"\n};\n\nconst output = Object.entries(input).reduce(\n (acc, [key, value]) => set(acc, key, value),\n {}\n);\n\n// Output:\n//\n// {\n// "one": {\n// "one": "1.1",\n// "two": "1.2"\n// },\n// "two": {\n// "one": {\n// "one": "2.1.1"\n// }\n// }\n// }\n')))}exports.IntlError=t,exports.IntlErrorCode=n,exports.defaultGetMessageFallback=r,exports.defaultOnError=o,exports.initializeConfig=function(e){let{getMessageFallback:n,messages:t,onError:i,...a}=e;const c=i||o,l=n||r;return t&&s(t,c),{...a,messages:t,onError:c,getMessageFallback:l}};
|
package/dist/esm/react.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./_IntlProvider.js"),t=require("./_useLocale-89b32eb9.js"),r=require("react"),o=require("./
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./_IntlProvider.js"),t=require("./_useLocale-89b32eb9.js"),r=require("react"),o=require("./createFormatter-cccbd794.js"),n=require("./initializeConfig-29e7ba4c.js");require("./IntlContext-381f3ce4.js"),require("intl-messageformat");let s=!1;const a="undefined"==typeof window;function u(){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("No messages found. Have you configured them correctly? See https://next-intl-docs.vercel.app/docs/configuration#messages");return e.messages},exports.useNow=function(e){const o=null==e?void 0:e.updateInterval,{now:n}=t.useIntlContext(),[s,a]=r.useState(n||u());return r.useEffect((()=>{if(!o)return;const e=setInterval((()=>{a(u())}),o);return()=>{clearInterval(e)}}),[n,o]),s},exports.useTimeZone=function(){return t.useIntlContext().timeZone},exports.useTranslations=function(e){return function(e,u,i){const{defaultTranslationValues:l,formats:c,getMessageFallback:m,locale:f,messageFormatCache:d,onError:g,timeZone:p}=t.useIntlContext();return e=e[i],u=o.resolveNamespace(u,i),p||s||!a||(s=!0,g(new n.IntlError(n.IntlErrorCode.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"))),r.useMemo((()=>o.createBaseTranslator({messageFormatCache:d,getMessageFallback:m,messages:e,defaultTranslationValues:l,namespace:u,onError:g,formats:c,locale:f,timeZone:p})),[d,m,e,u,g,l,c,f,p])}({"!":t.useIntlContext().messages},e?"!.".concat(e):"!","!")};
|
package/dist/production/core.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./createFormatter-8c0b8eb2.js"),r=require("./initializeConfig-984a566d.js");require("intl-messageformat"),require("react"),exports.IntlError=e.IntlError,exports.IntlErrorCode=e.IntlErrorCode,exports.createBaseTranslator=e.createBaseTranslator,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,...c}=a;return function(r,a){let{getMessageFallback:t,messages:s,namespace:o,onError:n,...c}=r;s=s[a],o=e.resolveNamespace(o,a);const l=e.createBaseTranslator({...c,onError:n,getMessageFallback:t,messages:s,namespace:o}),i=l.rich;function g(){return l(...arguments)}return g.rich=(r,a,s)=>{const c=i(r,a,s);if("string"!=typeof c){const a=new e.IntlError(e.IntlErrorCode.FORMATTING_ERROR,void 0);return n(a),t({error:a,key:r,namespace:o})}return c},g.raw=l.raw,g}({...c,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-984a566d.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 c(e,t,r){if(!e)throw new Error(void 0);let n=e;return t.split(".").forEach((e=>{const t=n[e];if(null==e||null==t)throw new Error(void 0);n=t})),n}const l=60,f=60*l,m=24*f,E=7*m,d=m*(365/12),I=3*d,S=365*m,g={second:1,seconds:1,minute:l,minutes:l,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){let{messages:t,namespace:n,onError:o=r.defaultOnError}=e;try{if(!t)throw new Error(void 0);const e=n?c(t,n):t;if(!e)throw new Error(void 0);return e}catch(e){const t=new s(a.MISSING_MESSAGE,e.message);return o(t),t}}({messages:e.messages,namespace:e.namespace,onError:e.onError});return function(e){let{defaultTranslationValues:n,formats:i,getMessageFallback:l=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),l({error:n,key:e,namespace:d})}function N(e,r,I){if(E instanceof s)return l({error:E,key:e,namespace:d});const N=E;let A;try{A=c(N,e)}catch(t){return g(e,a.MISSING_MESSAGE,t.message)}function v(e){return e.filter((e=>null!=e)).join(".")}const y=v([f,d,e,String(A)]);let w;if(null!=m&&m.has(y))w=m.get(y);else{if("object"==typeof A){let t,r;return t=Array.isArray(A)?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}(A,r);if(t)return t;try{w=new o.default(A,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,...I},S))}catch(t){return g(e,a.INVALID_MESSAGE,t.message)}null==m||m.set(y,w)}try{const e=w.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,...r}));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 A(e,t,r){const n=N(e,t,r);return"string"!=typeof n?g(e,a.INVALID_MESSAGE,void 0):n}return A.rich=N,A.raw=e=>{if(E instanceof s)return l({error:E,key:e,namespace:d});const t=E;try{return c(t,e)}catch(t){return g(e,a.MISSING_MESSAGE,t.message)}},A}({...e,messagesOrError:n})},exports.createFormatter=function(e){let{formats:t,locale:n,now:o,onError:i=r.defaultOnError,timeZone:u}=e;function c(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}(r,t)}catch(t){return String(e)}try{return n(o)}catch(t){return i(new s(a.FORMATTING_ERROR,t.message)),String(e)}}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 c(e,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)}))},number:function(e,r){return c(e,r,null==t?void 0:t.number,(t=>new Intl.NumberFormat(n,t).format(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<l?"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:"auto"}).format(s,a)}catch(t){return i(new s(a.FORMATTING_ERROR,t.message)),String(e)}},list:function(e,r){return c(e,r,null==t?void 0:t.list,(t=>new Intl.ListFormat(n,t).format(e)))}}},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("./
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./createFormatter-8c0b8eb2.js"),r=require("./core.js"),t=require("./initializeConfig-984a566d.js"),s=require("./_IntlProvider.js"),o=require("./react.js"),a=require("./_useLocale-8e23751a.js");require("intl-messageformat"),require("react"),require("./IntlContext-381f3ce4.js"),exports.IntlError=e.IntlError,exports.IntlErrorCode=e.IntlErrorCode,exports.createBaseTranslator=e.createBaseTranslator,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=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-8e23751a.js"),r=require("react"),o=require("./
|
|
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-8c0b8eb2.js");require("./initializeConfig-984a566d.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):"!","!")};
|
|
@@ -29,7 +29,7 @@ type IntlConfig<Messages = AbstractIntlMessages> = {
|
|
|
29
29
|
/**
|
|
30
30
|
* Providing this value will have two effects:
|
|
31
31
|
* 1. It will be used as the default for the `now` argument of
|
|
32
|
-
* `
|
|
32
|
+
* `useFormatter().formatRelativeTime` if no explicit value is provided.
|
|
33
33
|
* 2. It will be returned as a static value from the `useNow` hook. Note
|
|
34
34
|
* however that when `updateInterval` is configured on the `useNow` hook,
|
|
35
35
|
* the global `now` value will only be used for the initial render, but
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export declare enum IntlErrorCode {
|
|
2
2
|
MISSING_MESSAGE = "MISSING_MESSAGE",
|
|
3
3
|
MISSING_FORMAT = "MISSING_FORMAT",
|
|
4
|
+
ENVIRONMENT_FALLBACK = "ENVIRONMENT_FALLBACK",
|
|
4
5
|
INSUFFICIENT_PATH = "INSUFFICIENT_PATH",
|
|
5
6
|
INVALID_MESSAGE = "INVALID_MESSAGE",
|
|
6
7
|
INVALID_KEY = "INVALID_KEY",
|
|
@@ -2,6 +2,7 @@ import DateTimeFormatOptions from './DateTimeFormatOptions';
|
|
|
2
2
|
import Formats from './Formats';
|
|
3
3
|
import IntlError from './IntlError';
|
|
4
4
|
import NumberFormatOptions from './NumberFormatOptions';
|
|
5
|
+
import RelativeTimeFormatOptions from './RelativeTimeFormatOptions';
|
|
5
6
|
import TimeZone from './TimeZone';
|
|
6
7
|
type Props = {
|
|
7
8
|
locale: string;
|
|
@@ -10,10 +11,10 @@ type Props = {
|
|
|
10
11
|
formats?: Partial<Formats>;
|
|
11
12
|
now?: Date;
|
|
12
13
|
};
|
|
13
|
-
export default function createFormatter({ formats, locale, now: globalNow, onError, timeZone }: Props): {
|
|
14
|
+
export default function createFormatter({ formats, locale, now: globalNow, onError, timeZone: globalTimeZone }: Props): {
|
|
14
15
|
dateTime: (value: Date | number, formatOrOptions?: string | DateTimeFormatOptions) => string;
|
|
15
16
|
number: (value: number | bigint, formatOrOptions?: string | NumberFormatOptions) => string;
|
|
16
|
-
relativeTime: (date: number | Date,
|
|
17
|
+
relativeTime: (date: number | Date, nowOrOptions?: RelativeTimeFormatOptions['now'] | RelativeTimeFormatOptions) => string;
|
|
17
18
|
list: (value: Iterable<string>, formatOrOptions?: string | Intl.ListFormatOptions) => string;
|
|
18
19
|
};
|
|
19
20
|
export {};
|
|
@@ -13,4 +13,3 @@ export type { default as MessageKeys } from './utils/MessageKeys';
|
|
|
13
13
|
export type { default as NamespaceKeys } from './utils/NamespaceKeys';
|
|
14
14
|
export type { default as NestedKeyOf } from './utils/NestedKeyOf';
|
|
15
15
|
export type { default as NestedValueOf } from './utils/NestedValueOf';
|
|
16
|
-
export { default as createIntl } from './createIntl';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export default function useFormatter(): {
|
|
2
2
|
dateTime: (value: number | Date, formatOrOptions?: string | import("../core/DateTimeFormatOptions").default | undefined) => string;
|
|
3
3
|
number: (value: number | bigint, formatOrOptions?: string | import("@formatjs/ecma402-abstract/types/number").NumberFormatOptions | undefined) => string;
|
|
4
|
-
relativeTime: (date: number | Date,
|
|
4
|
+
relativeTime: (date: number | Date, nowOrOptions?: number | Date | import("../core/RelativeTimeFormatOptions").default | undefined) => string;
|
|
5
5
|
list: (value: Iterable<string>, formatOrOptions?: string | Intl.ListFormatOptions | undefined) => string;
|
|
6
6
|
};
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { AbstractIntlMessages } from '../core';
|
|
2
|
+
export default function useMessages(): AbstractIntlMessages;
|
|
@@ -3,6 +3,6 @@ import AbstractIntlMessages from '../core/AbstractIntlMessages';
|
|
|
3
3
|
import NestedKeyOf from '../core/utils/NestedKeyOf';
|
|
4
4
|
export default function useTranslationsImpl<Messages extends AbstractIntlMessages, NestedKey extends NestedKeyOf<Messages>>(allMessages: Messages, namespace: NestedKey, namespacePrefix: string): {
|
|
5
5
|
<TargetKey extends unknown>(key: TargetKey, values?: import("../core/TranslationValues").default | undefined, formats?: Partial<import("../core/Formats").default> | undefined): string;
|
|
6
|
-
rich: (key: string, values?: import("
|
|
6
|
+
rich: (key: string, values?: import("../core").RichTranslationValues | undefined, formats?: Partial<import("../core/Formats").default> | undefined) => string | import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | import("react").ReactNodeArray;
|
|
7
7
|
raw(key: string): any;
|
|
8
8
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "use-intl",
|
|
3
|
-
"version": "3.0.0-
|
|
3
|
+
"version": "3.0.0-rc.5",
|
|
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.",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"@types/react": "^18.2.5",
|
|
68
68
|
"date-fns": "^2.16.1",
|
|
69
69
|
"eslint": "^8.46.0",
|
|
70
|
-
"eslint-config-molindo": "7.0.0
|
|
70
|
+
"eslint-config-molindo": "^7.0.0",
|
|
71
71
|
"react": "^18.2.0",
|
|
72
72
|
"react-dom": "^18.2.0",
|
|
73
73
|
"rollup": "^3.28.1",
|
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
"size-limit": [
|
|
79
79
|
{
|
|
80
80
|
"path": "dist/production/index.js",
|
|
81
|
-
"limit": "12.
|
|
81
|
+
"limit": "12.3 kB"
|
|
82
82
|
}
|
|
83
83
|
],
|
|
84
84
|
"scripts": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var e=require("intl-messageformat"),r=require("react"),t=require("./initializeConfig-c316f266.js");function n(e){return e&&e.__esModule?e:{default:e}}var o=n(e);function a(e,r){return e?Object.keys(e).reduce(((t,n)=>(t[n]={timeZone:r,...e[n]},t)),{}):e}function s(e,r,t){if(!e)throw new Error("No messages available at `".concat(t,"`."));let n=e;return r.split(".").forEach((e=>{const o=n[e];if(null==e||null==o)throw new Error("Could not resolve `".concat(r,"` in ").concat(t?"`".concat(t,"`"):"messages","."));n=o})),n}const c=60,i=60*c,u=24*i,l=7*u,m=u*(365/12),f=365*u;function d(e){let{formats:r,locale:n,now:o,onError:a=t.defaultOnError,timeZone:s}=e;function d(e,r,n,o){let s;try{s=function(e,r){let n;if("string"==typeof r){const o=r;if(n=null==e?void 0:e[o],!n){const e=new t.IntlError(t.IntlErrorCode.MISSING_FORMAT,"Format `".concat(o,"` is not available. You can configure it on the provider or provide custom options."));throw a(e),e}}else n=r;return n}(n,r)}catch(r){return String(e)}try{return o(s)}catch(r){return a(new t.IntlError(t.IntlErrorCode.FORMATTING_ERROR,r.message)),String(e)}}return{dateTime:function(e,t){return d(e,t,null==r?void 0:r.dateTime,(r=>{var t;return!s||null!==(t=r)&&void 0!==t&&t.timeZone||(r={...r,timeZone:s}),new Intl.DateTimeFormat(n,r).format(e)}))},number:function(e,t){return d(e,t,null==r?void 0:r.number,(r=>new Intl.NumberFormat(n,r).format(e)))},relativeTime:function(e,r){try{if(!r){if(!o)throw new Error("The `now` parameter wasn't provided and there was no global fallback configured on the provider.");r=o}const t=e instanceof Date?e:new Date(e),a=r instanceof Date?r:new Date(r),s=(t.getTime()-a.getTime())/1e3,{unit:d,value:g}=function(e){const r=Math.abs(e);let t,n;return r<c?(n="second",t=Math.round(e)):r<i?(n="minute",t=Math.round(e/c)):r<u?(n="hour",t=Math.round(e/i)):r<l?(n="day",t=Math.round(e/u)):r<m?(n="week",t=Math.round(e/l)):r<f?(n="month",t=Math.round(e/m)):(n="year",t=Math.round(e/f)),{value:t,unit:n}}(s);return new Intl.RelativeTimeFormat(n,{numeric:"auto"}).format(g,d)}catch(r){return a(new t.IntlError(t.IntlErrorCode.FORMATTING_ERROR,r.message)),String(e)}},list:function(e,t){return d(e,t,null==r?void 0:r.list,(r=>new Intl.ListFormat(n,r).format(e)))}}}exports.createBaseTranslator=function(e){const n=function(e){let{messages:r,namespace:n,onError:o=t.defaultOnError}=e;try{if(!r)throw new Error("No messages were configured on the provider.");const e=n?s(r,n):r;if(!e)throw new Error("No messages for namespace `".concat(n,"` found."));return e}catch(e){const r=new t.IntlError(t.IntlErrorCode.MISSING_MESSAGE,e.message);return o(r),r}}({messages:e.messages,namespace:e.namespace,onError:e.onError});return function(e){let{defaultTranslationValues:n,formats:c,getMessageFallback:i=t.defaultGetMessageFallback,locale:u,messageFormatCache:l,messagesOrError:m,namespace:f,onError:d,timeZone:g}=e;function E(e,r,n){const o=new t.IntlError(r,n);return d(o),i({error:o,key:e,namespace:f})}function I(e,d,I){if(m instanceof t.IntlError)return i({error:m,key:e,namespace:f});const h=m;let p;try{p=s(h,e,f)}catch(r){return E(e,t.IntlErrorCode.MISSING_MESSAGE,r.message)}function v(e){return e.filter((e=>null!=e)).join(".")}const w=v([u,f,e,String(p)]);let y;if(null!=l&&l.has(w))y=l.get(w);else{if("object"==typeof p){let r,n;return Array.isArray(p)?(r=t.IntlErrorCode.INVALID_MESSAGE,n="Message at `".concat(v([f,e]),"` resolved to an array, but only strings are supported. See https://next-intl-docs.vercel.app/docs/usage/messages#arrays-of-messages")):(r=t.IntlErrorCode.INSUFFICIENT_PATH,n="Message at `".concat(v([f,e]),"` 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")),E(e,r,n)}const r=function(e,r){if(r)return;const t=e.replace(/'([{}])/gi,"$1");return/<|{/.test(t)?void 0:t}(p,d);if(r)return r;try{y=new o.default(p,u,function(e,r){const t=r?{...e,dateTime:a(e.dateTime,r)}:e,n=o.default.formats.date,s=r?a(n,r):n,c=o.default.formats.time,i=r?a(c,r):c;return{...t,date:{...s,...null==t?void 0:t.dateTime},time:{...i,...null==t?void 0:t.dateTime}}}({...c,...I},g))}catch(r){return E(e,t.IntlErrorCode.INVALID_MESSAGE,r.message)}null==l||l.set(w,y)}try{const t=y.format(function(e){if(0===Object.keys(e).length)return;const t={};return Object.keys(e).forEach((n=>{let o=0;const a=e[n];let s;s="function"==typeof a?e=>{const t=a(e);return r.isValidElement(t)?r.cloneElement(t,{key:n+o++}):t}:a,t[n]=s})),t}({...n,...d}));if(null==t)throw new Error("Unable to format `".concat(e,"` in ").concat(f?"namespace `".concat(f,"`"):"messages"));return r.isValidElement(t)||Array.isArray(t)||"string"==typeof t?t:String(t)}catch(r){return E(e,t.IntlErrorCode.FORMATTING_ERROR,r.message)}}function h(e,r,n){const o=I(e,r,n);return"string"!=typeof o?E(e,t.IntlErrorCode.INVALID_MESSAGE,"The message `".concat(e,"` in ").concat(f?"namespace `".concat(f,"`"):"messages"," didn't resolve to a string. If you want to format rich text, use `t.rich` instead.")):o}return h.rich=I,h.raw=e=>{if(m instanceof t.IntlError)return i({error:m,key:e,namespace:f});const r=m;try{return s(r,e,f)}catch(r){return E(e,t.IntlErrorCode.MISSING_MESSAGE,r.message)}},h}({...e,messagesOrError:n})},exports.createFormatter=d,exports.createIntl=function(){const e=d(...arguments);return{formatDateTime:e.dateTime,formatNumber:e.number,formatRelativeTime:e.relativeTime}},exports.resolveNamespace=function(e,r){return e===r?void 0:e.slice((r+".").length)};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";function e(e,n,t){return(n=function(e){var n=function(e,n){if("object"!=typeof e||null===e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var r=t.call(e,n||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===n?String:Number)(e)}(e,"string");return"symbol"==typeof n?n:String(n)}(n))in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}let n=function(e){return e.MISSING_MESSAGE="MISSING_MESSAGE",e.MISSING_FORMAT="MISSING_FORMAT",e.INSUFFICIENT_PATH="INSUFFICIENT_PATH",e.INVALID_MESSAGE="INVALID_MESSAGE",e.INVALID_KEY="INVALID_KEY",e.FORMATTING_ERROR="FORMATTING_ERROR",e}({});class t extends Error{constructor(n,t){let r=n;t&&(r+=": "+t),super(r),e(this,"code",void 0),e(this,"originalMessage",void 0),this.code=n,t&&(this.originalMessage=t)}}function r(e){return[e.namespace,e.key].filter((e=>null!=e)).join(".")}function o(e){console.error(e)}function i(e,n,t){Object.entries(e).forEach((e=>{let[r,o]=e;if(r.includes(".")){let e=r;t&&(e+=" (at ".concat(t,")")),n.push(e)}null!=o&&"object"==typeof o&&i(o,n,[t,r].filter((e=>null!=e)).join("."))}))}function s(e,r){const o=[];i(e,o),o.length>0&&r(new t(n.INVALID_KEY,'Namespace keys can not contain the character "." as this is used to express nesting. Please remove it or replace it with another character.\n\nInvalid '.concat(1===o.length?"key":"keys",": ").concat(o.join(", "),'\n\nIf you\'re migrating from a flat structure, you can convert your messages as follows:\n\nimport {set} from "lodash";\n\nconst input = {\n "one.one": "1.1",\n "one.two": "1.2",\n "two.one.one": "2.1.1"\n};\n\nconst output = Object.entries(input).reduce(\n (acc, [key, value]) => set(acc, key, value),\n {}\n);\n\n// Output:\n//\n// {\n// "one": {\n// "one": "1.1",\n// "two": "1.2"\n// },\n// "two": {\n// "one": {\n// "one": "2.1.1"\n// }\n// }\n// }\n')))}exports.IntlError=t,exports.IntlErrorCode=n,exports.defaultGetMessageFallback=r,exports.defaultOnError=o,exports.initializeConfig=function(e){let{getMessageFallback:n,messages:t,onError:i,...a}=e;const c=i||o,l=n||r;return t&&s(t,c),{...a,messages:t,onError:c,getMessageFallback:l}};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var e=require("intl-messageformat"),t=require("react"),r=require("./initializeConfig-984a566d.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.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 c(e,t,r){if(!e)throw new Error(void 0);let n=e;return t.split(".").forEach((e=>{const t=n[e];if(null==e||null==t)throw new Error(void 0);n=t})),n}const l=60,f=60*l,m=24*f,d=7*m,E=m*(365/12),I=365*m;function S(e){let{formats:t,locale:n,now:o,onError:i=r.defaultOnError,timeZone:s}=e;function c(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}(r,t)}catch(t){return String(e)}try{return n(o)}catch(t){return i(new u(a.FORMATTING_ERROR,t.message)),String(e)}}return{dateTime:function(e,r){return c(e,r,null==t?void 0:t.dateTime,(t=>{var r;return!s||null!==(r=t)&&void 0!==r&&r.timeZone||(t={...t,timeZone:s}),new Intl.DateTimeFormat(n,t).format(e)}))},number:function(e,r){return c(e,r,null==t?void 0:t.number,(t=>new Intl.NumberFormat(n,t).format(e)))},relativeTime:function(e,t){try{if(!t){if(!o)throw new Error(void 0);t=o}const r=e instanceof Date?e:new Date(e),i=t instanceof Date?t:new Date(t),a=(r.getTime()-i.getTime())/1e3,{unit:u,value:s}=function(e){const t=Math.abs(e);let r,n;return t<l?(n="second",r=Math.round(e)):t<f?(n="minute",r=Math.round(e/l)):t<m?(n="hour",r=Math.round(e/f)):t<d?(n="day",r=Math.round(e/m)):t<E?(n="week",r=Math.round(e/d)):t<I?(n="month",r=Math.round(e/E)):(n="year",r=Math.round(e/I)),{value:r,unit:n}}(a);return new Intl.RelativeTimeFormat(n,{numeric:"auto"}).format(s,u)}catch(t){return i(new u(a.FORMATTING_ERROR,t.message)),String(e)}},list:function(e,r){return c(e,r,null==t?void 0:t.list,(t=>new Intl.ListFormat(n,t).format(e)))}}}exports.IntlError=u,exports.IntlErrorCode=a,exports.createBaseTranslator=function(e){const n=function(e){let{messages:t,namespace:n,onError:o=r.defaultOnError}=e;try{if(!t)throw new Error(void 0);const e=n?c(t,n):t;if(!e)throw new Error(void 0);return e}catch(e){const t=new u(a.MISSING_MESSAGE,e.message);return o(t),t}}({messages:e.messages,namespace:e.namespace,onError:e.onError});return function(e){let{defaultTranslationValues:n,formats:i,getMessageFallback:l=r.defaultGetMessageFallback,locale:f,messageFormatCache:m,messagesOrError:d,namespace:E,onError:I,timeZone:S}=e;function g(e,t,r){const n=new u(t,r);return I(n),l({error:n,key:e,namespace:E})}function M(e,r,I){if(d instanceof u)return l({error:d,key:e,namespace:E});const M=d;let v;try{v=c(M,e)}catch(t){return g(e,a.MISSING_MESSAGE,t.message)}function h(e){return e.filter((e=>null!=e)).join(".")}const T=h([f,E,e,String(v)]);let y;if(null!=m&&m.has(T))y=m.get(T);else{if("object"==typeof v){let t,r;return t=Array.isArray(v)?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}(v,r);if(t)return t;try{y=new o.default(v,f,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,...I},S))}catch(t){return g(e,a.INVALID_MESSAGE,t.message)}null==m||m.set(T,y)}try{const e=y.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,...r}));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 v(e,t,r){const n=M(e,t,r);return"string"!=typeof n?g(e,a.INVALID_MESSAGE,void 0):n}return v.rich=M,v.raw=e=>{if(d instanceof u)return l({error:d,key:e,namespace:E});const t=d;try{return c(t,e)}catch(t){return g(e,a.MISSING_MESSAGE,t.message)}},v}({...e,messagesOrError:n})},exports.createFormatter=S,exports.createIntl=function(){const e=S(...arguments);return{formatDateTime:e.dateTime,formatNumber:e.number,formatRelativeTime:e.relativeTime}},exports.resolveNamespace=function(e,t){return e===t?void 0:e.slice((t+".").length)};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import createFormatter from './createFormatter';
|
|
2
|
-
/** @deprecated Switch to `createFormatter` */
|
|
3
|
-
export default function createIntl(...args: Parameters<typeof createFormatter>): {
|
|
4
|
-
formatDateTime: (value: number | Date, formatOrOptions?: string | import("./DateTimeFormatOptions").default | undefined) => string;
|
|
5
|
-
formatNumber: (value: number | bigint, formatOrOptions?: string | import("@formatjs/ecma402-abstract/types/number").NumberFormatOptions | undefined) => string;
|
|
6
|
-
formatRelativeTime: (date: number | Date, now?: number | Date | undefined) => string;
|
|
7
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from '../core/initializeConfig';
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
/** @deprecated Switch to `useFormatter` instead. */
|
|
2
|
-
export default function useIntl(): {
|
|
3
|
-
formatDateTime: (value: number | Date, formatOrOptions?: string | import("../core/DateTimeFormatOptions").default | undefined) => string;
|
|
4
|
-
formatNumber: (value: number | bigint, formatOrOptions?: string | import("@formatjs/ecma402-abstract/types/number").NumberFormatOptions | undefined) => string;
|
|
5
|
-
formatRelativeTime: (date: number | Date, now?: number | Date | undefined) => string;
|
|
6
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|