@menapo/vi18n 0.1.0 → 0.1.2
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/README.md +14 -14
- package/dist/{apply-Bre-lY9J.js → apply-FAHl1R6T.js} +69 -89
- package/dist/{captured-Bj8bO6vd.js → captured-CTjjDF5o.js} +196 -217
- package/dist/{check-DyrAbv73.js → check-DwFwOB1d.js} +66 -84
- package/dist/cli.js +2 -3
- package/dist/{collect-Cx4_SKOe.js → collect-CYATDjdo.js} +1 -2
- package/dist/collisions-uMTuq36M.js +215 -0
- package/dist/compile-CEvH-6sY.js +240 -0
- package/dist/{compile-Cc97JaW2.js → compile-DqkofbiO.js} +376 -331
- package/dist/concurrency-BCY_4zcr.js +1 -0
- package/dist/concurrency-Dy2ny50V.js +107 -0
- package/dist/config.d.ts +1 -5
- package/dist/config.js +4 -5
- package/dist/{types-D3QGM8XO.js → diagnostics-1onDF6Ua.js} +26 -26
- package/dist/{dir-zw6bGMKQ.js → dir-TGLYuOZb.js} +34 -37
- package/dist/{duplicates-yuRljQ6h.js → duplicates-CsUXRX2J.js} +10 -27
- package/dist/engine-Bf7nVigL.js +556 -0
- package/dist/engine.d.ts +1 -5
- package/dist/engine.js +297 -168
- package/dist/exchange-DYG9RZoT.js +41 -0
- package/dist/{exclude-Du-Zd_qI.js → exclude-vMnm3lqU.js} +2 -3
- package/dist/{export-DGsMbcTZ.js → export-BYq0gfLd.js} +17 -38
- package/dist/{extract-Dujlsgnk.js → extract-CYtuEo8u.js} +114 -82
- package/dist/{formats-KPIg-08V.js → formats-ChV1LVH_.js} +352 -276
- package/dist/fs-ezCMZeDV.js +52 -0
- package/dist/i18next-1waHziMy.js +1 -0
- package/dist/i18next-D66Icz3L.js +1907 -0
- package/dist/{import-Cwdhcywt.js → import-BApbQlmm.js} +81 -75
- package/dist/index.d.ts +1 -13
- package/dist/index.js +14 -16
- package/dist/{init-BecCTvKi.js → init-J7AwwA5e.js} +466 -501
- package/dist/{library-D5CWvTQs.js → library-BfSOBeBd.js} +975 -451
- package/dist/lingui-Ee2farVo.js +902 -0
- package/dist/lint.d.ts +0 -4
- package/dist/lint.js +69 -82
- package/dist/{load-gW-oJt1Q.js → load-BFLLqY8x.js} +272 -147
- package/dist/{load-CQRz4PpM.js → load-CMwhukZ4.js} +1211 -1115
- package/dist/{locales-DX4MOBFE.js → locales-DxLDrx-h.js} +271 -237
- package/dist/{lsp-Cq1Nuu-Q.js → lsp-BC7xDGON.js} +4 -5
- package/dist/{match-BGr8EXB3.js → match-BLDcj610.js} +11 -4
- package/dist/{mcp-Cf0T7qPW.js → mcp-Cka8ywDF.js} +4 -5
- package/dist/{merge-driver-CpiiSVIc.js → merge-driver-B04Apm29.js} +138 -122
- package/dist/migrate-D7TNl6SD.js +2169 -0
- package/dist/migrate-khCY8TE0.js +1 -0
- package/dist/{openai-CTaMDcl-.js → openai-RWw0YlAx.js} +128 -87
- package/dist/{output-DsaHKHEt.js → output-CF9uvk_-.js} +15 -9
- package/dist/parse.d.ts +1 -3
- package/dist/parse.js +7 -8
- package/dist/{pipeline-wxS0SApG.js → pipeline-B30irGMD.js} +1 -1
- package/dist/{pipeline-C7g11THL.js → pipeline-sgl_q_op.js} +387 -359
- package/dist/project-DSzWKU3C.js +544 -0
- package/dist/{pseudo-DRv30iN5.js → pseudo-DNbNNVGP.js} +125 -3
- package/dist/{raw-C4Y6vyGY.js → raw-YsYZMS9n.js} +52 -29
- package/dist/react-intl-tzGIk6G3.js +634 -0
- package/dist/restore-BG_zMpSj.js +199 -0
- package/dist/rewrite-hAcRJwiZ.js +415 -0
- package/dist/{rich-DCUKl5HM.js → rich-ApY1Dm4S.js} +35 -28
- package/dist/rolldown-runtime-C1I3wEg2.js +43 -0
- package/dist/{rolldown-runtime-D7D4PA-g.js → rolldown-runtime-D8jQpDG7.js} +1 -2
- package/dist/run-CFzR3V93.js +647 -0
- package/dist/scan-worker.d.ts +2 -4
- package/dist/scan-worker.js +1 -1
- package/dist/{scoped-BMYpSthj.js → scoped-h3KE8XWW.js} +3 -4
- package/dist/{server-BDkykMjb.js → server-WlxZH0oX.js} +275 -330
- package/dist/{server-qv3mz70d.js → server-ceuzzkal.js} +292 -386
- package/dist/server.d.ts +1 -17
- package/dist/server.js +415 -381
- package/dist/{sitemap-DV3o8QD7.js → sitemap-796jJKUT.js} +21 -33
- package/dist/{sources-D19czDSA.js → sources-DuOdM02f.js} +712 -373
- package/dist/{status-DZArW5aE.js → status-CTH3qI-0.js} +30 -30
- package/dist/{stdio-FPOKQAgu.js → stdio-D9kTzyqB.js} +2 -4
- package/dist/{stdio-CVaJfxA7.js → stdio-FWIVU3P4.js} +1 -2
- package/dist/sync-CpL0Qsgw.js +1352 -0
- package/dist/{t-DC-c9zE5.js → t-gvEXx25s.js} +76 -53
- package/dist/test.d.ts +5 -16
- package/dist/test.js +77 -48
- package/dist/translate-BrfVRkjl.js +336 -0
- package/dist/{ts-BaU5yOf0.js → ts-BX6kwig5.js} +25 -14
- package/dist/{types-DtvQ7UdD.js → types-3kwyaCAm.js} +1 -2
- package/dist/{types-DsdWBG0b.d.ts → types-BaG1LboH.d.ts} +2 -6
- package/dist/{types-CgUCkFU1.d.ts → types-Cy2bPdSg.d.ts} +14 -20
- package/dist/types-Ds_vebja.js +41 -0
- package/dist/{units-CQ5Q99RC.js → units-VVLgQ7x7.js} +7 -16
- package/dist/{url-CRfCOhUI.js → url-Bpc6wLea.js} +24 -11
- package/dist/{url-CsBkRaJy.js → url-D2_VlEeH.js} +25 -12
- package/dist/{validate-D6DJepZv.js → validate-PGgMsasz.js} +3 -5
- package/dist/{validate-BxpupdAf.js → validate-zv4-IZyZ.js} +690 -377
- package/dist/{version-BlyLGlOa.js → version-BFs370Ce.js} +3 -5
- package/dist/{vite-scan-B_YW4X_a.js → vite-scan-DFKSGVE9.js} +87 -92
- package/dist/vite.d.ts +2 -6
- package/dist/vite.js +6482 -6018
- package/dist/vue-i18n-CBmZqHbG.js +806 -0
- package/dist/{which-C6PFI1Dm.js → which-BpyJyBkX.js} +44 -37
- package/dist/{worker-84U6uYB3.js → worker-BjzVqJVO.js} +454 -608
- package/package.json +8 -8
- package/dist/check-D34P-S--.js +0 -1
- package/dist/codec-DuvU2VQy.js +0 -207
- package/dist/collisions-CfpZU8e4.js +0 -217
- package/dist/compile-B5Mz6WJm.js +0 -245
- package/dist/concurrency-C9UUWuDC.js +0 -96
- package/dist/concurrency-DONL7t4V.js +0 -1
- package/dist/engine-B7p40M__.js +0 -531
- package/dist/i18next-CrUnKFfh.js +0 -1596
- package/dist/i18next-Rgo-v9l0.js +0 -1
- package/dist/lingui--PcOOYry.js +0 -833
- package/dist/messages-Cxa-5tR0.js +0 -166
- package/dist/migrate-CntqvrW4.js +0 -1
- package/dist/migrate-dPgq9uzy.js +0 -1484
- package/dist/project-Dwx7iPm6.js +0 -381
- package/dist/project-pXipT8iG.js +0 -1046
- package/dist/react-intl-CaBVwJ9u.js +0 -519
- package/dist/restore-Btq66Tid.js +0 -175
- package/dist/rewrite-CiTRAICl.js +0 -803
- package/dist/run-DYD_VXKy.js +0 -694
- package/dist/runtime-DTMmliT1.js +0 -64
- package/dist/sync-CcVzger_.js +0 -658
- package/dist/translate-DZR3MkSA.js +0 -299
- package/dist/types-wSh9fCBY.js +0 -11
- package/dist/vue-i18n-CEMnpv7k.js +0 -651
package/dist/engine.js
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
import { _ as
|
|
2
|
-
import {
|
|
3
|
-
import { a as
|
|
4
|
-
|
|
1
|
+
import { _ as browser, a as nav, b as warnOnce, d as setEngine, f as subs, g as DEV, h as BUILD, i as created, l as report, n as S, o as noop, r as changed, s as page, t as textDirection, u as resolved } from "./dir-TGLYuOZb.js";
|
|
2
|
+
import { i as awayHref, l as localizePath, o as escapeRegExp, p as splitLocalePath, s as hostLocale, t as ROUTES } from "./url-D2_VlEeH.js";
|
|
3
|
+
import { a as matchLocale, c as urlLocale, i as clientLocale, n as STORAGE_KEY, o as readCookie, s as strategyFor } from "./match-BLDcj610.js";
|
|
4
|
+
// src/runtime/devtools-protocol.ts
|
|
5
5
|
/** Client → server: one translation to write. */
|
|
6
6
|
const EDIT_EVENT = "vi18n:edit";
|
|
7
7
|
/** Server → the client that asked: the outcome of one `EDIT_EVENT`. */
|
|
8
8
|
const EDIT_RESULT_EVENT = "vi18n:edit-result";
|
|
9
|
+
/** Server → client: a catalog changed (§2.11.5); Vue's glue re-renders and the dock refreshes. */
|
|
10
|
+
const CATALOG_UPDATE_EVENT = "vi18n:catalog-update";
|
|
9
11
|
/**
|
|
10
12
|
* The page global through which the dock, a same-origin iframe, reaches the
|
|
11
13
|
* editor: it is a separate document with no module graph of its own.
|
|
12
14
|
*/
|
|
13
15
|
const BRIDGE$1 = "__vi18nDevtools";
|
|
14
|
-
|
|
15
|
-
//#region src/runtime/devtools.ts
|
|
16
|
+
// src/runtime/devtools.ts
|
|
16
17
|
/**
|
|
17
18
|
* In-context editing (PLAN §4.13 P2; INTERNALS §2.18), dev only. With
|
|
18
19
|
* `devtools: true` the plugin's dev client boot calls `inContext`; nothing
|
|
@@ -35,7 +36,7 @@ const WILD = "[\\s\\S]*?";
|
|
|
35
36
|
const normalizeText = (text) => text.replace(/\s+/g, " ").trim();
|
|
36
37
|
function literal(text, weight) {
|
|
37
38
|
weight.n += text.replace(/\s+/g, "").length;
|
|
38
|
-
return text.split(/\s+/).map(
|
|
39
|
+
return text.split(/\s+/).map(escapeRegExp).join("\\s*");
|
|
39
40
|
}
|
|
40
41
|
function partSource(part, weight) {
|
|
41
42
|
if (typeof part === "string") return literal(part, weight);
|
|
@@ -191,71 +192,134 @@ function h(tag, props = {}, ...children) {
|
|
|
191
192
|
for (const child of children) if (child !== null && child !== false) element.append(child);
|
|
192
193
|
return element;
|
|
193
194
|
}
|
|
194
|
-
/**
|
|
195
|
-
|
|
195
|
+
/** How long a save waits for the dev server's answer before giving up. */
|
|
196
|
+
const SAVE_TIMEOUT = 1e4;
|
|
197
|
+
/** A refusal for a save the dev server never answered (restarted, or the reply was lost). */
|
|
198
|
+
const unanswered = (nonce) => ({
|
|
199
|
+
nonce,
|
|
200
|
+
ok: false,
|
|
201
|
+
problems: [{
|
|
202
|
+
code: "timeout",
|
|
203
|
+
severity: "error",
|
|
204
|
+
message: "the dev server did not answer; save again once it is running"
|
|
205
|
+
}],
|
|
206
|
+
message: null
|
|
207
|
+
});
|
|
208
|
+
/** The card's header, source, notes and state for one message. */
|
|
209
|
+
function cardBody(id, data, message, close) {
|
|
210
|
+
return [
|
|
211
|
+
h("div", { className: "row" }, h("code", { className: "grow" }, id), h("span", { className: `badge ${message.state}` }, message.reason ?? message.state), h("span", { className: "muted" }, data.locale), h("button", {
|
|
212
|
+
textContent: "×",
|
|
213
|
+
title: "Close (Esc)",
|
|
214
|
+
onclick: close
|
|
215
|
+
})),
|
|
216
|
+
h("div", { className: "muted" }, "Source"),
|
|
217
|
+
h("pre", {}, message.source),
|
|
218
|
+
message.contexts.length > 0 ? h("div", { className: "muted" }, message.contexts.join(" · ")) : "",
|
|
219
|
+
h("div", { className: "muted" }, [message.at, message.file].filter(Boolean).join(" → "), message.maxLength === null ? "" : ` · max ${message.maxLength}`)
|
|
220
|
+
];
|
|
221
|
+
}
|
|
222
|
+
/** Why a message cannot be edited here. */
|
|
223
|
+
function readOnlyNote(data) {
|
|
224
|
+
return h("div", { className: "muted" }, data.locale === data.sourceLocale ? "The source locale's text is the code's: edit the call." : `${data.locale} has no catalog of its own.`);
|
|
225
|
+
}
|
|
226
|
+
/** The page's messages as list items, each opening its card. */
|
|
227
|
+
const pageList = (messages, pick) => messages.map((m) => h("li", { onclick: () => pick(m.id) }, h("span", { className: `badge ${m.state}` }, m.reason ?? m.state), " ", m.text || m.source));
|
|
228
|
+
/** A save's problems, one line each. */
|
|
229
|
+
const problemLines = (result) => result.problems.map((p) => h("div", { className: `problem ${p.severity}` }, `${p.code}: ${p.message}`));
|
|
196
230
|
/**
|
|
197
|
-
*
|
|
198
|
-
*
|
|
199
|
-
*
|
|
200
|
-
* `import.meta.hot`; a no-op outside a document or without HMR.
|
|
231
|
+
* The page's one editor: the `seen` recorder, the reverse index, the HMR
|
|
232
|
+
* channel with the saves waiting on it, and the overlay (a highlight box
|
|
233
|
+
* and the card, in a shadow root).
|
|
201
234
|
*/
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
channel =
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
235
|
+
var Editor = class {
|
|
236
|
+
seen = /* @__PURE__ */ new Set();
|
|
237
|
+
host = document.createElement("div");
|
|
238
|
+
root = this.host.attachShadow({ mode: "open" });
|
|
239
|
+
box = h("div", { className: "box" });
|
|
240
|
+
card = h("div", { className: "card" });
|
|
241
|
+
waiting = /* @__PURE__ */ new Map();
|
|
242
|
+
listeners = /* @__PURE__ */ new Set();
|
|
243
|
+
indexed;
|
|
244
|
+
index = reverseIndex(/* @__PURE__ */ new Map());
|
|
245
|
+
nonce = 0;
|
|
246
|
+
/** The latest `show()`: an earlier one still loading must not replace its card. */
|
|
247
|
+
shown = 0;
|
|
248
|
+
/** The text the card belongs to; null when the dock opened it. */
|
|
249
|
+
anchor = null;
|
|
250
|
+
channel;
|
|
251
|
+
endpoint;
|
|
252
|
+
page;
|
|
253
|
+
constructor(channel, endpoint, page) {
|
|
254
|
+
this.channel = channel;
|
|
255
|
+
this.endpoint = endpoint;
|
|
256
|
+
this.page = page;
|
|
257
|
+
page.seen = (id) => {
|
|
258
|
+
this.seen.add(id);
|
|
259
|
+
};
|
|
260
|
+
this.host.setAttribute("data-vi18n-devtools", "");
|
|
261
|
+
this.root.append(h("style", { textContent: STYLE }));
|
|
262
|
+
new ResizeObserver(() => this.place()).observe(this.card);
|
|
263
|
+
this.attach(channel);
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Listens on `hot`. A catalog update can run the boot module again, and
|
|
267
|
+
* Vite drops the listeners of a module's previous `hot` when it makes the
|
|
268
|
+
* next one: the reply to a save in flight would never arrive.
|
|
269
|
+
*/
|
|
270
|
+
attach(hot) {
|
|
271
|
+
this.channel = hot;
|
|
272
|
+
hot.on(EDIT_RESULT_EVENT, (result) => {
|
|
273
|
+
this.waiting.get(result.nonce)?.(result);
|
|
274
|
+
this.waiting.delete(result.nonce);
|
|
225
275
|
});
|
|
226
|
-
|
|
227
|
-
for (const listener of listeners) listener();
|
|
276
|
+
hot.on(CATALOG_UPDATE_EVENT, () => {
|
|
277
|
+
for (const listener of this.listeners) listener();
|
|
228
278
|
});
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
279
|
+
}
|
|
280
|
+
/** The reverse index of the page's messages; merges and HMR replace the Map, so its identity says when to rebuild. */
|
|
281
|
+
currentIndex() {
|
|
282
|
+
if (this.indexed !== this.page.messages) this.index = reverseIndex(this.indexed = this.page.messages);
|
|
283
|
+
return this.index;
|
|
284
|
+
}
|
|
285
|
+
/** Sends one edit; a save the dev server never answers settles as a refusal. */
|
|
286
|
+
save(request) {
|
|
287
|
+
const nonce = ++this.nonce;
|
|
288
|
+
return new Promise((done) => {
|
|
289
|
+
const timer = setTimeout(() => {
|
|
290
|
+
this.waiting.delete(nonce);
|
|
291
|
+
done(unanswered(nonce));
|
|
292
|
+
}, SAVE_TIMEOUT);
|
|
293
|
+
this.waiting.set(nonce, (result) => {
|
|
294
|
+
clearTimeout(timer);
|
|
295
|
+
done(result);
|
|
296
|
+
});
|
|
297
|
+
this.channel.send(EDIT_EVENT, {
|
|
298
|
+
...request,
|
|
299
|
+
nonce
|
|
300
|
+
});
|
|
236
301
|
});
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
|
|
302
|
+
}
|
|
303
|
+
/** The dev server's view of `ids` in the page's locale. */
|
|
304
|
+
async load(ids) {
|
|
305
|
+
const query = new URLSearchParams({ locale: this.page.locale });
|
|
240
306
|
for (const id of ids) query.append("id", id);
|
|
241
|
-
const response = await fetch(`${endpoint}?${query}`, { cache: "no-store" });
|
|
242
|
-
if (!response.ok) throw new Error(`${endpoint} answered ${response.status}`);
|
|
307
|
+
const response = await fetch(`${this.endpoint}?${query}`, { cache: "no-store" });
|
|
308
|
+
if (!response.ok) throw new Error(`${this.endpoint} answered ${response.status}`);
|
|
243
309
|
return await response.json();
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
card
|
|
257
|
-
};
|
|
258
|
-
const place = () => {
|
|
310
|
+
}
|
|
311
|
+
close() {
|
|
312
|
+
this.anchor = null;
|
|
313
|
+
this.box.remove();
|
|
314
|
+
this.card.remove();
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Follows the text through scrolls, resizes and the card's own content
|
|
318
|
+
* changing size (the message loading, problems, the page list): closing on
|
|
319
|
+
* scroll would lose a translation being typed.
|
|
320
|
+
*/
|
|
321
|
+
place() {
|
|
322
|
+
const { anchor, box, card } = this;
|
|
259
323
|
if (anchor === null || !card.isConnected) return;
|
|
260
324
|
if (!anchor.isConnected) {
|
|
261
325
|
box.remove();
|
|
@@ -278,22 +342,48 @@ function inContext(hot, endpoint) {
|
|
|
278
342
|
left: `${at.left}px`,
|
|
279
343
|
maxHeight: at.maxHeight === null ? "" : `${at.maxHeight}px`
|
|
280
344
|
});
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
|
|
345
|
+
}
|
|
346
|
+
/** Opens the card for `ids` at `element`'s text, or (from the dock) in the corner the dock leaves free. */
|
|
347
|
+
open(element, ids) {
|
|
348
|
+
if (!this.host.isConnected) document.body.append(this.host);
|
|
349
|
+
this.anchor = element;
|
|
350
|
+
if (element === null) {
|
|
351
|
+
this.box.remove();
|
|
352
|
+
Object.assign(this.card.style, {
|
|
353
|
+
top: "8px",
|
|
354
|
+
left: `${Math.max(8, innerWidth - 396)}px`,
|
|
355
|
+
maxHeight: ""
|
|
356
|
+
});
|
|
357
|
+
this.root.append(this.card);
|
|
358
|
+
} else {
|
|
359
|
+
this.root.append(this.box, this.card);
|
|
360
|
+
this.place();
|
|
361
|
+
}
|
|
362
|
+
this.show(ids, 0);
|
|
363
|
+
}
|
|
364
|
+
/** Fills the card with message `ids[at]`, once it loaded and no later `show()` started. */
|
|
365
|
+
async show(ids, at) {
|
|
366
|
+
const ticket = ++this.shown;
|
|
284
367
|
const id = ids[at];
|
|
285
368
|
let data;
|
|
286
369
|
try {
|
|
287
|
-
data = await load([id]);
|
|
370
|
+
data = await this.load([id]);
|
|
288
371
|
} catch (error) {
|
|
289
|
-
card.replaceChildren(h("div", { className: "problem" }, String(error)));
|
|
372
|
+
if (ticket === this.shown) this.card.replaceChildren(h("div", { className: "problem" }, String(error)));
|
|
290
373
|
return;
|
|
291
374
|
}
|
|
375
|
+
if (ticket !== this.shown) return;
|
|
292
376
|
const message = data.messages[0];
|
|
293
377
|
if (message === void 0) {
|
|
294
|
-
card.replaceChildren(h("div", {}, h("code", {}, id), " is not a message the dev server knows."));
|
|
378
|
+
this.card.replaceChildren(h("div", {}, h("code", {}, id), " is not a message the dev server knows."));
|
|
295
379
|
return;
|
|
296
380
|
}
|
|
381
|
+
const close = () => this.close();
|
|
382
|
+
const [area, problems, saveButton] = this.editor(id, data, message);
|
|
383
|
+
this.card.replaceChildren(...cardBody(id, data, message, close), data.editable ? area : readOnlyNote(data), problems, this.controls(ids, at, saveButton));
|
|
384
|
+
}
|
|
385
|
+
/** The translation field, its problems and its Save button. */
|
|
386
|
+
editor(id, data, message) {
|
|
297
387
|
const area = h("textarea", {
|
|
298
388
|
value: message.text,
|
|
299
389
|
readOnly: !data.editable,
|
|
@@ -305,90 +395,103 @@ function inContext(hot, endpoint) {
|
|
|
305
395
|
disabled: !data.editable,
|
|
306
396
|
onclick: async () => {
|
|
307
397
|
button.disabled = true;
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
398
|
+
try {
|
|
399
|
+
const result = await this.save({
|
|
400
|
+
id,
|
|
401
|
+
locale: data.locale,
|
|
402
|
+
source: message.source,
|
|
403
|
+
expected: message.text,
|
|
404
|
+
translation: area.value
|
|
405
|
+
});
|
|
406
|
+
problems.replaceChildren(...problemLines(result));
|
|
407
|
+
if (result.ok && result.problems.length === 0) this.close();
|
|
408
|
+
} finally {
|
|
409
|
+
button.disabled = false;
|
|
410
|
+
}
|
|
318
411
|
}
|
|
319
412
|
});
|
|
320
413
|
area.addEventListener("keydown", (event) => {
|
|
321
414
|
if (event.key === "Enter" && (event.metaKey || event.ctrlKey)) button.click();
|
|
322
415
|
});
|
|
416
|
+
return [
|
|
417
|
+
area,
|
|
418
|
+
problems,
|
|
419
|
+
button
|
|
420
|
+
];
|
|
421
|
+
}
|
|
422
|
+
/** Save, the ‹ › steps through `ids`, and the page's message list. */
|
|
423
|
+
controls(ids, at, saveButton) {
|
|
323
424
|
const list = h("ul", { hidden: true });
|
|
324
425
|
const listButton = h("button", {
|
|
325
|
-
textContent: `Page messages (${seen.size})`,
|
|
426
|
+
textContent: `Page messages (${this.seen.size})`,
|
|
326
427
|
onclick: async () => {
|
|
327
428
|
list.hidden = !list.hidden;
|
|
328
429
|
if (list.hidden) return;
|
|
329
|
-
const all = await load([...seen]);
|
|
330
|
-
list.replaceChildren(...all.messages
|
|
430
|
+
const all = await this.load([...this.seen]);
|
|
431
|
+
list.replaceChildren(...pageList(all.messages, (picked) => void this.show([picked], 0)));
|
|
331
432
|
}
|
|
332
433
|
});
|
|
333
434
|
const step = (by) => h("button", {
|
|
334
435
|
textContent: by < 0 ? "‹" : "›",
|
|
335
436
|
disabled: at + by < 0 || at + by >= ids.length,
|
|
336
|
-
onclick: () => void show(ids, at + by)
|
|
437
|
+
onclick: () => void this.show(ids, at + by)
|
|
337
438
|
});
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
place
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
439
|
+
const many = ids.length > 1;
|
|
440
|
+
const fragment = document.createDocumentFragment();
|
|
441
|
+
fragment.append(h("div", { className: "row" }, saveButton, many && step(-1), many && `${at + 1}/${ids.length}`, many && step(1), h("span", { className: "grow" }), listButton), list);
|
|
442
|
+
return fragment;
|
|
443
|
+
}
|
|
444
|
+
/** Alt+click on text opens its card; Esc closes it; the card follows scrolls and resizes. */
|
|
445
|
+
listen() {
|
|
446
|
+
document.addEventListener("click", (event) => {
|
|
447
|
+
if (!event.altKey || event.composedPath().includes(this.host)) return;
|
|
448
|
+
const target = event.target;
|
|
449
|
+
if (!(target instanceof Element)) return;
|
|
450
|
+
const found = locate(target, this.currentIndex(), this.seen);
|
|
451
|
+
if (found === null) return;
|
|
452
|
+
event.preventDefault();
|
|
453
|
+
event.stopPropagation();
|
|
454
|
+
this.open(found.element, found.ids);
|
|
455
|
+
}, true);
|
|
456
|
+
document.addEventListener("keydown", (event) => {
|
|
457
|
+
if (event.key === "Escape") this.close();
|
|
458
|
+
});
|
|
459
|
+
const place = () => this.place();
|
|
460
|
+
addEventListener("scroll", place, {
|
|
461
|
+
passive: true,
|
|
462
|
+
capture: true
|
|
463
|
+
});
|
|
464
|
+
addEventListener("resize", place, { passive: true });
|
|
465
|
+
}
|
|
466
|
+
/** What the Vite DevTools dock reads and calls. */
|
|
467
|
+
bridge() {
|
|
468
|
+
return {
|
|
469
|
+
locale: () => this.page.locale,
|
|
470
|
+
seen: () => [...this.seen],
|
|
471
|
+
open: (id) => this.open(null, [id]),
|
|
472
|
+
subscribe: (listener) => {
|
|
473
|
+
this.listeners.add(listener);
|
|
474
|
+
return () => void this.listeners.delete(listener);
|
|
475
|
+
}
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
};
|
|
479
|
+
/** The page's editor, once installed; a boot module that ran again moves it to its `hot`. */
|
|
480
|
+
let editor;
|
|
481
|
+
/**
|
|
482
|
+
* Installs the editor on the page: the `seen` recorder on the page scope,
|
|
483
|
+
* the Alt+click listener, the HMR reply listener and the dock's bridge.
|
|
484
|
+
* Called by the plugin's dev client boot (`devtools: true`) with its
|
|
485
|
+
* `import.meta.hot`; a no-op outside a document or without HMR.
|
|
486
|
+
*/
|
|
487
|
+
function inContext(hot, endpoint) {
|
|
488
|
+
if (hot === void 0 || typeof document !== "object") return;
|
|
489
|
+
if (editor !== void 0) return editor.attach(hot);
|
|
490
|
+
editor = new Editor(hot, endpoint, S.resolve());
|
|
491
|
+
editor.listen();
|
|
492
|
+
globalThis[BRIDGE$1] = editor.bridge();
|
|
389
493
|
}
|
|
390
|
-
|
|
391
|
-
//#region src/runtime/fetch.ts
|
|
494
|
+
// src/runtime/fetch.ts
|
|
392
495
|
/**
|
|
393
496
|
* The same-origin `fetch` wrapper (PLAN §5.12): server functions, actions and
|
|
394
497
|
* API calls learn the tab's locale from `x-vi18n-locale`, per tab and without
|
|
@@ -431,8 +534,7 @@ function wrapFetch(header) {
|
|
|
431
534
|
if (globalThis.fetch === wrapped) globalThis.fetch = original;
|
|
432
535
|
};
|
|
433
536
|
}
|
|
434
|
-
|
|
435
|
-
//#region src/runtime/navigation.ts
|
|
537
|
+
// src/runtime/navigation.ts
|
|
436
538
|
/**
|
|
437
539
|
* Navigation watcher (INTERNALS §2.11.7): a client-router navigation to a URL
|
|
438
540
|
* in another locale (a plain `<a href="/de/pricing">`) switches the page in
|
|
@@ -459,8 +561,7 @@ function watchNavigation(onChange) {
|
|
|
459
561
|
}
|
|
460
562
|
addEventListener("popstate", onChange);
|
|
461
563
|
}
|
|
462
|
-
|
|
463
|
-
//#region src/runtime/loader.ts
|
|
564
|
+
// src/runtime/loader.ts
|
|
464
565
|
/**
|
|
465
566
|
* The client engine behind the global state (INTERNALS §2.11): registration,
|
|
466
567
|
* bundle loading, skew handling, locale switching, the navigation watcher,
|
|
@@ -827,29 +928,35 @@ function flip(l) {
|
|
|
827
928
|
});
|
|
828
929
|
}
|
|
829
930
|
/**
|
|
931
|
+
* A build's page: the manifest it inlines or names, the deploy version, the
|
|
932
|
+
* payloads already in the document, and the map for `l`, which boot never
|
|
933
|
+
* awaits (importers stay synchronous); `need()` awaits it.
|
|
934
|
+
*/
|
|
935
|
+
function startLoading(m, p, l) {
|
|
936
|
+
inline = m && typeof m === "object" ? m : byId("__vi18n_manifest");
|
|
937
|
+
version = p?.v ?? S.boot?.v ?? inline?.v;
|
|
938
|
+
try {
|
|
939
|
+
adoptLate();
|
|
940
|
+
} catch {}
|
|
941
|
+
inFlight(manifest(l)).catch(noop);
|
|
942
|
+
}
|
|
943
|
+
/**
|
|
830
944
|
* The engine's half of `register`: the core already recorded the
|
|
831
945
|
* registration, filled `locales` and set the page scope to the source locale.
|
|
832
946
|
*/
|
|
833
947
|
function boot(r) {
|
|
834
948
|
reg = r;
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
return devCatalog(r.config.sourceLocale);
|
|
838
|
-
}
|
|
839
|
-
if (!BUILD && r.consumer !== "client") return resolved;
|
|
840
|
-
if (!BUILD && !browser() && globalThis.WorkerGlobalScope) return worker(r);
|
|
841
|
-
if (ROUTES && r.config.routing.domains && (BUILD || browser())) r.config.routing.home = hostLocale(location.host, r.config);
|
|
949
|
+
const doc = BUILD || browser();
|
|
950
|
+
if (ROUTES && doc && r.config.routing.domains) r.config.routing.home = hostLocale(location.host, r.config);
|
|
842
951
|
const p = byId("__vi18n");
|
|
843
|
-
const n = BUILD ? navigator : globalThis.navigator;
|
|
844
952
|
const l = [p?.locale, S.boot?.locale].find((x) => S.locales.includes(x)) ?? clientLocale(r.config, {
|
|
845
|
-
pathname:
|
|
846
|
-
cookie:
|
|
953
|
+
pathname: doc ? location.pathname : "/",
|
|
954
|
+
cookie: doc ? document.cookie : "",
|
|
847
955
|
storage: (k) => localStorage.getItem(k),
|
|
848
|
-
languages: BUILD ? navigator.languages ?? [navigator.language] :
|
|
956
|
+
languages: BUILD ? navigator.languages ?? [navigator.language] : hostLanguages()
|
|
849
957
|
}).locale;
|
|
850
|
-
if (p && !BUILD && r.mode === "dev") hydrate(p);
|
|
851
958
|
flip(l);
|
|
852
|
-
if (
|
|
959
|
+
if (doc) {
|
|
853
960
|
const tz = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
854
961
|
if (tz && readCookie(document.cookie, "vi18n_tz") !== tz) setCookie("vi18n_tz", tz, 31536e3);
|
|
855
962
|
if (BUILD || !watching) {
|
|
@@ -860,15 +967,35 @@ function boot(r) {
|
|
|
860
967
|
}
|
|
861
968
|
}
|
|
862
969
|
if (!BUILD && r.mode === "dev") return inFlight(devCatalog(l));
|
|
863
|
-
|
|
864
|
-
inline = m && typeof m === "object" ? m : byId("__vi18n_manifest");
|
|
865
|
-
version = p?.v ?? S.boot?.v ?? inline?.v;
|
|
866
|
-
try {
|
|
867
|
-
adoptLate();
|
|
868
|
-
} catch {}
|
|
869
|
-
inFlight(manifest(l)).catch(noop);
|
|
970
|
+
startLoading(r.manifest, p, l);
|
|
870
971
|
return resolved;
|
|
871
972
|
}
|
|
973
|
+
/**
|
|
974
|
+
* `boot` outside builds, which also see registrations that boot no page: a
|
|
975
|
+
* Vitest suite's, a server's and a module worker's.
|
|
976
|
+
*/
|
|
977
|
+
function bootAny(r) {
|
|
978
|
+
reg = r;
|
|
979
|
+
if (r.test) {
|
|
980
|
+
unwrap();
|
|
981
|
+
return devCatalog(r.config.sourceLocale);
|
|
982
|
+
}
|
|
983
|
+
if (r.consumer !== "client") return resolved;
|
|
984
|
+
if (!browser() && globalThis.WorkerGlobalScope) return worker(r);
|
|
985
|
+
if (r.mode === "dev") {
|
|
986
|
+
const p = byId("__vi18n");
|
|
987
|
+
if (p) hydrate(p);
|
|
988
|
+
}
|
|
989
|
+
return boot(r);
|
|
990
|
+
}
|
|
991
|
+
/**
|
|
992
|
+
* Outside builds: the languages of whatever navigator the host has; without
|
|
993
|
+
* one at all, `matchLocale` skips the undefined entry.
|
|
994
|
+
*/
|
|
995
|
+
function hostLanguages() {
|
|
996
|
+
const n = globalThis.navigator;
|
|
997
|
+
return n?.languages ?? [n?.language];
|
|
998
|
+
}
|
|
872
999
|
/** Whether `path`'s strategy chain lists `strategy`. */
|
|
873
1000
|
const lists = (path, strategy) => strategyFor(reg.config, path).includes(strategy);
|
|
874
1001
|
/** The locale `path` names where the URL decides the locale, else null. */
|
|
@@ -968,6 +1095,8 @@ function cancel() {
|
|
|
968
1095
|
switches++;
|
|
969
1096
|
heading = void 0;
|
|
970
1097
|
}
|
|
1098
|
+
/** Dev: the advice an unknown locale's error ends with. */
|
|
1099
|
+
const configured = () => `; configured: ${S.locales.join(", ")} (add it to locales in vi18n.config.ts)`;
|
|
971
1100
|
/**
|
|
972
1101
|
* `setLocale`: loads `l` for every key the page uses, flips, then puts `l`
|
|
973
1102
|
* into the URL through the navigator.
|
|
@@ -976,7 +1105,7 @@ async function switchTo(l) {
|
|
|
976
1105
|
if (!S.locales.includes(l)) throw new RangeError("vi18n: unknown locale " + l);
|
|
977
1106
|
const config = reg.config;
|
|
978
1107
|
const url = (BUILD || browser()) && config.routing.url !== "no_prefix" && lists(location.pathname, "url");
|
|
979
|
-
if (config.routing.switch === "navigate" || url && !nav || ROUTES &&
|
|
1108
|
+
if (config.routing.switch === "navigate" || url && (!nav || ROUTES && away(l))) return leave(l);
|
|
980
1109
|
const link = heading;
|
|
981
1110
|
const kept = l === page.locale;
|
|
982
1111
|
if (kept) {
|
|
@@ -1026,6 +1155,7 @@ function toward(l, commit) {
|
|
|
1026
1155
|
/** `setLocale` where a server registration may reach this engine: it throws there. */
|
|
1027
1156
|
function setLocale(l) {
|
|
1028
1157
|
if (S.serverResolver || reg?.consumer === "server") return clientOnly(l);
|
|
1158
|
+
if (DEV && !S.locales.includes(l)) return Promise.reject(/* @__PURE__ */ new RangeError("vi18n: unknown locale " + l + configured()));
|
|
1029
1159
|
return switchTo(l);
|
|
1030
1160
|
}
|
|
1031
1161
|
/** A same-document navigation committed: `location` is the new URL. */
|
|
@@ -1081,7 +1211,7 @@ function hold(p) {
|
|
|
1081
1211
|
* worker's own `setLocale` do: no URL, cookie or document to update.
|
|
1082
1212
|
*/
|
|
1083
1213
|
function inPlace(l) {
|
|
1084
|
-
if (!S.locales.includes(l)) return Promise.reject(/* @__PURE__ */ new RangeError("vi18n: unknown locale " + l));
|
|
1214
|
+
if (!S.locales.includes(l)) return Promise.reject(/* @__PURE__ */ new RangeError("vi18n: unknown locale " + l + (DEV ? configured() : "")));
|
|
1085
1215
|
if (l === page.locale) {
|
|
1086
1216
|
cancel();
|
|
1087
1217
|
return resolved;
|
|
@@ -1208,7 +1338,7 @@ const localeHeader = () => reg?.config.routing.propagate === "header" && (BUILD
|
|
|
1208
1338
|
/** Hooks into `register` and replaces the core's client stubs with this engine's methods. */
|
|
1209
1339
|
function install() {
|
|
1210
1340
|
if (BUILD || browser()) unwrap = wrapFetch(localeHeader);
|
|
1211
|
-
setEngine(boot);
|
|
1341
|
+
setEngine(BUILD ? boot : bootAny);
|
|
1212
1342
|
const methods = {
|
|
1213
1343
|
need,
|
|
1214
1344
|
lazy: (importer, keys) => Promise.all([importer(), need(keys)]).then((r) => r[0]),
|
|
@@ -1226,16 +1356,15 @@ function install() {
|
|
|
1226
1356
|
report(key, scope.locale, reason);
|
|
1227
1357
|
}
|
|
1228
1358
|
};
|
|
1229
|
-
if (INLINE) methods.add = (b) => merge(page.locale, [b]);
|
|
1230
1359
|
if (DEV) methods.replace = (l, catalog) => {
|
|
1231
1360
|
if (!S.locales.includes(l)) return;
|
|
1232
1361
|
setDev(l, catalog);
|
|
1233
1362
|
changed(false);
|
|
1234
1363
|
};
|
|
1235
1364
|
Object.assign(S, methods);
|
|
1236
|
-
if (
|
|
1365
|
+
if (INLINE) S.add = (b) => merge(page.locale, [b]);
|
|
1366
|
+
if (!BUILD && S.registration) bootAny(S.registration);
|
|
1237
1367
|
}
|
|
1238
1368
|
if (created) install();
|
|
1239
1369
|
else if (DEV && S.need === S.ready) warnOnce("another copy of @menapo/vi18n without the client engine created the page state first, so this boot module's \"@menapo/vi18n/engine\" cannot install and t() renders no translations; dedupe the package");
|
|
1240
|
-
//#endregion
|
|
1241
1370
|
export { bridge, inContext };
|