@menapo/vi18n 0.1.1 → 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.
Files changed (118) hide show
  1. package/dist/{apply-Bre-lY9J.js → apply-FAHl1R6T.js} +69 -89
  2. package/dist/{captured-Bj8bO6vd.js → captured-CTjjDF5o.js} +196 -217
  3. package/dist/{check-BIKEuu6B.js → check-DwFwOB1d.js} +66 -84
  4. package/dist/cli.js +2 -3
  5. package/dist/{collect-Cx4_SKOe.js → collect-CYATDjdo.js} +1 -2
  6. package/dist/collisions-uMTuq36M.js +215 -0
  7. package/dist/compile-CEvH-6sY.js +240 -0
  8. package/dist/{compile-Cc97JaW2.js → compile-DqkofbiO.js} +376 -331
  9. package/dist/concurrency-BCY_4zcr.js +1 -0
  10. package/dist/concurrency-Dy2ny50V.js +107 -0
  11. package/dist/config.d.ts +1 -5
  12. package/dist/config.js +4 -5
  13. package/dist/{types-D3QGM8XO.js → diagnostics-1onDF6Ua.js} +26 -26
  14. package/dist/{dir-zw6bGMKQ.js → dir-TGLYuOZb.js} +34 -37
  15. package/dist/{duplicates-yuRljQ6h.js → duplicates-CsUXRX2J.js} +10 -27
  16. package/dist/engine-Bf7nVigL.js +556 -0
  17. package/dist/engine.d.ts +1 -5
  18. package/dist/engine.js +297 -168
  19. package/dist/exchange-DYG9RZoT.js +41 -0
  20. package/dist/{exclude-Du-Zd_qI.js → exclude-vMnm3lqU.js} +2 -3
  21. package/dist/{export-C9Sy6UWv.js → export-BYq0gfLd.js} +17 -38
  22. package/dist/{extract-C3S8btx0.js → extract-CYtuEo8u.js} +114 -82
  23. package/dist/{formats-9unqj_fZ.js → formats-ChV1LVH_.js} +352 -276
  24. package/dist/fs-ezCMZeDV.js +52 -0
  25. package/dist/i18next-1waHziMy.js +1 -0
  26. package/dist/i18next-D66Icz3L.js +1907 -0
  27. package/dist/{import-nANvQutw.js → import-BApbQlmm.js} +81 -75
  28. package/dist/index.d.ts +1 -13
  29. package/dist/index.js +14 -16
  30. package/dist/{init-C2ScuW6a.js → init-J7AwwA5e.js} +466 -501
  31. package/dist/{library-D5CWvTQs.js → library-BfSOBeBd.js} +975 -451
  32. package/dist/lingui-Ee2farVo.js +902 -0
  33. package/dist/lint.d.ts +0 -4
  34. package/dist/lint.js +68 -81
  35. package/dist/{load-gW-oJt1Q.js → load-BFLLqY8x.js} +272 -147
  36. package/dist/{load-CQRz4PpM.js → load-CMwhukZ4.js} +1211 -1115
  37. package/dist/{locales-DX4MOBFE.js → locales-DxLDrx-h.js} +271 -237
  38. package/dist/{lsp-RMMMc88P.js → lsp-BC7xDGON.js} +4 -5
  39. package/dist/{match-BGr8EXB3.js → match-BLDcj610.js} +11 -4
  40. package/dist/{mcp-CHVwBoRP.js → mcp-Cka8ywDF.js} +4 -5
  41. package/dist/{merge-driver-BTX87aVm.js → merge-driver-B04Apm29.js} +138 -122
  42. package/dist/migrate-D7TNl6SD.js +2169 -0
  43. package/dist/migrate-khCY8TE0.js +1 -0
  44. package/dist/{openai-CTaMDcl-.js → openai-RWw0YlAx.js} +128 -87
  45. package/dist/{output-DWE3SIUA.js → output-CF9uvk_-.js} +15 -9
  46. package/dist/parse.d.ts +1 -3
  47. package/dist/parse.js +7 -8
  48. package/dist/{pipeline-DbX6rlo5.js → pipeline-B30irGMD.js} +1 -1
  49. package/dist/{pipeline-C9Dbotkh.js → pipeline-sgl_q_op.js} +387 -359
  50. package/dist/project-DSzWKU3C.js +544 -0
  51. package/dist/{pseudo-DRv30iN5.js → pseudo-DNbNNVGP.js} +125 -3
  52. package/dist/{raw-C4Y6vyGY.js → raw-YsYZMS9n.js} +52 -29
  53. package/dist/react-intl-tzGIk6G3.js +634 -0
  54. package/dist/restore-BG_zMpSj.js +199 -0
  55. package/dist/rewrite-hAcRJwiZ.js +415 -0
  56. package/dist/{rich-DCUKl5HM.js → rich-ApY1Dm4S.js} +35 -28
  57. package/dist/rolldown-runtime-C1I3wEg2.js +43 -0
  58. package/dist/{rolldown-runtime-D7D4PA-g.js → rolldown-runtime-D8jQpDG7.js} +1 -2
  59. package/dist/run-CFzR3V93.js +647 -0
  60. package/dist/scan-worker.d.ts +2 -4
  61. package/dist/scan-worker.js +1 -1
  62. package/dist/{scoped-BMYpSthj.js → scoped-h3KE8XWW.js} +3 -4
  63. package/dist/{server-deBOq2vq.js → server-WlxZH0oX.js} +275 -330
  64. package/dist/{server-Da1Ot9IN.js → server-ceuzzkal.js} +292 -386
  65. package/dist/server.d.ts +1 -17
  66. package/dist/server.js +415 -381
  67. package/dist/{sitemap-DJXzKoza.js → sitemap-796jJKUT.js} +21 -33
  68. package/dist/{sources-D19czDSA.js → sources-DuOdM02f.js} +712 -373
  69. package/dist/{status-zr4jY59Y.js → status-CTH3qI-0.js} +30 -30
  70. package/dist/{stdio-FPOKQAgu.js → stdio-D9kTzyqB.js} +2 -4
  71. package/dist/{stdio-CVaJfxA7.js → stdio-FWIVU3P4.js} +1 -2
  72. package/dist/sync-CpL0Qsgw.js +1352 -0
  73. package/dist/{t-DC-c9zE5.js → t-gvEXx25s.js} +76 -53
  74. package/dist/test.d.ts +5 -16
  75. package/dist/test.js +77 -48
  76. package/dist/translate-BrfVRkjl.js +336 -0
  77. package/dist/{ts-BaU5yOf0.js → ts-BX6kwig5.js} +25 -14
  78. package/dist/{types-DtvQ7UdD.js → types-3kwyaCAm.js} +1 -2
  79. package/dist/{types-DsdWBG0b.d.ts → types-BaG1LboH.d.ts} +2 -6
  80. package/dist/{types-CgUCkFU1.d.ts → types-Cy2bPdSg.d.ts} +14 -20
  81. package/dist/types-Ds_vebja.js +41 -0
  82. package/dist/{units-CQ5Q99RC.js → units-VVLgQ7x7.js} +7 -16
  83. package/dist/{url-CRfCOhUI.js → url-Bpc6wLea.js} +24 -11
  84. package/dist/{url-CsBkRaJy.js → url-D2_VlEeH.js} +25 -12
  85. package/dist/{validate-D6DJepZv.js → validate-PGgMsasz.js} +3 -5
  86. package/dist/{validate-BxpupdAf.js → validate-zv4-IZyZ.js} +690 -377
  87. package/dist/{version-Byqi2guX.js → version-BFs370Ce.js} +3 -5
  88. package/dist/{vite-scan-CT_vsp4g.js → vite-scan-DFKSGVE9.js} +87 -92
  89. package/dist/vite.d.ts +2 -6
  90. package/dist/vite.js +6482 -6018
  91. package/dist/vue-i18n-CBmZqHbG.js +806 -0
  92. package/dist/{which-BOemZ5Q8.js → which-BpyJyBkX.js} +44 -37
  93. package/dist/{worker-84U6uYB3.js → worker-BjzVqJVO.js} +454 -608
  94. package/package.json +5 -5
  95. package/dist/check-HsmmpJZg.js +0 -1
  96. package/dist/codec-DuvU2VQy.js +0 -207
  97. package/dist/collisions-CfpZU8e4.js +0 -217
  98. package/dist/compile-BaDh0cHG.js +0 -245
  99. package/dist/concurrency-C9UUWuDC.js +0 -96
  100. package/dist/concurrency-DONL7t4V.js +0 -1
  101. package/dist/engine-C2ENBRJe.js +0 -531
  102. package/dist/i18next-9HAoxwUI.js +0 -1
  103. package/dist/i18next-BEJgv_S8.js +0 -1596
  104. package/dist/lingui-zUiCl9Um.js +0 -833
  105. package/dist/messages-BfjIExyB.js +0 -166
  106. package/dist/migrate-IpLDMXmq.js +0 -1484
  107. package/dist/migrate-rCQuOGsf.js +0 -1
  108. package/dist/project-Bw9UPIdx.js +0 -1046
  109. package/dist/project-C4GpaN-n.js +0 -381
  110. package/dist/react-intl-BP0u-D5m.js +0 -519
  111. package/dist/restore-CiYv-jxS.js +0 -175
  112. package/dist/rewrite-EsIw_lsq.js +0 -803
  113. package/dist/run-BEcnBbu-.js +0 -694
  114. package/dist/runtime-DTMmliT1.js +0 -64
  115. package/dist/sync-B9V2KFwb.js +0 -658
  116. package/dist/translate-CQnJfLjO.js +0 -299
  117. package/dist/types-wSh9fCBY.js +0 -11
  118. package/dist/vue-i18n-g0iGy6CZ.js +0 -651
