@depup/use-intl 4.13.3-depup.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +33 -0
- package/changes.json +18 -0
- package/core.d.ts +2 -0
- package/dist/esm/development/core.js +76 -0
- package/dist/esm/development/format-message/format-only.js +145 -0
- package/dist/esm/development/format-message/index.js +138 -0
- package/dist/esm/development/formatters-r4aAmsMP.js +79 -0
- package/dist/esm/development/index.js +8 -0
- package/dist/esm/development/initializeConfig-CUsOI8u2.js +527 -0
- package/dist/esm/development/react.js +231 -0
- package/dist/esm/production/core.js +1 -0
- package/dist/esm/production/format-message/format-only.js +1 -0
- package/dist/esm/production/format-message/index.js +1 -0
- package/dist/esm/production/formatters-CJcico0N.js +1 -0
- package/dist/esm/production/index.js +1 -0
- package/dist/esm/production/initializeConfig-CHgjheii.js +1 -0
- package/dist/esm/production/react.js +1 -0
- package/dist/types/core/AbstractIntlMessages.d.ts +10 -0
- package/dist/types/core/AppConfig.d.ts +29 -0
- package/dist/types/core/DateTimeFormatOptions.d.ts +73 -0
- package/dist/types/core/Formats.d.ts +9 -0
- package/dist/types/core/ICUArgs.d.ts +3 -0
- package/dist/types/core/ICUTags.d.ts +2 -0
- package/dist/types/core/IntlConfig.d.ts +54 -0
- package/dist/types/core/IntlError.d.ts +6 -0
- package/dist/types/core/IntlErrorCode.d.ts +10 -0
- package/dist/types/core/MessageKeys.d.ts +10 -0
- package/dist/types/core/NumberFormatOptions.d.ts +3 -0
- package/dist/types/core/RelativeTimeFormatOptions.d.ts +7 -0
- package/dist/types/core/TimeZone.d.ts +2 -0
- package/dist/types/core/TranslationValues.d.ts +6 -0
- package/dist/types/core/convertFormatsToIntlMessageFormat.d.ts +11 -0
- package/dist/types/core/createBaseTranslator.d.ts +21 -0
- package/dist/types/core/createFormatter.d.ts +47 -0
- package/dist/types/core/createTranslator.d.ts +59 -0
- package/dist/types/core/createTranslatorImpl.d.ts +17 -0
- package/dist/types/core/defaults.d.ts +11 -0
- package/dist/types/core/format-message/compile-format.d.ts +12 -0
- package/dist/types/core/format-message/format-only.d.ts +13 -0
- package/dist/types/core/format-message/index.d.ts +5 -0
- package/dist/types/core/format-message/types.d.ts +15 -0
- package/dist/types/core/formatters.d.ts +25 -0
- package/dist/types/core/hasLocale.d.ts +7 -0
- package/dist/types/core/index.d.ts +22 -0
- package/dist/types/core/initializeConfig.d.ts +14 -0
- package/dist/types/core/joinPath.d.ts +1 -0
- package/dist/types/core/resolveNamespace.d.ts +5 -0
- package/dist/types/core/types.d.ts +6 -0
- package/dist/types/core/validateMessages.d.ts +3 -0
- package/dist/types/core.d.ts +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/react/IntlContext.d.ts +8 -0
- package/dist/types/react/IntlProvider.d.ts +7 -0
- package/dist/types/react/index.d.ts +9 -0
- package/dist/types/react/useExtracted.d.ts +42 -0
- package/dist/types/react/useFormatter.d.ts +2 -0
- package/dist/types/react/useIntlContext.d.ts +2 -0
- package/dist/types/react/useLocale.d.ts +2 -0
- package/dist/types/react/useMessages.d.ts +2 -0
- package/dist/types/react/useNow.d.ts +8 -0
- package/dist/types/react/useTimeZone.d.ts +1 -0
- package/dist/types/react/useTranslations.d.ts +12 -0
- package/dist/types/react/useTranslationsImpl.d.ts +9 -0
- package/dist/types/react.d.ts +1 -0
- package/format-message/format-only.d.ts +2 -0
- package/format-message.d.ts +2 -0
- package/package.json +115 -0
- package/react.d.ts +2 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Jan Amann
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# @depup/use-intl
|
|
2
|
+
|
|
3
|
+
> Dependency-bumped version of [use-intl](https://www.npmjs.com/package/use-intl)
|
|
4
|
+
|
|
5
|
+
Generated by [DepUp](https://github.com/depup/npm) -- all production
|
|
6
|
+
dependencies bumped to latest versions.
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @depup/use-intl
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
| Field | Value |
|
|
15
|
+
|-------|-------|
|
|
16
|
+
| Original | [use-intl](https://www.npmjs.com/package/use-intl) @ 4.13.3 |
|
|
17
|
+
| Processed | 2026-07-21 |
|
|
18
|
+
| Smoke test | failed |
|
|
19
|
+
| Deps updated | 3 |
|
|
20
|
+
|
|
21
|
+
## Dependency Changes
|
|
22
|
+
|
|
23
|
+
| Dependency | From | To |
|
|
24
|
+
|------------|------|-----|
|
|
25
|
+
| @formatjs/fast-memoize | ^3.1.0 | ^3.1.7 |
|
|
26
|
+
| @schummar/icu-type-parser | 1.21.5 | ^1.26.1 |
|
|
27
|
+
| intl-messageformat | ^11.1.0 | ^11.2.12 |
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
Source: https://github.com/depup/npm | Original: https://www.npmjs.com/package/use-intl
|
|
32
|
+
|
|
33
|
+
License inherited from the original package.
|
package/changes.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"bumped": {
|
|
3
|
+
"@formatjs/fast-memoize": {
|
|
4
|
+
"from": "^3.1.0",
|
|
5
|
+
"to": "^3.1.7"
|
|
6
|
+
},
|
|
7
|
+
"@schummar/icu-type-parser": {
|
|
8
|
+
"from": "1.21.5",
|
|
9
|
+
"to": "^1.26.1"
|
|
10
|
+
},
|
|
11
|
+
"intl-messageformat": {
|
|
12
|
+
"from": "^11.1.0",
|
|
13
|
+
"to": "^11.2.12"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"timestamp": "2026-07-21T16:26:01.866Z",
|
|
17
|
+
"totalUpdated": 3
|
|
18
|
+
}
|
package/core.d.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { c as createIntlFormatters, b as createCache } from './formatters-r4aAmsMP.js';
|
|
2
|
+
export { I as IntlError, a as IntlErrorCode } from './formatters-r4aAmsMP.js';
|
|
3
|
+
import { r as resolveNamespace, a as createBaseTranslator, d as defaultGetMessageFallback, b as defaultOnError } from './initializeConfig-CUsOI8u2.js';
|
|
4
|
+
export { c as createFormatter, i as initializeConfig } from './initializeConfig-CUsOI8u2.js';
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
function createTranslatorImpl({
|
|
10
|
+
messages,
|
|
11
|
+
namespace,
|
|
12
|
+
...rest
|
|
13
|
+
}, namespacePrefix) {
|
|
14
|
+
// The `namespacePrefix` is part of the type system.
|
|
15
|
+
// See the comment in the function invocation.
|
|
16
|
+
messages = messages[namespacePrefix];
|
|
17
|
+
namespace = resolveNamespace(namespace, namespacePrefix);
|
|
18
|
+
return createBaseTranslator({
|
|
19
|
+
...rest,
|
|
20
|
+
messages,
|
|
21
|
+
namespace
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// This type is slightly more loose than `AbstractIntlMessages`
|
|
26
|
+
// in order to avoid a type error.
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @private Not intended for direct use.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Translates messages from the given namespace by using the ICU syntax.
|
|
34
|
+
* See https://formatjs.io/docs/core-concepts/icu-syntax.
|
|
35
|
+
*
|
|
36
|
+
* If no namespace is provided, all available messages are returned.
|
|
37
|
+
* The namespace can also indicate nesting by using a dot
|
|
38
|
+
* (e.g. `namespace.Component`).
|
|
39
|
+
*/
|
|
40
|
+
function createTranslator({
|
|
41
|
+
_cache = createCache(),
|
|
42
|
+
_formatters = createIntlFormatters(_cache),
|
|
43
|
+
getMessageFallback = defaultGetMessageFallback,
|
|
44
|
+
messages,
|
|
45
|
+
namespace,
|
|
46
|
+
onError = defaultOnError,
|
|
47
|
+
...rest
|
|
48
|
+
}) {
|
|
49
|
+
// We have to wrap the actual function so the type inference for the optional
|
|
50
|
+
// namespace works correctly. See https://stackoverflow.com/a/71529575/343045
|
|
51
|
+
// The prefix ("!") is arbitrary.
|
|
52
|
+
// @ts-expect-error Use the explicit annotation instead
|
|
53
|
+
return createTranslatorImpl({
|
|
54
|
+
...rest,
|
|
55
|
+
onError,
|
|
56
|
+
cache: _cache,
|
|
57
|
+
formatters: _formatters,
|
|
58
|
+
getMessageFallback,
|
|
59
|
+
// @ts-expect-error `messages` is allowed to be `undefined` here and will be handled internally
|
|
60
|
+
messages: {
|
|
61
|
+
'!': messages
|
|
62
|
+
},
|
|
63
|
+
namespace: namespace ? `!.${namespace}` : '!'
|
|
64
|
+
}, '!');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Checks if a locale exists in a list of locales.
|
|
69
|
+
*
|
|
70
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale
|
|
71
|
+
*/
|
|
72
|
+
function hasLocale(locales, candidate) {
|
|
73
|
+
return locales.includes(candidate);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export { createCache as _createCache, createIntlFormatters as _createIntlFormatters, createTranslator, hasLocale };
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
const a$1 = 0,
|
|
2
|
+
s = 1,
|
|
3
|
+
c$1 = 2,
|
|
4
|
+
e = 3,
|
|
5
|
+
o = 4,
|
|
6
|
+
t = 5,
|
|
7
|
+
b = 6;
|
|
8
|
+
|
|
9
|
+
function f(t, r, n = {}, e) {
|
|
10
|
+
if ("string" == typeof t) return t;
|
|
11
|
+
return g(i(t, r, n, e, void 0));
|
|
12
|
+
}
|
|
13
|
+
function i(t, r, n, e, o) {
|
|
14
|
+
const u = [];
|
|
15
|
+
for (const s of t) {
|
|
16
|
+
const t = a(s, r, n, e, o);
|
|
17
|
+
Array.isArray(t) ? u.push(...t) : u.push(t);
|
|
18
|
+
}
|
|
19
|
+
return u;
|
|
20
|
+
}
|
|
21
|
+
function a(f, a, y, d, h) {
|
|
22
|
+
if ("string" == typeof f) return f;
|
|
23
|
+
if (f === a$1) {
|
|
24
|
+
const t = h;
|
|
25
|
+
return d.formatters.getNumberFormat(t.locale).format(t.value);
|
|
26
|
+
}
|
|
27
|
+
const [b$1, v, ...A] = f;
|
|
28
|
+
if (void 0 === v) {
|
|
29
|
+
const t = c(y, b$1);
|
|
30
|
+
return String(t);
|
|
31
|
+
}
|
|
32
|
+
if ("number" != typeof v || v === a$1) return function (t, r, n, e, o, u) {
|
|
33
|
+
const s = c(e, t),
|
|
34
|
+
f = s,
|
|
35
|
+
a = i(r, n, e, o, u),
|
|
36
|
+
m = g(a),
|
|
37
|
+
l = Array.isArray(m) ? m : [m];
|
|
38
|
+
return f(l);
|
|
39
|
+
}(b$1, [v, ...A], a, y, d, h);
|
|
40
|
+
switch (v) {
|
|
41
|
+
case s:
|
|
42
|
+
return function (t, r, n, e, o, u) {
|
|
43
|
+
const s = String(c(e, t)),
|
|
44
|
+
f = r[s] ?? r.other;
|
|
45
|
+
return l(f, n, e, o, u);
|
|
46
|
+
}(b$1, A[0], a, y, d, h);
|
|
47
|
+
case c$1:
|
|
48
|
+
return m(b$1, A[0], a, y, d, "cardinal");
|
|
49
|
+
case e:
|
|
50
|
+
return m(b$1, A[0], a, y, d, "ordinal");
|
|
51
|
+
case o:
|
|
52
|
+
return function (t, r, n, e, o) {
|
|
53
|
+
const u = c(e, t),
|
|
54
|
+
s = u,
|
|
55
|
+
f = function (t, r) {
|
|
56
|
+
if (!t) return;
|
|
57
|
+
if ("string" == typeof t) return r.formats?.number?.[t] ? r.formats.number[t] : void 0;
|
|
58
|
+
return t;
|
|
59
|
+
}(r, o);
|
|
60
|
+
return o.formatters.getNumberFormat(n, f).format(s);
|
|
61
|
+
}(b$1, A[0], a, y, d);
|
|
62
|
+
case t:
|
|
63
|
+
return p(b$1, A[0], a, y, d);
|
|
64
|
+
case b:
|
|
65
|
+
return p(b$1, A[0], a, y, d);
|
|
66
|
+
default:
|
|
67
|
+
return "";
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function c(t, r) {
|
|
71
|
+
return t[r];
|
|
72
|
+
}
|
|
73
|
+
function m(t, r, n, e, o, u) {
|
|
74
|
+
const s = c(e, t),
|
|
75
|
+
f = `=${s}`;
|
|
76
|
+
if (f in r) return l(r[f], n, e, o, {
|
|
77
|
+
value: s,
|
|
78
|
+
locale: n
|
|
79
|
+
});
|
|
80
|
+
return l(r[o.formatters.getPluralRules(n, {
|
|
81
|
+
type: u
|
|
82
|
+
}).select(s)] ?? r.other, n, e, o, {
|
|
83
|
+
value: s,
|
|
84
|
+
locale: n
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
function l(r, n, e, o, u) {
|
|
88
|
+
return "string" == typeof r ? r : r === a$1 ? a(r, n, e, o, u) : i(r, n, e, o, u);
|
|
89
|
+
}
|
|
90
|
+
function p(t, r, n, e, o, u) {
|
|
91
|
+
const s = c(e, t),
|
|
92
|
+
f = function (t, r, n) {
|
|
93
|
+
if (!t) return;
|
|
94
|
+
if ("string" == typeof t) {
|
|
95
|
+
const r = n.formats?.dateTime?.[t];
|
|
96
|
+
return r;
|
|
97
|
+
}
|
|
98
|
+
return t;
|
|
99
|
+
}(r, 0, o),
|
|
100
|
+
i = {
|
|
101
|
+
...f,
|
|
102
|
+
timeZone: f?.timeZone ?? o.timeZone
|
|
103
|
+
};
|
|
104
|
+
return o.formatters.getDateTimeFormat(n, i).format(s);
|
|
105
|
+
}
|
|
106
|
+
function g(t) {
|
|
107
|
+
if (0 === t.length) return "";
|
|
108
|
+
const r = [];
|
|
109
|
+
let n = "";
|
|
110
|
+
for (const e of t) "string" == typeof e ? n += e : (n && (r.push(n), n = ""), r.push(e));
|
|
111
|
+
return n && r.push(n), 1 === r.length ? r[0] : r;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Formats a precompiled ICU message using icu-minify/format.
|
|
116
|
+
* This implementation requires messages to be precompiled at build time.
|
|
117
|
+
*/
|
|
118
|
+
function formatMessage(/** The precompiled ICU message (CompiledMessage from icu-minify) */
|
|
119
|
+
...[, message, values, options]) {
|
|
120
|
+
const {
|
|
121
|
+
formats,
|
|
122
|
+
globalFormats,
|
|
123
|
+
locale,
|
|
124
|
+
...rest
|
|
125
|
+
} = options;
|
|
126
|
+
const result = f(message, locale, values, {
|
|
127
|
+
formats: {
|
|
128
|
+
dateTime: {
|
|
129
|
+
...globalFormats?.dateTime,
|
|
130
|
+
...formats?.dateTime
|
|
131
|
+
},
|
|
132
|
+
number: {
|
|
133
|
+
...globalFormats?.number,
|
|
134
|
+
...formats?.number
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
...rest
|
|
138
|
+
});
|
|
139
|
+
return result;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// `t.raw` is not supported
|
|
143
|
+
formatMessage.raw = false;
|
|
144
|
+
|
|
145
|
+
export { formatMessage as default };
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { IntlMessageFormat } from 'intl-messageformat';
|
|
2
|
+
import { isValidElement } from 'react';
|
|
3
|
+
import { I as IntlError, a as IntlErrorCode, m as memoFn } from '../formatters-r4aAmsMP.js';
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* `intl-messageformat` uses separate keys for `date` and `time`, but there's
|
|
8
|
+
* only one native API: `Intl.DateTimeFormat`. Additionally you might want to
|
|
9
|
+
* include both a time and a date in a value, therefore the separation doesn't
|
|
10
|
+
* seem so useful. We offer a single `dateTime` namespace instead, but we have
|
|
11
|
+
* to convert the format before `intl-messageformat` can be used.
|
|
12
|
+
*/
|
|
13
|
+
function convertFormatsToIntlMessageFormat(globalFormats, inlineFormats, timeZone) {
|
|
14
|
+
const mfDateDefaults = IntlMessageFormat.formats.date;
|
|
15
|
+
const mfTimeDefaults = IntlMessageFormat.formats.time;
|
|
16
|
+
const dateTimeFormats = {
|
|
17
|
+
...globalFormats?.dateTime,
|
|
18
|
+
...inlineFormats?.dateTime
|
|
19
|
+
};
|
|
20
|
+
const allFormats = {
|
|
21
|
+
date: {
|
|
22
|
+
...mfDateDefaults,
|
|
23
|
+
...dateTimeFormats
|
|
24
|
+
},
|
|
25
|
+
time: {
|
|
26
|
+
...mfTimeDefaults,
|
|
27
|
+
...dateTimeFormats
|
|
28
|
+
},
|
|
29
|
+
number: {
|
|
30
|
+
...globalFormats?.number,
|
|
31
|
+
...inlineFormats?.number
|
|
32
|
+
}
|
|
33
|
+
// (list is not supported in ICU messages)
|
|
34
|
+
};
|
|
35
|
+
if (timeZone) {
|
|
36
|
+
// The only way to set a time zone with `intl-messageformat` is to merge it into the formats
|
|
37
|
+
// https://github.com/formatjs/formatjs/blob/8256c5271505cf2606e48e3c97ecdd16ede4f1b5/packages/intl/src/message.ts#L15
|
|
38
|
+
['date', 'time'].forEach(property => {
|
|
39
|
+
const formats = allFormats[property];
|
|
40
|
+
for (const [key, value] of Object.entries(formats)) {
|
|
41
|
+
formats[key] = {
|
|
42
|
+
timeZone,
|
|
43
|
+
...value
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
return allFormats;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Placed here for improved tree shaking. Somehow when this is placed in
|
|
52
|
+
// `formatters.tsx`, then it can't be shaken off from `next-intl`.
|
|
53
|
+
function createMessageFormatter(cache, intlFormatters) {
|
|
54
|
+
const getMessageFormat = memoFn((...args) => new IntlMessageFormat(args[0], args[1], args[2], {
|
|
55
|
+
formatters: intlFormatters,
|
|
56
|
+
...args[3]
|
|
57
|
+
}), cache.message);
|
|
58
|
+
return getMessageFormat;
|
|
59
|
+
}
|
|
60
|
+
function getPlainMessage(candidate, values) {
|
|
61
|
+
// To improve runtime performance, only compile message if:
|
|
62
|
+
return (
|
|
63
|
+
// 1. Values are provided
|
|
64
|
+
values ||
|
|
65
|
+
// 2. There are ICU escape sequences (e.g. "'{name'}")
|
|
66
|
+
/'[{}<#|']/.test(candidate) ||
|
|
67
|
+
// 3. There are missing arguments or tags (dev-only error handling)
|
|
68
|
+
/<|{/.test(candidate) ? undefined // Compile
|
|
69
|
+
: candidate // Don't compile
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Compiles and formats an ICU message at runtime using intl-messageformat.
|
|
75
|
+
* This is the default implementation used when messages are not precompiled.
|
|
76
|
+
*/
|
|
77
|
+
function formatMessage(/** The raw ICU message string (or precompiled message, though this implementation ignores precompilation) */
|
|
78
|
+
...[key, message, values, options]) {
|
|
79
|
+
if (Array.isArray(message)) {
|
|
80
|
+
throw new IntlError(IntlErrorCode.INVALID_MESSAGE, `Message at \`${key}\` resolved to an array, but only strings are supported. See https://next-intl.dev/docs/usage/translations#arrays-of-messages` );
|
|
81
|
+
}
|
|
82
|
+
if (typeof message === 'object') {
|
|
83
|
+
throw new IntlError(IntlErrorCode.INSUFFICIENT_PATH, `Message at \`${key}\` resolved to \`${typeof message}\`, but only strings are supported. Use a \`.\` to retrieve nested messages. See https://next-intl.dev/docs/usage/translations#structuring-messages` );
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Hot path that avoids creating an `IntlMessageFormat` instance
|
|
87
|
+
if (typeof message === 'string') {
|
|
88
|
+
const plainMessage = getPlainMessage(message, values);
|
|
89
|
+
if (plainMessage) return plainMessage;
|
|
90
|
+
}
|
|
91
|
+
const {
|
|
92
|
+
cache,
|
|
93
|
+
formats,
|
|
94
|
+
formatters,
|
|
95
|
+
globalFormats,
|
|
96
|
+
locale,
|
|
97
|
+
timeZone
|
|
98
|
+
} = options;
|
|
99
|
+
|
|
100
|
+
// Lazy init the message formatter for better tree
|
|
101
|
+
// shaking in case message formatting is not used.
|
|
102
|
+
if (!formatters.getMessageFormat) {
|
|
103
|
+
formatters.getMessageFormat = createMessageFormatter(cache, formatters);
|
|
104
|
+
}
|
|
105
|
+
let messageFormat;
|
|
106
|
+
try {
|
|
107
|
+
messageFormat = formatters.getMessageFormat(message, locale, convertFormatsToIntlMessageFormat(globalFormats, formats, timeZone), {
|
|
108
|
+
formatters: {
|
|
109
|
+
...formatters,
|
|
110
|
+
getDateTimeFormat(locales, dateTimeOptions) {
|
|
111
|
+
// Workaround for https://github.com/formatjs/formatjs/issues/4279
|
|
112
|
+
return formatters.getDateTimeFormat(locales, {
|
|
113
|
+
...dateTimeOptions,
|
|
114
|
+
timeZone: dateTimeOptions?.timeZone ?? timeZone
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
} catch (error) {
|
|
120
|
+
throw new IntlError(IntlErrorCode.INVALID_MESSAGE, `${error.message} (${error.originalMessage})` );
|
|
121
|
+
}
|
|
122
|
+
const formattedMessage = messageFormat.format(
|
|
123
|
+
// @ts-expect-error `intl-messageformat` expects a different format
|
|
124
|
+
// for rich text elements since a recent minor update. This
|
|
125
|
+
// needs to be evaluated in detail, possibly also in regard
|
|
126
|
+
// to be able to format to parts.
|
|
127
|
+
values);
|
|
128
|
+
|
|
129
|
+
// Limit the function signature to return strings or React elements
|
|
130
|
+
return /*#__PURE__*/isValidElement(formattedMessage) ||
|
|
131
|
+
// Arrays of React elements
|
|
132
|
+
Array.isArray(formattedMessage) || typeof formattedMessage === 'string' ? formattedMessage : String(formattedMessage);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// `t.raw` is supported
|
|
136
|
+
formatMessage.raw = true;
|
|
137
|
+
|
|
138
|
+
export { formatMessage as default };
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { memoize, strategies } from '@formatjs/fast-memoize';
|
|
2
|
+
|
|
3
|
+
class IntlError extends Error {
|
|
4
|
+
constructor(code, originalMessage) {
|
|
5
|
+
let message = code;
|
|
6
|
+
if (originalMessage) {
|
|
7
|
+
message += ': ' + originalMessage;
|
|
8
|
+
}
|
|
9
|
+
super(message);
|
|
10
|
+
this.code = code;
|
|
11
|
+
if (originalMessage) {
|
|
12
|
+
this.originalMessage = originalMessage;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
var IntlErrorCode = /*#__PURE__*/function (IntlErrorCode) {
|
|
18
|
+
IntlErrorCode["MISSING_MESSAGE"] = "MISSING_MESSAGE";
|
|
19
|
+
IntlErrorCode["MISSING_FORMAT"] = "MISSING_FORMAT";
|
|
20
|
+
IntlErrorCode["ENVIRONMENT_FALLBACK"] = "ENVIRONMENT_FALLBACK";
|
|
21
|
+
IntlErrorCode["INSUFFICIENT_PATH"] = "INSUFFICIENT_PATH";
|
|
22
|
+
IntlErrorCode["INVALID_MESSAGE"] = "INVALID_MESSAGE";
|
|
23
|
+
IntlErrorCode["INVALID_KEY"] = "INVALID_KEY";
|
|
24
|
+
IntlErrorCode["FORMATTING_ERROR"] = "FORMATTING_ERROR";
|
|
25
|
+
return IntlErrorCode;
|
|
26
|
+
}(IntlErrorCode || {});
|
|
27
|
+
|
|
28
|
+
function createCache() {
|
|
29
|
+
return {
|
|
30
|
+
dateTime: {},
|
|
31
|
+
number: {},
|
|
32
|
+
message: {},
|
|
33
|
+
relativeTime: {},
|
|
34
|
+
pluralRules: {},
|
|
35
|
+
list: {},
|
|
36
|
+
displayNames: {}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function createMemoCache(store) {
|
|
40
|
+
return {
|
|
41
|
+
create() {
|
|
42
|
+
return {
|
|
43
|
+
get(key) {
|
|
44
|
+
return store[key];
|
|
45
|
+
},
|
|
46
|
+
set(key, value) {
|
|
47
|
+
store[key] = value;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function memoFn(fn, cache) {
|
|
54
|
+
return memoize(fn, {
|
|
55
|
+
cache: createMemoCache(cache),
|
|
56
|
+
strategy: strategies.variadic
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
function memoConstructor(ConstructorFn, cache) {
|
|
60
|
+
return memoFn((...args) => new ConstructorFn(...args), cache);
|
|
61
|
+
}
|
|
62
|
+
function createIntlFormatters(cache) {
|
|
63
|
+
const getDateTimeFormat = memoConstructor(Intl.DateTimeFormat, cache.dateTime);
|
|
64
|
+
const getNumberFormat = memoConstructor(Intl.NumberFormat, cache.number);
|
|
65
|
+
const getPluralRules = memoConstructor(Intl.PluralRules, cache.pluralRules);
|
|
66
|
+
const getRelativeTimeFormat = memoConstructor(Intl.RelativeTimeFormat, cache.relativeTime);
|
|
67
|
+
const getListFormat = memoConstructor(Intl.ListFormat, cache.list);
|
|
68
|
+
const getDisplayNames = memoConstructor(Intl.DisplayNames, cache.displayNames);
|
|
69
|
+
return {
|
|
70
|
+
getDateTimeFormat,
|
|
71
|
+
getNumberFormat,
|
|
72
|
+
getPluralRules,
|
|
73
|
+
getRelativeTimeFormat,
|
|
74
|
+
getListFormat,
|
|
75
|
+
getDisplayNames
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export { IntlError as I, IntlErrorCode as a, createCache as b, createIntlFormatters as c, memoFn as m };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { I as IntlError, a as IntlErrorCode, b as _createCache, c as _createIntlFormatters } from './formatters-r4aAmsMP.js';
|
|
2
|
+
export { createTranslator, hasLocale } from './core.js';
|
|
3
|
+
export { c as createFormatter, i as initializeConfig } from './initializeConfig-CUsOI8u2.js';
|
|
4
|
+
export { IntlProvider, _useExtracted, useFormatter, useLocale, useMessages, useNow, useTimeZone, useTranslations } from './react.js';
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|