@menapo/vi18n 0.1.1 → 0.2.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.
Files changed (121) hide show
  1. package/README.md +19 -0
  2. package/dist/{apply-Bre-lY9J.js → apply-Bg-3rB2m.js} +69 -89
  3. package/dist/{captured-Bj8bO6vd.js → captured-DfLk50Ji.js} +196 -217
  4. package/dist/{check-BIKEuu6B.js → check-CunekuYs.js} +76 -85
  5. package/dist/cli.js +2 -3
  6. package/dist/{collect-Cx4_SKOe.js → collect-CYATDjdo.js} +1 -2
  7. package/dist/collisions-CDSdtLQm.js +215 -0
  8. package/dist/{compile-Cc97JaW2.js → compile-DqkofbiO.js} +376 -331
  9. package/dist/compile-hva0qjhZ.js +240 -0
  10. package/dist/concurrency-BCY_4zcr.js +1 -0
  11. package/dist/concurrency-Dy2ny50V.js +107 -0
  12. package/dist/config.d.ts +1 -5
  13. package/dist/config.js +4 -5
  14. package/dist/{types-D3QGM8XO.js → diagnostics-LgIWyeSp.js} +28 -27
  15. package/dist/{dir-zw6bGMKQ.js → dir-TGLYuOZb.js} +34 -37
  16. package/dist/{duplicates-yuRljQ6h.js → duplicates-8cudcHNj.js} +10 -27
  17. package/dist/engine-ecRD8-IE.js +556 -0
  18. package/dist/engine.d.ts +1 -5
  19. package/dist/engine.js +297 -168
  20. package/dist/exchange-DjwlrTQ9.js +41 -0
  21. package/dist/{exclude-Du-Zd_qI.js → exclude-BFETmvde.js} +2 -3
  22. package/dist/{export-C9Sy6UWv.js → export-D2tsqWIr.js} +17 -38
  23. package/dist/{extract-C3S8btx0.js → extract-BxYchVmY.js} +114 -82
  24. package/dist/{formats-9unqj_fZ.js → formats-BaryZ2N7.js} +352 -276
  25. package/dist/fs-ezCMZeDV.js +52 -0
  26. package/dist/i18next-COO6o0tX.js +1907 -0
  27. package/dist/i18next-Dr7DCQlQ.js +1 -0
  28. package/dist/{import-nANvQutw.js → import-vSC29Cn4.js} +81 -75
  29. package/dist/index.d.ts +1 -13
  30. package/dist/index.js +14 -16
  31. package/dist/{init-C2ScuW6a.js → init-Cc7A-8VX.js} +466 -501
  32. package/dist/{library-D5CWvTQs.js → library-tp_xqzSY.js} +975 -451
  33. package/dist/lingui-BnnlqGXT.js +902 -0
  34. package/dist/lint.d.ts +0 -4
  35. package/dist/lint.js +70 -82
  36. package/dist/{load-gW-oJt1Q.js → load-BSIeGJ5v.js} +275 -148
  37. package/dist/{load-CQRz4PpM.js → load-SSrAeJVB.js} +1214 -1116
  38. package/dist/{locales-DX4MOBFE.js → locales-D0U-yVRm.js} +271 -237
  39. package/dist/{lsp-RMMMc88P.js → lsp-DvC11pBZ.js} +4 -5
  40. package/dist/{match-BGr8EXB3.js → match-BLDcj610.js} +11 -4
  41. package/dist/{mcp-CHVwBoRP.js → mcp-D2zzOTBy.js} +4 -5
  42. package/dist/{merge-driver-BTX87aVm.js → merge-driver-BLI8OtAc.js} +138 -122
  43. package/dist/migrate-1r43OBfe.js +1 -0
  44. package/dist/migrate-ChDGhlC-.js +2169 -0
  45. package/dist/{openai-CTaMDcl-.js → openai-CLn4puY8.js} +128 -87
  46. package/dist/{output-DWE3SIUA.js → output-D5tAt8q4.js} +15 -9
  47. package/dist/parse.d.ts +1 -3
  48. package/dist/parse.js +7 -8
  49. package/dist/{pipeline-C9Dbotkh.js → pipeline-BJSkkRYC.js} +387 -359
  50. package/dist/{pipeline-DbX6rlo5.js → pipeline-BeCc441z.js} +1 -1
  51. package/dist/project-B5KIO0q-.js +544 -0
  52. package/dist/{pseudo-DRv30iN5.js → pseudo-B2DUpoLu.js} +126 -3
  53. package/dist/{raw-C4Y6vyGY.js → raw-YsYZMS9n.js} +52 -29
  54. package/dist/react-intl-C8JehBBL.js +634 -0
  55. package/dist/rename-ZVGq9ZG1.js +577 -0
  56. package/dist/repeated-uuI1tUGg.js +85 -0
  57. package/dist/restore-xlBIrtRt.js +199 -0
  58. package/dist/rewrite-BwzXoBiA.js +415 -0
  59. package/dist/{rich-DCUKl5HM.js → rich-ApY1Dm4S.js} +35 -28
  60. package/dist/rolldown-runtime-C1I3wEg2.js +43 -0
  61. package/dist/{rolldown-runtime-D7D4PA-g.js → rolldown-runtime-D8jQpDG7.js} +1 -2
  62. package/dist/run-CQ9pDLSa.js +674 -0
  63. package/dist/scan-worker.d.ts +2 -4
  64. package/dist/scan-worker.js +1 -1
  65. package/dist/{scoped-BMYpSthj.js → scoped-h3KE8XWW.js} +3 -4
  66. package/dist/{server-Da1Ot9IN.js → server-Br8tAuG2.js} +312 -386
  67. package/dist/{server-deBOq2vq.js → server-DJRpUQVZ.js} +1059 -333
  68. package/dist/server.d.ts +1 -17
  69. package/dist/server.js +419 -379
  70. package/dist/{sitemap-DJXzKoza.js → sitemap-CSAkm6oi.js} +21 -33
  71. package/dist/{sources-D19czDSA.js → sources-DNVbYsgs.js} +713 -373
  72. package/dist/{status-zr4jY59Y.js → status-q6M3rBrh.js} +30 -30
  73. package/dist/{stdio-FPOKQAgu.js → stdio-D9kTzyqB.js} +2 -4
  74. package/dist/{stdio-CVaJfxA7.js → stdio-FWIVU3P4.js} +1 -2
  75. package/dist/sync-BNIAwMhR.js +1352 -0
  76. package/dist/{t-DC-c9zE5.js → t-gvEXx25s.js} +76 -53
  77. package/dist/test.d.ts +5 -16
  78. package/dist/test.js +126 -56
  79. package/dist/translate-BP4iVhOR.js +336 -0
  80. package/dist/{ts-BaU5yOf0.js → ts-BX6kwig5.js} +25 -14
  81. package/dist/{types-DtvQ7UdD.js → types-3kwyaCAm.js} +1 -2
  82. package/dist/{types-DsdWBG0b.d.ts → types-B4wNX6PA.d.ts} +6 -8
  83. package/dist/{types-CgUCkFU1.d.ts → types-_4UdFhR9.d.ts} +24 -21
  84. package/dist/types-xR2exI3L.js +42 -0
  85. package/dist/{units-CQ5Q99RC.js → units-DPPfCN7j.js} +7 -16
  86. package/dist/{url-CRfCOhUI.js → url-Bpc6wLea.js} +24 -11
  87. package/dist/{url-CsBkRaJy.js → url-D2_VlEeH.js} +25 -12
  88. package/dist/{validate-BxpupdAf.js → validate-CgzaDdOY.js} +690 -377
  89. package/dist/{validate-D6DJepZv.js → validate-PGgMsasz.js} +3 -5
  90. package/dist/{version-Byqi2guX.js → version-DC-J5WvV.js} +3 -5
  91. package/dist/{vite-scan-CT_vsp4g.js → vite-scan-kM8Ta3rO.js} +87 -92
  92. package/dist/vite.d.ts +2 -6
  93. package/dist/vite.js +6500 -6032
  94. package/dist/vue-i18n-_uIXlFVh.js +806 -0
  95. package/dist/{which-BOemZ5Q8.js → which-DFWk_KwN.js} +44 -37
  96. package/dist/{worker-84U6uYB3.js → worker-zlhNj4y3.js} +454 -608
  97. package/package.json +5 -5
  98. package/dist/check-HsmmpJZg.js +0 -1
  99. package/dist/codec-DuvU2VQy.js +0 -207
  100. package/dist/collisions-CfpZU8e4.js +0 -217
  101. package/dist/compile-BaDh0cHG.js +0 -245
  102. package/dist/concurrency-C9UUWuDC.js +0 -96
  103. package/dist/concurrency-DONL7t4V.js +0 -1
  104. package/dist/engine-C2ENBRJe.js +0 -531
  105. package/dist/i18next-9HAoxwUI.js +0 -1
  106. package/dist/i18next-BEJgv_S8.js +0 -1596
  107. package/dist/lingui-zUiCl9Um.js +0 -833
  108. package/dist/messages-BfjIExyB.js +0 -166
  109. package/dist/migrate-IpLDMXmq.js +0 -1484
  110. package/dist/migrate-rCQuOGsf.js +0 -1
  111. package/dist/project-Bw9UPIdx.js +0 -1046
  112. package/dist/project-C4GpaN-n.js +0 -381
  113. package/dist/react-intl-BP0u-D5m.js +0 -519
  114. package/dist/restore-CiYv-jxS.js +0 -175
  115. package/dist/rewrite-EsIw_lsq.js +0 -803
  116. package/dist/run-BEcnBbu-.js +0 -694
  117. package/dist/runtime-DTMmliT1.js +0 -64
  118. package/dist/sync-B9V2KFwb.js +0 -658
  119. package/dist/translate-CQnJfLjO.js +0 -299
  120. package/dist/types-wSh9fCBY.js +0 -11
  121. package/dist/vue-i18n-g0iGy6CZ.js +0 -651
