@voltro/i18n 0.85.0 → 0.87.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/CHANGELOG.md +5987 -0
- package/THIRD-PARTY-NOTICES.md +1 -1
- package/dist/catalog.js +94 -0
- package/dist/components.js +9 -0
- package/dist/cookieNames.js +4 -0
- package/dist/format.js +95 -0
- package/dist/formatterCache.js +81 -0
- package/dist/hooks.js +9 -0
- package/dist/index.js +15 -411
- package/dist/instanceRegistry.js +30 -0
- package/dist/lazyCatalog.js +27 -0
- package/dist/lazyProvider.js +28 -0
- package/dist/localeSwitcher.js +37 -0
- package/dist/provider.js +31 -0
- package/dist/renderClock.js +5 -0
- package/dist/server.d.ts +15 -1
- package/dist/server.js +25 -18
- package/dist/ssgWrap.js +14 -0
- package/dist/{cookieNames-CqdYWVpp.js → timeZone.js} +2 -2
- package/dist/typed.js +13 -0
- package/package.json +1 -1
package/THIRD-PARTY-NOTICES.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Third-Party Notices — @voltro/i18n
|
|
2
2
|
|
|
3
|
-
This package
|
|
3
|
+
This package uses the open-source software listed below. Each is the
|
|
4
4
|
property of its respective copyright holders and is used under the terms of
|
|
5
5
|
its license. This file is provided for attribution; it grants no rights in
|
|
6
6
|
@voltro/i18n itself, which is proprietary (see LICENSE).
|
package/dist/catalog.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
//#region src/catalog.ts
|
|
2
|
+
var e = (e) => e, t = () => (e) => e, n = (e, t, n) => e[t ?? n] ?? e[n], r = (e) => {
|
|
3
|
+
let t = /* @__PURE__ */ new Set();
|
|
4
|
+
if (!e.includes("{")) return t;
|
|
5
|
+
let n = 0, r, o = (t, o) => {
|
|
6
|
+
e.length >= 1024 && ++n === 4 && (r = i(e));
|
|
7
|
+
let s = r?.get(t);
|
|
8
|
+
return s === void 0 ? a(e, t, o) : Math.min(s, o);
|
|
9
|
+
}, s = (n, r) => {
|
|
10
|
+
let i = n;
|
|
11
|
+
for (; i < r;) {
|
|
12
|
+
let n = e[i];
|
|
13
|
+
if (n === "'") {
|
|
14
|
+
let t = e.indexOf("'", i + 1);
|
|
15
|
+
i = t === -1 ? r : t + 1;
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
if (n !== "{") {
|
|
19
|
+
i += 1;
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
let a = o(i, r), c = e.slice(i + 1, a), l = /^\s*([A-Za-z0-9_]+)/.exec(c)?.[1];
|
|
23
|
+
l !== void 0 && t.add(l);
|
|
24
|
+
let u = c.indexOf(",");
|
|
25
|
+
if (u !== -1) {
|
|
26
|
+
let t = i + 1 + u;
|
|
27
|
+
for (; t < a;) if (e[t] === "{") {
|
|
28
|
+
let e = o(t, a);
|
|
29
|
+
s(t + 1, e), t = e + 1;
|
|
30
|
+
} else t += 1;
|
|
31
|
+
}
|
|
32
|
+
i = a + 1;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
return s(0, e.length), t;
|
|
36
|
+
}, i = (e) => {
|
|
37
|
+
let t = /* @__PURE__ */ new Map(), n = [];
|
|
38
|
+
for (let r = 0; r < e.length; r += 1) {
|
|
39
|
+
let i = e[r];
|
|
40
|
+
if (i === "'") {
|
|
41
|
+
let t = e.indexOf("'", r + 1);
|
|
42
|
+
if (t === -1) break;
|
|
43
|
+
r = t;
|
|
44
|
+
} else if (i === "{") n.push(r);
|
|
45
|
+
else if (i === "}") {
|
|
46
|
+
let e = n.pop();
|
|
47
|
+
e !== void 0 && t.set(e, r);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return t;
|
|
51
|
+
}, a = (e, t, n) => {
|
|
52
|
+
let r = 0;
|
|
53
|
+
for (let i = t; i < n; i += 1) {
|
|
54
|
+
let t = e[i];
|
|
55
|
+
if (t === "'") {
|
|
56
|
+
let t = e.indexOf("'", i + 1);
|
|
57
|
+
if (t === -1) return n;
|
|
58
|
+
i = t;
|
|
59
|
+
} else if (t === "{") r += 1;
|
|
60
|
+
else if (t === "}" && (--r, r === 0)) return i;
|
|
61
|
+
}
|
|
62
|
+
return n;
|
|
63
|
+
}, o = (e, t) => {
|
|
64
|
+
let n = Object.keys(e);
|
|
65
|
+
if (n.length < 2) return;
|
|
66
|
+
let i = t?.baseLocale ?? n[0], a = e[i] ?? {}, o = [], s = /* @__PURE__ */ new Map(), c = (e) => {
|
|
67
|
+
if (e.length < 128) return r(e);
|
|
68
|
+
let t = s.get(e);
|
|
69
|
+
if (t !== void 0) return t;
|
|
70
|
+
let n = r(e);
|
|
71
|
+
return s.set(e, n), n;
|
|
72
|
+
};
|
|
73
|
+
for (let [t, r] of Object.entries(a)) {
|
|
74
|
+
let a = c(r);
|
|
75
|
+
for (let r of n) {
|
|
76
|
+
if (r === i) continue;
|
|
77
|
+
let n = e[r]?.[t];
|
|
78
|
+
if (n === void 0) continue;
|
|
79
|
+
let s = c(n), l = [], u = [];
|
|
80
|
+
for (let e of a) s.has(e) || l.push(e);
|
|
81
|
+
for (let e of s) a.has(e) || u.push(e);
|
|
82
|
+
if (l.length > 0 || u.length > 0) {
|
|
83
|
+
let e = [l.length > 0 ? `missing {${l.join("}, {")}}` : "", u.length > 0 ? `unexpected {${u.join("}, {")}}` : ""].filter(Boolean);
|
|
84
|
+
o.push(`${r} '${t}': ${e.join("; ")} (base ${i} has {${[...a].join("}, {")}})`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (o.length === 0) return;
|
|
89
|
+
let l = `i18n placeholder parity — a translation dropped or renamed an ICU {var}; it would throw only in that locale, only when the message renders:\n ${o.join("\n ")}`;
|
|
90
|
+
if (t?.onMismatch === "warn") console.warn(l);
|
|
91
|
+
else throw Error(l);
|
|
92
|
+
};
|
|
93
|
+
//#endregion
|
|
94
|
+
export { o as assertCatalogParity, e as defineCatalog, t as defineLocale, n as pickCatalog, r as placeholdersOf };
|
package/dist/format.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { useRenderClock as e } from "./renderClock.js";
|
|
2
|
+
import { useLocale as t } from "./hooks.js";
|
|
3
|
+
import { dateTimeFormat as n, numberFormat as r, pluralRules as i, relativeTimeFormat as a } from "./formatterCache.js";
|
|
4
|
+
import { useCallback as o, useMemo as s } from "react";
|
|
5
|
+
import { useIntl as c } from "react-intl";
|
|
6
|
+
//#region src/format.ts
|
|
7
|
+
var l = (e, t, n, r) => {
|
|
8
|
+
if (t === 0 && n.zero !== void 0) return n.zero.replace(/\{count\}/g, String(t));
|
|
9
|
+
let a = "other";
|
|
10
|
+
try {
|
|
11
|
+
a = i(e, r).select(t);
|
|
12
|
+
} catch {}
|
|
13
|
+
return (n[a] ?? n.other).replace(/\{count\}/g, String(t));
|
|
14
|
+
}, u = () => {
|
|
15
|
+
let e = t();
|
|
16
|
+
return o((t, n, r) => l(e, t, n, r), [e]);
|
|
17
|
+
}, d = (e) => e instanceof Date ? e : new Date(e), f = (e) => e != null, p = () => c().timeZone, m = (e, t, r, i) => {
|
|
18
|
+
let { fallback: a = "", ...o } = i ?? {};
|
|
19
|
+
if (!f(r)) return a;
|
|
20
|
+
let s = d(r);
|
|
21
|
+
if (Number.isNaN(s.getTime())) return a;
|
|
22
|
+
try {
|
|
23
|
+
return n(e, {
|
|
24
|
+
...t ? { timeZone: t } : {},
|
|
25
|
+
...o
|
|
26
|
+
}).format(s);
|
|
27
|
+
} catch {
|
|
28
|
+
return String(r);
|
|
29
|
+
}
|
|
30
|
+
}, h = () => {
|
|
31
|
+
let e = t(), n = p();
|
|
32
|
+
return o((t, r) => m(e, n, t, r), [e, n]);
|
|
33
|
+
}, g = [
|
|
34
|
+
["year", 31536e6],
|
|
35
|
+
["month", 2592e6],
|
|
36
|
+
["week", 6048e5],
|
|
37
|
+
["day", 864e5],
|
|
38
|
+
["hour", 36e5],
|
|
39
|
+
["minute", 6e4],
|
|
40
|
+
["second", 1e3]
|
|
41
|
+
], _ = () => {
|
|
42
|
+
let n = t(), r = e();
|
|
43
|
+
return o((e, t) => {
|
|
44
|
+
let { now: i, fallback: o = "", ...s } = t ?? {};
|
|
45
|
+
if (!f(e)) return o;
|
|
46
|
+
let c = d(e).getTime();
|
|
47
|
+
if (Number.isNaN(c)) return o;
|
|
48
|
+
let l = c - (i === void 0 ? r ?? Date.now() : d(i).getTime());
|
|
49
|
+
try {
|
|
50
|
+
let e = a(n, {
|
|
51
|
+
numeric: "auto",
|
|
52
|
+
...s
|
|
53
|
+
});
|
|
54
|
+
for (let [t, n] of g) if (Math.abs(l) >= n || t === "second") return e.format(Math.round(l / n), t);
|
|
55
|
+
return e.format(0, "second");
|
|
56
|
+
} catch {
|
|
57
|
+
return String(e);
|
|
58
|
+
}
|
|
59
|
+
}, [n, r]);
|
|
60
|
+
}, v = () => {
|
|
61
|
+
let e = t();
|
|
62
|
+
return o((t, n) => {
|
|
63
|
+
try {
|
|
64
|
+
return r(e, n).format(t);
|
|
65
|
+
} catch {
|
|
66
|
+
return String(t);
|
|
67
|
+
}
|
|
68
|
+
}, [e]);
|
|
69
|
+
}, y = (e) => {
|
|
70
|
+
let t = v();
|
|
71
|
+
return o((n, r) => t(n, {
|
|
72
|
+
style: "currency",
|
|
73
|
+
currency: e,
|
|
74
|
+
...r
|
|
75
|
+
}), [t, e]);
|
|
76
|
+
}, b = () => {
|
|
77
|
+
let e = t(), n = p(), r = h(), i = _(), a = v(), o = u();
|
|
78
|
+
return s(() => ({
|
|
79
|
+
locale: e,
|
|
80
|
+
timeZone: n,
|
|
81
|
+
formatDate: r,
|
|
82
|
+
relativeTime: i,
|
|
83
|
+
formatNumber: a,
|
|
84
|
+
plural: o
|
|
85
|
+
}), [
|
|
86
|
+
e,
|
|
87
|
+
n,
|
|
88
|
+
r,
|
|
89
|
+
i,
|
|
90
|
+
a,
|
|
91
|
+
o
|
|
92
|
+
]);
|
|
93
|
+
};
|
|
94
|
+
//#endregion
|
|
95
|
+
export { m as formatDateValue, l as plural, y as useFormatCurrency, h as useFormatDate, v as useFormatNumber, b as useFormatters, u as usePlural, _ as useRelativeTime, p as useTimeZone };
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
//#region src/formatterCache.ts
|
|
2
|
+
var e = (e, t, n = () => !0) => {
|
|
3
|
+
let r = /* @__PURE__ */ new Map(), i = new Set(e), a = t();
|
|
4
|
+
return (o, s) => {
|
|
5
|
+
let c = t();
|
|
6
|
+
c !== a && (r.clear(), a = c);
|
|
7
|
+
let l;
|
|
8
|
+
if (s === void 0) n(s) && (l = JSON.stringify([o, ...e.map(() => null)]));
|
|
9
|
+
else if (Object.getPrototypeOf(s) === Object.prototype || Object.getPrototypeOf(s) === null) {
|
|
10
|
+
let t = Object.getOwnPropertyDescriptors(s);
|
|
11
|
+
Reflect.ownKeys(t).every((e) => {
|
|
12
|
+
let n = t[e];
|
|
13
|
+
return i.has(e) && n !== void 0 && "value" in n && (n.value === void 0 || typeof n.value == "string" || typeof n.value == "boolean" || typeof n.value == "number" && Number.isFinite(n.value));
|
|
14
|
+
}) && e.every((e) => Object.hasOwn(s, e) || !(e in s)) && n(s) && (l = JSON.stringify([o, ...e.map((e) => t[e]?.value ?? null)]));
|
|
15
|
+
}
|
|
16
|
+
if (l === void 0) return new c(o, s);
|
|
17
|
+
let u = r.get(l);
|
|
18
|
+
if (u !== void 0) return r.delete(l), r.set(l, u), u;
|
|
19
|
+
let d = new c(o, s);
|
|
20
|
+
if (r.set(l, d), r.size > 128) {
|
|
21
|
+
let e = r.keys().next();
|
|
22
|
+
e.done || r.delete(e.value);
|
|
23
|
+
}
|
|
24
|
+
return d;
|
|
25
|
+
};
|
|
26
|
+
}, t = [
|
|
27
|
+
"minimumIntegerDigits",
|
|
28
|
+
"minimumFractionDigits",
|
|
29
|
+
"maximumFractionDigits",
|
|
30
|
+
"minimumSignificantDigits",
|
|
31
|
+
"maximumSignificantDigits"
|
|
32
|
+
], n = e([
|
|
33
|
+
"localeMatcher",
|
|
34
|
+
"type",
|
|
35
|
+
...t
|
|
36
|
+
], () => Intl.PluralRules), r = e([
|
|
37
|
+
"localeMatcher",
|
|
38
|
+
"calendar",
|
|
39
|
+
"numberingSystem",
|
|
40
|
+
"hour12",
|
|
41
|
+
"hourCycle",
|
|
42
|
+
"timeZone",
|
|
43
|
+
"weekday",
|
|
44
|
+
"era",
|
|
45
|
+
"year",
|
|
46
|
+
"month",
|
|
47
|
+
"day",
|
|
48
|
+
"hour",
|
|
49
|
+
"minute",
|
|
50
|
+
"second",
|
|
51
|
+
"fractionalSecondDigits",
|
|
52
|
+
"timeZoneName",
|
|
53
|
+
"formatMatcher",
|
|
54
|
+
"dateStyle",
|
|
55
|
+
"timeStyle",
|
|
56
|
+
"dayPeriod"
|
|
57
|
+
], () => Intl.DateTimeFormat, (e) => typeof e?.timeZone == "string"), i = e([
|
|
58
|
+
"localeMatcher",
|
|
59
|
+
"numberingSystem",
|
|
60
|
+
"style",
|
|
61
|
+
"currency",
|
|
62
|
+
"currencyDisplay",
|
|
63
|
+
"currencySign",
|
|
64
|
+
"unit",
|
|
65
|
+
"unitDisplay",
|
|
66
|
+
"notation",
|
|
67
|
+
"compactDisplay",
|
|
68
|
+
"useGrouping",
|
|
69
|
+
"signDisplay",
|
|
70
|
+
...t,
|
|
71
|
+
"roundingPriority",
|
|
72
|
+
"roundingIncrement",
|
|
73
|
+
"roundingMode",
|
|
74
|
+
"trailingZeroDisplay"
|
|
75
|
+
], () => Intl.NumberFormat), a = e([
|
|
76
|
+
"localeMatcher",
|
|
77
|
+
"numeric",
|
|
78
|
+
"style"
|
|
79
|
+
], () => Intl.RelativeTimeFormat);
|
|
80
|
+
//#endregion
|
|
81
|
+
export { r as dateTimeFormat, i as numberFormat, n as pluralRules, a as relativeTimeFormat };
|
package/dist/hooks.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { useCallback as e } from "react";
|
|
2
|
+
import { useIntl as t } from "react-intl";
|
|
3
|
+
//#region src/hooks.ts
|
|
4
|
+
var n = (e, n) => t().formatMessage({ id: e }, n), r = () => t().locale, i = () => t().messages, a = () => {
|
|
5
|
+
let n = t();
|
|
6
|
+
return e((e, t) => n.formatMessage({ id: e }, t), [n]);
|
|
7
|
+
};
|
|
8
|
+
//#endregion
|
|
9
|
+
export { r as useLocale, i as useMessages, n as useT, a as useTFn };
|