@@ -1,5 +1,5 @@
1
- import { _ as DEV, b as trim, g as BUILD, l as quiet, n as S, t as textDirection, x as warnOnce, y as own } from "./dir-zw6bGMKQ.js";
2
- //#region src/runtime/bidi.ts
1
+ import { b as warnOnce, c as quiet, g as DEV, h as BUILD, n as S, t as textDirection, v as own, y as trim } from "./dir-TGLYuOZb.js";
2
+ // src/runtime/bidi.ts
3
3
  /**
4
4
  * Automatic bidi isolation of interpolated strings (INTERNALS §2.3, PLAN
5
5
  * §4.2): a user-supplied name in Arabic inside an English sentence, or a Latin
@@ -15,8 +15,7 @@ const RTL_OR_CONTROL = /[\u0590-\u08FF\u200E\u200F\u202A-\u202E\u2066-\u2069\uFB
15
15
  * counts the value's open isolates (a parameter, not a local: no block body).
16
16
  */
17
17
  const isolate = (value, locale, open = 0) => value && (textDirection(locale) === "rtl" || RTL_OR_CONTROL.test(value)) ? "⁨" + value.replace(/[\u2066-\u2069]/g, (c) => (c < "⁩" ? ++open : open && open--) ? c : "") + "⁩".repeat(open + 1) : value;
