@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.
- package/dist/{apply-Bre-lY9J.js → apply-FAHl1R6T.js} +69 -89
- package/dist/{captured-Bj8bO6vd.js → captured-CTjjDF5o.js} +196 -217
- package/dist/{check-BIKEuu6B.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-C9Sy6UWv.js → export-BYq0gfLd.js} +17 -38
- package/dist/{extract-C3S8btx0.js → extract-CYtuEo8u.js} +114 -82
- package/dist/{formats-9unqj_fZ.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-nANvQutw.js → import-BApbQlmm.js} +81 -75
- package/dist/index.d.ts +1 -13
- package/dist/index.js +14 -16
- package/dist/{init-C2ScuW6a.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 +68 -81
- 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-RMMMc88P.js → lsp-BC7xDGON.js} +4 -5
- package/dist/{match-BGr8EXB3.js → match-BLDcj610.js} +11 -4
- package/dist/{mcp-CHVwBoRP.js → mcp-Cka8ywDF.js} +4 -5
- package/dist/{merge-driver-BTX87aVm.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-DWE3SIUA.js → output-CF9uvk_-.js} +15 -9
- package/dist/parse.d.ts +1 -3
- package/dist/parse.js +7 -8
- package/dist/{pipeline-DbX6rlo5.js → pipeline-B30irGMD.js} +1 -1
- package/dist/{pipeline-C9Dbotkh.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-deBOq2vq.js → server-WlxZH0oX.js} +275 -330
- package/dist/{server-Da1Ot9IN.js → server-ceuzzkal.js} +292 -386
- package/dist/server.d.ts +1 -17
- package/dist/server.js +415 -381
- package/dist/{sitemap-DJXzKoza.js → sitemap-796jJKUT.js} +21 -33
- package/dist/{sources-D19czDSA.js → sources-DuOdM02f.js} +712 -373
- package/dist/{status-zr4jY59Y.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-Byqi2guX.js → version-BFs370Ce.js} +3 -5
- package/dist/{vite-scan-CT_vsp4g.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-BOemZ5Q8.js → which-BpyJyBkX.js} +44 -37
- package/dist/{worker-84U6uYB3.js → worker-BjzVqJVO.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,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as protocolConsole } from "./stdio-
|
|
3
|
-
|
|
1
|
+
import { r as EXIT } from "./types-Ds_vebja.js";
|
|
2
|
+
import { t as protocolConsole } from "./stdio-FWIVU3P4.js";
|
|
3
|
+
// src/cli/commands/lsp.ts
|
|
4
4
|
/**
|
|
5
5
|
* `vi18n lsp [--stdio]` (INTERNALS §2.17): runs the language server on the
|
|
6
6
|
* process's stdin and stdout until the editor exits it. The server and
|
|
@@ -10,7 +10,7 @@ import { t as protocolConsole } from "./stdio-CVaJfxA7.js";
|
|
|
10
10
|
async function lsp(ctx, _flags) {
|
|
11
11
|
const streams = ctx.io.streams;
|
|
12
12
|
if (streams === void 0) throw new Error("vi18n lsp needs the process's stdin and stdout");
|
|
13
|
-
const { startLanguageServer } = await import("./server-
|
|
13
|
+
const { startLanguageServer } = await import("./server-WlxZH0oX.js");
|
|
14
14
|
const restore = protocolConsole(streams.output);
|
|
15
15
|
try {
|
|
16
16
|
return {
|
|
@@ -27,5 +27,4 @@ async function lsp(ctx, _flags) {
|
|
|
27
27
|
restore();
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
-
//#endregion
|
|
31
30
|
export { lsp };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { d as
|
|
2
|
-
|
|
1
|
+
import { d as matchRoute, f as routePath, p as splitLocalePath, t as ROUTES } from "./url-D2_VlEeH.js";
|
|
2
|
+
// src/runtime/match.ts
|
|
3
3
|
/**
|
|
4
4
|
* The first candidate that reaches a configured locale: exactly, through its
|
|
5
5
|
* maximized form's truncations (`zh-TW` → `zh-Hant-TW` → `zh-Hant` → `zh`),
|
|
@@ -63,6 +63,14 @@ function readCookie(cookies, name) {
|
|
|
63
63
|
}
|
|
64
64
|
/** Storage key of the `localStorage` strategy (INTERNALS §6 D29). */
|
|
65
65
|
const STORAGE_KEY = "vi18n_locale";
|
|
66
|
+
/**
|
|
67
|
+
* Header the client runtime adds to same-origin `fetch` calls
|
|
68
|
+
* (`routing.propagate`). The engine spells it, and the zone cookie, inline:
|
|
69
|
+
* a shared binding measured larger in its bundle.
|
|
70
|
+
*/
|
|
71
|
+
const LOCALE_HEADER = "x-vi18n-locale";
|
|
72
|
+
/** Cookie the client runtime writes with the browser's IANA zone. */
|
|
73
|
+
const TIME_ZONE_COOKIE = "vi18n_tz";
|
|
66
74
|
/** The client steps of §2.11.9: the effective chain, first result wins. */
|
|
67
75
|
function clientLocale(config, input) {
|
|
68
76
|
const { locales, sourceLocale } = config;
|
|
@@ -85,5 +93,4 @@ function clientLocale(config, input) {
|
|
|
85
93
|
source: "default"
|
|
86
94
|
};
|
|
87
95
|
}
|
|
88
|
-
|
|
89
|
-
export { strategyFor as a, readCookie as i, clientLocale as n, urlLocale as o, matchLocale as r, STORAGE_KEY as t };
|
|
96
|
+
export { matchLocale as a, urlLocale as c, clientLocale as i, STORAGE_KEY as n, readCookie as o, TIME_ZONE_COOKIE as r, strategyFor as s, LOCALE_HEADER as t };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { t as protocolConsole } from "./stdio-FWIVU3P4.js";
|
|
2
|
+
import { r as EXIT } from "./types-Ds_vebja.js";
|
|
3
|
+
// src/cli/commands/mcp.ts
|
|
4
4
|
async function mcp(ctx, _flags) {
|
|
5
5
|
const streams = ctx.io.streams;
|
|
6
6
|
if (streams === void 0) throw new Error("vi18n mcp needs the process's stdin and stdout");
|
|
7
|
-
const { serveMcp } = await import("./server-
|
|
7
|
+
const { serveMcp } = await import("./server-ceuzzkal.js");
|
|
8
8
|
const restore = protocolConsole(streams.output);
|
|
9
9
|
try {
|
|
10
10
|
await serveMcp({
|
|
@@ -24,5 +24,4 @@ async function mcp(ctx, _flags) {
|
|
|
24
24
|
restore();
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
|
-
//#endregion
|
|
28
27
|
export { mcp };
|
|
@@ -1,25 +1,21 @@
|
|
|
1
|
-
import { d as parseCatalogBytes, o as catalogLayout, p as serializeCatalog } from "./library-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import { D as flagKey, O as stricterLimit, d as parseCatalogBytes, o as catalogLayout, p as serializeCatalog, v as STATE_RANK, y as catalogIdentity } from "./library-BfSOBeBd.js";
|
|
2
|
+
import { r as loadConfig } from "./load-BFLLqY8x.js";
|
|
3
|
+
import { n as isDiagnosticError } from "./diagnostics-1onDF6Ua.js";
|
|
4
|
+
import { t as VERSION } from "./version-BFs370Ce.js";
|
|
5
|
+
import { o as errorMessage, r as plural } from "./output-CF9uvk_-.js";
|
|
6
|
+
import { r as EXIT } from "./types-Ds_vebja.js";
|
|
6
7
|
import { dirname, resolve } from "node:path";
|
|
7
8
|
import { readFile, writeFile } from "node:fs/promises";
|
|
8
9
|
import { promisify } from "node:util";
|
|
9
10
|
import { execFile } from "node:child_process";
|
|
10
|
-
|
|
11
|
-
/** The identity git-level tools use: `msgctxt` + `msgid`, or the JSON key. */
|
|
12
|
-
function mergeKey(entry, layout) {
|
|
13
|
-
if (layout === "json") return entry.manualId ?? entry.label ?? "";
|
|
14
|
-
return `${entry.manualId ?? entry.foreignContext ?? ""}\u0004${(layout === "id" ? entry.label : entry.source) ?? ""}`;
|
|
15
|
-
}
|
|
11
|
+
// src/core/catalog/merge.ts
|
|
16
12
|
function index(catalog, layout) {
|
|
17
13
|
const side = {
|
|
18
14
|
first: /* @__PURE__ */ new Map(),
|
|
19
15
|
rest: []
|
|
20
16
|
};
|
|
21
17
|
for (const entry of catalog?.entries ?? []) {
|
|
22
|
-
const key =
|
|
18
|
+
const key = catalogIdentity(entry, layout);
|
|
23
19
|
if (side.first.has(key)) side.rest.push(entry);
|
|
24
20
|
else side.first.set(key, entry);
|
|
25
21
|
}
|
|
@@ -83,63 +79,73 @@ function mergeList(base, ours, theirs, id) {
|
|
|
83
79
|
return out;
|
|
84
80
|
}
|
|
85
81
|
const text = (value) => value;
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
translated: 2,
|
|
89
|
-
ai: 1,
|
|
90
|
-
untranslated: 0
|
|
91
|
-
};
|
|
92
|
-
function mergeEntry(base, ours, theirs) {
|
|
93
|
-
const sorted = (values) => values.slice().sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
|
|
82
|
+
/** The fields that merge as sets, and `maxLength` and `extra`, which merge as values with a tie rule. */
|
|
83
|
+
function mergeShared(base, ours, theirs) {
|
|
94
84
|
const common = {
|
|
95
85
|
...ours,
|
|
96
|
-
refs:
|
|
86
|
+
refs: mergeList(base?.refs ?? [], ours.refs, theirs.refs, text).sort(),
|
|
97
87
|
contexts: mergeList(base?.contexts ?? [], ours.contexts, theirs.contexts, text),
|
|
98
88
|
comments: mergeList(base?.comments ?? [], ours.comments, theirs.comments, text),
|
|
99
|
-
flags: mergeList(base?.flags ?? [], ours.flags, theirs.flags,
|
|
89
|
+
flags: mergeList(base?.flags ?? [], ours.flags, theirs.flags, flagKey),
|
|
100
90
|
line: 0,
|
|
101
91
|
wrapped: false
|
|
102
92
|
};
|
|
103
93
|
const was = from(base);
|
|
104
94
|
const maxLength = pick(was((e) => e.maxLength), ours.maxLength, theirs.maxLength, equal);
|
|
105
|
-
common.maxLength = maxLength
|
|
95
|
+
common.maxLength = maxLength === null ? stricterLimit(ours.maxLength, theirs.maxLength) : maxLength.value;
|
|
106
96
|
const extra = pick(was((e) => e.extra), ours.extra, theirs.extra, sameJson);
|
|
107
97
|
const extraValue = extra === null ? ours.extra : extra.value;
|
|
108
98
|
if (extraValue === void 0) delete common.extra;
|
|
109
99
|
else common.extra = extraValue;
|
|
110
|
-
|
|
100
|
+
return common;
|
|
101
|
+
}
|
|
102
|
+
const sourceOf = (entry) => ({
|
|
103
|
+
source: entry.source,
|
|
104
|
+
label: entry.label
|
|
105
|
+
});
|
|
106
|
+
const valueOf = (entry) => ({
|
|
107
|
+
translation: entry.translation,
|
|
108
|
+
state: entry.state,
|
|
109
|
+
fuzzy: entry.fuzzy
|
|
110
|
+
});
|
|
111
|
+
/**
|
|
112
|
+
* A translation belongs to the source it was made for (D10): one side's new
|
|
113
|
+
* translation cannot land on a source only the other side changed, which
|
|
114
|
+
* git's line merge also refuses, since `source` and `translation` (or
|
|
115
|
+
* `#. source:` and `msgstr`) are adjacent lines.
|
|
116
|
+
*/
|
|
117
|
+
function isStale(base, ours, theirs) {
|
|
118
|
+
const moved = (entry) => !sameJson(sourceOf(base), sourceOf(entry));
|
|
119
|
+
const edited = (entry) => !sameJson(valueOf(base), valueOf(entry));
|
|
120
|
+
return moved(ours) && !moved(theirs) && edited(theirs) || moved(theirs) && !moved(ours) && edited(ours);
|
|
121
|
+
}
|
|
122
|
+
function mergeEntry(base, ours, theirs) {
|
|
123
|
+
const common = mergeShared(base, ours, theirs);
|
|
111
124
|
const oursView = { ...common };
|
|
112
125
|
const theirsView = { ...common };
|
|
113
|
-
const
|
|
114
|
-
source: entry.source,
|
|
115
|
-
label: entry.label
|
|
116
|
-
});
|
|
117
|
-
const valueOf = (entry) => ({
|
|
118
|
-
translation: entry.translation,
|
|
119
|
-
state: entry.state,
|
|
120
|
-
fuzzy: entry.fuzzy
|
|
121
|
-
});
|
|
126
|
+
const was = from(base);
|
|
122
127
|
const source = pick(was(sourceOf), sourceOf(ours), sourceOf(theirs), sameJson);
|
|
123
128
|
let value = pick(was(valueOf), valueOf(ours), valueOf(theirs), sameJson);
|
|
124
|
-
if (value === null && ours.translation === theirs.translation && ours.fuzzy === theirs.fuzzy)
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
const moved = (entry) => !sameJson(sourceOf(base), sourceOf(entry));
|
|
128
|
-
const edited = (entry) => !sameJson(valueOf(base), valueOf(entry));
|
|
129
|
-
stale = moved(ours) && !moved(theirs) && edited(theirs) || moved(theirs) && !moved(ours) && edited(ours);
|
|
129
|
+
if (value === null && ours.translation === theirs.translation && ours.fuzzy === theirs.fuzzy) {
|
|
130
|
+
const oursWins = STATE_RANK[ours.state] >= STATE_RANK[theirs.state];
|
|
131
|
+
value = { value: valueOf(oursWins ? ours : theirs) };
|
|
130
132
|
}
|
|
133
|
+
const stale = base !== void 0 && source !== null && value !== null && isStale(base, ours, theirs);
|
|
131
134
|
if (source === null || value === null || stale) {
|
|
132
|
-
conflict = true;
|
|
133
135
|
Object.assign(oursView, sourceOf(ours), valueOf(ours));
|
|
134
136
|
Object.assign(theirsView, sourceOf(theirs), valueOf(theirs));
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
137
|
+
return {
|
|
138
|
+
ours: oursView,
|
|
139
|
+
theirs: theirsView,
|
|
140
|
+
conflict: true
|
|
141
|
+
};
|
|
138
142
|
}
|
|
143
|
+
Object.assign(oursView, source.value, value.value);
|
|
144
|
+
Object.assign(theirsView, source.value, value.value);
|
|
139
145
|
return {
|
|
140
146
|
ours: oursView,
|
|
141
147
|
theirs: theirsView,
|
|
142
|
-
conflict
|
|
148
|
+
conflict: false
|
|
143
149
|
};
|
|
144
150
|
}
|
|
145
151
|
function mergeHeader(base, ours, theirs) {
|
|
@@ -276,30 +282,24 @@ function mergeCatalogs(input) {
|
|
|
276
282
|
conflicts,
|
|
277
283
|
conflicting
|
|
278
284
|
};
|
|
279
|
-
const theirsText = serializeCatalog(view(header.theirs, theirsEntries), options);
|
|
280
|
-
const left = blocks(oursText, layout);
|
|
281
|
-
const right = blocks(theirsText, layout);
|
|
282
|
-
let lines;
|
|
283
|
-
if (left.length !== right.length) {
|
|
284
|
-
lines = conflictLines(oursText.split("\n"), theirsText.split("\n"));
|
|
285
|
-
return {
|
|
286
|
-
text: `${lines.join("\n")}\n`,
|
|
287
|
-
conflicts,
|
|
288
|
-
conflicting
|
|
289
|
-
};
|
|
290
|
-
}
|
|
291
|
-
const separator = layout === "json" ? "\n" : "\n\n";
|
|
292
285
|
return {
|
|
293
|
-
text:
|
|
294
|
-
const other = right[i];
|
|
295
|
-
return (block.length === other.length && block.every((line, k) => line === other[k]) ? block : conflictLines(block, other)).join("\n");
|
|
296
|
-
}).join(separator)}\n`,
|
|
286
|
+
text: conflictText(oursText, serializeCatalog(view(header.theirs, theirsEntries), options), layout),
|
|
297
287
|
conflicts,
|
|
298
288
|
conflicting
|
|
299
289
|
};
|
|
300
290
|
}
|
|
301
|
-
|
|
302
|
-
|
|
291
|
+
/** The two views of the file, with conflict markers around each entry whose blocks differ. */
|
|
292
|
+
function conflictText(oursText, theirsText, layout) {
|
|
293
|
+
const left = blocks(oursText, layout);
|
|
294
|
+
const right = blocks(theirsText, layout);
|
|
295
|
+
if (left.length !== right.length) return `${conflictLines(oursText.split("\n"), theirsText.split("\n")).join("\n")}\n`;
|
|
296
|
+
const separator = layout === "json" ? "\n" : "\n\n";
|
|
297
|
+
return `${left.map((block, i) => {
|
|
298
|
+
const other = right[i];
|
|
299
|
+
return (block.length === other.length && block.every((line, k) => line === other[k]) ? block : conflictLines(block, other)).join("\n");
|
|
300
|
+
}).join(separator)}\n`;
|
|
301
|
+
}
|
|
302
|
+
// src/cli/commands/merge-driver.ts
|
|
303
303
|
/**
|
|
304
304
|
* `vi18n merge-driver <base> <ours> <theirs> [<path>]` (PLAN §4.4 P2,
|
|
305
305
|
* INTERNALS §2.6.10): the catalog merge driver git runs as
|
|
@@ -311,16 +311,18 @@ function mergeCatalogs(input) {
|
|
|
311
311
|
* failure never loses either side.
|
|
312
312
|
*/
|
|
313
313
|
const run = promisify(execFile);
|
|
314
|
+
/** The config the catalog belongs to, or why there is none (the reason a line merge runs instead). */
|
|
314
315
|
async function findConfig(ctx, start) {
|
|
316
|
+
let config;
|
|
315
317
|
try {
|
|
316
|
-
|
|
318
|
+
config = await loadConfig({
|
|
317
319
|
cwd: start,
|
|
318
320
|
configFile: ctx.global.config
|
|
319
321
|
});
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
return null;
|
|
322
|
+
} catch (error) {
|
|
323
|
+
return `vi18n.config.ts could not be loaded (${isDiagnosticError(error) ? error.diagnostic.message : errorMessage(error)}); fix it`;
|
|
323
324
|
}
|
|
325
|
+
return config.configFile === null ? "no vi18n.config.ts found" : config;
|
|
324
326
|
}
|
|
325
327
|
/** Parses one side; null when it is not a catalog vi18n reads without errors. */
|
|
326
328
|
function read(bytes, layout, locale, isSourceLocale) {
|
|
@@ -333,9 +335,11 @@ function read(bytes, layout, locale, isSourceLocale) {
|
|
|
333
335
|
}
|
|
334
336
|
async function mergeDriver(ctx, flags) {
|
|
335
337
|
const cwd = ctx.global.cwd;
|
|
336
|
-
const
|
|
337
|
-
|
|
338
|
-
|
|
338
|
+
const files = {
|
|
339
|
+
base: resolve(cwd, flags.base),
|
|
340
|
+
ours: resolve(cwd, flags.ours),
|
|
341
|
+
theirs: resolve(cwd, flags.theirs)
|
|
342
|
+
};
|
|
339
343
|
const data = {
|
|
340
344
|
path: flags.path,
|
|
341
345
|
conflicts: 0,
|
|
@@ -343,63 +347,19 @@ async function mergeDriver(ctx, flags) {
|
|
|
343
347
|
fallback: false
|
|
344
348
|
};
|
|
345
349
|
const shown = flags.path ?? flags.ours;
|
|
346
|
-
const fallback =
|
|
347
|
-
data.fallback = true;
|
|
350
|
+
const fallback = (reason) => {
|
|
348
351
|
ctx.out.note(`vi18n merge-driver: ${shown}: ${reason}; merging lines with git merge-file`);
|
|
349
|
-
|
|
350
|
-
await run("git", [
|
|
351
|
-
"merge-file",
|
|
352
|
-
"-L",
|
|
353
|
-
"ours",
|
|
354
|
-
"-L",
|
|
355
|
-
"base",
|
|
356
|
-
"-L",
|
|
357
|
-
"theirs",
|
|
358
|
-
ours,
|
|
359
|
-
base,
|
|
360
|
-
theirs
|
|
361
|
-
]);
|
|
362
|
-
return {
|
|
363
|
-
exitCode: EXIT.ok,
|
|
364
|
-
data
|
|
365
|
-
};
|
|
366
|
-
} catch (error) {
|
|
367
|
-
const status = error.code;
|
|
368
|
-
if (typeof status === "number" && status > 0) {
|
|
369
|
-
data.conflicts = status;
|
|
370
|
-
return {
|
|
371
|
-
exitCode: EXIT.failure,
|
|
372
|
-
data
|
|
373
|
-
};
|
|
374
|
-
}
|
|
375
|
-
throw error;
|
|
376
|
-
}
|
|
352
|
+
return lineMerge(files, data);
|
|
377
353
|
};
|
|
378
354
|
const config = await findConfig(ctx, flags.path === null ? cwd : dirname(resolve(cwd, flags.path)));
|
|
379
|
-
if (config ===
|
|
380
|
-
const
|
|
381
|
-
|
|
382
|
-
base,
|
|
383
|
-
ours,
|
|
384
|
-
theirs
|
|
385
|
-
].map((file) => readFile(file)));
|
|
386
|
-
const probe = read(oursBytes, layout, "", false) ?? read(theirsBytes, layout, "", false);
|
|
387
|
-
if (probe === null) return fallback("a side is not a catalog vi18n can read");
|
|
388
|
-
const locale = probe.header.language;
|
|
389
|
-
const isSourceLocale = locale === config.sourceLocale;
|
|
390
|
-
const mine = read(oursBytes, layout, locale, isSourceLocale);
|
|
391
|
-
const other = read(theirsBytes, layout, locale, isSourceLocale);
|
|
392
|
-
const empty = baseBytes.toString("utf8").trim() === "";
|
|
393
|
-
const was = empty ? null : read(baseBytes, layout, locale, isSourceLocale);
|
|
394
|
-
if (mine === null || other === null || !empty && was === null) return fallback("a side is not a catalog vi18n can read");
|
|
355
|
+
if (typeof config === "string") return fallback(config);
|
|
356
|
+
const sides = await readSides(config, files);
|
|
357
|
+
if (sides === null) return fallback("a side is not a catalog vi18n can read");
|
|
395
358
|
const outcome = mergeCatalogs({
|
|
396
|
-
|
|
397
|
-
ours: mine,
|
|
398
|
-
theirs: other,
|
|
399
|
-
isSourceLocale,
|
|
359
|
+
...sides,
|
|
400
360
|
version: VERSION
|
|
401
361
|
});
|
|
402
|
-
await writeFile(ours, outcome.text);
|
|
362
|
+
await writeFile(files.ours, outcome.text);
|
|
403
363
|
data.conflicts = outcome.conflicts;
|
|
404
364
|
data.conflicting = outcome.conflicting;
|
|
405
365
|
if (outcome.conflicts === 0) return {
|
|
@@ -418,5 +378,61 @@ async function mergeDriver(ctx, flags) {
|
|
|
418
378
|
data
|
|
419
379
|
};
|
|
420
380
|
}
|
|
421
|
-
|
|
381
|
+
/** The three sides as catalogs; null when one is not a catalog vi18n reads without errors. */
|
|
382
|
+
async function readSides(config, files) {
|
|
383
|
+
const layout = catalogLayout(config);
|
|
384
|
+
const [baseBytes, oursBytes, theirsBytes] = await Promise.all([
|
|
385
|
+
readFile(files.base),
|
|
386
|
+
readFile(files.ours),
|
|
387
|
+
readFile(files.theirs)
|
|
388
|
+
]);
|
|
389
|
+
const probe = read(oursBytes, layout, "", false) ?? read(theirsBytes, layout, "", false);
|
|
390
|
+
if (probe === null) return null;
|
|
391
|
+
const locale = probe.header.language;
|
|
392
|
+
const isSourceLocale = locale === config.sourceLocale;
|
|
393
|
+
const ours = read(oursBytes, layout, locale, isSourceLocale);
|
|
394
|
+
const theirs = read(theirsBytes, layout, locale, isSourceLocale);
|
|
395
|
+
const empty = baseBytes.toString("utf8").trim() === "";
|
|
396
|
+
const base = empty ? null : read(baseBytes, layout, locale, isSourceLocale);
|
|
397
|
+
if (ours === null || theirs === null || !empty && base === null) return null;
|
|
398
|
+
return {
|
|
399
|
+
base,
|
|
400
|
+
ours,
|
|
401
|
+
theirs,
|
|
402
|
+
isSourceLocale
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
/** git's own line merge into `<ours>`; a positive status is the number of conflicts left as markers. */
|
|
406
|
+
async function lineMerge(files, data) {
|
|
407
|
+
data.fallback = true;
|
|
408
|
+
const { base, ours, theirs } = files;
|
|
409
|
+
try {
|
|
410
|
+
await run("git", [
|
|
411
|
+
"merge-file",
|
|
412
|
+
"-L",
|
|
413
|
+
"ours",
|
|
414
|
+
"-L",
|
|
415
|
+
"base",
|
|
416
|
+
"-L",
|
|
417
|
+
"theirs",
|
|
418
|
+
ours,
|
|
419
|
+
base,
|
|
420
|
+
theirs
|
|
421
|
+
]);
|
|
422
|
+
return {
|
|
423
|
+
exitCode: EXIT.ok,
|
|
424
|
+
data
|
|
425
|
+
};
|
|
426
|
+
} catch (error) {
|
|
427
|
+
const status = error.code;
|
|
428
|
+
if (typeof status === "number" && status > 0) {
|
|
429
|
+
data.conflicts = status;
|
|
430
|
+
return {
|
|
431
|
+
exitCode: EXIT.failure,
|
|
432
|
+
data
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
throw error;
|
|
436
|
+
}
|
|
437
|
+
}
|
|
422
438
|
export { mergeDriver };
|