use-intl 3.17.4 → 3.17.6
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 +8 -6
- package/dist/development/core.js +7 -4
- package/dist/development/{createFormatter-D6te1ReQ.js → createFormatter-BRxeaiQU.js} +22 -4
- package/dist/development/index.js +4 -3
- package/dist/development/{initializeConfig-DOn-8mVr.js → initializeConfig-o7L_y07P.js} +7 -20
- package/dist/development/react.js +9 -6
- package/dist/esm/_IntlProvider.js +1 -1
- package/dist/esm/core.js +1 -1
- package/dist/esm/createFormatter-s2RNdTF5.js +1 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/initializeConfig-D2A8plWf.js +1 -0
- package/dist/esm/react.js +1 -1
- package/dist/production/_IntlProvider.js +1 -1
- package/dist/production/core.js +1 -1
- package/dist/production/createFormatter-BUmzSWag.js +1 -0
- package/dist/production/index.js +1 -1
- package/dist/production/initializeConfig-AbYTngyP.js +1 -0
- package/dist/production/react.js +1 -1
- package/dist/types/src/core/IntlConfig.d.ts +3 -3
- package/dist/types/src/core/NumberFormatOptions.d.ts +1 -1
- package/dist/types/src/core/createBaseTranslator.d.ts +2 -1
- package/dist/types/src/core/createFormatter.d.ts +4 -2
- package/dist/types/src/core/createTranslator.d.ts +4 -2
- package/dist/types/src/core/createTranslatorImpl.d.ts +2 -1
- package/dist/types/src/core/formatters.d.ts +10 -5
- package/dist/types/src/core/index.d.ts +2 -1
- package/dist/types/src/react/IntlContext.d.ts +2 -1
- package/dist/types/src/react/useTranslationsImpl.d.ts +1 -1
- package/package.json +2 -8
- package/dist/esm/createFormatter-C4S7xHL_.js +0 -1
- package/dist/esm/initializeConfig-BB2Ue6Z9.js +0 -1
- package/dist/production/createFormatter-DdXLo8F4.js +0 -1
- package/dist/production/initializeConfig-BLiF0aUh.js +0 -1
|
@@ -3,10 +3,9 @@
|
|
|
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-o7L_y07P.js');
|
|
7
7
|
var IntlContext = require('./IntlContext-BKfsnzBx.js');
|
|
8
8
|
require('@formatjs/fast-memoize');
|
|
9
|
-
require('intl-messageformat');
|
|
10
9
|
|
|
11
10
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
11
|
|
|
@@ -27,8 +26,10 @@ function IntlProvider(_ref) {
|
|
|
27
26
|
// The formatter cache is released when the locale changes. For
|
|
28
27
|
// long-running apps with a persistent `IntlProvider` at the root,
|
|
29
28
|
// this can reduce the memory footprint (e.g. in React Native).
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
const cache = React.useMemo(() => {
|
|
30
|
+
return initializeConfig.createCache();
|
|
31
|
+
}, [locale]);
|
|
32
|
+
const formatters = React.useMemo(() => initializeConfig.createIntlFormatters(cache), [cache]);
|
|
32
33
|
|
|
33
34
|
// Memoizing this value helps to avoid triggering a re-render of all
|
|
34
35
|
// context consumers in case the configuration didn't change. However,
|
|
@@ -49,8 +50,9 @@ function IntlProvider(_ref) {
|
|
|
49
50
|
onError,
|
|
50
51
|
timeZone
|
|
51
52
|
}),
|
|
52
|
-
formatters
|
|
53
|
-
|
|
53
|
+
formatters,
|
|
54
|
+
cache
|
|
55
|
+
}), [cache, defaultTranslationValues, formats, formatters, getMessageFallback, locale, messages, now, onError, timeZone]);
|
|
54
56
|
return /*#__PURE__*/React__default.default.createElement(IntlContext.IntlContext.Provider, {
|
|
55
57
|
value: value
|
|
56
58
|
}, children);
|
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-o7L_y07P.js');
|
|
6
|
+
var createFormatter = require('./createFormatter-BRxeaiQU.js');
|
|
7
7
|
require('@formatjs/fast-memoize');
|
|
8
8
|
require('intl-messageformat');
|
|
9
9
|
require('react');
|
|
@@ -35,7 +35,8 @@ function createTranslatorImpl(_ref, namespacePrefix) {
|
|
|
35
35
|
*/
|
|
36
36
|
function createTranslator(_ref) {
|
|
37
37
|
let {
|
|
38
|
-
|
|
38
|
+
_cache = initializeConfig.createCache(),
|
|
39
|
+
_formatters = initializeConfig.createIntlFormatters(_cache),
|
|
39
40
|
getMessageFallback = initializeConfig.defaultGetMessageFallback,
|
|
40
41
|
messages,
|
|
41
42
|
namespace,
|
|
@@ -48,6 +49,7 @@ function createTranslator(_ref) {
|
|
|
48
49
|
return createTranslatorImpl({
|
|
49
50
|
...rest,
|
|
50
51
|
onError,
|
|
52
|
+
cache: _cache,
|
|
51
53
|
formatters: _formatters,
|
|
52
54
|
getMessageFallback,
|
|
53
55
|
// @ts-expect-error `messages` is allowed to be `undefined` here and will be handled internally
|
|
@@ -60,7 +62,8 @@ function createTranslator(_ref) {
|
|
|
60
62
|
|
|
61
63
|
exports.IntlError = initializeConfig.IntlError;
|
|
62
64
|
exports.IntlErrorCode = initializeConfig.IntlErrorCode;
|
|
63
|
-
exports.
|
|
65
|
+
exports._createCache = initializeConfig.createCache;
|
|
66
|
+
exports._createIntlFormatters = initializeConfig.createIntlFormatters;
|
|
64
67
|
exports.initializeConfig = initializeConfig.initializeConfig;
|
|
65
68
|
exports.createFormatter = createFormatter.createFormatter;
|
|
66
69
|
exports.createTranslator = createTranslator;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var React = require('react');
|
|
4
|
-
var initializeConfig = require('./initializeConfig-DOn-8mVr.js');
|
|
5
3
|
var IntlMessageFormat = require('intl-messageformat');
|
|
4
|
+
var React = require('react');
|
|
5
|
+
var initializeConfig = require('./initializeConfig-o7L_y07P.js');
|
|
6
6
|
|
|
7
7
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
8
8
|
|
|
@@ -53,7 +53,17 @@ function convertFormatsToIntlMessageFormat(formats, timeZone) {
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
// eslint-disable-next-line import/no-named-as-default -- False positive
|
|
56
|
-
|
|
56
|
+
// Placed here for improved tree shaking. Somehow when this is placed in
|
|
57
|
+
// `formatters.tsx`, then it can't be shaken off from `next-intl`.
|
|
58
|
+
function createMessageFormatter(cache, intlFormatters) {
|
|
59
|
+
const getMessageFormat = initializeConfig.memoFn(function () {
|
|
60
|
+
return new IntlMessageFormat__default.default(arguments.length <= 0 ? undefined : arguments[0], arguments.length <= 1 ? undefined : arguments[1], arguments.length <= 2 ? undefined : arguments[2], {
|
|
61
|
+
formatters: intlFormatters,
|
|
62
|
+
...(arguments.length <= 3 ? undefined : arguments[3])
|
|
63
|
+
});
|
|
64
|
+
}, cache.message);
|
|
65
|
+
return getMessageFormat;
|
|
66
|
+
}
|
|
57
67
|
function resolvePath(locale, messages, key, namespace) {
|
|
58
68
|
const fullKey = initializeConfig.joinPath(namespace, key);
|
|
59
69
|
if (!messages) {
|
|
@@ -131,6 +141,7 @@ function createBaseTranslator(config) {
|
|
|
131
141
|
}
|
|
132
142
|
function createBaseTranslatorImpl(_ref) {
|
|
133
143
|
let {
|
|
144
|
+
cache,
|
|
134
145
|
defaultTranslationValues,
|
|
135
146
|
formats: globalFormats,
|
|
136
147
|
formatters,
|
|
@@ -189,6 +200,12 @@ function createBaseTranslatorImpl(_ref) {
|
|
|
189
200
|
// Hot path that avoids creating an `IntlMessageFormat` instance
|
|
190
201
|
const plainMessage = getPlainMessage(message, values);
|
|
191
202
|
if (plainMessage) return plainMessage;
|
|
203
|
+
|
|
204
|
+
// Lazy init the message formatter for better tree
|
|
205
|
+
// shaking in case message formatting is not used.
|
|
206
|
+
if (!formatters.getMessageFormat) {
|
|
207
|
+
formatters.getMessageFormat = createMessageFormatter(cache, formatters);
|
|
208
|
+
}
|
|
192
209
|
try {
|
|
193
210
|
messageFormat = formatters.getMessageFormat(message, locale, convertFormatsToIntlMessageFormat({
|
|
194
211
|
...globalFormats,
|
|
@@ -342,7 +359,8 @@ function calculateRelativeTimeValue(seconds, unit) {
|
|
|
342
359
|
}
|
|
343
360
|
function createFormatter(_ref) {
|
|
344
361
|
let {
|
|
345
|
-
|
|
362
|
+
_cache: cache = initializeConfig.createCache(),
|
|
363
|
+
_formatters: formatters = initializeConfig.createIntlFormatters(cache),
|
|
346
364
|
formats,
|
|
347
365
|
locale,
|
|
348
366
|
now: globalNow,
|
|
@@ -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-o7L_y07P.js');
|
|
6
6
|
var core = require('./core.js');
|
|
7
|
-
var createFormatter = require('./createFormatter-
|
|
7
|
+
var createFormatter = require('./createFormatter-BRxeaiQU.js');
|
|
8
8
|
var _IntlProvider = require('./_IntlProvider.js');
|
|
9
9
|
var react = require('./react.js');
|
|
10
10
|
var _useLocale = require('./_useLocale-0Rl9uR82.js');
|
|
@@ -17,7 +17,8 @@ require('./IntlContext-BKfsnzBx.js');
|
|
|
17
17
|
|
|
18
18
|
exports.IntlError = initializeConfig.IntlError;
|
|
19
19
|
exports.IntlErrorCode = initializeConfig.IntlErrorCode;
|
|
20
|
-
exports.
|
|
20
|
+
exports._createCache = initializeConfig.createCache;
|
|
21
|
+
exports._createIntlFormatters = initializeConfig.createIntlFormatters;
|
|
21
22
|
exports.initializeConfig = initializeConfig.initializeConfig;
|
|
22
23
|
exports.createTranslator = core.createTranslator;
|
|
23
24
|
exports.createFormatter = createFormatter.createFormatter;
|
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var fastMemoize = require('@formatjs/fast-memoize');
|
|
4
|
-
var IntlMessageFormat = require('intl-messageformat');
|
|
5
|
-
|
|
6
|
-
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
7
|
-
|
|
8
|
-
var IntlMessageFormat__default = /*#__PURE__*/_interopDefault(IntlMessageFormat);
|
|
9
4
|
|
|
10
5
|
function _defineProperty(e, r, t) {
|
|
11
6
|
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
@@ -75,7 +70,9 @@ function defaultOnError(error) {
|
|
|
75
70
|
console.error(error);
|
|
76
71
|
}
|
|
77
72
|
|
|
78
|
-
|
|
73
|
+
// eslint-disable-next-line import/no-named-as-default -- False positive
|
|
74
|
+
|
|
75
|
+
function createCache() {
|
|
79
76
|
return {
|
|
80
77
|
dateTime: {},
|
|
81
78
|
number: {},
|
|
@@ -114,29 +111,17 @@ function memoConstructor(ConstructorFn, cache) {
|
|
|
114
111
|
return new ConstructorFn(...args);
|
|
115
112
|
}, cache);
|
|
116
113
|
}
|
|
117
|
-
function
|
|
118
|
-
const cache = createIntlCache();
|
|
114
|
+
function createIntlFormatters(cache) {
|
|
119
115
|
const getDateTimeFormat = memoConstructor(Intl.DateTimeFormat, cache.dateTime);
|
|
120
116
|
const getNumberFormat = memoConstructor(Intl.NumberFormat, cache.number);
|
|
121
117
|
const getPluralRules = memoConstructor(Intl.PluralRules, cache.pluralRules);
|
|
122
118
|
const getRelativeTimeFormat = memoConstructor(Intl.RelativeTimeFormat, cache.relativeTime);
|
|
123
119
|
const getListFormat = memoConstructor(Intl.ListFormat, cache.list);
|
|
124
120
|
const getDisplayNames = memoConstructor(Intl.DisplayNames, cache.displayNames);
|
|
125
|
-
const getMessageFormat = memoFn(function () {
|
|
126
|
-
return new IntlMessageFormat__default.default(arguments.length <= 0 ? undefined : arguments[0], arguments.length <= 1 ? undefined : arguments[1], arguments.length <= 2 ? undefined : arguments[2], {
|
|
127
|
-
formatters: {
|
|
128
|
-
getNumberFormat,
|
|
129
|
-
getDateTimeFormat,
|
|
130
|
-
getPluralRules
|
|
131
|
-
},
|
|
132
|
-
...(arguments.length <= 3 ? undefined : arguments[3])
|
|
133
|
-
});
|
|
134
|
-
}, cache.message);
|
|
135
121
|
return {
|
|
136
122
|
getDateTimeFormat,
|
|
137
123
|
getNumberFormat,
|
|
138
124
|
getPluralRules,
|
|
139
|
-
getMessageFormat,
|
|
140
125
|
getRelativeTimeFormat,
|
|
141
126
|
getListFormat,
|
|
142
127
|
getDisplayNames
|
|
@@ -191,8 +176,10 @@ function initializeConfig(_ref) {
|
|
|
191
176
|
|
|
192
177
|
exports.IntlError = IntlError;
|
|
193
178
|
exports.IntlErrorCode = IntlErrorCode;
|
|
194
|
-
exports.
|
|
179
|
+
exports.createCache = createCache;
|
|
180
|
+
exports.createIntlFormatters = createIntlFormatters;
|
|
195
181
|
exports.defaultGetMessageFallback = defaultGetMessageFallback;
|
|
196
182
|
exports.defaultOnError = defaultOnError;
|
|
197
183
|
exports.initializeConfig = initializeConfig;
|
|
198
184
|
exports.joinPath = joinPath;
|
|
185
|
+
exports.memoFn = memoFn;
|
|
@@ -5,16 +5,17 @@ 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-BRxeaiQU.js');
|
|
9
|
+
var initializeConfig = require('./initializeConfig-o7L_y07P.js');
|
|
10
10
|
require('./IntlContext-BKfsnzBx.js');
|
|
11
11
|
require('intl-messageformat');
|
|
12
12
|
require('@formatjs/fast-memoize');
|
|
13
13
|
|
|
14
14
|
let hasWarnedForMissingTimezone = false;
|
|
15
15
|
const isServer = typeof window === 'undefined';
|
|
16
|
-
function useTranslationsImpl(
|
|
16
|
+
function useTranslationsImpl(allMessagesPrefixed, namespacePrefixed, namespacePrefix) {
|
|
17
17
|
const {
|
|
18
|
+
cache,
|
|
18
19
|
defaultTranslationValues,
|
|
19
20
|
formats: globalFormats,
|
|
20
21
|
formatters,
|
|
@@ -26,13 +27,15 @@ function useTranslationsImpl(allMessages, namespace, namespacePrefix) {
|
|
|
26
27
|
|
|
27
28
|
// The `namespacePrefix` is part of the type system.
|
|
28
29
|
// See the comment in the hook invocation.
|
|
29
|
-
allMessages =
|
|
30
|
-
namespace = createFormatter.resolveNamespace(
|
|
30
|
+
const allMessages = allMessagesPrefixed[namespacePrefix];
|
|
31
|
+
const namespace = createFormatter.resolveNamespace(namespacePrefixed, namespacePrefix);
|
|
31
32
|
if (!timeZone && !hasWarnedForMissingTimezone && isServer) {
|
|
33
|
+
// eslint-disable-next-line react-compiler/react-compiler
|
|
32
34
|
hasWarnedForMissingTimezone = true;
|
|
33
35
|
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" ));
|
|
34
36
|
}
|
|
35
37
|
const translate = React.useMemo(() => createFormatter.createBaseTranslator({
|
|
38
|
+
cache,
|
|
36
39
|
formatters,
|
|
37
40
|
getMessageFallback,
|
|
38
41
|
messages: allMessages,
|
|
@@ -42,7 +45,7 @@ function useTranslationsImpl(allMessages, namespace, namespacePrefix) {
|
|
|
42
45
|
formats: globalFormats,
|
|
43
46
|
locale,
|
|
44
47
|
timeZone
|
|
45
|
-
}), [formatters, getMessageFallback, allMessages, defaultTranslationValues, namespace, onError, globalFormats, locale, timeZone]);
|
|
48
|
+
}), [cache, formatters, getMessageFallback, allMessages, defaultTranslationValues, namespace, onError, globalFormats, locale, timeZone]);
|
|
46
49
|
return translate;
|
|
47
50
|
}
|
|
48
51
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import e,{useMemo as
|
|
1
|
+
import e,{useMemo as a}from"react";import{b as o,c as t,i as r}from"./initializeConfig-D2A8plWf.js";import{I as s}from"./IntlContext-DoS4CDM3.js";import"@formatjs/fast-memoize";function l(l){let{children:n,defaultTranslationValues:i,formats:m,getMessageFallback:c,locale:f,messages:g,now:u,onError:p,timeZone:d}=l;const b=a((()=>o()),[f]),j=a((()=>t(b)),[b]),E=a((()=>({...r({locale:f,defaultTranslationValues:i,formats:m,getMessageFallback:c,messages:g,now:u,onError:p,timeZone:d}),formatters:j,cache:b})),[b,i,m,j,c,f,g,u,p,d]);return e.createElement(s.Provider,{value:E},n)}export{l as IntlProvider};
|
package/dist/esm/core.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
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-s2RNdTF5.js";export{c as createFormatter}from"./createFormatter-s2RNdTF5.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;function T(e,t,n){const o=new r(t,n);return w(o),p({error:o,key:e,namespace:v})}function S(s,i,w){if(y instanceof r)return p({error:y,key:s,namespace:v});const S=y;let b,M;try{b=f(h,S,s,v)}catch(e){return T(s,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,s),"` resolved to an array, but only strings are supported. See https://next-intl-docs.vercel.app/docs/usage/messages#arrays-of-messages")):(e=o.INSUFFICIENT_PATH,t="Message at `".concat(a(v,s),"` resolved to an object, but only strings are supported. Use a `.` to retrieve nested messages. See https://next-intl-docs.vercel.app/docs/usage/messages#structuring-messages")),T(s,e,t)}const I=function(e,t){if(t)return;const n=e.replace(/'([{}])/gi,"$1");return/<|{/.test(n)?void 0:n}(b,i);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,...w},E),{formatters:{...d,getDateTimeFormat:(e,t)=>d.getDateTimeFormat(e,{timeZone:E,...t})}})}catch(e){const t=e;return T(s,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,...i}));if(null==e)throw new Error("Unable to format `".concat(s,"` in ").concat(v?"namespace `".concat(v,"`"):"messages"));return t(e)||Array.isArray(e)||"string"==typeof e?e:String(e)}catch(e){return T(s,o.FORMATTING_ERROR,e.message)}}function b(e,t,n){const r=S(e,t,n);return"string"!=typeof r?T(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 b.rich=S,b.markup=(e,t,n)=>{const a=S(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},b.raw=e=>{if(y instanceof r)return p({error:y,key:e,namespace:v});const t=y;try{return f(h,t,e,v)}catch(t){return T(e,o.MISSING_MESSAGE,t.message)}},b}({...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,c as
|
|
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-s2RNdTF5.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";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{memoize as e,strategies as t}from"@formatjs/fast-memoize";function n(e,t,n){return(t=function(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t||"default");if("object"!=typeof r)return r;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:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}let r=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 a extends Error{constructor(e,t){let r=e;t&&(r+=": "+t),super(r),n(this,"code",void 0),n(this,"originalMessage",void 0),this.code=e,t&&(this.originalMessage=t)}}function o(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return t.filter(Boolean).join(".")}function i(e){return o(e.namespace,e.key)}function s(e){console.error(e)}function l(){return{dateTime:{},number:{},message:{},relativeTime:{},pluralRules:{},list:{},displayNames:{}}}function u(n,r){return e(n,{cache:(a=r,{create:()=>({get:e=>a[e],set(e,t){a[e]=t}})}),strategy:t.variadic});var a}function c(e,t){return u((function(){for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];return new e(...n)}),t)}function m(e){return{getDateTimeFormat:c(Intl.DateTimeFormat,e.dateTime),getNumberFormat:c(Intl.NumberFormat,e.number),getPluralRules:c(Intl.PluralRules,e.pluralRules),getRelativeTimeFormat:c(Intl.RelativeTimeFormat,e.relativeTime),getListFormat:c(Intl.ListFormat,e.list),getDisplayNames:c(Intl.DisplayNames,e.displayNames)}}function f(e,t,n){Object.entries(e).forEach((e=>{let[r,a]=e;if(r.includes(".")){let e=r;n&&(e+=" (at ".concat(n,")")),t.push(e)}null!=a&&"object"==typeof a&&f(a,t,o(n,r))}))}function I(e,t){const n=[];f(e,n),n.length>0&&t(new a(r.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===n.length?"key":"keys",": ").concat(n.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')))}function g(e){let{getMessageFallback:t,messages:n,onError:r,...a}=e;const o=r||s,l=t||i;return n&&I(n,o),{...a,messages:n,onError:o,getMessageFallback:l}}export{a as I,r as a,l as b,m as c,s as d,i as e,g as i,o as j,u as m};
|
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-s2RNdTF5.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};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("./initializeConfig-AbYTngyP.js"),r=require("./IntlContext-DcFt0tgW.js");function a(e){return e&&e.__esModule?e:{default:e}}require("@formatjs/fast-memoize");var o=a(e);exports.IntlProvider=function(a){let{children:s,defaultTranslationValues:n,formats:l,getMessageFallback:i,locale:u,messages:c,now:m,onError:f,timeZone:d}=a;const g=e.useMemo((()=>t.createCache()),[u]),M=e.useMemo((()=>t.createIntlFormatters(g)),[g]),v=e.useMemo((()=>({...t.initializeConfig({locale:u,defaultTranslationValues:n,formats:l,getMessageFallback:i,messages:c,now:m,onError:f,timeZone:d}),formatters:M,cache:g})),[g,n,l,M,i,u,c,m,f,d]);return o.default.createElement(r.IntlContext.Provider,{value:v},s)};
|
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-BUmzSWag.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,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;function y(e,t,r){const n=new s(t,r);return I(n),f({error:n,key:e,namespace:E})}function T(e,I,T){if(d instanceof s)return f({error:d,key:e,namespace:E});const h=d;let v,M;try{v=c(g,h,e,E)}catch(t){return y(e,i.MISSING_MESSAGE,t.message)}if("object"==typeof v){let t,r;return t=Array.isArray(v)?i.INVALID_MESSAGE:i.INSUFFICIENT_PATH,y(e,t,r)}const N=function(e,t){if(t)return;const r=e.replace(/'([{}])/gi,"$1");return/<|{/.test(r)?void 0:r}(v,I);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,...T},S),{formatters:{...m,getDateTimeFormat:(e,t)=>m.getDateTimeFormat(e,{timeZone:S,...t})}})}catch(t){const r=t;return y(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,...I}));if(null==e)throw new Error(void 0);return t.isValidElement(e)||Array.isArray(e)||"string"==typeof e?e:String(e)}catch(t){return y(e,i.FORMATTING_ERROR,t.message)}}function h(e,t,r){const n=T(e,t,r);return"string"!=typeof n?y(e,i.INVALID_MESSAGE,void 0):n}return h.rich=T,h.markup=(e,t,r)=>{const n=T(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},h.raw=e=>{if(d instanceof s)return f({error:d,key:e,namespace:E});const t=d;try{return c(g,t,e,E)}catch(t){return y(e,i.MISSING_MESSAGE,t.message)}},h}({...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)};
|
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-BUmzSWag.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;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("@formatjs/fast-memoize");function t(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return t.filter(Boolean).join(".")}function r(e){return t(e.namespace,e.key)}function a(e){console.error(e)}function n(t,r){return e.memoize(t,{cache:(a=r,{create:()=>({get:e=>a[e],set(e,t){a[e]=t}})}),strategy:e.strategies.variadic});var a}function s(e,t){return n((function(){for(var t=arguments.length,r=new Array(t),a=0;a<t;a++)r[a]=arguments[a];return new e(...r)}),t)}exports.createCache=function(){return{dateTime:{},number:{},message:{},relativeTime:{},pluralRules:{},list:{},displayNames:{}}},exports.createIntlFormatters=function(e){return{getDateTimeFormat:s(Intl.DateTimeFormat,e.dateTime),getNumberFormat:s(Intl.NumberFormat,e.number),getPluralRules:s(Intl.PluralRules,e.pluralRules),getRelativeTimeFormat:s(Intl.RelativeTimeFormat,e.relativeTime),getListFormat:s(Intl.ListFormat,e.list),getDisplayNames:s(Intl.DisplayNames,e.displayNames)}},exports.defaultGetMessageFallback=r,exports.defaultOnError=a,exports.initializeConfig=function(e){let{getMessageFallback:t,messages:n,onError:s,...i}=e;return{...i,messages:n,onError:s||a,getMessageFallback:t||r}},exports.joinPath=t,exports.memoFn=n;
|
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-BUmzSWag.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):"!","!")};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type AbstractIntlMessages from './AbstractIntlMessages';
|
|
2
|
-
import Formats from './Formats';
|
|
3
|
-
import IntlError from './IntlError';
|
|
4
|
-
import TimeZone from './TimeZone';
|
|
2
|
+
import type Formats from './Formats';
|
|
3
|
+
import type IntlError from './IntlError';
|
|
4
|
+
import type TimeZone from './TimeZone';
|
|
5
5
|
import type { RichTranslationValues } from './TranslationValues';
|
|
6
6
|
/**
|
|
7
7
|
* Should be used for entry points that configure the library.
|
|
@@ -4,11 +4,12 @@ import Formats from './Formats';
|
|
|
4
4
|
import { InitializedIntlConfig } from './IntlConfig';
|
|
5
5
|
import IntlError from './IntlError';
|
|
6
6
|
import TranslationValues, { MarkupTranslationValues, RichTranslationValues } from './TranslationValues';
|
|
7
|
-
import { Formatters } from './formatters';
|
|
7
|
+
import { Formatters, IntlCache } from './formatters';
|
|
8
8
|
import MessageKeys from './utils/MessageKeys';
|
|
9
9
|
import NestedKeyOf from './utils/NestedKeyOf';
|
|
10
10
|
import NestedValueOf from './utils/NestedValueOf';
|
|
11
11
|
export type CreateBaseTranslatorProps<Messages> = InitializedIntlConfig & {
|
|
12
|
+
cache: IntlCache;
|
|
12
13
|
formatters: Formatters;
|
|
13
14
|
defaultTranslationValues?: RichTranslationValues;
|
|
14
15
|
namespace?: string;
|
|
@@ -5,7 +5,7 @@ import IntlError from './IntlError';
|
|
|
5
5
|
import NumberFormatOptions from './NumberFormatOptions';
|
|
6
6
|
import RelativeTimeFormatOptions from './RelativeTimeFormatOptions';
|
|
7
7
|
import TimeZone from './TimeZone';
|
|
8
|
-
import { Formatters } from './formatters';
|
|
8
|
+
import { Formatters, IntlCache } from './formatters';
|
|
9
9
|
type Props = {
|
|
10
10
|
locale: string;
|
|
11
11
|
timeZone?: TimeZone;
|
|
@@ -14,8 +14,10 @@ type Props = {
|
|
|
14
14
|
now?: Date;
|
|
15
15
|
/** @private */
|
|
16
16
|
_formatters?: Formatters;
|
|
17
|
+
/** @private */
|
|
18
|
+
_cache?: IntlCache;
|
|
17
19
|
};
|
|
18
|
-
export default function createFormatter({ _formatters: formatters, formats, locale, now: globalNow, onError, timeZone: globalTimeZone }: Props): {
|
|
20
|
+
export default function createFormatter({ _cache: cache, _formatters: formatters, formats, locale, now: globalNow, onError, timeZone: globalTimeZone }: Props): {
|
|
19
21
|
dateTime: (value: Date | number, formatOrOptions?: string | DateTimeFormatOptions) => string;
|
|
20
22
|
number: (value: number | bigint, formatOrOptions?: string | NumberFormatOptions) => string;
|
|
21
23
|
relativeTime: (date: number | Date, nowOrOptions?: RelativeTimeFormatOptions["now"] | RelativeTimeFormatOptions) => string;
|
|
@@ -2,7 +2,7 @@ import { ReactElement, ReactNodeArray } from 'react';
|
|
|
2
2
|
import Formats from './Formats';
|
|
3
3
|
import IntlConfig from './IntlConfig';
|
|
4
4
|
import TranslationValues, { MarkupTranslationValues, RichTranslationValues } from './TranslationValues';
|
|
5
|
-
import { Formatters } from './formatters';
|
|
5
|
+
import { Formatters, IntlCache } from './formatters';
|
|
6
6
|
import MessageKeys from './utils/MessageKeys';
|
|
7
7
|
import NamespaceKeys from './utils/NamespaceKeys';
|
|
8
8
|
import NestedKeyOf from './utils/NestedKeyOf';
|
|
@@ -15,11 +15,13 @@ import NestedValueOf from './utils/NestedValueOf';
|
|
|
15
15
|
* The namespace can also indicate nesting by using a dot
|
|
16
16
|
* (e.g. `namespace.Component`).
|
|
17
17
|
*/
|
|
18
|
-
export default function createTranslator<NestedKey extends NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>> = never>({ _formatters, getMessageFallback, messages, namespace, onError, ...rest }: Omit<IntlConfig<IntlMessages>, 'defaultTranslationValues' | 'messages'> & {
|
|
18
|
+
export default function createTranslator<NestedKey extends NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>> = never>({ _cache, _formatters, getMessageFallback, messages, namespace, onError, ...rest }: Omit<IntlConfig<IntlMessages>, 'defaultTranslationValues' | 'messages'> & {
|
|
19
19
|
messages?: IntlConfig<IntlMessages>['messages'];
|
|
20
20
|
namespace?: NestedKey;
|
|
21
21
|
/** @private */
|
|
22
22
|
_formatters?: Formatters;
|
|
23
|
+
/** @private */
|
|
24
|
+
_cache?: IntlCache;
|
|
23
25
|
}): {
|
|
24
26
|
<TargetKey extends MessageKeys<NestedValueOf<{
|
|
25
27
|
'!': IntlMessages;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import AbstractIntlMessages from './AbstractIntlMessages';
|
|
2
2
|
import { InitializedIntlConfig } from './IntlConfig';
|
|
3
|
-
import { Formatters } from './formatters';
|
|
3
|
+
import { Formatters, IntlCache } from './formatters';
|
|
4
4
|
import NestedKeyOf from './utils/NestedKeyOf';
|
|
5
5
|
export type CreateTranslatorImplProps<Messages> = Omit<InitializedIntlConfig, 'messages'> & {
|
|
6
6
|
namespace: string;
|
|
7
7
|
messages: Messages;
|
|
8
8
|
formatters: Formatters;
|
|
9
|
+
cache: IntlCache;
|
|
9
10
|
};
|
|
10
11
|
export default function createTranslatorImpl<Messages extends AbstractIntlMessages, NestedKey extends NestedKeyOf<Messages>>({ messages, namespace, ...rest }: CreateTranslatorImplProps<Messages>, namespacePrefix: string): {
|
|
11
12
|
<TargetKey extends import(".").MessageKeys<import(".").NestedValueOf<Messages, NestedKey>, NestedKeyOf<import(".").NestedValueOf<Messages, NestedKey>>>>(key: TargetKey, values?: import("./TranslationValues").default, formats?: Partial<import("./Formats").default>): string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import IntlMessageFormat from 'intl-messageformat';
|
|
2
|
-
export
|
|
1
|
+
import type IntlMessageFormat from 'intl-messageformat';
|
|
2
|
+
export type IntlCache = {
|
|
3
3
|
dateTime: Record<string, Intl.DateTimeFormat>;
|
|
4
4
|
number: Record<string, Intl.NumberFormat>;
|
|
5
5
|
message: Record<string, IntlMessageFormat>;
|
|
@@ -8,13 +8,18 @@ export declare function createIntlCache(): {
|
|
|
8
8
|
list: Record<string, Intl.ListFormat>;
|
|
9
9
|
displayNames: Record<string, Intl.DisplayNames>;
|
|
10
10
|
};
|
|
11
|
-
export declare function
|
|
11
|
+
export declare function createCache(): IntlCache;
|
|
12
|
+
export declare function memoFn<Fn extends (...args: Array<any>) => any>(fn: Fn, cache: Record<string, ReturnType<Fn> | undefined>): Fn;
|
|
13
|
+
export type IntlFormatters = {
|
|
12
14
|
getDateTimeFormat(...args: ConstructorParameters<typeof Intl.DateTimeFormat>): Intl.DateTimeFormat;
|
|
13
15
|
getNumberFormat(...args: ConstructorParameters<typeof Intl.NumberFormat>): Intl.NumberFormat;
|
|
14
16
|
getPluralRules(...args: ConstructorParameters<typeof Intl.PluralRules>): Intl.PluralRules;
|
|
15
|
-
getMessageFormat(...args: ConstructorParameters<typeof IntlMessageFormat>): IntlMessageFormat;
|
|
16
17
|
getRelativeTimeFormat(...args: ConstructorParameters<typeof Intl.RelativeTimeFormat>): Intl.RelativeTimeFormat;
|
|
17
18
|
getListFormat(...args: ConstructorParameters<typeof Intl.ListFormat>): Intl.ListFormat;
|
|
18
19
|
getDisplayNames(...args: ConstructorParameters<typeof Intl.DisplayNames>): Intl.DisplayNames;
|
|
19
20
|
};
|
|
20
|
-
export
|
|
21
|
+
export declare function createIntlFormatters(cache: IntlCache): IntlFormatters;
|
|
22
|
+
export type MessageFormatter = (...args: ConstructorParameters<typeof IntlMessageFormat>) => IntlMessageFormat;
|
|
23
|
+
export type Formatters = IntlFormatters & {
|
|
24
|
+
getMessageFormat?: MessageFormatter;
|
|
25
|
+
};
|
|
@@ -12,4 +12,5 @@ export type { default as MessageKeys } from './utils/MessageKeys';
|
|
|
12
12
|
export type { default as NamespaceKeys } from './utils/NamespaceKeys';
|
|
13
13
|
export type { default as NestedKeyOf } from './utils/NestedKeyOf';
|
|
14
14
|
export type { default as NestedValueOf } from './utils/NestedValueOf';
|
|
15
|
-
export {
|
|
15
|
+
export { createIntlFormatters as _createIntlFormatters } from './formatters';
|
|
16
|
+
export { createCache as _createCache } from './formatters';
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { InitializedIntlConfig } from '../core/IntlConfig';
|
|
2
|
-
import type { Formatters } from '../core/formatters';
|
|
2
|
+
import type { Formatters, IntlCache } from '../core/formatters';
|
|
3
3
|
export type IntlContextValue = InitializedIntlConfig & {
|
|
4
4
|
formatters: Formatters;
|
|
5
|
+
cache: IntlCache;
|
|
5
6
|
};
|
|
6
7
|
declare const IntlContext: import("react").Context<IntlContextValue | undefined>;
|
|
7
8
|
export default IntlContext;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import AbstractIntlMessages from '../core/AbstractIntlMessages';
|
|
2
2
|
import NestedKeyOf from '../core/utils/NestedKeyOf';
|
|
3
|
-
export default function useTranslationsImpl<Messages extends AbstractIntlMessages, NestedKey extends NestedKeyOf<Messages>>(
|
|
3
|
+
export default function useTranslationsImpl<Messages extends AbstractIntlMessages, NestedKey extends NestedKeyOf<Messages>>(allMessagesPrefixed: Messages, namespacePrefixed: NestedKey, namespacePrefix: string): {
|
|
4
4
|
<TargetKey extends unknown>(key: TargetKey, values?: import("../core").TranslationValues, formats?: Partial<import("../core").Formats>): string;
|
|
5
5
|
rich: (key: string, values?: import("../core").RichTranslationValues, formats?: Partial<import("../core").Formats>) => string | import("react").ReactElement | import("react").ReactNodeArray;
|
|
6
6
|
markup(key: Parameters<(key: string, values?: import("../core").RichTranslationValues, formats?: Partial<import("../core").Formats>) => string | import("react").ReactElement | import("react").ReactNodeArray>[0], values: import("../core").MarkupTranslationValues, formats?: Parameters<(key: string, values?: import("../core").RichTranslationValues, formats?: Partial<import("../core").Formats>) => string | import("react").ReactElement | import("react").ReactNodeArray>[2]): string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "use-intl",
|
|
3
|
-
"version": "3.17.
|
|
3
|
+
"version": "3.17.6",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"author": "Jan Amann <jan@amann.work>",
|
|
6
6
|
"description": "Internationalization (i18n) for React",
|
|
@@ -69,11 +69,5 @@
|
|
|
69
69
|
"peerDependencies": {
|
|
70
70
|
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
|
|
71
71
|
},
|
|
72
|
-
"
|
|
73
|
-
{
|
|
74
|
-
"path": "dist/production/index.js",
|
|
75
|
-
"limit": "15.545 kB"
|
|
76
|
-
}
|
|
77
|
-
],
|
|
78
|
-
"gitHead": "720c254b5f1b189adfd5406e501793ad4d4cc8a6"
|
|
72
|
+
"gitHead": "9d9d53c9e55f80ce5c6f5cb9bb5f1be04e4d302c"
|
|
79
73
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{isValidElement as e,cloneElement as t}from"react";import{I as n,a as r,j as o,d as a,b as s,c as i}from"./initializeConfig-BB2Ue6Z9.js";import c from"intl-messageformat";function u(e,t){return e?Object.keys(e).reduce(((n,r)=>(n[r]={timeZone:t,...e[r]},n)),{}):e}function m(e,t,n,r){const a=o(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(a,"` in messages for locale `").concat(e,"`."));s=n})),s}function l(i){const l=function(e,t,o){let s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:a;try{if(!t)throw new Error("No messages were configured on the provider.");const n=o?m(e,t,o):t;if(!n)throw new Error("No messages for namespace `".concat(o,"` found."));return n}catch(e){const t=new n(r.MISSING_MESSAGE,e.message);return s(t),t}}(i.locale,i.messages,i.namespace,i.onError);return function(a){let{defaultTranslationValues:i,formats:l,formatters:f,getMessageFallback:g=s,locale:d,messagesOrError:p,namespace:y,onError:h,timeZone:v}=a;function w(e,t,r){const o=new n(t,r);return h(o),g({error:o,key:e,namespace:y})}function E(a,s,h){if(p instanceof n)return g({error:p,key:a,namespace:y});const E=p;let T,S;try{T=m(d,E,a,y)}catch(e){return w(a,r.MISSING_MESSAGE,e.message)}if("object"==typeof T){let e,t;return Array.isArray(T)?(e=r.INVALID_MESSAGE,t="Message at `".concat(o(y,a),"` resolved to an array, but only strings are supported. See https://next-intl-docs.vercel.app/docs/usage/messages#arrays-of-messages")):(e=r.INSUFFICIENT_PATH,t="Message at `".concat(o(y,a),"` 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")),w(a,e,t)}const b=function(e,t){if(t)return;const n=e.replace(/'([{}])/gi,"$1");return/<|{/.test(n)?void 0:n}(T,s);if(b)return b;try{S=f.getMessageFormat(T,d,function(e,t){const n=t?{...e,dateTime:u(e.dateTime,t)}:e,r=c.formats.date,o=t?u(r,t):r,a=c.formats.time,s=t?u(a,t):a;return{...n,date:{...o,...null==n?void 0:n.dateTime},time:{...s,...null==n?void 0:n.dateTime}}}({...l,...h},v),{formatters:{...f,getDateTimeFormat:(e,t)=>f.getDateTimeFormat(e,{timeZone:v,...t})}})}catch(e){const t=e;return w(a,r.INVALID_MESSAGE,t.message+("originalMessage"in t?" (".concat(t.originalMessage,")"):""))}try{const n=S.format(function(n){if(0===Object.keys(n).length)return;const r={};return Object.keys(n).forEach((o=>{let a=0;const s=n[o];let i;i="function"==typeof s?n=>{const r=s(n);return e(r)?t(r,{key:o+a++}):r}:s,r[o]=i})),r}({...i,...s}));if(null==n)throw new Error("Unable to format `".concat(a,"` in ").concat(y?"namespace `".concat(y,"`"):"messages"));return e(n)||Array.isArray(n)||"string"==typeof n?n:String(n)}catch(e){return w(a,r.FORMATTING_ERROR,e.message)}}function T(e,t,n){const o=E(e,t,n);return"string"!=typeof o?w(e,r.INVALID_MESSAGE,"The message `".concat(e,"` in ").concat(y?"namespace `".concat(y,"`"):"messages"," didn't resolve to a string. If you want to format rich text, use `t.rich` instead.")):o}return T.rich=E,T.markup=(e,t,o)=>{const a=E(e,t,o);if("string"!=typeof a){const t=new n(r.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 h(t),g({error:t,key:e,namespace:y})}return a},T.raw=e=>{if(p instanceof n)return g({error:p,key:e,namespace:y});const t=p;try{return m(d,t,e,y)}catch(t){return w(e,r.MISSING_MESSAGE,t.message)}},T}({...i,messagesOrError:l})}function f(e,t){return e===t?void 0:e.slice((t+".").length)}const g=60,d=60*g,p=24*d,y=7*p,h=p*(365/12),v=3*h,w=365*p,E={second:1,seconds:1,minute:g,minutes:g,hour:d,hours:d,day:p,days:p,week:y,weeks:y,month:h,months:h,quarter:v,quarters:v,year:w,years:w};function T(e){let{_formatters:t=i(),formats:o,locale:s,now:c,onError:u=a,timeZone:m}=e;function l(e){var t;return null!==(t=e)&&void 0!==t&&t.timeZone||(m?e={...e,timeZone:m}:u(new n(r.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 f(e,t,o,a){let s;try{s=function(e,t){let o;if("string"==typeof t){const a=t;if(o=null==e?void 0:e[a],!o){const e=new n(r.MISSING_FORMAT,"Format `".concat(a,"` is not available. You can configure it on the provider or provide custom options."));throw u(e),e}}else o=t;return o}(t,e)}catch(e){return a()}try{return o(s)}catch(e){return u(new n(r.FORMATTING_ERROR,e.message)),a()}}function v(e,n){return f(n,null==o?void 0:o.dateTime,(n=>(n=l(n),t.getDateTimeFormat(s,n).format(e))),(()=>String(e)))}function T(){return c||(u(new n(r.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:v,number:function(e,n){return f(n,null==o?void 0:o.number,(n=>t.getNumberFormat(s,n).format(e)),(()=>String(e)))},relativeTime:function(e,o){try{let n,r;const a={};o instanceof Date||"number"==typeof o?n=new Date(o):o&&(n=null!=o.now?new Date(o.now):T(),r=o.unit,a.style=o.style,a.numberingSystem=o.numberingSystem),n||(n=T());const i=(new Date(e).getTime()-n.getTime())/1e3;r||(r=function(e){const t=Math.abs(e);return t<g?"second":t<d?"minute":t<p?"hour":t<y?"day":t<h?"week":t<w?"month":"year"}(i)),a.numeric="second"===r?"auto":"always";const c=function(e,t){return Math.round(e/E[t])}(i,r);return t.getRelativeTimeFormat(s,a).format(c,r)}catch(t){return u(new n(r.FORMATTING_ERROR,t.message)),String(e)}},list:function(e,n){const r=[],a=new Map;let i=0;for(const t of e){let e;"object"==typeof t?(e=String(i),a.set(e,t)):e=String(t),r.push(e),i++}return f(n,null==o?void 0:o.list,(e=>{const n=t.getListFormat(s,e).formatToParts(r).map((e=>"literal"===e.type?e.value:a.get(e.value)||e.value));return a.size>0?n:n.join("")}),(()=>String(e)))},dateTimeRange:function(e,n,r){return f(r,null==o?void 0:o.dateTime,(r=>(r=l(r),t.getDateTimeFormat(s,r).formatRange(e,n))),(()=>[v(e),v(n)].join(" – ")))}}}export{l as a,T as c,f as r};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{memoize as e,strategies as t}from"@formatjs/fast-memoize";import n from"intl-messageformat";function r(e,t,n){return(t=function(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t||"default");if("object"!=typeof r)return r;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:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}let o=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 a extends Error{constructor(e,t){let n=e;t&&(n+=": "+t),super(n),r(this,"code",void 0),r(this,"originalMessage",void 0),this.code=e,t&&(this.originalMessage=t)}}function i(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return t.filter(Boolean).join(".")}function s(e){return i(e.namespace,e.key)}function l(e){console.error(e)}function u(n,r){return e(n,{cache:(o=r,{create:()=>({get:e=>o[e],set(e,t){o[e]=t}})}),strategy:t.variadic});var o}function c(e,t){return u((function(){for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];return new e(...n)}),t)}function m(){const e={dateTime:{},number:{},message:{},relativeTime:{},pluralRules:{},list:{},displayNames:{}},t=c(Intl.DateTimeFormat,e.dateTime),r=c(Intl.NumberFormat,e.number),o=c(Intl.PluralRules,e.pluralRules),a=c(Intl.RelativeTimeFormat,e.relativeTime),i=c(Intl.ListFormat,e.list),s=c(Intl.DisplayNames,e.displayNames),l=u((function(){return new n(arguments.length<=0?void 0:arguments[0],arguments.length<=1?void 0:arguments[1],arguments.length<=2?void 0:arguments[2],{formatters:{getNumberFormat:r,getDateTimeFormat:t,getPluralRules:o},...arguments.length<=3?void 0:arguments[3]})}),e.message);return{getDateTimeFormat:t,getNumberFormat:r,getPluralRules:o,getMessageFormat:l,getRelativeTimeFormat:a,getListFormat:i,getDisplayNames:s}}function g(e,t,n){Object.entries(e).forEach((e=>{let[r,o]=e;if(r.includes(".")){let e=r;n&&(e+=" (at ".concat(n,")")),t.push(e)}null!=o&&"object"==typeof o&&g(o,t,i(n,r))}))}function f(e,t){const n=[];g(e,n),n.length>0&&t(new a(o.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===n.length?"key":"keys",": ").concat(n.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')))}function I(e){let{getMessageFallback:t,messages:n,onError:r,...o}=e;const a=r||l,i=t||s;return n&&f(n,a),{...o,messages:n,onError:a,getMessageFallback:i}}export{a as I,o as a,s as b,m as c,l as d,I as i,i as j};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var e=require("react"),t=require("intl-messageformat"),r=require("./initializeConfig-BLiF0aUh.js");function n(e){return e&&e.__esModule?e:{default:e}}var o=n(t);function i(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 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,n,o){const i=r.joinPath(o,n);if(!t)throw new Error(i);let a=t;return n.split(".").forEach((t=>{const r=a[t];if(null==t||null==r)throw new Error(i+" (".concat(e,")"));a=r})),a}const l=60,m=60*l,f=24*m,E=7*f,d=f*(365/12),g=3*d,I=365*f,S={second:1,seconds:1,minute:l,minutes:l,hour:m,hours:m,day:f,days:f,week:E,weeks:E,month:d,months:d,quarter:g,quarters:g,year:I,years:I};exports.IntlError=s,exports.IntlErrorCode=a,exports.createBaseTranslator=function(t){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(a.MISSING_MESSAGE,e.message);return o(t),t}}(t.locale,t.messages,t.namespace,t.onError);return function(t){let{defaultTranslationValues:n,formats:i,formatters:l,getMessageFallback:m=r.defaultGetMessageFallback,locale:f,messagesOrError:E,namespace:d,onError:g,timeZone:I}=t;function S(e,t,r){const n=new s(t,r);return g(n),m({error:n,key:e,namespace:d})}function y(t,r,g){if(E instanceof s)return m({error:E,key:t,namespace:d});const y=E;let T,N;try{T=c(f,y,t,d)}catch(e){return S(t,a.MISSING_MESSAGE,e.message)}if("object"==typeof T){let e,r;return e=Array.isArray(T)?a.INVALID_MESSAGE:a.INSUFFICIENT_PATH,S(t,e,r)}const A=function(e,t){if(t)return;const r=e.replace(/'([{}])/gi,"$1");return/<|{/.test(r)?void 0:r}(T,r);if(A)return A;try{N=l.getMessageFormat(T,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,...g},I),{formatters:{...l,getDateTimeFormat:(e,t)=>l.getDateTimeFormat(e,{timeZone:I,...t})}})}catch(e){const r=e;return S(t,a.INVALID_MESSAGE,r.message)}try{const t=N.format(function(t){if(0===Object.keys(t).length)return;const r={};return Object.keys(t).forEach((n=>{let o=0;const i=t[n];let a;a="function"==typeof i?t=>{const r=i(t);return e.isValidElement(r)?e.cloneElement(r,{key:n+o++}):r}:i,r[n]=a})),r}({...n,...r}));if(null==t)throw new Error(void 0);return e.isValidElement(t)||Array.isArray(t)||"string"==typeof t?t:String(t)}catch(e){return S(t,a.FORMATTING_ERROR,e.message)}}function T(e,t,r){const n=y(e,t,r);return"string"!=typeof n?S(e,a.INVALID_MESSAGE,void 0):n}return T.rich=y,T.markup=(e,t,r)=>{const n=y(e,t,r);if("string"!=typeof n){const t=new s(a.FORMATTING_ERROR,void 0);return g(t),m({error:t,key:e,namespace:d})}return n},T.raw=e=>{if(E instanceof s)return m({error:E,key:e,namespace:d});const t=E;try{return c(f,t,e,d)}catch(t){return S(e,a.MISSING_MESSAGE,t.message)}},T}({...t,messagesOrError:n})},exports.createFormatter=function(e){let{_formatters:t=r.createFormatters(),formats:n,locale:o,now:i,onError:u=r.defaultOnError,timeZone:c}=e;function g(e){var t;return null!==(t=e)&&void 0!==t&&t.timeZone||(c?e={...e,timeZone:c}:u(new s(a.ENVIRONMENT_FALLBACK,void 0))),e}function y(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 u(e),e}}else r=t;return r}(t,e)}catch(e){return n()}try{return r(o)}catch(e){return u(new s(a.FORMATTING_ERROR,e.message)),n()}}function T(e,r){return y(r,null==n?void 0:n.dateTime,(r=>(r=g(r),t.getDateTimeFormat(o,r).format(e))),(()=>String(e)))}function N(){return i||(u(new s(a.ENVIRONMENT_FALLBACK,void 0)),new Date)}return{dateTime:T,number:function(e,r){return y(r,null==n?void 0:n.number,(r=>t.getNumberFormat(o,r).format(e)),(()=>String(e)))},relativeTime:function(e,r){try{let n,i;const a={};r instanceof Date||"number"==typeof r?n=new Date(r):r&&(n=null!=r.now?new Date(r.now):N(),i=r.unit,a.style=r.style,a.numberingSystem=r.numberingSystem),n||(n=N());const s=(new Date(e).getTime()-n.getTime())/1e3;i||(i=function(e){const t=Math.abs(e);return t<l?"second":t<m?"minute":t<f?"hour":t<E?"day":t<d?"week":t<I?"month":"year"}(s)),a.numeric="second"===i?"auto":"always";const u=function(e,t){return Math.round(e/S[t])}(s,i);return t.getRelativeTimeFormat(o,a).format(u,i)}catch(t){return u(new s(a.FORMATTING_ERROR,t.message)),String(e)}},list:function(e,r){const i=[],a=new Map;let s=0;for(const t of e){let e;"object"==typeof t?(e=String(s),a.set(e,t)):e=String(t),i.push(e),s++}return y(r,null==n?void 0:n.list,(e=>{const r=t.getListFormat(o,e).formatToParts(i).map((e=>"literal"===e.type?e.value:a.get(e.value)||e.value));return a.size>0?r:r.join("")}),(()=>String(e)))},dateTimeRange:function(e,r,i){return y(i,null==n?void 0:n.dateTime,(n=>(n=g(n),t.getDateTimeFormat(o,n).formatRange(e,r))),(()=>[T(e),T(r)].join(" – ")))}}},exports.resolveNamespace=function(e,t){return e===t?void 0:e.slice((t+".").length)};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var e=require("@formatjs/fast-memoize");function t(e){return e&&e.__esModule?e:{default:e}}var r=t(require("intl-messageformat"));function a(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return t.filter(Boolean).join(".")}function n(e){return a(e.namespace,e.key)}function s(e){console.error(e)}function l(t,r){return e.memoize(t,{cache:(a=r,{create:()=>({get:e=>a[e],set(e,t){a[e]=t}})}),strategy:e.strategies.variadic});var a}function o(e,t){return l((function(){for(var t=arguments.length,r=new Array(t),a=0;a<t;a++)r[a]=arguments[a];return new e(...r)}),t)}exports.createFormatters=function(){const e={dateTime:{},number:{},message:{},relativeTime:{},pluralRules:{},list:{},displayNames:{}},t=o(Intl.DateTimeFormat,e.dateTime),a=o(Intl.NumberFormat,e.number),n=o(Intl.PluralRules,e.pluralRules),s=o(Intl.RelativeTimeFormat,e.relativeTime),i=o(Intl.ListFormat,e.list),m=o(Intl.DisplayNames,e.displayNames),u=l((function(){return new r.default(arguments.length<=0?void 0:arguments[0],arguments.length<=1?void 0:arguments[1],arguments.length<=2?void 0:arguments[2],{formatters:{getNumberFormat:a,getDateTimeFormat:t,getPluralRules:n},...arguments.length<=3?void 0:arguments[3]})}),e.message);return{getDateTimeFormat:t,getNumberFormat:a,getPluralRules:n,getMessageFormat:u,getRelativeTimeFormat:s,getListFormat:i,getDisplayNames:m}},exports.defaultGetMessageFallback=n,exports.defaultOnError=s,exports.initializeConfig=function(e){let{getMessageFallback:t,messages:r,onError:a,...l}=e;return{...l,messages:r,onError:a||s,getMessageFallback:t||n}},exports.joinPath=a;
|