@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.
- package/README.md +19 -0
- package/dist/{apply-Bre-lY9J.js → apply-Bg-3rB2m.js} +69 -89
- package/dist/{captured-Bj8bO6vd.js → captured-DfLk50Ji.js} +196 -217
- package/dist/{check-BIKEuu6B.js → check-CunekuYs.js} +76 -85
- package/dist/cli.js +2 -3
- package/dist/{collect-Cx4_SKOe.js → collect-CYATDjdo.js} +1 -2
- package/dist/collisions-CDSdtLQm.js +215 -0
- package/dist/{compile-Cc97JaW2.js → compile-DqkofbiO.js} +376 -331
- package/dist/compile-hva0qjhZ.js +240 -0
- 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-LgIWyeSp.js} +28 -27
- package/dist/{dir-zw6bGMKQ.js → dir-TGLYuOZb.js} +34 -37
- package/dist/{duplicates-yuRljQ6h.js → duplicates-8cudcHNj.js} +10 -27
- package/dist/engine-ecRD8-IE.js +556 -0
- package/dist/engine.d.ts +1 -5
- package/dist/engine.js +297 -168
- package/dist/exchange-DjwlrTQ9.js +41 -0
- package/dist/{exclude-Du-Zd_qI.js → exclude-BFETmvde.js} +2 -3
- package/dist/{export-C9Sy6UWv.js → export-D2tsqWIr.js} +17 -38
- package/dist/{extract-C3S8btx0.js → extract-BxYchVmY.js} +114 -82
- package/dist/{formats-9unqj_fZ.js → formats-BaryZ2N7.js} +352 -276
- package/dist/fs-ezCMZeDV.js +52 -0
- package/dist/i18next-COO6o0tX.js +1907 -0
- package/dist/i18next-Dr7DCQlQ.js +1 -0
- package/dist/{import-nANvQutw.js → import-vSC29Cn4.js} +81 -75
- package/dist/index.d.ts +1 -13
- package/dist/index.js +14 -16
- package/dist/{init-C2ScuW6a.js → init-Cc7A-8VX.js} +466 -501
- package/dist/{library-D5CWvTQs.js → library-tp_xqzSY.js} +975 -451
- package/dist/lingui-BnnlqGXT.js +902 -0
- package/dist/lint.d.ts +0 -4
- package/dist/lint.js +70 -82
- package/dist/{load-gW-oJt1Q.js → load-BSIeGJ5v.js} +275 -148
- package/dist/{load-CQRz4PpM.js → load-SSrAeJVB.js} +1214 -1116
- package/dist/{locales-DX4MOBFE.js → locales-D0U-yVRm.js} +271 -237
- package/dist/{lsp-RMMMc88P.js → lsp-DvC11pBZ.js} +4 -5
- package/dist/{match-BGr8EXB3.js → match-BLDcj610.js} +11 -4
- package/dist/{mcp-CHVwBoRP.js → mcp-D2zzOTBy.js} +4 -5
- package/dist/{merge-driver-BTX87aVm.js → merge-driver-BLI8OtAc.js} +138 -122
- package/dist/migrate-1r43OBfe.js +1 -0
- package/dist/migrate-ChDGhlC-.js +2169 -0
- package/dist/{openai-CTaMDcl-.js → openai-CLn4puY8.js} +128 -87
- package/dist/{output-DWE3SIUA.js → output-D5tAt8q4.js} +15 -9
- package/dist/parse.d.ts +1 -3
- package/dist/parse.js +7 -8
- package/dist/{pipeline-C9Dbotkh.js → pipeline-BJSkkRYC.js} +387 -359
- package/dist/{pipeline-DbX6rlo5.js → pipeline-BeCc441z.js} +1 -1
- package/dist/project-B5KIO0q-.js +544 -0
- package/dist/{pseudo-DRv30iN5.js → pseudo-B2DUpoLu.js} +126 -3
- package/dist/{raw-C4Y6vyGY.js → raw-YsYZMS9n.js} +52 -29
- package/dist/react-intl-C8JehBBL.js +634 -0
- package/dist/rename-ZVGq9ZG1.js +577 -0
- package/dist/repeated-uuI1tUGg.js +85 -0
- package/dist/restore-xlBIrtRt.js +199 -0
- package/dist/rewrite-BwzXoBiA.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-CQ9pDLSa.js +674 -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-Da1Ot9IN.js → server-Br8tAuG2.js} +312 -386
- package/dist/{server-deBOq2vq.js → server-DJRpUQVZ.js} +1059 -333
- package/dist/server.d.ts +1 -17
- package/dist/server.js +419 -379
- package/dist/{sitemap-DJXzKoza.js → sitemap-CSAkm6oi.js} +21 -33
- package/dist/{sources-D19czDSA.js → sources-DNVbYsgs.js} +713 -373
- package/dist/{status-zr4jY59Y.js → status-q6M3rBrh.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-BNIAwMhR.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 +126 -56
- package/dist/translate-BP4iVhOR.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-B4wNX6PA.d.ts} +6 -8
- package/dist/{types-CgUCkFU1.d.ts → types-_4UdFhR9.d.ts} +24 -21
- package/dist/types-xR2exI3L.js +42 -0
- package/dist/{units-CQ5Q99RC.js → units-DPPfCN7j.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-BxpupdAf.js → validate-CgzaDdOY.js} +690 -377
- package/dist/{validate-D6DJepZv.js → validate-PGgMsasz.js} +3 -5
- package/dist/{version-Byqi2guX.js → version-DC-J5WvV.js} +3 -5
- package/dist/{vite-scan-CT_vsp4g.js → vite-scan-kM8Ta3rO.js} +87 -92
- package/dist/vite.d.ts +2 -6
- package/dist/vite.js +6500 -6032
- package/dist/vue-i18n-_uIXlFVh.js +806 -0
- package/dist/{which-BOemZ5Q8.js → which-DFWk_KwN.js} +44 -37
- package/dist/{worker-84U6uYB3.js → worker-zlhNj4y3.js} +454 -608
- package/package.json +5 -5
- package/dist/check-HsmmpJZg.js +0 -1
- package/dist/codec-DuvU2VQy.js +0 -207
- package/dist/collisions-CfpZU8e4.js +0 -217
- package/dist/compile-BaDh0cHG.js +0 -245
- package/dist/concurrency-C9UUWuDC.js +0 -96
- package/dist/concurrency-DONL7t4V.js +0 -1
- package/dist/engine-C2ENBRJe.js +0 -531
- package/dist/i18next-9HAoxwUI.js +0 -1
- package/dist/i18next-BEJgv_S8.js +0 -1596
- package/dist/lingui-zUiCl9Um.js +0 -833
- package/dist/messages-BfjIExyB.js +0 -166
- package/dist/migrate-IpLDMXmq.js +0 -1484
- package/dist/migrate-rCQuOGsf.js +0 -1
- package/dist/project-Bw9UPIdx.js +0 -1046
- package/dist/project-C4GpaN-n.js +0 -381
- package/dist/react-intl-BP0u-D5m.js +0 -519
- package/dist/restore-CiYv-jxS.js +0 -175
- package/dist/rewrite-EsIw_lsq.js +0 -803
- package/dist/run-BEcnBbu-.js +0 -694
- package/dist/runtime-DTMmliT1.js +0 -64
- package/dist/sync-B9V2KFwb.js +0 -658
- package/dist/translate-CQnJfLjO.js +0 -299
- package/dist/types-wSh9fCBY.js +0 -11
- package/dist/vue-i18n-g0iGy6CZ.js +0 -651
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { r as
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { t as
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
import { a as loadCatalogs, c as ownStatus, d as referencedMessages, f as scan, o as loadProject, s as occurrencesOf } from "./project-C4GpaN-n.js";
|
|
9
|
-
//#region src/cli/commands/check.ts
|
|
1
|
+
import { t as findCollisions } from "./collisions-CDSdtLQm.js";
|
|
2
|
+
import { r as resolveDuplicates, t as duplicateDiagnostics } from "./duplicates-8cudcHNj.js";
|
|
3
|
+
import { n as repeatedDiagnostics, r as repeatedTexts } from "./repeated-uuI1tUGg.js";
|
|
4
|
+
import { C as idSchemeMismatch, S as checkTranslation, c as occurrencesOf, l as ownStatus, m as scan, n as catalogFile, o as loadCatalogs, p as referencedMessages, s as loadProject, w as syntaxOfEntry } from "./project-B5KIO0q-.js";
|
|
5
|
+
import { r as plural, t as countBySeverity } from "./output-D5tAt8q4.js";
|
|
6
|
+
import { r as EXIT, t as CHECK_CATEGORIES } from "./types-xR2exI3L.js";
|
|
7
|
+
// src/cli/commands/check.ts
|
|
10
8
|
/**
|
|
11
9
|
* `vi18n check [missing] [placeholders] [syntax] [--ci] [--format …]`
|
|
12
10
|
* (INTERNALS §2.14, PLAN §4.14): validation of the catalogs against the
|
|
@@ -15,17 +13,13 @@ import { a as loadCatalogs, c as ownStatus, d as referencedMessages, f as scan,
|
|
|
15
13
|
*
|
|
16
14
|
* - syntax: catalogs that do not parse, invalid sources and translations,
|
|
17
15
|
* wrapped lines, duplicates, foreign contexts, collisions, id-scheme drift,
|
|
18
|
-
*
|
|
16
|
+
* the code's own extraction errors, and a text written at many call sites
|
|
17
|
+
* (`extraction.repeatedText`);
|
|
19
18
|
* - placeholders: everything `validateTranslation` finds in a translation
|
|
20
19
|
* (argument and tag mismatches, plural categories, length, apostrophes);
|
|
21
20
|
* - missing: referenced messages without a usable own translation per target
|
|
22
21
|
* locale, fuzzy and invalid ones included.
|
|
23
22
|
*/
|
|
24
|
-
const ALL = [
|
|
25
|
-
"missing",
|
|
26
|
-
"placeholders",
|
|
27
|
-
"syntax"
|
|
28
|
-
];
|
|
29
23
|
/** Missing ids named in each locale's summary; the count says how many more there are. */
|
|
30
24
|
const MISSING_LISTED = 20;
|
|
31
25
|
/** Scan findings that belong to `check syntax`: invalid source messages, and anything the build would fail on. */
|
|
@@ -33,9 +27,9 @@ function isSyntaxFinding(diagnostic) {
|
|
|
33
27
|
return diagnostic.severity === "error" || diagnostic.code.startsWith("icu-");
|
|
34
28
|
}
|
|
35
29
|
async function check(ctx, flags) {
|
|
36
|
-
const categories = flags.categories.length === 0 ?
|
|
30
|
+
const categories = flags.categories.length === 0 ? CHECK_CATEGORIES.slice() : flags.categories;
|
|
31
|
+
const selected = new Set(categories);
|
|
37
32
|
const project = await loadProject(ctx);
|
|
38
|
-
const { config } = project;
|
|
39
33
|
const found = {
|
|
40
34
|
missing: [],
|
|
41
35
|
placeholders: [],
|
|
@@ -44,74 +38,80 @@ async function check(ctx, flags) {
|
|
|
44
38
|
const scanned = await scan(project);
|
|
45
39
|
const loaded = await loadCatalogs(project);
|
|
46
40
|
const referenced = referencedMessages(project, scanned.messages, loaded.set);
|
|
47
|
-
if (
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
if (
|
|
41
|
+
if (selected.has("syntax")) found.syntax.push(...scanned.diagnostics.filter(isSyntaxFinding), ...loaded.diagnostics, ...referenced.diagnostics, ...findCollisions(occurrencesOf(scanned), loaded.set, project.codec, { referenced: new Set(project.config.extraction.keep) }), ...repeated(project, scanned));
|
|
42
|
+
const sources = new SourceCache(project.codec, referenced.identities);
|
|
43
|
+
for (const locale of project.config.locales) checkLocale(project, locale, loaded.set.get(locale), {
|
|
44
|
+
identities: referenced.identities,
|
|
45
|
+
sources,
|
|
46
|
+
selected,
|
|
47
|
+
found
|
|
48
|
+
});
|
|
49
|
+
return finish(ctx, flags, categories, found);
|
|
50
|
+
}
|
|
51
|
+
/** `extract-repeated-text` warnings: one text at `extraction.repeatedText` call sites or more. */
|
|
52
|
+
function repeated(project, scanned) {
|
|
53
|
+
const threshold = project.config.extraction.repeatedText;
|
|
54
|
+
if (threshold === false) return [];
|
|
55
|
+
const occurrences = scanned.files.flatMap((file) => file.occurrences);
|
|
56
|
+
return repeatedDiagnostics(repeatedTexts(occurrences, threshold));
|
|
57
|
+
}
|
|
58
|
+
/** One locale's findings in the selected categories. */
|
|
59
|
+
function checkLocale(project, locale, catalog, { identities, sources, selected, found }) {
|
|
60
|
+
const { config } = project;
|
|
61
|
+
const file = catalogFile(config, locale, catalog);
|
|
62
|
+
const read = catalog?.catalog ?? null;
|
|
63
|
+
if (selected.has("syntax") && read !== null) {
|
|
64
|
+
for (const entry of read.entries) syntaxOfEntry(found.syntax, entry, file, locale);
|
|
65
|
+
found.syntax.push(...duplicateDiagnostics(resolveDuplicates(read, project.codec).duplicates, file));
|
|
66
|
+
const scheme = idSchemeMismatch(project, file, locale, read.header.idScheme);
|
|
67
|
+
if (scheme !== null) found.syntax.push(scheme);
|
|
74
68
|
}
|
|
69
|
+
if (locale === config.sourceLocale) return;
|
|
70
|
+
const status = ownStatus(project, locale, catalog, identities);
|
|
71
|
+
const findings = translationFindings(project.codec, status, sources, file);
|
|
72
|
+
if (selected.has("syntax")) found.syntax.push(...findings.syntax);
|
|
73
|
+
if (selected.has("placeholders")) found.placeholders.push(...findings.placeholders);
|
|
74
|
+
if (selected.has("missing")) found.missing.push(...missing(project, status, file));
|
|
75
|
+
}
|
|
76
|
+
function finish(ctx, flags, categories, found) {
|
|
75
77
|
const data = {
|
|
76
78
|
categories,
|
|
77
79
|
counts: {}
|
|
78
80
|
};
|
|
79
81
|
let failed = false;
|
|
82
|
+
const summary = [];
|
|
80
83
|
for (const category of categories) {
|
|
81
84
|
const list = found[category];
|
|
82
85
|
ctx.out.report(list);
|
|
83
86
|
const counts = countBySeverity(list);
|
|
84
87
|
data.counts[category] = counts;
|
|
85
88
|
if (counts.error > 0 || flags.ci && counts.warning > 0) failed = true;
|
|
89
|
+
summary.push(`${category}: ${plural(counts.error, "error")}, ${plural(counts.warning, "warning")}`);
|
|
86
90
|
}
|
|
87
|
-
ctx.out.result(
|
|
88
|
-
const counts = data.counts[category];
|
|
89
|
-
return `${category}: ${plural(counts.error, "error")}, ${plural(counts.warning, "warning")}`;
|
|
90
|
-
}).join("; "));
|
|
91
|
+
ctx.out.result(summary.join("; "));
|
|
91
92
|
return {
|
|
92
93
|
exitCode: failed ? EXIT.failure : EXIT.ok,
|
|
93
94
|
data
|
|
94
95
|
};
|
|
95
96
|
}
|
|
96
|
-
/**
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
}
|
|
97
|
+
/** Each referenced source parsed once, however many locales check a translation against it. */
|
|
98
|
+
var SourceCache = class {
|
|
99
|
+
parsed = /* @__PURE__ */ new Map();
|
|
100
|
+
codec;
|
|
101
|
+
identities;
|
|
102
|
+
constructor(codec, identities) {
|
|
103
|
+
this.codec = codec;
|
|
104
|
+
this.identities = identities;
|
|
105
|
+
}
|
|
106
|
+
get(id) {
|
|
107
|
+
let source = this.parsed.get(id);
|
|
108
|
+
if (source === void 0) {
|
|
109
|
+
source = this.codec.parse(this.identities.get(id).canonical);
|
|
110
|
+
this.parsed.set(id, source);
|
|
111
|
+
}
|
|
112
|
+
return source;
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
115
|
/**
|
|
116
116
|
* Every referenced entry with a translation whose source still matches:
|
|
117
117
|
* a translation that does not parse is a syntax finding; otherwise every
|
|
@@ -120,8 +120,7 @@ function syntaxOfEntry(into, entry, file, locale) {
|
|
|
120
120
|
* plural categories, `maxLength`, apostrophes). Located at the entry's line,
|
|
121
121
|
* since positions inside the text mean nothing in a catalog.
|
|
122
122
|
*/
|
|
123
|
-
function translationFindings(
|
|
124
|
-
const { codec } = project;
|
|
123
|
+
function translationFindings(codec, status, sources, file) {
|
|
125
124
|
const out = {
|
|
126
125
|
syntax: [],
|
|
127
126
|
placeholders: []
|
|
@@ -142,21 +141,14 @@ function translationFindings(project, status, identities, file) {
|
|
|
142
141
|
if (entry.translation === "") continue;
|
|
143
142
|
const reason = status.reasons.get(id);
|
|
144
143
|
if (reason === "source-mismatch" || reason === "scheme-mismatch") continue;
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
parsed = codec.parse(entry.translation);
|
|
149
|
-
} catch (error) {
|
|
150
|
-
if (!isDiagnosticError(error)) throw error;
|
|
151
|
-
out.syntax.push(at(error.diagnostic, id, entry));
|
|
152
|
-
continue;
|
|
153
|
-
}
|
|
154
|
-
const options = {
|
|
144
|
+
const checked = checkTranslation(codec, {
|
|
145
|
+
translation: entry.translation,
|
|
146
|
+
source: sources.get(id),
|
|
155
147
|
locale: status.locale,
|
|
156
|
-
|
|
157
|
-
};
|
|
158
|
-
if (
|
|
159
|
-
for (const diagnostic of
|
|
148
|
+
maxLength: entry.maxLength
|
|
149
|
+
});
|
|
150
|
+
if (checked.parseError !== null) out.syntax.push(at(checked.parseError, id, entry));
|
|
151
|
+
for (const diagnostic of checked.findings) out.placeholders.push(at(diagnostic, id, entry));
|
|
160
152
|
}
|
|
161
153
|
return out;
|
|
162
154
|
}
|
|
@@ -197,5 +189,4 @@ function missing(project, status, file) {
|
|
|
197
189
|
});
|
|
198
190
|
return out;
|
|
199
191
|
}
|
|
200
|
-
|
|
201
|
-
export { syntaxOfEntry as n, check as t };
|
|
192
|
+
export { check };
|
package/dist/cli.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { t as run } from "./run-
|
|
2
|
+
import { t as run } from "./run-CQ9pDLSa.js";
|
|
3
3
|
import { createInterface } from "node:readline/promises";
|
|
4
|
-
|
|
4
|
+
// src/cli/bin.ts
|
|
5
5
|
/**
|
|
6
6
|
* The `vi18n` binary (docs/INTERNALS.md §3.5). In the workspace this `.ts`
|
|
7
7
|
* file runs with Node's type stripping; published, `dist/cli.js`. Everything
|
|
@@ -37,5 +37,4 @@ process.exitCode = await run(process.argv.slice(2), {
|
|
|
37
37
|
}
|
|
38
38
|
} } : {}
|
|
39
39
|
});
|
|
40
|
-
//#endregion
|
|
41
40
|
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/core/extract/collect.ts
|
|
2
2
|
const KEY = Symbol.for("@menapo/vi18n:extract-collector");
|
|
3
3
|
/** The collector `vi18n extract --vite` set, or null outside it. */
|
|
4
4
|
function activeCollector() {
|
|
@@ -9,5 +9,4 @@ function setCollector(collector) {
|
|
|
9
9
|
if (collector === null) delete globalThis[KEY];
|
|
10
10
|
else globalThis[KEY] = collector;
|
|
11
11
|
}
|
|
12
|
-
//#endregion
|
|
13
12
|
export { setCollector as n, activeCollector as t };
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { r as resolveDuplicates } from "./duplicates-8cudcHNj.js";
|
|
2
|
+
import { E as entryKey, T as entryCanonical, b as compareText } from "./library-tp_xqzSY.js";
|
|
3
|
+
// src/core/catalog/collisions.ts
|
|
4
|
+
const DELETED_HINT = "; if that message was deleted, run vi18n extract first";
|
|
5
|
+
function posix(path) {
|
|
6
|
+
return path.replaceAll("\\", "/");
|
|
7
|
+
}
|
|
8
|
+
function where(file, line) {
|
|
9
|
+
return line > 0 ? `${file}:${line}` : file;
|
|
10
|
+
}
|
|
11
|
+
function messagePlace(message) {
|
|
12
|
+
const location = message.locations?.[0] ?? (message.file === void 0 ? void 0 : {
|
|
13
|
+
file: message.file,
|
|
14
|
+
line: message.line ?? 0
|
|
15
|
+
});
|
|
16
|
+
if (location === void 0) return { text: "" };
|
|
17
|
+
return {
|
|
18
|
+
file: location.file,
|
|
19
|
+
line: location.line,
|
|
20
|
+
text: ` (${where(location.file, location.line)})`
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Canonical text → where it was first seen, per generated key. Only entries
|
|
25
|
+
* whose source hashes to their key take part: in the `"id"` layout and JSON a
|
|
26
|
+
* hand-edited or stripped source note is a stale entry (reported as a source
|
|
27
|
+
* mismatch elsewhere), not a second text behind the id, and a file still on
|
|
28
|
+
* another id length would match nothing anyway. PLAN §5.5 makes a collision
|
|
29
|
+
* two live texts with one id, and §5.6 says an edited `#. source:` never
|
|
30
|
+
* changes what ships, which a build-stopping collision would; this narrows
|
|
31
|
+
* the wording of INTERNALS §2.6.7 to that intent.
|
|
32
|
+
*/
|
|
33
|
+
function indexEntries(set, codec, ignoreKeys) {
|
|
34
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
35
|
+
for (const loaded of set.values()) {
|
|
36
|
+
if (loaded.catalog === null) continue;
|
|
37
|
+
const { catalog } = resolveDuplicates(loaded.catalog, codec);
|
|
38
|
+
const file = posix(loaded.path);
|
|
39
|
+
for (const entry of catalog.entries) {
|
|
40
|
+
if (entry.manualId !== null || entry.foreignContext !== null || entry.source === null) continue;
|
|
41
|
+
const key = entryKey(entry, catalog.layout, codec);
|
|
42
|
+
if (key === null || ignoreKeys !== void 0 && ignoreKeys.has(key)) continue;
|
|
43
|
+
const canonical = entryCanonical(entry, codec);
|
|
44
|
+
if (canonical === null || codec.label(canonical) !== key) continue;
|
|
45
|
+
let texts = byKey.get(key);
|
|
46
|
+
if (texts === void 0) byKey.set(key, texts = /* @__PURE__ */ new Map());
|
|
47
|
+
const known = texts.get(canonical);
|
|
48
|
+
if (known === void 0) texts.set(canonical, {
|
|
49
|
+
locale: loaded.locale,
|
|
50
|
+
file,
|
|
51
|
+
line: entry.line,
|
|
52
|
+
translated: isTranslated(entry)
|
|
53
|
+
});
|
|
54
|
+
else if (!known.translated && isTranslated(entry)) known.translated = true;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return byKey;
|
|
58
|
+
}
|
|
59
|
+
function isTranslated(entry) {
|
|
60
|
+
return entry.translation !== "" && entry.state !== "untranslated";
|
|
61
|
+
}
|
|
62
|
+
function fixes(a, aTranslated, b, bTranslated, codec) {
|
|
63
|
+
const longer = `use a longer ids.length (now ${codec.idLength})`;
|
|
64
|
+
if (aTranslated !== bTranslated) return `give ${JSON.stringify(aTranslated ? b : a)} a manual id (it has no translations yet), or ${longer}`;
|
|
65
|
+
return `give the message that has no translations yet a manual id, or ${longer}`;
|
|
66
|
+
}
|
|
67
|
+
/** An `id-collision` error placed where the first text is (when known), the other text in `related`. */
|
|
68
|
+
function collision(id, message, place, related, locale) {
|
|
69
|
+
const diagnostic = {
|
|
70
|
+
code: "id-collision",
|
|
71
|
+
severity: "error",
|
|
72
|
+
message,
|
|
73
|
+
id,
|
|
74
|
+
...locale === void 0 ? {} : { locale },
|
|
75
|
+
related: [related]
|
|
76
|
+
};
|
|
77
|
+
if (place.file !== void 0) {
|
|
78
|
+
diagnostic.file = place.file;
|
|
79
|
+
diagnostic.line = place.line;
|
|
80
|
+
}
|
|
81
|
+
return diagnostic;
|
|
82
|
+
}
|
|
83
|
+
/** The second text of a message collision, at the message's place when it has one. */
|
|
84
|
+
function relatedText(place, message) {
|
|
85
|
+
return {
|
|
86
|
+
...place.file === void 0 ? {} : {
|
|
87
|
+
file: place.file,
|
|
88
|
+
line: place.line
|
|
89
|
+
},
|
|
90
|
+
message
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
/** Two messages with one id and different canonical text; returns the messages by id and their source literals. */
|
|
94
|
+
function messageCollisions(messages, passes) {
|
|
95
|
+
const byId = /* @__PURE__ */ new Map();
|
|
96
|
+
const literals = [];
|
|
97
|
+
for (const message of messages) {
|
|
98
|
+
if (!message.manual) for (const literal of message.sources ?? (message.source === void 0 ? [] : [message.source])) literals.push([message, literal]);
|
|
99
|
+
const first = byId.get(message.id);
|
|
100
|
+
if (first === void 0) {
|
|
101
|
+
byId.set(message.id, message);
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
if (first.canonical === message.canonical) continue;
|
|
105
|
+
if (!passes.report(message.id, first.canonical, message.canonical)) continue;
|
|
106
|
+
const a = messagePlace(first);
|
|
107
|
+
const b = messagePlace(message);
|
|
108
|
+
const texts = passes.entries.get(message.id);
|
|
109
|
+
const fix = message.manual ? "give each text its own manual id" : fixes(first.canonical, texts?.get(first.canonical)?.translated === true, message.canonical, texts?.get(message.canonical)?.translated === true, passes.codec);
|
|
110
|
+
passes.diagnostics.push(collision(message.id, `${message.id} is the id of two texts, ${JSON.stringify(first.canonical)}${a.text} and ${JSON.stringify(message.canonical)}${b.text}: ${fix}`, a, relatedText(b, message.canonical)));
|
|
111
|
+
}
|
|
112
|
+
return {
|
|
113
|
+
byId,
|
|
114
|
+
literals
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* A source literal that spells another message's id. `/server` resolves a
|
|
119
|
+
* string key through `sources.json` before taking it as an id (§2.11.2), so
|
|
120
|
+
* it would render this message on the server for every `t("<that id>")` the
|
|
121
|
+
* build emits, while the client renders the right one: a hydration mismatch.
|
|
122
|
+
*/
|
|
123
|
+
function literalCollisions(literals, byId, passes) {
|
|
124
|
+
for (const [owner, literal] of literals) {
|
|
125
|
+
const other = byId.get(literal);
|
|
126
|
+
if (other === void 0 || other.id === owner.id) continue;
|
|
127
|
+
if (!passes.report(literal, `\0source:${owner.id}`, other.canonical)) continue;
|
|
128
|
+
const a = messagePlace(owner);
|
|
129
|
+
const b = messagePlace(other);
|
|
130
|
+
passes.diagnostics.push(collision(literal, `${JSON.stringify(literal)} is the text of ${owner.id}${a.text} and the id of ${JSON.stringify(other.canonical)}${b.text}, so the server would render one for the other: ${other.manual ? "rename the manual id" : `give ${JSON.stringify(owner.canonical)} a manual id`}`, a, relatedText(b, other.canonical)));
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
/** A generated message and an entry of any locale with its id but a different canonical source. */
|
|
134
|
+
function entryCollisions(byId, passes) {
|
|
135
|
+
for (const message of byId.values()) {
|
|
136
|
+
if (message.manual) continue;
|
|
137
|
+
const texts = passes.entries.get(message.id);
|
|
138
|
+
if (texts === void 0) continue;
|
|
139
|
+
const own = texts.get(message.canonical);
|
|
140
|
+
for (const [canonical, entry] of texts) {
|
|
141
|
+
if (canonical === message.canonical) continue;
|
|
142
|
+
if (!passes.report(message.id, message.canonical, canonical)) continue;
|
|
143
|
+
const place = messagePlace(message);
|
|
144
|
+
const live = passes.referenced?.has(message.id) === true;
|
|
145
|
+
passes.diagnostics.push(collision(message.id, `${message.id} is the id of ${JSON.stringify(message.canonical)}${place.text} and of ${JSON.stringify(canonical)} in the ${entry.locale} catalog (${where(entry.file, entry.line)}): ` + fixes(message.canonical, own?.translated === true, canonical, entry.translated, passes.codec) + (live ? "" : DELETED_HINT), place, {
|
|
146
|
+
file: entry.file,
|
|
147
|
+
line: entry.line,
|
|
148
|
+
message: canonical
|
|
149
|
+
}, entry.locale));
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/** Two generated entries of the set with one key, no message, and different sources. */
|
|
154
|
+
function catalogCollisions(byId, passes) {
|
|
155
|
+
const colliding = [];
|
|
156
|
+
for (const [key, texts] of passes.entries) if (!byId.has(key) && texts.size > 1) colliding.push([key, texts]);
|
|
157
|
+
colliding.sort(([a], [b]) => compareText(a, b));
|
|
158
|
+
for (const [key, entryTexts] of colliding) {
|
|
159
|
+
const [first, ...others] = entryTexts;
|
|
160
|
+
if (first === void 0) continue;
|
|
161
|
+
const [firstText, firstEntry] = first;
|
|
162
|
+
const live = passes.referenced?.has(key) === true;
|
|
163
|
+
for (const [canonical, entry] of others) {
|
|
164
|
+
if (!passes.report(key, firstText, canonical)) continue;
|
|
165
|
+
passes.diagnostics.push({
|
|
166
|
+
code: "id-collision",
|
|
167
|
+
severity: "error",
|
|
168
|
+
message: `${key} is the id of ${JSON.stringify(firstText)} in the ${firstEntry.locale} catalog (${where(firstEntry.file, firstEntry.line)}) and of ${JSON.stringify(canonical)} in the ${entry.locale} catalog (${where(entry.file, entry.line)}): ` + fixes(firstText, firstEntry.translated, canonical, entry.translated, passes.codec) + (live ? "" : DELETED_HINT),
|
|
169
|
+
id: key,
|
|
170
|
+
locale: firstEntry.locale,
|
|
171
|
+
file: firstEntry.file,
|
|
172
|
+
line: firstEntry.line,
|
|
173
|
+
related: [{
|
|
174
|
+
file: entry.file,
|
|
175
|
+
line: entry.line,
|
|
176
|
+
message: canonical
|
|
177
|
+
}]
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* `id-collision` errors for: two messages with one id and different
|
|
184
|
+
* canonical text; a generated message and an entry of any locale with its id
|
|
185
|
+
* but a different canonical source; two generated entries of the set with
|
|
186
|
+
* one key and different sources.
|
|
187
|
+
*
|
|
188
|
+
* `referenced`: ids that count as live beyond `messages` (`extraction.keep`,
|
|
189
|
+
* apps sharing the set that this scan does not cover). A colliding entry
|
|
190
|
+
* whose text no message uses and whose id is not in `referenced` gets the
|
|
191
|
+
* "run vi18n extract first" hint, since extract would delete it.
|
|
192
|
+
* `ignoreKeys`: entries extract is about to delete, which therefore never
|
|
193
|
+
* collide.
|
|
194
|
+
*/
|
|
195
|
+
function findCollisions(messages, set, codec, options = {}) {
|
|
196
|
+
const reported = /* @__PURE__ */ new Set();
|
|
197
|
+
const passes = {
|
|
198
|
+
codec,
|
|
199
|
+
entries: indexEntries(set, codec, options.ignoreKeys),
|
|
200
|
+
referenced: options.referenced,
|
|
201
|
+
report: (id, a, b) => {
|
|
202
|
+
const pair = a < b ? `${id}\0${a}\0${b}` : `${id}\0${b}\0${a}`;
|
|
203
|
+
if (reported.has(pair)) return false;
|
|
204
|
+
reported.add(pair);
|
|
205
|
+
return true;
|
|
206
|
+
},
|
|
207
|
+
diagnostics: []
|
|
208
|
+
};
|
|
209
|
+
const { byId, literals } = messageCollisions(messages, passes);
|
|
210
|
+
literalCollisions(literals, byId, passes);
|
|
211
|
+
entryCollisions(byId, passes);
|
|
212
|
+
catalogCollisions(byId, passes);
|
|
213
|
+
return passes.diagnostics;
|
|
214
|
+
}
|
|
215
|
+
export { findCollisions as t };
|