package/README.md CHANGED
@@ -90,6 +90,25 @@ The same pages, with the benchmarks, build as a site from
90
90
  [`site/`](https://github.com/menapo/kit/tree/main/site) in the
91
91
  repository; `vp run --filter @menapo/site dev` serves it locally.
92
92
 
93
+ ## For agents
94
+
95
+ Read [Start here](https://github.com/menapo/kit/blob/main/packages/vi18n/docs/guide/start-here.md),
96
+ then the [Cookbook](https://github.com/menapo/kit/blob/main/packages/vi18n/docs/guide/cookbook.md)
97
+ for your task. Signatures are in the
98
+ [API reference](https://github.com/menapo/kit/blob/main/packages/vi18n/docs/guide/reference.md);
99
+ an error message is looked up in
100
+ [Troubleshooting](https://github.com/menapo/kit/blob/main/packages/vi18n/docs/guide/troubleshooting.md).
101
+
102
+ - Entry points: `@menapo/vi18n` (app code), `/server`, `/parse`, `/vite`,
103
+ `/config`, `/lint`, `/test`, and the `vi18n` CLI. Never import `/engine`, and
104
+ there is no `/react`, `/vue` or `/svelte`.
105
+ - A message is one string literal, with values as ICU arguments.
106
+ - `t()` runs inside a function, a component or a request; at module level use
107
+ `msg()`.
108
+ - A plain `t()` result never goes into HTML: use `richHtml()`.
109
+ - Reword a message with `vi18n rename`, not by editing catalogs.
110
+ - Run `vp` only, and commit `vi18n.gen.ts` and `locales/`.
111
+
93
112
  ## Entry points
94
113
 
95
114
  | Import | For |
@@ -1,9 +1,8 @@
1
- import { o as isDiagnosticError } from "./types-D3QGM8XO.js";
2
- import { a as isManualId, r as validateTranslation } from "./validate-BxpupdAf.js";
3
- import { S as entryKey } from "./library-D5CWvTQs.js";
4
- import { r as resolveDuplicates } from "./duplicates-yuRljQ6h.js";
5
- import { i as entrySource, r as canonicalOrNull } from "./units-CQ5Q99RC.js";
6
- //#region src/core/exchange/apply.ts
1
+ import { r as resolveDuplicates } from "./duplicates-8cudcHNj.js";
2
+ import { E as entryKey, j as withSubject, k as translationErrors } from "./library-tp_xqzSY.js";
3
+ import { g as isManualId, m as tryCanonicalize } from "./validate-CgzaDdOY.js";
4
+ import { r as entrySource } from "./units-DPPfCN7j.js";
5
+ // src/core/exchange/apply.ts
7
6
  /**
8
7
  * Applying imported rows and restored entries to a catalog (PLAN §4.3, §4.4,
9
8
  * §5.19). Both are pure functions of the catalog they receive, so writers
@@ -24,29 +23,67 @@ function keyIndex(catalog, codec) {
24
23
  });
25
24
  return index;
26
25
  }
27
- /** The ICU errors that keep a translation from shipping, as `usableTranslation` finds them. */
28
- function translationErrors(translation, canonical, codec, locale) {
29
- try {
30
- const parsed = codec.parse(translation);
31
- return validateTranslation(parsed, codec.parse(canonical), {
32
- locale,
33
- text: translation
34
- }).filter((diagnostic) => diagnostic.severity === "error");
35
- } catch (error) {
36
- if (isDiagnosticError(error)) return [error.diagnostic];
37
- throw error;
26
+ /** The first entry per key after the read-side duplicate pick: what "the current translation" is. */
27
+ function currentEntries(catalog, codec) {
28
+ const current = /* @__PURE__ */ new Map();
29
+ for (const entry of resolveDuplicates(catalog, codec).catalog.entries) {
30
+ const key = entryKey(entry, catalog.layout, codec);
31
+ if (key !== null && !current.has(key)) current.set(key, entry);
32
+ }
33
+ return current;
34
+ }
35
+ /** The entry a row translates, and the canonical source that translation must fit; or why there is none. */
36
+ function matchRecord(record, current, context) {
37
+ const { codec } = context;
38
+ if (record.unsupported !== void 0) return {
39
+ skip: "unsupported",
40
+ id: record.key
41
+ };
42
+ let key = record.key;
43
+ let recordCanonical = null;
44
+ if (record.source !== null) {
45
+ recordCanonical = tryCanonicalize(codec, record.source);
46
+ if (recordCanonical === null) return {
47
+ skip: key === null ? "unknown" : "source-changed",
48
+ id: key
49
+ };
50
+ key ??= codec.label(recordCanonical);
38
51
  }
52
+ const entry = key === null ? void 0 : current.get(key);
53
+ if (key === null || entry === void 0) return {
54
+ skip: "unknown",
55
+ id: key
56
+ };
57
+ const source = entrySource(entry, key, context);
58
+ if (source === null) return {
59
+ skip: "no-source",
60
+ id: key
61
+ };
62
+ if (recordCanonical !== null) {
63
+ if (!(context.layout === "id" ? codec.label(recordCanonical) === source.label : recordCanonical === source.canonical)) return {
64
+ skip: "source-changed",
65
+ id: key
66
+ };
67
+ }
68
+ if (record.label !== null && record.label !== source.label) return {
69
+ skip: "source-changed",
70
+ id: key
71
+ };
72
+ if (recordCanonical === null && record.label === null && isManualId(key)) return {
73
+ skip: "no-source",
74
+ id: key
75
+ };
76
+ return {
77
+ key,
78
+ entry,
79
+ canonical: source.canonical
80
+ };
39
81
  }
40
82
  function applyImport(input) {
41
83
  const { catalog, records, context, locale } = input;
42
84
  const { codec } = context;
43
85
  const index = keyIndex(catalog, codec);
44
- const resolved = resolveDuplicates(catalog, codec).catalog;
45
- const current = /* @__PURE__ */ new Map();
46
- for (const entry of resolved.entries) {
47
- const key = entryKey(entry, catalog.layout, codec);
48
- if (key !== null && !current.has(key)) current.set(key, entry);
49
- }
86
+ const current = currentEntries(catalog, codec);
50
87
  const outcome = {
51
88
  catalog,
52
89
  changed: [],
@@ -65,50 +102,14 @@ function applyImport(input) {
65
102
  });
66
103
  };
67
104
  for (const record of records) {
68
- if (record.unsupported !== void 0) {
69
- skip(record, "unsupported", record.key);
70
- continue;
71
- }
72
- let key = record.key;
73
- let recordCanonical = null;
74
- if (record.source !== null) {
75
- recordCanonical = canonicalOrNull(record.source, codec);
76
- if (recordCanonical === null) {
77
- skip(record, key === null ? "unknown" : "source-changed", key);
78
- continue;
79
- }
80
- key ??= codec.label(recordCanonical);
81
- }
82
- const entry = key === null ? void 0 : current.get(key);
83
- if (key === null || entry === void 0) {
84
- skip(record, "unknown", key);
85
- continue;
86
- }
87
- const source = entrySource(entry, key, context);
88
- if (source === null) {
89
- skip(record, "no-source", key);
90
- continue;
91
- }
92
- if (recordCanonical !== null) {
93
- if (!(context.layout === "id" ? codec.label(recordCanonical) === source.label : recordCanonical === source.canonical)) {
94
- skip(record, "source-changed", key);
95
- continue;
96
- }
97
- }
98
- if (record.label !== null && record.label !== source.label) {
99
- skip(record, "source-changed", key);
100
- continue;
101
- }
102
- if (recordCanonical === null && record.label === null && isManualId(key)) {
103
- skip(record, "no-source", key);
104
- continue;
105
- }
106
- if (record.translation === "") {
107
- skip(record, "empty", key);
105
+ const match = matchRecord(record, current, context);
106
+ if ("skip" in match) {
107
+ skip(record, match.skip, match.id);
108
108
  continue;
109
109
  }
110
- if (record.draft) {
111
- skip(record, "draft", key);
110
+ const { key, entry } = match;
111
+ if (record.translation === "" || record.draft) {
112
+ skip(record, record.translation === "" ? "empty" : "draft", key);
112
113
  continue;
113
114
  }
114
115
  const earlier = taken.get(key);
@@ -117,20 +118,10 @@ function applyImport(input) {
117
118
  continue;
118
119
  }
119
120
  taken.set(key, record.translation);
120
- const errors = translationErrors(record.translation, source.canonical, codec, locale);
121
+ const errors = translationErrors(record.translation, match.canonical, codec, locale);
121
122
  if (errors.length > 0) {
122
123
  skip(record, "invalid", key);
123
- for (const diagnostic of errors) {
124
- const located = {
125
- ...diagnostic,
126
- locale,
127
- id: key
128
- };
129
- delete located.column;
130
- if (record.line > 0) located.line = record.line;
131
- else delete located.line;
132
- outcome.diagnostics.push(located);
133
- }
124
+ outcome.diagnostics.push(...errors.map((d) => withSubject(d, locale, key, record.line)));
134
125
  continue;
135
126
  }
136
127
  const state = record.state ?? (entry.translation === record.translation ? entry.state : "translated");
@@ -193,17 +184,7 @@ function applyRestore(input) {
193
184
  if (found === void 0) return;
194
185
  const errors = translationErrors(found.translation, source.canonical, codec, locale);
195
186
  if (errors.length > 0) {
196
- for (const diagnostic of errors) {
197
- const located = {
198
- ...diagnostic,
199
- locale,
200
- id: key
201
- };
202
- delete located.column;
203
- if (entry.line > 0) located.line = entry.line;
204
- else delete located.line;
205
- outcome.diagnostics.push(located);
206
- }
187
+ outcome.diagnostics.push(...errors.map((d) => withSubject(d, locale, key, entry.line)));
207
188
  return;
208
189
  }
209
190
  entries ??= catalog.entries.slice();
@@ -224,5 +205,4 @@ function applyRestore(input) {
224
205
  };
225
206
  return outcome;
226
207
  }
227
- //#endregion
228
208
  export { applyRestore as n, applyImport as t };