@voltro/i18n 0.84.0 → 0.86.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 +1215 -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 -305
- 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 +7 -0
- package/dist/server.js +44 -35
- 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 };
|
package/dist/index.js
CHANGED
|
@@ -1,305 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
if (e?.[1] !== void 0) return e[1];
|
|
17
|
-
}
|
|
18
|
-
} catch {}
|
|
19
|
-
return "unknown";
|
|
20
|
-
}, b = (e) => {
|
|
21
|
-
v().records.push({
|
|
22
|
-
file: y(),
|
|
23
|
-
intlProvider: e
|
|
24
|
-
});
|
|
25
|
-
}, x = () => {
|
|
26
|
-
let e = globalThis[_]?.records ?? [];
|
|
27
|
-
return {
|
|
28
|
-
instances: e.length,
|
|
29
|
-
reactIntlCopies: new Set(e.map((e) => e.intlProvider)).size,
|
|
30
|
-
files: [...new Set(e.map((e) => e.file))]
|
|
31
|
-
};
|
|
32
|
-
}, S = o(void 0), C = () => l(S);
|
|
33
|
-
//#endregion
|
|
34
|
-
//#region src/provider.tsx
|
|
35
|
-
b(m);
|
|
36
|
-
var w = ({ locale: e, messages: t, defaultLocale: n, silenceMissingTranslations: i = !0, timeZone: a, renderedAt: o, intlConfig: s, children: c }) => {
|
|
37
|
-
let l = i ? (e) => {
|
|
38
|
-
e.code !== "MISSING_TRANSLATION" && console.error(e);
|
|
39
|
-
} : void 0, [d, p] = f(!1);
|
|
40
|
-
u(() => {
|
|
41
|
-
o !== void 0 && p(!0);
|
|
42
|
-
}, [o]);
|
|
43
|
-
let h = d ? void 0 : o, _ = r(a) ? a : void 0;
|
|
44
|
-
return /* @__PURE__ */ g(m, {
|
|
45
|
-
locale: e,
|
|
46
|
-
defaultLocale: n,
|
|
47
|
-
messages: t,
|
|
48
|
-
...l ? { onError: l } : {},
|
|
49
|
-
..._ ? { timeZone: _ } : {},
|
|
50
|
-
...s,
|
|
51
|
-
children: /* @__PURE__ */ g(S.Provider, {
|
|
52
|
-
value: h,
|
|
53
|
-
children: c
|
|
54
|
-
})
|
|
55
|
-
});
|
|
56
|
-
}, T = ({ id: e, ...t }) => /* @__PURE__ */ g(p, {
|
|
57
|
-
id: e,
|
|
58
|
-
...t
|
|
59
|
-
}), E = (e, t) => h().formatMessage({ id: e }, t), D = () => h().locale, O = () => h().messages, k = () => {
|
|
60
|
-
let e = h();
|
|
61
|
-
return c((t, n) => e.formatMessage({ id: t }, n), [e]);
|
|
62
|
-
}, A = (e, t, n, r) => {
|
|
63
|
-
if (t === 0 && n.zero !== void 0) return n.zero.replace(/\{count\}/g, String(t));
|
|
64
|
-
let i = "other";
|
|
65
|
-
try {
|
|
66
|
-
i = new Intl.PluralRules(e, r).select(t);
|
|
67
|
-
} catch {}
|
|
68
|
-
return (n[i] ?? n.other).replace(/\{count\}/g, String(t));
|
|
69
|
-
}, j = () => {
|
|
70
|
-
let e = D();
|
|
71
|
-
return c((t, n, r) => A(e, t, n, r), [e]);
|
|
72
|
-
}, M = (e) => e instanceof Date ? e : new Date(e), N = (e) => e != null, P = () => h().timeZone, F = (e, t, n, r) => {
|
|
73
|
-
let { fallback: i = "", ...a } = r ?? {};
|
|
74
|
-
if (!N(n)) return i;
|
|
75
|
-
let o = M(n);
|
|
76
|
-
if (Number.isNaN(o.getTime())) return i;
|
|
77
|
-
try {
|
|
78
|
-
return new Intl.DateTimeFormat(e, {
|
|
79
|
-
...t ? { timeZone: t } : {},
|
|
80
|
-
...a
|
|
81
|
-
}).format(o);
|
|
82
|
-
} catch {
|
|
83
|
-
return String(n);
|
|
84
|
-
}
|
|
85
|
-
}, I = () => {
|
|
86
|
-
let e = D(), t = P();
|
|
87
|
-
return c((n, r) => F(e, t, n, r), [e, t]);
|
|
88
|
-
}, L = [
|
|
89
|
-
["year", 31536e6],
|
|
90
|
-
["month", 2592e6],
|
|
91
|
-
["week", 6048e5],
|
|
92
|
-
["day", 864e5],
|
|
93
|
-
["hour", 36e5],
|
|
94
|
-
["minute", 6e4],
|
|
95
|
-
["second", 1e3]
|
|
96
|
-
], R = () => {
|
|
97
|
-
let e = D(), t = C();
|
|
98
|
-
return c((n, r) => {
|
|
99
|
-
let { now: i, fallback: a = "", ...o } = r ?? {};
|
|
100
|
-
if (!N(n)) return a;
|
|
101
|
-
let s = M(n).getTime();
|
|
102
|
-
if (Number.isNaN(s)) return a;
|
|
103
|
-
let c = s - (i === void 0 ? t ?? Date.now() : M(i).getTime());
|
|
104
|
-
try {
|
|
105
|
-
let t = new Intl.RelativeTimeFormat(e, {
|
|
106
|
-
numeric: "auto",
|
|
107
|
-
...o
|
|
108
|
-
});
|
|
109
|
-
for (let [e, n] of L) if (Math.abs(c) >= n || e === "second") return t.format(Math.round(c / n), e);
|
|
110
|
-
return t.format(0, "second");
|
|
111
|
-
} catch {
|
|
112
|
-
return String(n);
|
|
113
|
-
}
|
|
114
|
-
}, [e, t]);
|
|
115
|
-
}, z = () => {
|
|
116
|
-
let e = D();
|
|
117
|
-
return c((t, n) => {
|
|
118
|
-
try {
|
|
119
|
-
return new Intl.NumberFormat(e, n).format(t);
|
|
120
|
-
} catch {
|
|
121
|
-
return String(t);
|
|
122
|
-
}
|
|
123
|
-
}, [e]);
|
|
124
|
-
}, B = (e) => {
|
|
125
|
-
let t = z();
|
|
126
|
-
return c((n, r) => t(n, {
|
|
127
|
-
style: "currency",
|
|
128
|
-
currency: e,
|
|
129
|
-
...r
|
|
130
|
-
}), [t, e]);
|
|
131
|
-
}, V = () => {
|
|
132
|
-
let e = D(), t = P(), n = I(), r = R(), i = z(), a = j();
|
|
133
|
-
return d(() => ({
|
|
134
|
-
locale: e,
|
|
135
|
-
timeZone: t,
|
|
136
|
-
formatDate: n,
|
|
137
|
-
relativeTime: r,
|
|
138
|
-
formatNumber: i,
|
|
139
|
-
plural: a
|
|
140
|
-
}), [
|
|
141
|
-
e,
|
|
142
|
-
t,
|
|
143
|
-
n,
|
|
144
|
-
r,
|
|
145
|
-
i,
|
|
146
|
-
a
|
|
147
|
-
]);
|
|
148
|
-
}, H = (e) => e, U = () => (e) => e, W = (e, t, n) => e[t ?? n] ?? e[n], G = (e) => {
|
|
149
|
-
let t = /* @__PURE__ */ new Set(), n = (r, i) => {
|
|
150
|
-
let a = r;
|
|
151
|
-
for (; a < i;) {
|
|
152
|
-
let r = e[a];
|
|
153
|
-
if (r === "'") {
|
|
154
|
-
let t = e.indexOf("'", a + 1);
|
|
155
|
-
a = t === -1 ? i : t + 1;
|
|
156
|
-
continue;
|
|
157
|
-
}
|
|
158
|
-
if (r !== "{") {
|
|
159
|
-
a += 1;
|
|
160
|
-
continue;
|
|
161
|
-
}
|
|
162
|
-
let o = K(e, a, i), s = e.slice(a + 1, o), c = /^\s*([A-Za-z0-9_]+)/.exec(s)?.[1];
|
|
163
|
-
c !== void 0 && t.add(c);
|
|
164
|
-
let l = s.indexOf(",");
|
|
165
|
-
if (l !== -1) {
|
|
166
|
-
let t = a + 1 + l;
|
|
167
|
-
for (; t < o;) if (e[t] === "{") {
|
|
168
|
-
let r = K(e, t, o);
|
|
169
|
-
n(t + 1, r), t = r + 1;
|
|
170
|
-
} else t += 1;
|
|
171
|
-
}
|
|
172
|
-
a = o + 1;
|
|
173
|
-
}
|
|
174
|
-
};
|
|
175
|
-
return n(0, e.length), t;
|
|
176
|
-
}, K = (e, t, n) => {
|
|
177
|
-
let r = 0;
|
|
178
|
-
for (let i = t; i < n; i += 1) {
|
|
179
|
-
let t = e[i];
|
|
180
|
-
if (t === "'") {
|
|
181
|
-
let t = e.indexOf("'", i + 1);
|
|
182
|
-
if (t === -1) return n;
|
|
183
|
-
i = t;
|
|
184
|
-
continue;
|
|
185
|
-
}
|
|
186
|
-
if (t === "{") r += 1;
|
|
187
|
-
else if (t === "}" && (--r, r === 0)) return i;
|
|
188
|
-
}
|
|
189
|
-
return n;
|
|
190
|
-
}, q = (e, t) => {
|
|
191
|
-
let n = Object.keys(e);
|
|
192
|
-
if (n.length < 2) return;
|
|
193
|
-
let r = t?.baseLocale ?? n[0], i = e[r] ?? {}, a = [];
|
|
194
|
-
for (let [t, o] of Object.entries(i)) {
|
|
195
|
-
let i = G(o);
|
|
196
|
-
for (let o of n) {
|
|
197
|
-
if (o === r) continue;
|
|
198
|
-
let n = e[o]?.[t];
|
|
199
|
-
if (n === void 0) continue;
|
|
200
|
-
let s = G(n), c = [...i].filter((e) => !s.has(e)), l = [...s].filter((e) => !i.has(e));
|
|
201
|
-
if (c.length > 0 || l.length > 0) {
|
|
202
|
-
let e = [c.length > 0 ? `missing {${c.join("}, {")}}` : "", l.length > 0 ? `unexpected {${l.join("}, {")}}` : ""].filter(Boolean);
|
|
203
|
-
a.push(`${o} '${t}': ${e.join("; ")} (base ${r} has {${[...i].join("}, {")}})`);
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
if (a.length === 0) return;
|
|
208
|
-
let o = `i18n placeholder parity — a translation dropped or renamed an ICU {var}; it would throw only in that locale, only when the message renders:\n ${a.join("\n ")}`;
|
|
209
|
-
if (t?.onMismatch === "warn") {
|
|
210
|
-
console.warn(o);
|
|
211
|
-
return;
|
|
212
|
-
}
|
|
213
|
-
throw Error(o);
|
|
214
|
-
}, J = (e) => {
|
|
215
|
-
let t = e;
|
|
216
|
-
return t.dynamic === void 0 && (t.dynamic = (t, n) => e(t, n)), t;
|
|
217
|
-
}, Y = () => ({
|
|
218
|
-
useT: J((e, t) => E(e, t)),
|
|
219
|
-
useTFn: (() => J(k())),
|
|
220
|
-
T
|
|
221
|
-
}), X = (e) => "default" in e && typeof e.default == "object" ? e.default : e, Z = (e, t) => {
|
|
222
|
-
let n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(), i = (n) => n && n in e ? n : t, a = (t) => {
|
|
223
|
-
let a = i(t), o = n.get(a);
|
|
224
|
-
if (o) return Promise.resolve(o);
|
|
225
|
-
let s = r.get(a);
|
|
226
|
-
if (s) return s;
|
|
227
|
-
let c = e[a], l = c().then((e) => {
|
|
228
|
-
let t = X(e);
|
|
229
|
-
return n.set(a, t), r.delete(a), t;
|
|
230
|
-
}).catch((e) => {
|
|
231
|
-
throw r.delete(a), e;
|
|
232
|
-
});
|
|
233
|
-
return r.set(a, l), l;
|
|
234
|
-
};
|
|
235
|
-
return {
|
|
236
|
-
locales: Object.keys(e),
|
|
237
|
-
defaultLocale: t,
|
|
238
|
-
load: a,
|
|
239
|
-
peek: (e) => n.get(i(e)),
|
|
240
|
-
preload: (e) => {
|
|
241
|
-
a(e).catch(() => {});
|
|
242
|
-
}
|
|
243
|
-
};
|
|
244
|
-
}, Q = ({ catalogs: e, locale: t, fallback: n = null, silenceMissingTranslations: r, children: i }) => {
|
|
245
|
-
let [a, o] = f(() => e.peek(t));
|
|
246
|
-
return u(() => {
|
|
247
|
-
let n = e.peek(t);
|
|
248
|
-
if (n) {
|
|
249
|
-
o(n);
|
|
250
|
-
return;
|
|
251
|
-
}
|
|
252
|
-
let r = !0;
|
|
253
|
-
return o(void 0), e.load(t).then((e) => {
|
|
254
|
-
r && o(e);
|
|
255
|
-
}), () => {
|
|
256
|
-
r = !1;
|
|
257
|
-
};
|
|
258
|
-
}, [e, t]), a ? /* @__PURE__ */ g(w, {
|
|
259
|
-
locale: t,
|
|
260
|
-
messages: a,
|
|
261
|
-
defaultLocale: e.defaultLocale,
|
|
262
|
-
...r === void 0 ? {} : { silenceMissingTranslations: r },
|
|
263
|
-
children: i
|
|
264
|
-
}) : n;
|
|
265
|
-
}, $ = (e, t, n) => (r, i) => s(w, {
|
|
266
|
-
locale: e,
|
|
267
|
-
messages: t,
|
|
268
|
-
defaultLocale: n,
|
|
269
|
-
silenceMissingTranslations: !0,
|
|
270
|
-
...i?.timeZone === void 0 ? {} : { timeZone: i.timeZone },
|
|
271
|
-
...i?.renderedAt === void 0 ? {} : { renderedAt: i.renderedAt },
|
|
272
|
-
children: r
|
|
273
|
-
}), ee = 3456e4, te = (e) => {
|
|
274
|
-
if (!(typeof document > "u")) for (let t of document.cookie.split(";")) {
|
|
275
|
-
let n = t.indexOf("=");
|
|
276
|
-
if (!(n < 0) && t.slice(0, n).trim() === e) try {
|
|
277
|
-
return decodeURIComponent(t.slice(n + 1).trim());
|
|
278
|
-
} catch {
|
|
279
|
-
return;
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
}, ne = (e, t) => {
|
|
283
|
-
typeof document > "u" || (document.cookie = `${e}=${encodeURIComponent(t)}; path=/; max-age=${ee}; SameSite=Lax`);
|
|
284
|
-
}, re = ({ locales: e, current: t, onChange: n, ariaLabel: r = "Language", className: i }) => {
|
|
285
|
-
let [o, s] = f(void 0);
|
|
286
|
-
u(() => {
|
|
287
|
-
s(te(a));
|
|
288
|
-
}, []);
|
|
289
|
-
let c = t ?? o ?? e[0]?.code ?? "";
|
|
290
|
-
return /* @__PURE__ */ g("select", {
|
|
291
|
-
"aria-label": r,
|
|
292
|
-
value: c,
|
|
293
|
-
onChange: (e) => {
|
|
294
|
-
let t = e.target.value;
|
|
295
|
-
ne(a, t), s(t), n?.(t) !== !1 && typeof window < "u" && window.location.reload();
|
|
296
|
-
},
|
|
297
|
-
...i === void 0 ? {} : { className: i },
|
|
298
|
-
children: e.map((e) => /* @__PURE__ */ g("option", {
|
|
299
|
-
value: e.code,
|
|
300
|
-
children: e.label
|
|
301
|
-
}, e.code))
|
|
302
|
-
});
|
|
303
|
-
};
|
|
304
|
-
//#endregion
|
|
305
|
-
export { t as DEFAULT_TIME_ZONE, w as I18nProvider, a as LOCALE_COOKIE, Q as LazyI18nProvider, re as LocaleSwitcher, S as RenderClockContext, T, n as THEME_COOKIE, i as TIMEZONE_COOKIE, e as VIEWER_TIME_ZONE, q as assertCatalogParity, Y as createTypedMessages, H as defineCatalog, Z as defineCatalogs, U as defineLocale, x as i18nInstanceReport, r as isSupportedTimeZone, $ as makeSsgWrap, W as pickCatalog, G as placeholdersOf, A as plural, B as useFormatCurrency, I as useFormatDate, z as useFormatNumber, V as useFormatters, D as useLocale, O as useMessages, j as usePlural, R as useRelativeTime, C as useRenderClock, E as useT, k as useTFn, P as useTimeZone };
|
|
1
|
+
import { i18nInstanceReport as e } from "./instanceRegistry.js";
|
|
2
|
+
import { RenderClockContext as t, useRenderClock as n } from "./renderClock.js";
|
|
3
|
+
import { DEFAULT_TIME_ZONE as r, VIEWER_TIME_ZONE as i, isSupportedTimeZone as a } from "./timeZone.js";
|
|
4
|
+
import { I18nProvider as o } from "./provider.js";
|
|
5
|
+
import { T as s } from "./components.js";
|
|
6
|
+
import { useLocale as c, useMessages as l, useT as u, useTFn as d } from "./hooks.js";
|
|
7
|
+
import { plural as f, useFormatCurrency as p, useFormatDate as m, useFormatNumber as h, useFormatters as g, usePlural as _, useRelativeTime as v, useTimeZone as y } from "./format.js";
|
|
8
|
+
import { assertCatalogParity as b, defineCatalog as x, defineLocale as S, pickCatalog as C, placeholdersOf as w } from "./catalog.js";
|
|
9
|
+
import { createTypedMessages as T } from "./typed.js";
|
|
10
|
+
import { defineCatalogs as E } from "./lazyCatalog.js";
|
|
11
|
+
import { LazyI18nProvider as D } from "./lazyProvider.js";
|
|
12
|
+
import { makeSsgWrap as O } from "./ssgWrap.js";
|
|
13
|
+
import { LOCALE_COOKIE as k, THEME_COOKIE as A, TIMEZONE_COOKIE as j } from "./cookieNames.js";
|
|
14
|
+
import { LocaleSwitcher as M } from "./localeSwitcher.js";
|
|
15
|
+
export { r as DEFAULT_TIME_ZONE, o as I18nProvider, k as LOCALE_COOKIE, D as LazyI18nProvider, M as LocaleSwitcher, t as RenderClockContext, s as T, A as THEME_COOKIE, j as TIMEZONE_COOKIE, i as VIEWER_TIME_ZONE, b as assertCatalogParity, T as createTypedMessages, x as defineCatalog, E as defineCatalogs, S as defineLocale, e as i18nInstanceReport, a as isSupportedTimeZone, O as makeSsgWrap, C as pickCatalog, w as placeholdersOf, f as plural, p as useFormatCurrency, m as useFormatDate, h as useFormatNumber, g as useFormatters, c as useLocale, l as useMessages, _ as usePlural, v as useRelativeTime, n as useRenderClock, u as useT, d as useTFn, y as useTimeZone };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//#region src/instanceRegistry.ts
|
|
2
|
+
var e = "__voltro_i18n_instances__", t = () => {
|
|
3
|
+
let t = globalThis, n = t[e];
|
|
4
|
+
if (n !== void 0) return n;
|
|
5
|
+
let r = { records: [] };
|
|
6
|
+
return t[e] = r, r;
|
|
7
|
+
}, n = () => {
|
|
8
|
+
try {
|
|
9
|
+
let e = String((/* @__PURE__ */ Error()).stack ?? "").split("\n");
|
|
10
|
+
for (let t of e.slice(3)) {
|
|
11
|
+
let e = /\(?((?:file:\/\/|\/)[^\s)]+)/.exec(t);
|
|
12
|
+
if (e?.[1] !== void 0) return e[1];
|
|
13
|
+
}
|
|
14
|
+
} catch {}
|
|
15
|
+
return "unknown";
|
|
16
|
+
}, r = (e) => {
|
|
17
|
+
t().records.push({
|
|
18
|
+
file: n(),
|
|
19
|
+
intlProvider: e
|
|
20
|
+
});
|
|
21
|
+
}, i = () => {
|
|
22
|
+
let t = globalThis[e]?.records ?? [];
|
|
23
|
+
return {
|
|
24
|
+
instances: t.length,
|
|
25
|
+
reactIntlCopies: new Set(t.map((e) => e.intlProvider)).size,
|
|
26
|
+
files: [...new Set(t.map((e) => e.file))]
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
//#endregion
|
|
30
|
+
export { i as i18nInstanceReport, r as registerI18nInstance };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
//#region src/lazyCatalog.ts
|
|
2
|
+
var e = (e) => "default" in e && typeof e.default == "object" ? e.default : e, t = (t, n) => {
|
|
3
|
+
let r = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), a = (e) => e && e in t ? e : n, o = (n) => {
|
|
4
|
+
let o = a(n), s = r.get(o);
|
|
5
|
+
if (s) return Promise.resolve(s);
|
|
6
|
+
let c = i.get(o);
|
|
7
|
+
if (c) return c;
|
|
8
|
+
let l = t[o], u = l().then((t) => {
|
|
9
|
+
let n = e(t);
|
|
10
|
+
return r.set(o, n), i.delete(o), n;
|
|
11
|
+
}).catch((e) => {
|
|
12
|
+
throw i.delete(o), e;
|
|
13
|
+
});
|
|
14
|
+
return i.set(o, u), u;
|
|
15
|
+
};
|
|
16
|
+
return {
|
|
17
|
+
locales: Object.keys(t),
|
|
18
|
+
defaultLocale: n,
|
|
19
|
+
load: o,
|
|
20
|
+
peek: (e) => r.get(a(e)),
|
|
21
|
+
preload: (e) => {
|
|
22
|
+
o(e).catch(() => {});
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
//#endregion
|
|
27
|
+
export { t as defineCatalogs };
|