@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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@menapo/vi18n",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "i18n toolkit for Vite: source-as-id messages, per-route translation bundles, SSR and in-place locale switching in every framework",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"gettext",
|
|
@@ -11,14 +11,14 @@
|
|
|
11
11
|
"vite",
|
|
12
12
|
"vite-plugin"
|
|
13
13
|
],
|
|
14
|
-
"homepage": "https://github.com/menapo/
|
|
14
|
+
"homepage": "https://github.com/menapo/kit/blob/main/packages/vi18n/docs/guide/README.md",
|
|
15
15
|
"bugs": {
|
|
16
|
-
"url": "https://github.com/menapo/
|
|
16
|
+
"url": "https://github.com/menapo/kit/issues"
|
|
17
17
|
},
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"repository": {
|
|
20
20
|
"type": "git",
|
|
21
|
-
"url": "git+https://github.com/menapo/
|
|
21
|
+
"url": "git+https://github.com/menapo/kit.git",
|
|
22
22
|
"directory": "packages/vi18n"
|
|
23
23
|
},
|
|
24
24
|
"bin": {
|
|
@@ -53,11 +53,11 @@
|
|
|
53
53
|
"@vitejs/devtools": "0.8.0",
|
|
54
54
|
"@vue/compiler-sfc": "^3.5.44",
|
|
55
55
|
"eslint": "^10.13.0",
|
|
56
|
-
"oxc-parser": "0.
|
|
56
|
+
"oxc-parser": "0.156.0",
|
|
57
57
|
"svelte": "^5.57.2",
|
|
58
58
|
"typescript": "^7.0.2",
|
|
59
|
-
"vite": "npm:@voidzero-dev/vite-plus-core@1.
|
|
60
|
-
"vite-plus": "1.
|
|
59
|
+
"vite": "npm:@voidzero-dev/vite-plus-core@1.5.0",
|
|
60
|
+
"vite-plus": "1.5.0",
|
|
61
61
|
"vscode-languageserver": "^10.1.2",
|
|
62
62
|
"vscode-languageserver-textdocument": "^1.0.15"
|
|
63
63
|
},
|
|
@@ -83,7 +83,7 @@
|
|
|
83
83
|
"fast-deep-equal": "3.1.3",
|
|
84
84
|
"fast-uri": "3.1.8",
|
|
85
85
|
"json-schema-traverse": "1.0.0",
|
|
86
|
-
"oxc-parser": "0.
|
|
86
|
+
"oxc-parser": "0.156.0",
|
|
87
87
|
"vscode-jsonrpc": "9.0.3",
|
|
88
88
|
"vscode-languageserver": "10.1.2",
|
|
89
89
|
"vscode-languageserver-protocol": "3.18.4",
|
package/dist/check-D34P-S--.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { t as check } from "./check-DyrAbv73.js";
|
package/dist/codec-DuvU2VQy.js
DELETED
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
import { a as diagnosticError, o as isDiagnosticError } from "./types-D3QGM8XO.js";
|
|
2
|
-
import { c as sourceHash, d as parseSource, i as idScheme, l as isPlainText, u as normalizeSource } from "./validate-BxpupdAf.js";
|
|
3
|
-
//#region src/core/icu/print.ts
|
|
4
|
-
const HASH = 35;
|
|
5
|
-
const APOS = 39;
|
|
6
|
-
const SLASH = 47;
|
|
7
|
-
const LT = 60;
|
|
8
|
-
const GT = 62;
|
|
9
|
-
const LBRACE = 123;
|
|
10
|
-
const RBRACE = 125;
|
|
11
|
-
/** "Nothing follows": the end of the whole message. */
|
|
12
|
-
const END = -1;
|
|
13
|
-
/** Prints a message in canonical form. Literal text keeps every character. */
|
|
14
|
-
function printICU(message) {
|
|
15
|
-
return printNodes(message, false, END);
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* @param poundSensitive inside any plural/selectordinal option, where `#` must be quoted
|
|
19
|
-
* @param after first character printed after these nodes: `}` (option), `<` (closing tag) or END
|
|
20
|
-
*/
|
|
21
|
-
function printNodes(nodes, poundSensitive, after) {
|
|
22
|
-
let out = "";
|
|
23
|
-
const count = nodes.length;
|
|
24
|
-
for (let i = 0; i < count; i++) {
|
|
25
|
-
const node = nodes[i];
|
|
26
|
-
if (node.type === "literal") {
|
|
27
|
-
let value = node.value;
|
|
28
|
-
while (i + 1 < count && nodes[i + 1].type === "literal") value += nodes[++i].value;
|
|
29
|
-
const next = i + 1 < count ? firstChar(nodes[i + 1]) : after;
|
|
30
|
-
out += printLiteral(value, poundSensitive, next);
|
|
31
|
-
continue;
|
|
32
|
-
}
|
|
33
|
-
out += printNode(node, poundSensitive);
|
|
34
|
-
}
|
|
35
|
-
return out;
|
|
36
|
-
}
|
|
37
|
-
function printNode(node, poundSensitive) {
|
|
38
|
-
switch (node.type) {
|
|
39
|
-
case "literal": return printLiteral(node.value, poundSensitive, END);
|
|
40
|
-
case "argument": return `{${node.name}}`;
|
|
41
|
-
case "number":
|
|
42
|
-
case "date":
|
|
43
|
-
case "time": {
|
|
44
|
-
const style = node.style;
|
|
45
|
-
if (style === null) return `{${node.name}, ${node.type}}`;
|
|
46
|
-
return `{${node.name}, ${node.type}, ${style.kind === "skeleton" ? "::" + style.value : style.value}}`;
|
|
47
|
-
}
|
|
48
|
-
case "select": return `{${node.name}, select, ${printOptions(node.options, poundSensitive)}}`;
|
|
49
|
-
case "plural": {
|
|
50
|
-
const type = node.pluralType === "cardinal" ? "plural" : "selectordinal";
|
|
51
|
-
const offset = node.offset === 0 ? "" : `offset:${node.offset} `;
|
|
52
|
-
return `{${node.name}, ${type}, ${offset}${printOptions(node.options, true)}}`;
|
|
53
|
-
}
|
|
54
|
-
case "pound": return "#";
|
|
55
|
-
case "tag": return node.children === null ? `<${node.name}/>` : `<${node.name}>${printNodes(node.children, poundSensitive, LT)}</${node.name}>`;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
function printOptions(options, poundSensitive) {
|
|
59
|
-
let out = "";
|
|
60
|
-
for (let i = 0; i < options.length; i++) {
|
|
61
|
-
const option = options[i];
|
|
62
|
-
if (i > 0) out += " ";
|
|
63
|
-
out += `${option.key} {${printNodes(option.value, poundSensitive, RBRACE)}}`;
|
|
64
|
-
}
|
|
65
|
-
return out;
|
|
66
|
-
}
|
|
67
|
-
function firstChar(node) {
|
|
68
|
-
switch (node.type) {
|
|
69
|
-
case "tag": return LT;
|
|
70
|
-
case "pound": return HASH;
|
|
71
|
-
case "literal": return node.value.charCodeAt(0);
|
|
72
|
-
default: return LBRACE;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Minimal, deterministic quoting: a run starting at a special character
|
|
77
|
-
* (`{`, `}`, `#` where pound-sensitive, `<` before a letter or `/`) is wrapped
|
|
78
|
-
* in apostrophes together with any special characters and apostrophes that
|
|
79
|
-
* follow it; any other apostrophe is doubled only where a single one would
|
|
80
|
-
* open a quote.
|
|
81
|
-
*/
|
|
82
|
-
function printLiteral(value, poundSensitive, after) {
|
|
83
|
-
if (!needsQuoting(value, poundSensitive)) return value;
|
|
84
|
-
const length = value.length;
|
|
85
|
-
let out = "";
|
|
86
|
-
let run = 0;
|
|
87
|
-
let i = 0;
|
|
88
|
-
while (i < length) {
|
|
89
|
-
const c = value.charCodeAt(i);
|
|
90
|
-
if (isSpecial(value, i, c, poundSensitive)) {
|
|
91
|
-
let j = i + 1;
|
|
92
|
-
while (j < length) {
|
|
93
|
-
const d = value.charCodeAt(j);
|
|
94
|
-
if (d !== APOS && !isSpecial(value, j, d, poundSensitive)) break;
|
|
95
|
-
j++;
|
|
96
|
-
}
|
|
97
|
-
out += value.slice(run, i) + "'" + value.slice(i, j).replaceAll("'", "''") + "'";
|
|
98
|
-
i = j;
|
|
99
|
-
run = j;
|
|
100
|
-
continue;
|
|
101
|
-
}
|
|
102
|
-
if (c === APOS) {
|
|
103
|
-
const next = i + 1 < length ? value.charCodeAt(i + 1) : after;
|
|
104
|
-
if (next === APOS || next === LBRACE || next === RBRACE || next === LT || next === GT || next === HASH && poundSensitive) {
|
|
105
|
-
out += value.slice(run, i + 1) + "'";
|
|
106
|
-
run = i + 1;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
i++;
|
|
110
|
-
}
|
|
111
|
-
return out + value.slice(run);
|
|
112
|
-
}
|
|
113
|
-
function needsQuoting(value, poundSensitive) {
|
|
114
|
-
for (let i = 0; i < value.length; i++) {
|
|
115
|
-
const c = value.charCodeAt(i);
|
|
116
|
-
if (c === APOS || c === LBRACE || c === RBRACE || c === LT || c === HASH && poundSensitive) return true;
|
|
117
|
-
}
|
|
118
|
-
return false;
|
|
119
|
-
}
|
|
120
|
-
function isSpecial(value, i, c, poundSensitive) {
|
|
121
|
-
if (c === LBRACE || c === RBRACE) return true;
|
|
122
|
-
if (c === HASH) return poundSensitive;
|
|
123
|
-
if (c === LT) {
|
|
124
|
-
const next = value.charCodeAt(i + 1);
|
|
125
|
-
return next === SLASH || next >= 65 && next <= 90 || next >= 97 && next <= 122;
|
|
126
|
-
}
|
|
127
|
-
return false;
|
|
128
|
-
}
|
|
129
|
-
//#endregion
|
|
130
|
-
//#region src/core/codec.ts
|
|
131
|
-
/**
|
|
132
|
-
* The one place that turns source text into ids (INTERNALS §2.2). Extract,
|
|
133
|
-
* catalogs and compilation see the same message many times per run, so parses,
|
|
134
|
-
* canonical forms and hashes are memoised per string.
|
|
135
|
-
*/
|
|
136
|
-
/**
|
|
137
|
-
* Memo entries past this count are dropped all at once: a long dev session
|
|
138
|
-
* sees every edit of every message, while one scan of a large project needs
|
|
139
|
-
* the whole set warm.
|
|
140
|
-
*/
|
|
141
|
-
const MEMO_LIMIT = 2e5;
|
|
142
|
-
function createCodec(idLength) {
|
|
143
|
-
if (!Number.isInteger(idLength) || idLength < 8 || idLength > 16) throw diagnosticError({
|
|
144
|
-
code: "config-invalid",
|
|
145
|
-
severity: "error",
|
|
146
|
-
message: `ids.length must be an integer from 8 to 16, not ${String(idLength)}`
|
|
147
|
-
});
|
|
148
|
-
const parsed = /* @__PURE__ */ new Map();
|
|
149
|
-
const hashes = /* @__PURE__ */ new Map();
|
|
150
|
-
const entry = (source) => {
|
|
151
|
-
let found = parsed.get(source);
|
|
152
|
-
if (found === void 0) {
|
|
153
|
-
found = {
|
|
154
|
-
ast: null,
|
|
155
|
-
error: null,
|
|
156
|
-
canonical: null
|
|
157
|
-
};
|
|
158
|
-
try {
|
|
159
|
-
const normalized = normalizeSource(source);
|
|
160
|
-
found.ast = isPlainText(normalized) ? normalized === "" ? [] : [{
|
|
161
|
-
type: "literal",
|
|
162
|
-
value: normalized
|
|
163
|
-
}] : parseSource(normalized);
|
|
164
|
-
} catch (error) {
|
|
165
|
-
if (!isDiagnosticError(error)) throw error;
|
|
166
|
-
found.error = error;
|
|
167
|
-
}
|
|
168
|
-
if (parsed.size >= MEMO_LIMIT) parsed.clear();
|
|
169
|
-
parsed.set(source, found);
|
|
170
|
-
}
|
|
171
|
-
return found;
|
|
172
|
-
};
|
|
173
|
-
const hashOf = (canonical) => {
|
|
174
|
-
let found = hashes.get(canonical);
|
|
175
|
-
if (found === void 0) {
|
|
176
|
-
found = sourceHash(canonical);
|
|
177
|
-
if (hashes.size >= MEMO_LIMIT) hashes.clear();
|
|
178
|
-
hashes.set(canonical, found);
|
|
179
|
-
}
|
|
180
|
-
return found;
|
|
181
|
-
};
|
|
182
|
-
return {
|
|
183
|
-
idLength,
|
|
184
|
-
idScheme: idScheme(idLength),
|
|
185
|
-
canonicalize(source) {
|
|
186
|
-
const found = parsed.get(source);
|
|
187
|
-
if (found === void 0) {
|
|
188
|
-
const normalized = normalizeSource(source);
|
|
189
|
-
if (isPlainText(normalized)) return normalized;
|
|
190
|
-
}
|
|
191
|
-
const memo = found ?? entry(source);
|
|
192
|
-
if (memo.error !== null) throw memo.error;
|
|
193
|
-
return memo.canonical ??= printICU(memo.ast);
|
|
194
|
-
},
|
|
195
|
-
parse(source) {
|
|
196
|
-
const memo = entry(source);
|
|
197
|
-
if (memo.error !== null) throw memo.error;
|
|
198
|
-
return memo.ast;
|
|
199
|
-
},
|
|
200
|
-
sourceHash: hashOf,
|
|
201
|
-
label(canonical) {
|
|
202
|
-
return hashOf(canonical).slice(0, idLength);
|
|
203
|
-
}
|
|
204
|
-
};
|
|
205
|
-
}
|
|
206
|
-
//#endregion
|
|
207
|
-
export { printICU as n, createCodec as t };
|
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
import { o as isDiagnosticError } from "./types-D3QGM8XO.js";
|
|
2
|
-
import { S as entryKey } from "./library-D5CWvTQs.js";
|
|
3
|
-
import { r as resolveDuplicates } from "./duplicates-yuRljQ6h.js";
|
|
4
|
-
//#region src/core/catalog/collisions.ts
|
|
5
|
-
/**
|
|
6
|
-
* Id collisions (PLAN §5.5, INTERNALS §2.6.7): two different texts behind one
|
|
7
|
-
* id are a hard error, never resolved automatically, because any automatic
|
|
8
|
-
* rule would make one message's id depend on another's existence. The check
|
|
9
|
-
* covers the messages being compiled and every entry of the catalog set, so
|
|
10
|
-
* apps sharing catalogs collide loudly instead of overwriting each other.
|
|
11
|
-
*/
|
|
12
|
-
const DELETED_HINT = "; if that message was deleted, run vi18n extract first";
|
|
13
|
-
function posix(path) {
|
|
14
|
-
return path.replaceAll("\\", "/");
|
|
15
|
-
}
|
|
16
|
-
function where(file, line) {
|
|
17
|
-
return line > 0 ? `${file}:${line}` : file;
|
|
18
|
-
}
|
|
19
|
-
function messagePlace(message) {
|
|
20
|
-
const location = message.locations?.[0] ?? (message.file === void 0 ? void 0 : {
|
|
21
|
-
file: message.file,
|
|
22
|
-
line: message.line ?? 0
|
|
23
|
-
});
|
|
24
|
-
if (location === void 0) return { text: "" };
|
|
25
|
-
return {
|
|
26
|
-
file: location.file,
|
|
27
|
-
line: location.line,
|
|
28
|
-
text: ` (${where(location.file, location.line)})`
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
function canonicalOf(source, codec) {
|
|
32
|
-
try {
|
|
33
|
-
return codec.canonicalize(source);
|
|
34
|
-
} catch (error) {
|
|
35
|
-
if (isDiagnosticError(error)) return null;
|
|
36
|
-
throw error;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Canonical text → where it was first seen, per generated key. Only entries
|
|
41
|
-
* whose source hashes to their key take part: in the `"id"` layout and JSON a
|
|
42
|
-
* hand-edited or stripped source note is a stale entry (reported as a source
|
|
43
|
-
* mismatch elsewhere), not a second text behind the id, and a file still on
|
|
44
|
-
* another id length would match nothing anyway. PLAN §5.5 makes a collision
|
|
45
|
-
* two live texts with one id, and §5.6 says an edited `#. source:` never
|
|
46
|
-
* changes what ships, which a build-stopping collision would; this narrows
|
|
47
|
-
* the wording of INTERNALS §2.6.7 to that intent.
|
|
48
|
-
*/
|
|
49
|
-
function indexEntries(set, codec, ignoreKeys) {
|
|
50
|
-
const byKey = /* @__PURE__ */ new Map();
|
|
51
|
-
for (const loaded of set.values()) {
|
|
52
|
-
if (loaded.catalog === null) continue;
|
|
53
|
-
const { catalog } = resolveDuplicates(loaded.catalog, codec);
|
|
54
|
-
const file = posix(loaded.path);
|
|
55
|
-
for (const entry of catalog.entries) {
|
|
56
|
-
if (entry.manualId !== null || entry.foreignContext !== null || entry.source === null) continue;
|
|
57
|
-
const key = entryKey(entry, catalog.layout, codec);
|
|
58
|
-
if (key === null || ignoreKeys !== void 0 && ignoreKeys.has(key)) continue;
|
|
59
|
-
const canonical = canonicalOf(entry.source, codec);
|
|
60
|
-
if (canonical === null || codec.label(canonical) !== key) continue;
|
|
61
|
-
let texts = byKey.get(key);
|
|
62
|
-
if (texts === void 0) byKey.set(key, texts = /* @__PURE__ */ new Map());
|
|
63
|
-
const known = texts.get(canonical);
|
|
64
|
-
if (known === void 0) texts.set(canonical, {
|
|
65
|
-
locale: loaded.locale,
|
|
66
|
-
file,
|
|
67
|
-
line: entry.line,
|
|
68
|
-
translated: isTranslated(entry)
|
|
69
|
-
});
|
|
70
|
-
else if (!known.translated && isTranslated(entry)) known.translated = true;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
return byKey;
|
|
74
|
-
}
|
|
75
|
-
function isTranslated(entry) {
|
|
76
|
-
return entry.translation !== "" && entry.state !== "untranslated";
|
|
77
|
-
}
|
|
78
|
-
function fixes(a, aTranslated, b, bTranslated, codec) {
|
|
79
|
-
const longer = `use a longer ids.length (now ${codec.idLength})`;
|
|
80
|
-
if (aTranslated !== bTranslated) return `give ${JSON.stringify(aTranslated ? b : a)} a manual id (it has no translations yet), or ${longer}`;
|
|
81
|
-
return `give the message that has no translations yet a manual id, or ${longer}`;
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* `id-collision` errors for: two messages with one id and different
|
|
85
|
-
* canonical text; a generated message and an entry of any locale with its id
|
|
86
|
-
* but a different canonical source; two generated entries of the set with
|
|
87
|
-
* one key and different sources.
|
|
88
|
-
*
|
|
89
|
-
* `referenced`: ids that count as live beyond `messages` (`extraction.keep`,
|
|
90
|
-
* apps sharing the set that this scan does not cover). A colliding entry
|
|
91
|
-
* whose text no message uses and whose id is not in `referenced` gets the
|
|
92
|
-
* "run vi18n extract first" hint, since extract would delete it.
|
|
93
|
-
* `ignoreKeys`: entries extract is about to delete, which therefore never
|
|
94
|
-
* collide.
|
|
95
|
-
*/
|
|
96
|
-
function findCollisions(messages, set, codec, options = {}) {
|
|
97
|
-
const diagnostics = [];
|
|
98
|
-
const reported = /* @__PURE__ */ new Set();
|
|
99
|
-
const report = (id, a, b) => {
|
|
100
|
-
const pair = a < b ? `${id}\0${a}\0${b}` : `${id}\0${b}\0${a}`;
|
|
101
|
-
if (reported.has(pair)) return false;
|
|
102
|
-
reported.add(pair);
|
|
103
|
-
return true;
|
|
104
|
-
};
|
|
105
|
-
const entries = indexEntries(set, codec, options.ignoreKeys);
|
|
106
|
-
const byId = /* @__PURE__ */ new Map();
|
|
107
|
-
const literals = [];
|
|
108
|
-
for (const message of messages) {
|
|
109
|
-
if (!message.manual) for (const literal of message.sources ?? (message.source === void 0 ? [] : [message.source])) literals.push([message, literal]);
|
|
110
|
-
const first = byId.get(message.id);
|
|
111
|
-
if (first === void 0) byId.set(message.id, message);
|
|
112
|
-
else if (first.canonical !== message.canonical && report(message.id, first.canonical, message.canonical)) {
|
|
113
|
-
const a = messagePlace(first);
|
|
114
|
-
const b = messagePlace(message);
|
|
115
|
-
const texts = entries.get(message.id);
|
|
116
|
-
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, codec);
|
|
117
|
-
const diagnostic = {
|
|
118
|
-
code: "id-collision",
|
|
119
|
-
severity: "error",
|
|
120
|
-
message: `${message.id} is the id of two texts, ${JSON.stringify(first.canonical)}${a.text} and ${JSON.stringify(message.canonical)}${b.text}: ${fix}`,
|
|
121
|
-
id: message.id,
|
|
122
|
-
related: [{
|
|
123
|
-
...b.file === void 0 ? {} : {
|
|
124
|
-
file: b.file,
|
|
125
|
-
line: b.line
|
|
126
|
-
},
|
|
127
|
-
message: message.canonical
|
|
128
|
-
}]
|
|
129
|
-
};
|
|
130
|
-
if (a.file !== void 0) {
|
|
131
|
-
diagnostic.file = a.file;
|
|
132
|
-
diagnostic.line = a.line;
|
|
133
|
-
}
|
|
134
|
-
diagnostics.push(diagnostic);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
for (const [owner, literal] of literals) {
|
|
138
|
-
const other = byId.get(literal);
|
|
139
|
-
if (other === void 0 || other.id === owner.id) continue;
|
|
140
|
-
if (!report(literal, `\0source:${owner.id}`, other.canonical)) continue;
|
|
141
|
-
const a = messagePlace(owner);
|
|
142
|
-
const b = messagePlace(other);
|
|
143
|
-
const diagnostic = {
|
|
144
|
-
code: "id-collision",
|
|
145
|
-
severity: "error",
|
|
146
|
-
message: `${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`}`,
|
|
147
|
-
id: literal,
|
|
148
|
-
related: [{
|
|
149
|
-
...b.file === void 0 ? {} : {
|
|
150
|
-
file: b.file,
|
|
151
|
-
line: b.line
|
|
152
|
-
},
|
|
153
|
-
message: other.canonical
|
|
154
|
-
}]
|
|
155
|
-
};
|
|
156
|
-
if (a.file !== void 0) {
|
|
157
|
-
diagnostic.file = a.file;
|
|
158
|
-
diagnostic.line = a.line;
|
|
159
|
-
}
|
|
160
|
-
diagnostics.push(diagnostic);
|
|
161
|
-
}
|
|
162
|
-
for (const message of byId.values()) {
|
|
163
|
-
if (message.manual) continue;
|
|
164
|
-
const texts = entries.get(message.id);
|
|
165
|
-
if (texts === void 0) continue;
|
|
166
|
-
const own = texts.get(message.canonical);
|
|
167
|
-
for (const [canonical, entry] of texts) {
|
|
168
|
-
if (canonical === message.canonical || !report(message.id, message.canonical, canonical)) continue;
|
|
169
|
-
const place = messagePlace(message);
|
|
170
|
-
const live = options.referenced?.has(message.id) === true;
|
|
171
|
-
const diagnostic = {
|
|
172
|
-
code: "id-collision",
|
|
173
|
-
severity: "error",
|
|
174
|
-
message: `${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, codec) + (live ? "" : DELETED_HINT),
|
|
175
|
-
id: message.id,
|
|
176
|
-
locale: entry.locale,
|
|
177
|
-
related: [{
|
|
178
|
-
file: entry.file,
|
|
179
|
-
line: entry.line,
|
|
180
|
-
message: canonical
|
|
181
|
-
}]
|
|
182
|
-
};
|
|
183
|
-
if (place.file !== void 0) {
|
|
184
|
-
diagnostic.file = place.file;
|
|
185
|
-
diagnostic.line = place.line;
|
|
186
|
-
}
|
|
187
|
-
diagnostics.push(diagnostic);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
const keys = [...entries.keys()].filter((key) => !byId.has(key) && entries.get(key).size > 1);
|
|
191
|
-
keys.sort();
|
|
192
|
-
for (const key of keys) {
|
|
193
|
-
const texts = [...entries.get(key)];
|
|
194
|
-
const [firstText, firstEntry] = texts[0];
|
|
195
|
-
const live = options.referenced?.has(key) === true;
|
|
196
|
-
for (const [canonical, entry] of texts.slice(1)) {
|
|
197
|
-
if (!report(key, firstText, canonical)) continue;
|
|
198
|
-
diagnostics.push({
|
|
199
|
-
code: "id-collision",
|
|
200
|
-
severity: "error",
|
|
201
|
-
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, codec) + (live ? "" : DELETED_HINT),
|
|
202
|
-
id: key,
|
|
203
|
-
locale: firstEntry.locale,
|
|
204
|
-
file: firstEntry.file,
|
|
205
|
-
line: firstEntry.line,
|
|
206
|
-
related: [{
|
|
207
|
-
file: entry.file,
|
|
208
|
-
line: entry.line,
|
|
209
|
-
message: canonical
|
|
210
|
-
}]
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
return diagnostics;
|
|
215
|
-
}
|
|
216
|
-
//#endregion
|
|
217
|
-
export { findCollisions as t };
|