@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/dist/index.js
CHANGED
|
@@ -1,411 +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 = 128, j = (e, t, n = () => !0) => {
|
|
63
|
-
let r = /* @__PURE__ */ new Map(), i = new Set(e), a = t();
|
|
64
|
-
return (o, s) => {
|
|
65
|
-
let c = t();
|
|
66
|
-
c !== a && (r.clear(), a = c);
|
|
67
|
-
let l;
|
|
68
|
-
if (s === void 0) n(s) && (l = JSON.stringify([o, ...e.map(() => null)]));
|
|
69
|
-
else if (Object.getPrototypeOf(s) === Object.prototype || Object.getPrototypeOf(s) === null) {
|
|
70
|
-
let t = Object.getOwnPropertyDescriptors(s);
|
|
71
|
-
Reflect.ownKeys(t).every((e) => {
|
|
72
|
-
let n = t[e];
|
|
73
|
-
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));
|
|
74
|
-
}) && e.every((e) => Object.hasOwn(s, e) || !(e in s)) && n(s) && (l = JSON.stringify([o, ...e.map((e) => t[e]?.value ?? null)]));
|
|
75
|
-
}
|
|
76
|
-
if (l === void 0) return new c(o, s);
|
|
77
|
-
let u = r.get(l);
|
|
78
|
-
if (u !== void 0) return r.delete(l), r.set(l, u), u;
|
|
79
|
-
let d = new c(o, s);
|
|
80
|
-
if (r.set(l, d), r.size > A) {
|
|
81
|
-
let e = r.keys().next();
|
|
82
|
-
e.done || r.delete(e.value);
|
|
83
|
-
}
|
|
84
|
-
return d;
|
|
85
|
-
};
|
|
86
|
-
}, M = [
|
|
87
|
-
"minimumIntegerDigits",
|
|
88
|
-
"minimumFractionDigits",
|
|
89
|
-
"maximumFractionDigits",
|
|
90
|
-
"minimumSignificantDigits",
|
|
91
|
-
"maximumSignificantDigits"
|
|
92
|
-
], N = j([
|
|
93
|
-
"localeMatcher",
|
|
94
|
-
"type",
|
|
95
|
-
...M
|
|
96
|
-
], () => Intl.PluralRules), P = j([
|
|
97
|
-
"localeMatcher",
|
|
98
|
-
"calendar",
|
|
99
|
-
"numberingSystem",
|
|
100
|
-
"hour12",
|
|
101
|
-
"hourCycle",
|
|
102
|
-
"timeZone",
|
|
103
|
-
"weekday",
|
|
104
|
-
"era",
|
|
105
|
-
"year",
|
|
106
|
-
"month",
|
|
107
|
-
"day",
|
|
108
|
-
"hour",
|
|
109
|
-
"minute",
|
|
110
|
-
"second",
|
|
111
|
-
"fractionalSecondDigits",
|
|
112
|
-
"timeZoneName",
|
|
113
|
-
"formatMatcher",
|
|
114
|
-
"dateStyle",
|
|
115
|
-
"timeStyle",
|
|
116
|
-
"dayPeriod"
|
|
117
|
-
], () => Intl.DateTimeFormat, (e) => typeof e?.timeZone == "string"), F = j([
|
|
118
|
-
"localeMatcher",
|
|
119
|
-
"numberingSystem",
|
|
120
|
-
"style",
|
|
121
|
-
"currency",
|
|
122
|
-
"currencyDisplay",
|
|
123
|
-
"currencySign",
|
|
124
|
-
"unit",
|
|
125
|
-
"unitDisplay",
|
|
126
|
-
"notation",
|
|
127
|
-
"compactDisplay",
|
|
128
|
-
"useGrouping",
|
|
129
|
-
"signDisplay",
|
|
130
|
-
...M,
|
|
131
|
-
"roundingPriority",
|
|
132
|
-
"roundingIncrement",
|
|
133
|
-
"roundingMode",
|
|
134
|
-
"trailingZeroDisplay"
|
|
135
|
-
], () => Intl.NumberFormat), ee = j([
|
|
136
|
-
"localeMatcher",
|
|
137
|
-
"numeric",
|
|
138
|
-
"style"
|
|
139
|
-
], () => Intl.RelativeTimeFormat), I = (e, t, n, r) => {
|
|
140
|
-
if (t === 0 && n.zero !== void 0) return n.zero.replace(/\{count\}/g, String(t));
|
|
141
|
-
let i = "other";
|
|
142
|
-
try {
|
|
143
|
-
i = N(e, r).select(t);
|
|
144
|
-
} catch {}
|
|
145
|
-
return (n[i] ?? n.other).replace(/\{count\}/g, String(t));
|
|
146
|
-
}, L = () => {
|
|
147
|
-
let e = D();
|
|
148
|
-
return c((t, n, r) => I(e, t, n, r), [e]);
|
|
149
|
-
}, R = (e) => e instanceof Date ? e : new Date(e), z = (e) => e != null, B = () => h().timeZone, V = (e, t, n, r) => {
|
|
150
|
-
let { fallback: i = "", ...a } = r ?? {};
|
|
151
|
-
if (!z(n)) return i;
|
|
152
|
-
let o = R(n);
|
|
153
|
-
if (Number.isNaN(o.getTime())) return i;
|
|
154
|
-
try {
|
|
155
|
-
return P(e, {
|
|
156
|
-
...t ? { timeZone: t } : {},
|
|
157
|
-
...a
|
|
158
|
-
}).format(o);
|
|
159
|
-
} catch {
|
|
160
|
-
return String(n);
|
|
161
|
-
}
|
|
162
|
-
}, H = () => {
|
|
163
|
-
let e = D(), t = B();
|
|
164
|
-
return c((n, r) => V(e, t, n, r), [e, t]);
|
|
165
|
-
}, U = [
|
|
166
|
-
["year", 31536e6],
|
|
167
|
-
["month", 2592e6],
|
|
168
|
-
["week", 6048e5],
|
|
169
|
-
["day", 864e5],
|
|
170
|
-
["hour", 36e5],
|
|
171
|
-
["minute", 6e4],
|
|
172
|
-
["second", 1e3]
|
|
173
|
-
], W = () => {
|
|
174
|
-
let e = D(), t = C();
|
|
175
|
-
return c((n, r) => {
|
|
176
|
-
let { now: i, fallback: a = "", ...o } = r ?? {};
|
|
177
|
-
if (!z(n)) return a;
|
|
178
|
-
let s = R(n).getTime();
|
|
179
|
-
if (Number.isNaN(s)) return a;
|
|
180
|
-
let c = s - (i === void 0 ? t ?? Date.now() : R(i).getTime());
|
|
181
|
-
try {
|
|
182
|
-
let t = ee(e, {
|
|
183
|
-
numeric: "auto",
|
|
184
|
-
...o
|
|
185
|
-
});
|
|
186
|
-
for (let [e, n] of U) if (Math.abs(c) >= n || e === "second") return t.format(Math.round(c / n), e);
|
|
187
|
-
return t.format(0, "second");
|
|
188
|
-
} catch {
|
|
189
|
-
return String(n);
|
|
190
|
-
}
|
|
191
|
-
}, [e, t]);
|
|
192
|
-
}, G = () => {
|
|
193
|
-
let e = D();
|
|
194
|
-
return c((t, n) => {
|
|
195
|
-
try {
|
|
196
|
-
return F(e, n).format(t);
|
|
197
|
-
} catch {
|
|
198
|
-
return String(t);
|
|
199
|
-
}
|
|
200
|
-
}, [e]);
|
|
201
|
-
}, K = (e) => {
|
|
202
|
-
let t = G();
|
|
203
|
-
return c((n, r) => t(n, {
|
|
204
|
-
style: "currency",
|
|
205
|
-
currency: e,
|
|
206
|
-
...r
|
|
207
|
-
}), [t, e]);
|
|
208
|
-
}, q = () => {
|
|
209
|
-
let e = D(), t = B(), n = H(), r = W(), i = G(), a = L();
|
|
210
|
-
return d(() => ({
|
|
211
|
-
locale: e,
|
|
212
|
-
timeZone: t,
|
|
213
|
-
formatDate: n,
|
|
214
|
-
relativeTime: r,
|
|
215
|
-
formatNumber: i,
|
|
216
|
-
plural: a
|
|
217
|
-
}), [
|
|
218
|
-
e,
|
|
219
|
-
t,
|
|
220
|
-
n,
|
|
221
|
-
r,
|
|
222
|
-
i,
|
|
223
|
-
a
|
|
224
|
-
]);
|
|
225
|
-
}, J = (e) => e, Y = () => (e) => e, X = (e, t, n) => e[t ?? n] ?? e[n], Z = (e) => {
|
|
226
|
-
let t = /* @__PURE__ */ new Set();
|
|
227
|
-
if (!e.includes("{")) return t;
|
|
228
|
-
let n = 0, r, i = (t, i) => {
|
|
229
|
-
e.length >= 1024 && ++n === 4 && (r = Q(e));
|
|
230
|
-
let a = r?.get(t);
|
|
231
|
-
return a === void 0 ? te(e, t, i) : Math.min(a, i);
|
|
232
|
-
}, a = (n, r) => {
|
|
233
|
-
let o = n;
|
|
234
|
-
for (; o < r;) {
|
|
235
|
-
let n = e[o];
|
|
236
|
-
if (n === "'") {
|
|
237
|
-
let t = e.indexOf("'", o + 1);
|
|
238
|
-
o = t === -1 ? r : t + 1;
|
|
239
|
-
continue;
|
|
240
|
-
}
|
|
241
|
-
if (n !== "{") {
|
|
242
|
-
o += 1;
|
|
243
|
-
continue;
|
|
244
|
-
}
|
|
245
|
-
let s = i(o, r), c = e.slice(o + 1, s), l = /^\s*([A-Za-z0-9_]+)/.exec(c)?.[1];
|
|
246
|
-
l !== void 0 && t.add(l);
|
|
247
|
-
let u = c.indexOf(",");
|
|
248
|
-
if (u !== -1) {
|
|
249
|
-
let t = o + 1 + u;
|
|
250
|
-
for (; t < s;) if (e[t] === "{") {
|
|
251
|
-
let e = i(t, s);
|
|
252
|
-
a(t + 1, e), t = e + 1;
|
|
253
|
-
} else t += 1;
|
|
254
|
-
}
|
|
255
|
-
o = s + 1;
|
|
256
|
-
}
|
|
257
|
-
};
|
|
258
|
-
return a(0, e.length), t;
|
|
259
|
-
}, Q = (e) => {
|
|
260
|
-
let t = /* @__PURE__ */ new Map(), n = [];
|
|
261
|
-
for (let r = 0; r < e.length; r += 1) {
|
|
262
|
-
let i = e[r];
|
|
263
|
-
if (i === "'") {
|
|
264
|
-
let t = e.indexOf("'", r + 1);
|
|
265
|
-
if (t === -1) break;
|
|
266
|
-
r = t;
|
|
267
|
-
} else if (i === "{") n.push(r);
|
|
268
|
-
else if (i === "}") {
|
|
269
|
-
let e = n.pop();
|
|
270
|
-
e !== void 0 && t.set(e, r);
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
return t;
|
|
274
|
-
}, te = (e, t, n) => {
|
|
275
|
-
let r = 0;
|
|
276
|
-
for (let i = t; i < n; i += 1) {
|
|
277
|
-
let t = e[i];
|
|
278
|
-
if (t === "'") {
|
|
279
|
-
let t = e.indexOf("'", i + 1);
|
|
280
|
-
if (t === -1) return n;
|
|
281
|
-
i = t;
|
|
282
|
-
continue;
|
|
283
|
-
}
|
|
284
|
-
if (t === "{") r += 1;
|
|
285
|
-
else if (t === "}" && (--r, r === 0)) return i;
|
|
286
|
-
}
|
|
287
|
-
return n;
|
|
288
|
-
}, ne = (e, t) => {
|
|
289
|
-
let n = Object.keys(e);
|
|
290
|
-
if (n.length < 2) return;
|
|
291
|
-
let r = t?.baseLocale ?? n[0], i = e[r] ?? {}, a = [], o = /* @__PURE__ */ new Map(), s = (e) => {
|
|
292
|
-
if (e.length < 128) return Z(e);
|
|
293
|
-
let t = o.get(e);
|
|
294
|
-
if (t !== void 0) return t;
|
|
295
|
-
let n = Z(e);
|
|
296
|
-
return o.set(e, n), n;
|
|
297
|
-
};
|
|
298
|
-
for (let [t, o] of Object.entries(i)) {
|
|
299
|
-
let i = s(o);
|
|
300
|
-
for (let o of n) {
|
|
301
|
-
if (o === r) continue;
|
|
302
|
-
let n = e[o]?.[t];
|
|
303
|
-
if (n === void 0) continue;
|
|
304
|
-
let c = s(n), l = [], u = [];
|
|
305
|
-
for (let e of i) c.has(e) || l.push(e);
|
|
306
|
-
for (let e of c) i.has(e) || u.push(e);
|
|
307
|
-
if (l.length > 0 || u.length > 0) {
|
|
308
|
-
let e = [l.length > 0 ? `missing {${l.join("}, {")}}` : "", u.length > 0 ? `unexpected {${u.join("}, {")}}` : ""].filter(Boolean);
|
|
309
|
-
a.push(`${o} '${t}': ${e.join("; ")} (base ${r} has {${[...i].join("}, {")}})`);
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
if (a.length === 0) return;
|
|
314
|
-
let c = `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 ")}`;
|
|
315
|
-
if (t?.onMismatch === "warn") {
|
|
316
|
-
console.warn(c);
|
|
317
|
-
return;
|
|
318
|
-
}
|
|
319
|
-
throw Error(c);
|
|
320
|
-
}, $ = (e) => {
|
|
321
|
-
let t = e;
|
|
322
|
-
return t.dynamic === void 0 && (t.dynamic = (t, n) => e(t, n)), t;
|
|
323
|
-
}, re = () => ({
|
|
324
|
-
useT: $((e, t) => E(e, t)),
|
|
325
|
-
useTFn: (() => $(k())),
|
|
326
|
-
T
|
|
327
|
-
}), ie = (e) => "default" in e && typeof e.default == "object" ? e.default : e, ae = (e, t) => {
|
|
328
|
-
let n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(), i = (n) => n && n in e ? n : t, a = (t) => {
|
|
329
|
-
let a = i(t), o = n.get(a);
|
|
330
|
-
if (o) return Promise.resolve(o);
|
|
331
|
-
let s = r.get(a);
|
|
332
|
-
if (s) return s;
|
|
333
|
-
let c = e[a], l = c().then((e) => {
|
|
334
|
-
let t = ie(e);
|
|
335
|
-
return n.set(a, t), r.delete(a), t;
|
|
336
|
-
}).catch((e) => {
|
|
337
|
-
throw r.delete(a), e;
|
|
338
|
-
});
|
|
339
|
-
return r.set(a, l), l;
|
|
340
|
-
};
|
|
341
|
-
return {
|
|
342
|
-
locales: Object.keys(e),
|
|
343
|
-
defaultLocale: t,
|
|
344
|
-
load: a,
|
|
345
|
-
peek: (e) => n.get(i(e)),
|
|
346
|
-
preload: (e) => {
|
|
347
|
-
a(e).catch(() => {});
|
|
348
|
-
}
|
|
349
|
-
};
|
|
350
|
-
}, oe = ({ catalogs: e, locale: t, fallback: n = null, silenceMissingTranslations: r, children: i }) => {
|
|
351
|
-
let [a, o] = f(() => e.peek(t));
|
|
352
|
-
return u(() => {
|
|
353
|
-
let n = e.peek(t);
|
|
354
|
-
if (n) {
|
|
355
|
-
o(n);
|
|
356
|
-
return;
|
|
357
|
-
}
|
|
358
|
-
let r = !0;
|
|
359
|
-
return o(void 0), e.load(t).then((e) => {
|
|
360
|
-
r && o(e);
|
|
361
|
-
}), () => {
|
|
362
|
-
r = !1;
|
|
363
|
-
};
|
|
364
|
-
}, [e, t]), a ? /* @__PURE__ */ g(w, {
|
|
365
|
-
locale: t,
|
|
366
|
-
messages: a,
|
|
367
|
-
defaultLocale: e.defaultLocale,
|
|
368
|
-
...r === void 0 ? {} : { silenceMissingTranslations: r },
|
|
369
|
-
children: i
|
|
370
|
-
}) : n;
|
|
371
|
-
}, se = (e, t, n) => (r, i) => s(w, {
|
|
372
|
-
locale: e,
|
|
373
|
-
messages: t,
|
|
374
|
-
defaultLocale: n,
|
|
375
|
-
silenceMissingTranslations: !0,
|
|
376
|
-
...i?.timeZone === void 0 ? {} : { timeZone: i.timeZone },
|
|
377
|
-
...i?.renderedAt === void 0 ? {} : { renderedAt: i.renderedAt },
|
|
378
|
-
children: r
|
|
379
|
-
}), ce = 3456e4, le = (e) => {
|
|
380
|
-
if (!(typeof document > "u")) for (let t of document.cookie.split(";")) {
|
|
381
|
-
let n = t.indexOf("=");
|
|
382
|
-
if (!(n < 0) && t.slice(0, n).trim() === e) try {
|
|
383
|
-
return decodeURIComponent(t.slice(n + 1).trim());
|
|
384
|
-
} catch {
|
|
385
|
-
return;
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
}, ue = (e, t) => {
|
|
389
|
-
typeof document > "u" || (document.cookie = `${e}=${encodeURIComponent(t)}; path=/; max-age=${ce}; SameSite=Lax`);
|
|
390
|
-
}, de = ({ locales: e, current: t, onChange: n, ariaLabel: r = "Language", className: i }) => {
|
|
391
|
-
let [o, s] = f(void 0);
|
|
392
|
-
u(() => {
|
|
393
|
-
s(le(a));
|
|
394
|
-
}, []);
|
|
395
|
-
let c = t ?? o ?? e[0]?.code ?? "";
|
|
396
|
-
return /* @__PURE__ */ g("select", {
|
|
397
|
-
"aria-label": r,
|
|
398
|
-
value: c,
|
|
399
|
-
onChange: (e) => {
|
|
400
|
-
let t = e.target.value;
|
|
401
|
-
ue(a, t), s(t), n?.(t) !== !1 && typeof window < "u" && window.location.reload();
|
|
402
|
-
},
|
|
403
|
-
...i === void 0 ? {} : { className: i },
|
|
404
|
-
children: e.map((e) => /* @__PURE__ */ g("option", {
|
|
405
|
-
value: e.code,
|
|
406
|
-
children: e.label
|
|
407
|
-
}, e.code))
|
|
408
|
-
});
|
|
409
|
-
};
|
|
410
|
-
//#endregion
|
|
411
|
-
export { t as DEFAULT_TIME_ZONE, w as I18nProvider, a as LOCALE_COOKIE, oe as LazyI18nProvider, de as LocaleSwitcher, S as RenderClockContext, T, n as THEME_COOKIE, i as TIMEZONE_COOKIE, e as VIEWER_TIME_ZONE, ne as assertCatalogParity, re as createTypedMessages, J as defineCatalog, ae as defineCatalogs, Y as defineLocale, x as i18nInstanceReport, r as isSupportedTimeZone, se as makeSsgWrap, X as pickCatalog, Z as placeholdersOf, I as plural, K as useFormatCurrency, H as useFormatDate, G as useFormatNumber, q as useFormatters, D as useLocale, O as useMessages, L as usePlural, W as useRelativeTime, C as useRenderClock, E as useT, k as useTFn, B 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 };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { I18nProvider as e } from "./provider.js";
|
|
2
|
+
import { useEffect as t, useState as n } from "react";
|
|
3
|
+
import { jsx as r } from "react/jsx-runtime";
|
|
4
|
+
//#region src/lazyProvider.tsx
|
|
5
|
+
var i = ({ catalogs: i, locale: a, fallback: o = null, silenceMissingTranslations: s, children: c }) => {
|
|
6
|
+
let [l, u] = n(() => i.peek(a));
|
|
7
|
+
return t(() => {
|
|
8
|
+
let e = i.peek(a);
|
|
9
|
+
if (e) {
|
|
10
|
+
u(e);
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
let t = !0;
|
|
14
|
+
return u(void 0), i.load(a).then((e) => {
|
|
15
|
+
t && u(e);
|
|
16
|
+
}), () => {
|
|
17
|
+
t = !1;
|
|
18
|
+
};
|
|
19
|
+
}, [i, a]), l ? /* @__PURE__ */ r(e, {
|
|
20
|
+
locale: a,
|
|
21
|
+
messages: l,
|
|
22
|
+
defaultLocale: i.defaultLocale,
|
|
23
|
+
...s === void 0 ? {} : { silenceMissingTranslations: s },
|
|
24
|
+
children: c
|
|
25
|
+
}) : o;
|
|
26
|
+
};
|
|
27
|
+
//#endregion
|
|
28
|
+
export { i as LazyI18nProvider };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { LOCALE_COOKIE as e } from "./cookieNames.js";
|
|
2
|
+
import { useEffect as t, useState as n } from "react";
|
|
3
|
+
import { jsx as r } from "react/jsx-runtime";
|
|
4
|
+
//#region src/localeSwitcher.tsx
|
|
5
|
+
var i = 3456e4, a = (e) => {
|
|
6
|
+
if (typeof document < "u") for (let t of document.cookie.split(";")) {
|
|
7
|
+
let n = t.indexOf("=");
|
|
8
|
+
if (!(n < 0) && t.slice(0, n).trim() === e) try {
|
|
9
|
+
return decodeURIComponent(t.slice(n + 1).trim());
|
|
10
|
+
} catch {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}, o = (e, t) => {
|
|
15
|
+
typeof document < "u" && (document.cookie = `${e}=${encodeURIComponent(t)}; path=/; max-age=${i}; SameSite=Lax`);
|
|
16
|
+
}, s = ({ locales: i, current: s, onChange: c, ariaLabel: l = "Language", className: u }) => {
|
|
17
|
+
let [d, f] = n(void 0);
|
|
18
|
+
t(() => {
|
|
19
|
+
f(a(e));
|
|
20
|
+
}, []);
|
|
21
|
+
let p = s ?? d ?? i[0]?.code ?? "";
|
|
22
|
+
return /* @__PURE__ */ r("select", {
|
|
23
|
+
"aria-label": l,
|
|
24
|
+
value: p,
|
|
25
|
+
onChange: (t) => {
|
|
26
|
+
let n = t.target.value;
|
|
27
|
+
o(e, n), f(n), c?.(n) !== !1 && typeof window < "u" && window.location.reload();
|
|
28
|
+
},
|
|
29
|
+
...u === void 0 ? {} : { className: u },
|
|
30
|
+
children: i.map((e) => /* @__PURE__ */ r("option", {
|
|
31
|
+
value: e.code,
|
|
32
|
+
children: e.label
|
|
33
|
+
}, e.code))
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
//#endregion
|
|
37
|
+
export { s as LocaleSwitcher };
|
package/dist/provider.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { registerI18nInstance as e } from "./instanceRegistry.js";
|
|
2
|
+
import { RenderClockContext as t } from "./renderClock.js";
|
|
3
|
+
import { isSupportedTimeZone as n } from "./timeZone.js";
|
|
4
|
+
import { useEffect as r, useState as i } from "react";
|
|
5
|
+
import { IntlProvider as a } from "react-intl";
|
|
6
|
+
import { jsx as o } from "react/jsx-runtime";
|
|
7
|
+
//#region src/provider.tsx
|
|
8
|
+
e(a);
|
|
9
|
+
var s = (e) => {
|
|
10
|
+
e.code !== "MISSING_TRANSLATION" && console.error(e);
|
|
11
|
+
}, c = ({ locale: e, messages: c, defaultLocale: l, silenceMissingTranslations: u = !0, timeZone: d, renderedAt: f, intlConfig: p, children: m }) => {
|
|
12
|
+
let h = u ? s : void 0, [g, _] = i(!1);
|
|
13
|
+
r(() => {
|
|
14
|
+
f !== void 0 && _(!0);
|
|
15
|
+
}, [f]);
|
|
16
|
+
let v = g ? void 0 : f, y = n(d) ? d : void 0;
|
|
17
|
+
return /* @__PURE__ */ o(a, {
|
|
18
|
+
locale: e,
|
|
19
|
+
defaultLocale: l,
|
|
20
|
+
messages: c,
|
|
21
|
+
...h ? { onError: h } : {},
|
|
22
|
+
...y ? { timeZone: y } : {},
|
|
23
|
+
...p,
|
|
24
|
+
children: /* @__PURE__ */ o(t.Provider, {
|
|
25
|
+
value: v,
|
|
26
|
+
children: m
|
|
27
|
+
})
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
//#endregion
|
|
31
|
+
export { c as I18nProvider };
|
package/dist/server.d.ts
CHANGED
|
@@ -29,11 +29,15 @@ export declare const LOCALE_COOKIE = "voltro:locale";
|
|
|
29
29
|
* spread the result and omit `outerWrap` entirely rather than passing an
|
|
30
30
|
* identity wrap — an app without locales must render exactly as before.
|
|
31
31
|
*/
|
|
32
|
-
export declare const makeSsrI18nResolver: (args: SsrI18nResolverArgs) => ((cookieHeader?: string | null, acceptLanguageHeader?: string | null, routeLocale?: string | null) => ResolvedSsrI18n | undefined);
|
|
32
|
+
export declare const makeSsrI18nResolver: (args: SsrI18nResolverArgs) => ((cookieHeader?: string | null, acceptLanguageHeader?: string | null, routeLocale?: string | null, request?: SsrI18nRenderRequest) => ResolvedSsrI18n | undefined);
|
|
33
|
+
|
|
34
|
+
declare type MessageCatalog = Readonly<Record<string, string>>;
|
|
33
35
|
|
|
34
36
|
/** What a renderer needs to render one request in the right locale. */
|
|
35
37
|
export declare interface ResolvedSsrI18n {
|
|
36
38
|
readonly locale: string;
|
|
39
|
+
/** The exact instant bound to this request's provider. */
|
|
40
|
+
readonly renderedAt: number;
|
|
37
41
|
/**
|
|
38
42
|
* The IANA zone this request renders in, or `undefined` when the app pins
|
|
39
43
|
* none. The renderer PUBLISHES it (`<html data-voltro-tz>`) so the client's
|
|
@@ -43,6 +47,9 @@ export declare interface ResolvedSsrI18n {
|
|
|
43
47
|
readonly timeZone: string | undefined;
|
|
44
48
|
/** Mounts `<I18nProvider>` around the tree — `renderPageToHtml`'s `outerWrap`. */
|
|
45
49
|
readonly outerWrap: (children: unknown) => unknown;
|
|
50
|
+
/** The catalog of `locale`, when the caller passed `catalogs` — a page's
|
|
51
|
+
* `meta` reads its translated title from it (`ctx.messages`). */
|
|
52
|
+
readonly messages?: MessageCatalog;
|
|
46
53
|
}
|
|
47
54
|
|
|
48
55
|
export declare const resolveLocale: (args: ResolveLocaleArgs) => string;
|
|
@@ -98,6 +105,11 @@ export declare interface ResolveTimeZoneArgs {
|
|
|
98
105
|
readonly defaultTimeZone?: string | null;
|
|
99
106
|
}
|
|
100
107
|
|
|
108
|
+
export declare interface SsrI18nRenderRequest {
|
|
109
|
+
/** Use a retained render instant without replacing the host's real clock. */
|
|
110
|
+
readonly renderedAt?: number;
|
|
111
|
+
}
|
|
112
|
+
|
|
101
113
|
export declare interface SsrI18nResolverArgs {
|
|
102
114
|
/**
|
|
103
115
|
* Per-locale `<I18nProvider>` wrappers, built by the caller with
|
|
@@ -109,6 +121,8 @@ export declare interface SsrI18nResolverArgs {
|
|
|
109
121
|
readonly timeZone?: string | undefined;
|
|
110
122
|
readonly renderedAt?: number | undefined;
|
|
111
123
|
}) => unknown>>;
|
|
124
|
+
/** The catalogs behind `wraps`, by locale — handed back as `messages`. */
|
|
125
|
+
readonly catalogs?: Readonly<Record<string, MessageCatalog>>;
|
|
112
126
|
/** Locale codes the app ships catalogs for. */
|
|
113
127
|
readonly supported: ReadonlyArray<string>;
|
|
114
128
|
/** MUST be in `supported`. */
|