18
- //#endregion
19
- //#region src/runtime/intl.ts
18
+ // src/runtime/intl.ts
20
19
  /**
21
20
  * Intl formatter caches and the scope-taking implementations behind `fmt`
22
21
  * (PLAN §5.12, §5.17). Constructing an Intl formatter costs 23–228 µs and a
@@ -70,7 +69,7 @@ const intern = (o) => {
70
69
  */
71
70
  function formatPart(op, options, value, scope) {
72
71
  if (value == null) return "";
73
- const o = options ? DEV ? intern(options) : options : NO_OPTIONS[op - 4];
72
+ const o = DEV && options ? intern(options) : options ?? NO_OPTIONS[op - 4];
74
73
  let formatters = irCache.get(o);
75
74
  if (!formatters) irCache.set(o, formatters = /* @__PURE__ */ new Map());
76
75
  const { locale, timeZone: zone } = scope;
@@ -306,28 +305,23 @@ const fDuration = (scope, duration, options) => {
306
305
  const parts = [];
307
306
  const display = style === "digital" ? "short" : style;
308
307
  const v = (u) => duration[u + "s"] ?? 0;
309
- for (const u of DURATION_UNITS) {
310
- if (style === "digital" && u === "hour") {
311
- const two = nf(scope, "n", { minimumIntegerDigits: 2 });
312
- parts.push(fNumber(scope, v("hour")) + ":" + two.format(v("minute")) + ":" + two.format(v("second") + v("millisecond") / 1e3));
313
- break;
314
- }
315
- if (v(u)) parts.push(nf(scope, "U" + u + display, { unitDisplay: display }, {
316
- style: "unit",
317
- unit: u
318
- }).format(v(u)));
319
- }
320
- if (!parts.length) parts.push(nf(scope, "Usecond" + display, { unitDisplay: display }, {
308
+ const unitText = (u, n) => nf(scope, "U" + u + display, { unitDisplay: display }, {
321
309
  style: "unit",
322
- unit: "second"
323
- }).format(0));
310
+ unit: u
311
+ }).format(n);
312
+ const digital = style === "digital";
313
+ for (const u of digital ? DURATION_UNITS.slice(0, 4) : DURATION_UNITS) if (v(u)) parts.push(unitText(u, v(u)));
314
+ if (digital) {
315
+ const two = nf(scope, "n", { minimumIntegerDigits: 2 });
316
+ parts.push(fNumber(scope, v("hour")) + ":" + two.format(v("minute")) + ":" + two.format(v("second") + v("millisecond") / 1e3));
317
+ }
318
+ if (!parts.length) parts.push(unitText("second", 0));
324
319
  return fList(scope, parts, {
325
320
  type: "unit",
326
321
  style: display === "long" ? "long" : display
327
322
  });
328
323
  };
329
- //#endregion
330
- //#region src/runtime/format.ts
324
+ // src/runtime/format.ts
331
325
  /**
332
326
  * The IR interpreter (INTERNALS §2.3 "Interpretation"). Normative: the server
333
327
  * and the client must render byte-identical text, so every rule lives here
@@ -354,8 +348,23 @@ function caseOf(part, value, locale) {
354
348
  }
355
349
  return own(cases, key) ? cases[key] : cases.other;
356
350
  }
357
- /** `#` value inside a plural case: the raw number minus the offset; null (nothing) without a value. */
358
- const poundOf = (part, value) => value == null ? null : Number(value) - (part[3] ?? 0);
351
+ /**
352
+ * `#` value inside a case: a select's keeps `n`, the enclosing plural's; a
353
+ * plural's is the raw number minus the offset, null (nothing) without a value.
354
+ */
355
+ function poundOf(part, value, n) {
356
+ if (part[1] === 1) return n;
357
+ return value == null ? null : Number(value) - (part[3] ?? 0);
358
+ }
359
+ /**
360
+ * Dev only: warns about a value part whose argument has no value. A select
361
+ * without one takes `other`, as for any value it lacks a case for, and tags
362
+ * (7, 8) have handlers, not values.
363
+ */
364
+ function warnMissing(value, part, message) {
365
+ const op = part[1];
366
+ if (value == null && op !== 1 && !(op > 6)) warnOnce(`no value for {${part[0]}} in ${JSON.stringify(message)}`);
367
+ }
359
368
  /** `{x, date, medium}`'s options (FormatJS's default `formats`), one object so its formatters are cached. */
360
369
  const MEDIUM = {
361
370
  month: "short",
@@ -387,61 +396,76 @@ function formatMessage(message, values, scope, n = 0, from = 0) {
387
396
  const p = message[i];
388
397
  if (typeof p === "string") out += p;
389
398
  else if (p === 0) out += formatPart(4, void 0, n, scope);
399
+ else if (p[1] > 6) out += formatMessage(p, values, scope, n, 2);
390
400
  else {
391
401
  const op = p[1];
392
- if (op === 7) out += formatMessage(p, values, scope, n, 2);
393
- else if (op !== 8) {
394
- const value = valueOf(values, p[0]);
395
- if (DEV && value == null && op !== 1) warnOnce(`no value for {${p[0]}} in ${JSON.stringify(message)}`);
396
- if (op === void 0) out += argText(value, scope);
397
- else if (op < 4) {
398
- const c = caseOf(p, value, scope.locale);
399
- if (c !== void 0) out += formatMessage(c, values, scope, op === 1 ? n : poundOf(p, value));
400
- } else out += formatPart(op, p[2], value, scope);
401
- }
402
+ const value = valueOf(values, p[0]);
403
+ if (DEV) warnMissing(value, p, message);
404
+ if (op > 3) out += formatPart(op, p[2], value, scope);
405
+ else if (op) {
406
+ const c = caseOf(p, value, scope.locale);
407
+ if (c) out += formatMessage(c, values, scope, poundOf(p, value, n));
408
+ } else out += argText(value, scope);
402
409
  }
403
410
  }
404
411
  return out;
405
412
  }
406
- //#endregion
407
- //#region src/runtime/t.ts
413
+ // src/runtime/t.ts
408
414
  /**
409
415
  * `t` and `msg` (PLAN §5.3, §5.12; INTERNALS §2.11.2). The hot path for a
410
416
  * plain string is: resolve the scope, one `Map.get`, one `typeof`.
411
417
  */
412
418
  const { resolve, track: notify } = S;
413
419
  /**
420
+ * Dev only: the code's built-in message where the dev catalog's translation
421
+ * is for other text. The dev catalog is not recomputed when code changes, so
422
+ * its message for a manual id may translate older text (D10): the code's
423
+ * text wins. Only dev catalogs carry labels.
424
+ */
425
+ function staleTranslation(scope, id, d) {
426
+ if (d?.h === void 0 || d.ir === void 0) return void 0;
427
+ const label = scope.labels?.get(id);
428
+ if (label === void 0 || label === d.h) return void 0;
429
+ warnOnce(`${id}: translation is for other text than ${JSON.stringify(d.message)}; run vi18n extract`);
430
+ S.missing(scope, id, "source-mismatch");
431
+ return d.ir;
432
+ }
433
+ /**
434
+ * What renders for an id no catalog has. Client JS carries ids, not text: a
435
+ * production client renders nothing rather than an id; the server renders
436
+ * the key (PLAN §4.9). Dev renders the text and says why.
437
+ */
438
+ function unknownId(scope, id, text) {
439
+ S.missing(scope, id, "unknown-id");
440
+ if (DEV) {
441
+ warnOnce(`no message ${JSON.stringify(text)} in ${scope.locale}: unknown id, or a call the plugin did not process`);
442
+ return text;
443
+ }
444
+ return scope.kind === "page" && !S.serverResolver && S.registration?.consumer !== "server" ? "" : text;
445
+ }
446
+ /**
414
447
  * The message to render for `key` in `scope`. `track` notifies the framework
415
448
  * trackers; translators bound to a fixed scope pass false.
416
449
  */
417
450
  function lookup(scope, key, track) {
418
451
  let text;
452
+ let id;
419
453
  let d;
420
454
  if (key && typeof key === "object") {
421
455
  d = key;
422
- text = d.message ?? d.id ?? "";
456
+ id = d.id;
457
+ text = d.message ?? id ?? "";
423
458
  } else text = String(key);
424
- const id = d?.id ?? scope.sources?.get(text) ?? text;
459
+ id ??= scope.sources?.get(text) ?? text;
425
460
  if (!quiet) scope.used?.add(id);
426
461
  if (track) notify();
427
462
  if (DEV) scope.seen?.(id);
428
463
  if (!BUILD && scope.test) return scope.test(id, d, text);
429
- if (DEV && d && d.h !== void 0 && d.ir !== void 0) {
430
- const label = scope.labels?.get(id);
431
- if (label !== void 0 && label !== d.h) {
432
- warnOnce(`${id}: translation is for other text than ${JSON.stringify(d.message)}; run vi18n extract`);
433
- S.missing(scope, id, "source-mismatch");
434
- return d.ir;
435
- }
436
- }
437
- const m = scope.messages.get(id) ?? d?.ir;
438
- if (m !== void 0) return m;
439
- S.missing(scope, id, "unknown-id");
440
464
  if (DEV) {
441
- warnOnce(`no message ${JSON.stringify(text)} in ${scope.locale}: unknown id, or a call the plugin did not process`);
442
- return text;
465
+ const stale = staleTranslation(scope, id, d);
466
+ if (stale !== void 0) return stale;
443
467
  }
444
- return scope.kind === "page" && !S.serverResolver && S.registration?.consumer !== "server" ? "" : text;
468
+ return scope.messages.get(id) ?? d?.ir ?? unknownId(scope, id, text);
445
469
  }
446
470
  const t = ((key, values) => {
447
471
  const scope = resolve();
@@ -450,5 +474,4 @@ const t = ((key, values) => {
450
474
  function msg(message) {
451
475
  return message;
452
476
  }
453
- //#endregion
454
- export { fTime as C, fSegment as S, formatPart as T, fDuration as _, caseOf as a, fPercent as b, valueOf as c, fCompare as d, fCurrency as f, fDisplayName as g, fDateRange as h, argText as i, fCollator as l, fDate as m, msg as n, formatMessage as o, fCurrencyMinor as p, t as r, poundOf as s, lookup as t, fCompact as u, fList as v, fUnit as w, fRelative as x, fNumber as y };
477
+ export { fSegment as C, formatPart as E, fRelative as S, fUnit as T, fDisplayName as _, caseOf as a, fNumber as b, valueOf as c, fCompact as d, fCompare as f, fDateRange as g, fDate as h, argText as i, warnMissing as l, fCurrencyMinor as m, msg as n, formatMessage as o, fCurrency as p, t as r, poundOf as s, lookup as t, fCollator as u, fDuration as v, fTime as w, fPercent as x, fList as y };
package/dist/test.d.ts CHANGED
@@ -1,5 +1,4 @@
1
- import { a as Message, y as Translator } from "./types-DsdWBG0b.js";
2
- //#region src/test/i18n.d.ts
1
+ import { a as Message, y as Translator } from "./types-BaG1LboH.js";
3
2
  /** What every message renders as: its translation or source, its id, or pseudo text. */
4
3
  type TestMode = "source" | "ids" | "pseudo";
5
4
  /** One locale's translations from the project's catalogs (`loadCatalog`). */
@@ -44,8 +43,6 @@ export declare function resetTestI18n(): void;
44
43
  * a call, tests under the plugin render the source locale as before.
45
44
  */
46
45
  export declare function createTestI18n(options?: TestI18nOptions): TestI18n;
47
- //#endregion
48
- //#region src/test/catalog.d.ts
49
46
  interface LoadCatalogOptions {
50
47
  /**
51
48
  * Where to look for `vi18n.config.ts` (walking up). Default: the project
@@ -61,16 +58,9 @@ interface LoadCatalogOptions {
61
58
  * `vite dev`. Memoised per project and locale for the test file.
62
59
  */
63
60
  export declare function loadCatalog(locale: string, options?: LoadCatalogOptions): Promise<TestCatalog>;
64
- //#endregion
65
- //#region src/test/pseudo.d.ts
66
- /**
67
- * Pseudo-locale checks for browser tests (PLAN §4.14, §5.21; INTERNALS §6
68
- * D193): `en-XA` and `ar-XB` bracket every rendered message, so on a page
69
- * switched to one, letters outside any bracket pair are text that never went
70
- * through `t()`. The page is typed by the two methods used, so Playwright's
71
- * `Page` fits and nothing here depends on Playwright. This module imports no
72
- * runtime: the scanners run in the test runner, the page has its own copy.
73
- */
61
+ /** The two generated pseudo-locales (PLAN §4.7, §5.21). */
62
+ declare const PSEUDO_LOCALES: readonly ["en-XA", "ar-XB"];
63
+ type PseudoLocale = (typeof PSEUDO_LOCALES)[number];
74
64
  /** What the helpers call on a Playwright `Page` (or anything with the same methods). */
75
65
  interface PseudoPage {
76
66
  evaluate(fn: (arg: unknown) => unknown, arg?: unknown): Promise<unknown>;
@@ -109,8 +99,7 @@ export declare function scanPseudo(page: PseudoPage, options?: PseudoScanOptions
109
99
  * exist in `vite dev` and non-production builds that list them in
110
100
  * `pseudoLocales`.
111
101
  */
112
- export declare function setPseudoLocale(page: PseudoPage, locale?: "en-XA" | "ar-XB", options?: {
102
+ export declare function setPseudoLocale(page: PseudoPage, locale?: PseudoLocale, options?: {
113
103
  timeout?: number;
114
104
  }): Promise<void>;
115
- //#endregion
116
105
  export type { LoadCatalogOptions, PseudoLeak, PseudoPage, PseudoScanOptions, TestCatalog, TestI18n, TestI18nOptions, TestMode };
package/dist/test.js CHANGED
@@ -1,8 +1,8 @@
1
- import { c as page, n as S, p as subs, r as changed, t as textDirection } from "./dir-zw6bGMKQ.js";
2
- import { c as parseICU, i as normalizeSource, n as canonicalize, t as compileMessage } from "./compile-Cc97JaW2.js";
3
- import { t as createScopedApi } from "./scoped-BMYpSthj.js";
4
- import { t as pseudoLocalize } from "./pseudo-DRv30iN5.js";
5
- //#region src/test/catalog.ts
1
+ import { f as subs, n as S, r as changed, s as page, t as textDirection } from "./dir-TGLYuOZb.js";
2
+ import { a as ID_LENGTH, o as PSEUDO_LOCALES, r as DEFAULT_CONFIG, t as pseudoLocalize } from "./pseudo-DNbNNVGP.js";
3
+ import { c as parseICU, i as normalizeSource, n as canonicalize, t as compileMessage } from "./compile-DqkofbiO.js";
4
+ import { t as createScopedApi } from "./scoped-h3KE8XWW.js";
5
+ // src/test/catalog.ts
6
6
  /**
7
7
  * `loadCatalog` (INTERNALS §3.8, §6 D194): one locale's translations read
8
8
  * from the project's catalog files, as the build compiles them, for
@@ -26,14 +26,13 @@ function loadCatalog(locale, options = {}) {
26
26
  ]);
27
27
  let load = loads.get(key);
28
28
  if (load === void 0) {
29
- load = import("./load-CQRz4PpM.js").then((m) => m.compileCatalog(locale, root, configFile));
29
+ load = import("./load-CMwhukZ4.js").then((m) => m.compileCatalog(locale, root, configFile));
30
30
  loads.set(key, load);
31
31
  load.catch(() => loads.delete(key));
32
32
  }
33
33
  return load;
34
34
  }
35
- //#endregion
36
- //#region src/test/i18n.ts
35
+ // src/test/i18n.ts
37
36
  /**
38
37
  * `createTestI18n` (PLAN §5.22, INTERNALS §3.8): unit and component tests
39
38
  * render in a locale, with real or hand-written translations, with message
@@ -46,7 +45,7 @@ function loadCatalog(locale, options = {}) {
46
45
  * picks every message, because only it sees the descriptor (§6 D189).
47
46
  */
48
47
  const DEFAULT_NOW = Date.UTC(2026, 0, 1);
49
- const PSEUDO = /* @__PURE__ */ new Set(["en-XA", "ar-XB"]);
48
+ const PSEUDO = new Set(PSEUDO_LOCALES);
50
49
  /** What the page held before the first `createTestI18n`; null while nothing is applied. */
51
50
  let saved = null;
52
51
  const html = () => typeof document === "object" && document?.documentElement ? document.documentElement : null;
@@ -89,16 +88,13 @@ function testRegistration(locale) {
89
88
  redirectRoot: false,
90
89
  propagate: false,
91
90
  switch: "in-place",
92
- cookie: {
93
- name: "vi18n_locale",
94
- maxAge: 31536e3
95
- },
91
+ cookie: { ...DEFAULT_CONFIG.routing.cookie },
96
92
  base: "/"
97
93
  },
98
94
  ssr: {
99
- timeZone: "UTC",
95
+ timeZone: DEFAULT_CONFIG.ssr.timeZone,
100
96
  timeZoneFrom: {},
101
- normalizeSpaces: true
97
+ normalizeSpaces: DEFAULT_CONFIG.ssr.normalizeSpaces
102
98
  }
103
99
  },
104
100
  test: true
@@ -155,18 +151,7 @@ function check(condition, message) {
155
151
  * a call, tests under the plugin render the source locale as before.
156
152
  */
157
153
  function createTestI18n(options = {}) {
158
- const mode = options.mode ?? "source";
159
- check([
160
- "source",
161
- "ids",
162
- "pseudo"
163
- ].includes(mode), `unknown test mode ${JSON.stringify(mode)}`);
164
- const timeZone = options.timeZone ?? "UTC";
165
- new Intl.DateTimeFormat("en", { timeZone });
166
- const now = options.now instanceof Date ? options.now.getTime() : options.now ?? DEFAULT_NOW;
167
- check(Number.isFinite(now), "now must be a finite time");
168
- const idLength = options.idLength ?? 12;
169
- check(Number.isInteger(idLength) && idLength >= 8 && idLength <= 16, "idLength must be an integer from 8 to 16");
154
+ const { mode, timeZone, now, idLength } = checkedOptions(options);
170
155
  const catalog = options.catalog;
171
156
  const requested = options.locale ?? catalog?.locale;
172
157
  if (catalog && requested !== catalog.locale) throw new RangeError(`vi18n: the catalog is for ${catalog.locale}, not ${requested}`);
@@ -177,6 +162,52 @@ function createTestI18n(options = {}) {
177
162
  Intl.getCanonicalLocales(locale);
178
163
  check(base === null || base.config.locales.includes(locale) || PSEUDO.has(locale), `unknown locale ${locale} (${base?.config.locales.join(", ")})`);
179
164
  const h = html();
165
+ const before = saveOnce(h);
166
+ if (base === null) S.register(testRegistration(locale));
167
+ page.locale = locale;
168
+ page.messages = catalog?.messages ?? before.messages;
169
+ page.timeZone = timeZone;
170
+ page.now = now;
171
+ page.test = testHook({
172
+ mode,
173
+ locale,
174
+ own,
175
+ idLength
176
+ });
177
+ if (h) Object.assign(h, {
178
+ lang: locale,
179
+ dir: textDirection(locale)
180
+ });
181
+ notify();
182
+ return {
183
+ ...createScopedApi(page),
184
+ mode,
185
+ reset: resetTestI18n
186
+ };
187
+ }
188
+ /** The options with their defaults, each checked; throws a RangeError naming the bad one. */
189
+ function checkedOptions(options) {
190
+ const mode = options.mode ?? "source";
191
+ check([
192
+ "source",
193
+ "ids",
194
+ "pseudo"
195
+ ].includes(mode), `unknown test mode ${JSON.stringify(mode)}`);
196
+ const timeZone = options.timeZone ?? DEFAULT_CONFIG.ssr.timeZone;
197
+ new Intl.DateTimeFormat("en", { timeZone });
198
+ const now = options.now instanceof Date ? options.now.getTime() : options.now ?? DEFAULT_NOW;
199
+ check(Number.isFinite(now), "now must be a finite time");
200
+ const idLength = options.idLength ?? ID_LENGTH.default;
201
+ check(Number.isInteger(idLength) && idLength >= ID_LENGTH.min && idLength <= ID_LENGTH.max, `idLength must be an integer from ${ID_LENGTH.min} to ${ID_LENGTH.max}`);
202
+ return {
203
+ mode,
204
+ timeZone,
205
+ now,
206
+ idLength
207
+ };
208
+ }
209
+ /** Records what the page holds before the first `createTestI18n`, once. */
210
+ function saveOnce(h) {
180
211
  saved ??= {
181
212
  locale: page.locale,
182
213
  messages: page.messages,
@@ -190,13 +221,13 @@ function createTestI18n(options = {}) {
190
221
  dir: h.dir
191
222
  }
192
223
  };
193
- if (base === null) S.register(testRegistration(locale));
224
+ return saved;
225
+ }
226
+ /** The scope's `test` hook: what every message renders as in this mode and locale. */
227
+ function testHook(input) {
228
+ const { mode, locale, own, idLength } = input;
194
229
  const style = locale === "ar-XB" ? "ar-XB" : "en-XA";
195
- page.locale = locale;
196
- page.messages = catalog?.messages ?? saved.messages;
197
- page.timeZone = timeZone;
198
- page.now = now;
199
- page.test = (id, d, text) => {
230
+ return (id, d, text) => {
200
231
  const source = d?.message ?? text;
201
232
  if (mode === "ids") return d?.id ?? (page.messages.has(id) ? id : generatedId(canonicalOf(source), idLength));
202
233
  if (mode === "pseudo") return pseudo(source, style);
@@ -206,19 +237,8 @@ function createTestI18n(options = {}) {
206
237
  }
207
238
  return page.messages.get(id) ?? d?.ir ?? compiled(source);
208
239
  };
209
- if (h) Object.assign(h, {
210
- lang: locale,
211
- dir: textDirection(locale)
212
- });
213
- notify();
214
- return {
215
- ...createScopedApi(page),
216
- mode,
217
- reset: resetTestI18n
218
- };
219
240
  }
220
- //#endregion
221
- //#region src/test/pseudo.ts
241
+ // src/test/pseudo.ts
222
242
  const LETTER = /\p{L}/u;
223
243
  const BIDI_CONTROL = /[\u202A-\u202E\u2066-\u2069\u200E\u200F]/g;
224
244
  /**
@@ -295,6 +315,8 @@ function pageText(arg) {
295
315
  async function scanPseudo(page, options = {}) {
296
316
  return findPseudoLeaks(await page.evaluate(pageText, [...options.ignore ?? []]), options);
297
317
  }
318
+ /** Playwright's rejection when the page navigated away during `evaluate`. */
319
+ const NAVIGATED = /context was destroyed|navigat/i;
298
320
  /**
299
321
  * Switches the page to a pseudo-locale through its own vi18n runtime
300
322
  * (`setLocale`, in place or by navigation, as the app's routing does it) and
@@ -308,12 +330,19 @@ async function setPseudoLocale(page, locale = "en-XA", options = {}) {
308
330
  const state = globalThis[Symbol.for("menapo.vi18n")];
309
331
  if (!state?.locales) return "vi18n is not loaded on this page";
310
332
  if (!state.locales.includes(l)) return `${l} is not an active locale here (${state.locales.join(", ")})`;
311
- await state.setLocale(l);
333
+ try {
334
+ await state.setLocale(l);
335
+ } catch (error) {
336
+ return { failed: error instanceof Error ? error.message : String(error) };
337
+ }
312
338
  return null;
313
- }, locale).catch(() => null);
339
+ }, locale).catch((error) => {
340
+ if (NAVIGATED.test(error instanceof Error ? error.message : String(error))) return null;
341
+ throw error;
342
+ });
343
+ if (typeof problem === "object" && problem !== null && "failed" in problem) throw new Error(`vi18n: setLocale(${JSON.stringify(locale)}) failed in the page: ${String(problem.failed)}`);
314
344
  if (typeof problem === "string") throw new Error(`vi18n: ${problem}; pseudo-locales exist in vite dev and in builds of another mode than production (vite build --mode staging) that list them in pseudoLocales`);
315
345
  await page.waitForFunction((arg) => document.documentElement.lang === arg, locale, options.timeout === void 0 ? {} : { timeout: options.timeout });
316
346
  await page.evaluate(() => globalThis[Symbol.for("menapo.vi18n")]?.ready());
317
347
  }
318
- //#endregion
319
348
  export { createTestI18n, findPseudoLeaks, loadCatalog, resetTestI18n, scanPseudo, setPseudoLocale };