vbss-translator 1.1.2 → 2.0.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/LICENSE +21 -0
- package/README.md +47 -4
- package/dist/cli/index.js +24 -24
- package/dist/generator.cjs +17 -17
- package/dist/generator.js +304 -187
- package/dist/vbss-translator.js +2035 -1383
- package/dist/vbss-translator.umd.cjs +9 -9
- package/package.json +121 -111
package/dist/generator.js
CHANGED
|
@@ -1,360 +1,477 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
async function T(n) {
|
|
1
|
+
import { readdir as S, stat as x, mkdir as E, writeFile as O, readFile as D } from "fs/promises";
|
|
2
|
+
import { isAbsolute as L, parse as C, resolve as w, join as d, dirname as b, normalize as j, relative as N } from "path";
|
|
3
|
+
const R = /* @__PURE__ */ new Set(["ENOENT", "ENOTDIR", "EACCES", "EPERM"]), A = /* @__PURE__ */ new Set(["win32", "darwin"]), P = (t) => typeof t == "object" && t !== null && "code" in t && typeof t.code == "string" && R.has(t.code), v = async (t) => {
|
|
5
4
|
try {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
return await S(t, { withFileTypes: !0 });
|
|
6
|
+
} catch (n) {
|
|
7
|
+
if (P(n)) return [];
|
|
8
|
+
throw n;
|
|
9
|
+
}
|
|
10
|
+
}, F = async (t) => {
|
|
11
|
+
try {
|
|
12
|
+
return await x(t);
|
|
13
|
+
} catch (n) {
|
|
14
|
+
if (P(n)) return null;
|
|
15
|
+
throw n;
|
|
16
|
+
}
|
|
17
|
+
}, I = (t) => t.replace(/[.*+?^${}()|[\]\\/-]/g, "\\$&"), G = (t) => t.replace(/[\\\][^]/g, "\\$&"), _ = (t, n) => {
|
|
18
|
+
const e = [];
|
|
19
|
+
let s = 0, a = n + 1;
|
|
20
|
+
for (let r = n; r < t.length; r++) {
|
|
21
|
+
const o = t[r];
|
|
22
|
+
if (o === "{")
|
|
23
|
+
s++;
|
|
24
|
+
else if (o === "}") {
|
|
25
|
+
if (s--, s === 0)
|
|
26
|
+
return e.push(t.slice(a, r)), { alternatives: e, end: r };
|
|
27
|
+
} else o === "," && s === 1 && (e.push(t.slice(a, r)), a = r + 1);
|
|
28
|
+
}
|
|
29
|
+
return { alternatives: e, end: -1 };
|
|
30
|
+
}, $ = (t) => {
|
|
31
|
+
const n = t.indexOf("{");
|
|
32
|
+
if (n === -1) return [t];
|
|
33
|
+
const { alternatives: e, end: s } = _(t, n);
|
|
34
|
+
if (s === -1) return [t];
|
|
35
|
+
const a = t.slice(0, n), r = t.slice(s + 1);
|
|
36
|
+
if (e.length < 2) {
|
|
37
|
+
const o = t.slice(n, s + 1);
|
|
38
|
+
return $(r).map((u) => a + o + u);
|
|
39
|
+
}
|
|
40
|
+
return e.flatMap(
|
|
41
|
+
(o) => $(a + o + r)
|
|
42
|
+
);
|
|
43
|
+
}, J = (t, n) => {
|
|
44
|
+
let e = "";
|
|
45
|
+
for (let s = 0; s < t.length; s++) {
|
|
46
|
+
const a = t[s];
|
|
47
|
+
if (a === "*")
|
|
48
|
+
e += "[^/]*";
|
|
49
|
+
else if (a === "?")
|
|
50
|
+
e += "[^/]";
|
|
51
|
+
else if (a === "[") {
|
|
52
|
+
const r = t.indexOf("]", s + 2);
|
|
53
|
+
if (r === -1)
|
|
54
|
+
e += "\\[";
|
|
55
|
+
else {
|
|
56
|
+
const o = t.slice(s + 1, r), u = o.startsWith("!") || o.startsWith("^");
|
|
57
|
+
e += `[${u ? "^" : ""}${G(
|
|
58
|
+
u ? o.slice(1) : o
|
|
59
|
+
)}]`, s = r;
|
|
60
|
+
}
|
|
61
|
+
} else
|
|
62
|
+
e += I(a);
|
|
63
|
+
}
|
|
64
|
+
return new RegExp(`^${e}$`, n ? "i" : "");
|
|
65
|
+
}, M = (t, n) => {
|
|
66
|
+
var s;
|
|
67
|
+
const e = [];
|
|
68
|
+
for (const a of t)
|
|
69
|
+
a === "**" ? ((s = e[e.length - 1]) == null ? void 0 : s.kind) !== "globstar" && e.push({ kind: "globstar" }) : /[*?[]/.test(a) ? e.push({
|
|
70
|
+
kind: "pattern",
|
|
71
|
+
regexp: J(a, n),
|
|
72
|
+
matchesDotfiles: a.startsWith(".")
|
|
73
|
+
}) : e.push({ kind: "literal", text: a });
|
|
74
|
+
return e;
|
|
75
|
+
}, T = async (t, n) => {
|
|
76
|
+
var e;
|
|
77
|
+
return n.isFile() ? !0 : n.isSymbolicLink() ? ((e = await F(d(t, n.name))) == null ? void 0 : e.isFile()) ?? !1 : !1;
|
|
78
|
+
}, W = async (t, n) => {
|
|
79
|
+
var e;
|
|
80
|
+
return n.isDirectory() ? !0 : n.isSymbolicLink() ? ((e = await F(d(t, n.name))) == null ? void 0 : e.isDirectory()) ?? !1 : !1;
|
|
81
|
+
};
|
|
82
|
+
async function q(t, n) {
|
|
83
|
+
const e = A.has(process.platform), s = /* @__PURE__ */ new Set();
|
|
84
|
+
for (const a of $(t.replace(/\\/g, "/"))) {
|
|
85
|
+
const r = L(a) ? C(a).root : "", o = a.slice(r.length).split("/").filter((i) => i !== "" && i !== ".");
|
|
86
|
+
if (o.length === 0) continue;
|
|
87
|
+
const u = M(o, e), f = (i, h, c) => {
|
|
88
|
+
s.add(
|
|
89
|
+
r || n.absolute ? w(i, c) : [...h, c].join("/")
|
|
90
|
+
);
|
|
91
|
+
}, l = async (i, h, c) => {
|
|
92
|
+
const p = u[c], m = c === u.length - 1;
|
|
93
|
+
if (p.kind === "globstar") {
|
|
94
|
+
m || await l(i, h, c + 1);
|
|
95
|
+
for (const g of await v(i))
|
|
96
|
+
g.name.startsWith(".") || (g.isDirectory() ? await l(
|
|
97
|
+
d(i, g.name),
|
|
98
|
+
[...h, g.name],
|
|
99
|
+
c
|
|
100
|
+
) : m && await T(i, g) && f(i, h, g.name));
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (p.kind === "literal") {
|
|
104
|
+
const g = d(i, p.text), y = await F(g);
|
|
105
|
+
if (!y) return;
|
|
106
|
+
m ? y.isFile() && f(i, h, p.text) : y.isDirectory() && await l(g, [...h, p.text], c + 1);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
for (const g of await v(i))
|
|
110
|
+
p.regexp.test(g.name) && (g.name.startsWith(".") && !p.matchesDotfiles || (m ? await T(i, g) && f(i, h, g.name) : await W(i, g) && await l(
|
|
111
|
+
d(i, g.name),
|
|
112
|
+
[...h, g.name],
|
|
113
|
+
c + 1
|
|
114
|
+
)));
|
|
115
|
+
};
|
|
116
|
+
await l(r || w(n.cwd), [], 0);
|
|
117
|
+
}
|
|
118
|
+
return [...s].sort();
|
|
119
|
+
}
|
|
120
|
+
async function U(t) {
|
|
121
|
+
try {
|
|
122
|
+
const n = await q(t, {
|
|
123
|
+
cwd: process.cwd(),
|
|
124
|
+
absolute: !1
|
|
125
|
+
}), e = process.cwd();
|
|
126
|
+
return n.map((s) => ({
|
|
127
|
+
path: w(e, s),
|
|
128
|
+
relativePath: j(s).replace(/\\/g, "/"),
|
|
10
129
|
translations: []
|
|
11
130
|
}));
|
|
12
|
-
} catch (
|
|
13
|
-
const
|
|
131
|
+
} catch (n) {
|
|
132
|
+
const e = n instanceof Error ? n.message : "Unknown error";
|
|
14
133
|
return [
|
|
15
134
|
{
|
|
16
135
|
path: "",
|
|
17
136
|
relativePath: "",
|
|
18
137
|
translations: [],
|
|
19
138
|
error: {
|
|
20
|
-
file:
|
|
21
|
-
message: `Failed to discover files: ${
|
|
139
|
+
file: t,
|
|
140
|
+
message: `Failed to discover files: ${e}`,
|
|
22
141
|
type: "file_system"
|
|
23
142
|
}
|
|
24
143
|
}
|
|
25
144
|
];
|
|
26
145
|
}
|
|
27
146
|
}
|
|
28
|
-
async function
|
|
29
|
-
const
|
|
30
|
-
if (
|
|
31
|
-
return
|
|
147
|
+
async function B(t) {
|
|
148
|
+
const n = t.map(async (e) => {
|
|
149
|
+
if (e.error)
|
|
150
|
+
return e;
|
|
32
151
|
try {
|
|
33
|
-
const
|
|
152
|
+
const s = await D(e.path, "utf-8"), a = JSON.parse(s), r = [];
|
|
34
153
|
if (Array.isArray(a))
|
|
35
|
-
for (const
|
|
36
|
-
if (typeof
|
|
154
|
+
for (const o of a) {
|
|
155
|
+
if (typeof o != "object" || o === null)
|
|
37
156
|
return {
|
|
38
|
-
...
|
|
157
|
+
...e,
|
|
39
158
|
translations: [],
|
|
40
159
|
error: {
|
|
41
|
-
file:
|
|
160
|
+
file: e.path,
|
|
42
161
|
message: "Translation array must contain objects only",
|
|
43
162
|
type: "validation"
|
|
44
163
|
}
|
|
45
164
|
};
|
|
46
|
-
const
|
|
47
|
-
for (const [
|
|
48
|
-
if (typeof
|
|
165
|
+
const u = {};
|
|
166
|
+
for (const [f, l] of Object.entries(o)) {
|
|
167
|
+
if (typeof l != "string")
|
|
49
168
|
return {
|
|
50
|
-
...
|
|
169
|
+
...e,
|
|
51
170
|
translations: [],
|
|
52
171
|
error: {
|
|
53
|
-
file:
|
|
54
|
-
message: `Translation value for key "${
|
|
172
|
+
file: e.path,
|
|
173
|
+
message: `Translation value for key "${f}" must be a string, got ${typeof l}`,
|
|
55
174
|
type: "validation"
|
|
56
175
|
}
|
|
57
176
|
};
|
|
58
|
-
|
|
177
|
+
u[f] = l;
|
|
59
178
|
}
|
|
60
|
-
|
|
179
|
+
r.push(u);
|
|
61
180
|
}
|
|
62
181
|
else if (typeof a == "object" && a !== null) {
|
|
63
|
-
const
|
|
64
|
-
for (const [
|
|
65
|
-
if (typeof
|
|
182
|
+
const o = {};
|
|
183
|
+
for (const [u, f] of Object.entries(a)) {
|
|
184
|
+
if (typeof f != "string")
|
|
66
185
|
return {
|
|
67
|
-
...
|
|
186
|
+
...e,
|
|
68
187
|
translations: [],
|
|
69
188
|
error: {
|
|
70
|
-
file:
|
|
71
|
-
message: `Translation value for key "${
|
|
189
|
+
file: e.path,
|
|
190
|
+
message: `Translation value for key "${u}" must be a string, got ${typeof f}`,
|
|
72
191
|
type: "validation"
|
|
73
192
|
}
|
|
74
193
|
};
|
|
75
|
-
|
|
194
|
+
o[u] = f;
|
|
76
195
|
}
|
|
77
|
-
return
|
|
78
|
-
...
|
|
79
|
-
translations:
|
|
196
|
+
return r.push(o), {
|
|
197
|
+
...e,
|
|
198
|
+
translations: r,
|
|
80
199
|
wasSingleObject: !0
|
|
81
200
|
};
|
|
82
201
|
} else
|
|
83
202
|
return {
|
|
84
|
-
...
|
|
203
|
+
...e,
|
|
85
204
|
translations: [],
|
|
86
205
|
error: {
|
|
87
|
-
file:
|
|
206
|
+
file: e.path,
|
|
88
207
|
message: "Translation file must contain a JSON object or array of objects",
|
|
89
208
|
type: "validation"
|
|
90
209
|
}
|
|
91
210
|
};
|
|
92
211
|
return {
|
|
93
|
-
...
|
|
94
|
-
translations:
|
|
212
|
+
...e,
|
|
213
|
+
translations: r
|
|
95
214
|
};
|
|
96
|
-
} catch (
|
|
97
|
-
if (
|
|
215
|
+
} catch (s) {
|
|
216
|
+
if (s instanceof SyntaxError)
|
|
98
217
|
return {
|
|
99
|
-
...
|
|
218
|
+
...e,
|
|
100
219
|
translations: [],
|
|
101
220
|
error: {
|
|
102
|
-
file:
|
|
103
|
-
message: `Invalid JSON: ${
|
|
221
|
+
file: e.path,
|
|
222
|
+
message: `Invalid JSON: ${s.message}`,
|
|
104
223
|
type: "invalid_json"
|
|
105
224
|
}
|
|
106
225
|
};
|
|
107
|
-
const a =
|
|
226
|
+
const a = s instanceof Error ? s.message : "Unknown error";
|
|
108
227
|
return {
|
|
109
|
-
...
|
|
228
|
+
...e,
|
|
110
229
|
translations: [],
|
|
111
230
|
error: {
|
|
112
|
-
file:
|
|
231
|
+
file: e.path,
|
|
113
232
|
message: `Failed to read file: ${a}`,
|
|
114
233
|
type: "file_system"
|
|
115
234
|
}
|
|
116
235
|
};
|
|
117
236
|
}
|
|
118
237
|
});
|
|
119
|
-
return Promise.all(
|
|
238
|
+
return Promise.all(n);
|
|
120
239
|
}
|
|
121
|
-
function
|
|
122
|
-
for (const
|
|
123
|
-
if (!
|
|
124
|
-
return Object.keys(
|
|
240
|
+
function V(t) {
|
|
241
|
+
for (const n of t)
|
|
242
|
+
if (!n.error && n.translations.length > 0)
|
|
243
|
+
return Object.keys(n.translations[0]);
|
|
125
244
|
return null;
|
|
126
245
|
}
|
|
127
|
-
function
|
|
128
|
-
const
|
|
129
|
-
for (const
|
|
130
|
-
if (
|
|
246
|
+
function z(t, n) {
|
|
247
|
+
const e = [];
|
|
248
|
+
for (const s of t) {
|
|
249
|
+
if (s.error)
|
|
131
250
|
continue;
|
|
132
|
-
if (
|
|
133
|
-
|
|
134
|
-
file:
|
|
251
|
+
if (s.translations.length === 0) {
|
|
252
|
+
e.push({
|
|
253
|
+
file: s.path,
|
|
135
254
|
message: "File has no translations",
|
|
136
255
|
type: "validation"
|
|
137
256
|
});
|
|
138
257
|
continue;
|
|
139
258
|
}
|
|
140
|
-
const a = Object.keys(
|
|
141
|
-
for (let
|
|
142
|
-
const
|
|
143
|
-
if (JSON.stringify([...
|
|
144
|
-
|
|
145
|
-
file:
|
|
146
|
-
message: `Translation ${
|
|
259
|
+
const a = Object.keys(s.translations[0]);
|
|
260
|
+
for (let l = 1; l < s.translations.length; l++) {
|
|
261
|
+
const i = Object.keys(s.translations[l]);
|
|
262
|
+
if (JSON.stringify([...i].sort()) !== JSON.stringify([...a].sort())) {
|
|
263
|
+
e.push({
|
|
264
|
+
file: s.path,
|
|
265
|
+
message: `Translation ${l + 1} in file has different language keys`,
|
|
147
266
|
type: "validation"
|
|
148
267
|
});
|
|
149
268
|
continue;
|
|
150
269
|
}
|
|
151
270
|
}
|
|
152
|
-
const
|
|
153
|
-
(
|
|
154
|
-
),
|
|
155
|
-
(
|
|
271
|
+
const r = [...a].sort(), o = [...n].sort(), u = o.filter(
|
|
272
|
+
(l) => !r.includes(l)
|
|
273
|
+
), f = r.filter(
|
|
274
|
+
(l) => !o.includes(l)
|
|
156
275
|
);
|
|
157
|
-
if (
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
file:
|
|
161
|
-
message: `Language mismatch: ${
|
|
276
|
+
if (u.length > 0 || f.length > 0) {
|
|
277
|
+
const l = [];
|
|
278
|
+
u.length > 0 && l.push(`missing languages: ${u.join(", ")}`), f.length > 0 && l.push(`extra languages: ${f.join(", ")}`), e.push({
|
|
279
|
+
file: s.path,
|
|
280
|
+
message: `Language mismatch: ${l.join(
|
|
162
281
|
", "
|
|
163
|
-
)}. Expected: ${
|
|
282
|
+
)}. Expected: ${n.join(", ")}`,
|
|
164
283
|
type: "missing_languages"
|
|
165
284
|
});
|
|
166
285
|
}
|
|
167
286
|
}
|
|
168
|
-
return
|
|
287
|
+
return e;
|
|
169
288
|
}
|
|
170
|
-
function
|
|
171
|
-
const
|
|
172
|
-
for (const a of
|
|
173
|
-
const
|
|
174
|
-
if (
|
|
175
|
-
|
|
289
|
+
function X(t, n) {
|
|
290
|
+
const e = /* @__PURE__ */ new Set(), s = [];
|
|
291
|
+
for (const a of t) {
|
|
292
|
+
const r = a[n];
|
|
293
|
+
if (r === void 0) {
|
|
294
|
+
s.push(a);
|
|
176
295
|
continue;
|
|
177
296
|
}
|
|
178
|
-
const
|
|
179
|
-
|
|
297
|
+
const o = r;
|
|
298
|
+
e.has(o) || (e.add(o), s.push(a));
|
|
180
299
|
}
|
|
181
|
-
return
|
|
300
|
+
return s;
|
|
182
301
|
}
|
|
183
|
-
function
|
|
184
|
-
const
|
|
185
|
-
let a =
|
|
186
|
-
return a =
|
|
302
|
+
function H(t, n) {
|
|
303
|
+
const e = b(t);
|
|
304
|
+
let a = N(e, n);
|
|
305
|
+
return a = j(a).replace(/\\/g, "/"), a.startsWith(".") || (a = "./" + a), a;
|
|
187
306
|
}
|
|
188
|
-
function
|
|
189
|
-
const
|
|
190
|
-
if (
|
|
307
|
+
function k(t, n, e) {
|
|
308
|
+
const s = t.filter((i) => !i.error && i.translations.length > 0).sort((i, h) => i.path.localeCompare(h.path));
|
|
309
|
+
if (s.length === 0)
|
|
191
310
|
return `export default []
|
|
192
311
|
`;
|
|
193
|
-
const a =
|
|
194
|
-
const
|
|
195
|
-
return `import translations${
|
|
312
|
+
const a = s.map((i, h) => {
|
|
313
|
+
const c = H(n, i.path);
|
|
314
|
+
return `import translations${h} from '${c}' assert { type: 'json' };`;
|
|
196
315
|
}).join(`
|
|
197
|
-
`),
|
|
198
|
-
`),
|
|
199
|
-
${
|
|
316
|
+
`), r = s.map((i, h) => i.wasSingleObject ? ` ...(Array.isArray(translations${h}) ? translations${h} : [translations${h}])` : ` ...translations${h}`).join(`,
|
|
317
|
+
`), u = `export interface Translation {
|
|
318
|
+
${e.map((i) => ` ${i}: string;`).join(`
|
|
200
319
|
`)}
|
|
201
320
|
[key: string]: string;
|
|
202
|
-
}`,
|
|
321
|
+
}`, f = e[0] || "en", l = s.length > 0 ? `
|
|
203
322
|
const uniqueTranslations = allTranslations.filter(
|
|
204
|
-
(translation, index, self) => index === self.findIndex((t) => t.${
|
|
323
|
+
(translation, index, self) => index === self.findIndex((t) => t.${f} === translation.${f})
|
|
205
324
|
);` : "";
|
|
206
325
|
return `${a}
|
|
207
326
|
|
|
208
|
-
${
|
|
327
|
+
${u}
|
|
209
328
|
|
|
210
329
|
const allTranslations: Translation[] = [
|
|
211
|
-
${
|
|
212
|
-
];${
|
|
330
|
+
${r}
|
|
331
|
+
];${l}
|
|
213
332
|
|
|
214
333
|
export default uniqueTranslations;
|
|
215
334
|
`;
|
|
216
335
|
}
|
|
217
|
-
function
|
|
218
|
-
const
|
|
219
|
-
if (
|
|
336
|
+
function K(t) {
|
|
337
|
+
const n = t.filter((o) => !o.error && o.translations.length > 0).sort((o, u) => o.path.localeCompare(u.path));
|
|
338
|
+
if (n.length === 0)
|
|
220
339
|
return `export default []
|
|
221
340
|
`;
|
|
222
|
-
const
|
|
223
|
-
for (const
|
|
224
|
-
|
|
225
|
-
const
|
|
226
|
-
`).map((
|
|
341
|
+
const e = [];
|
|
342
|
+
for (const o of n)
|
|
343
|
+
o.wasSingleObject && o.translations.length === 1 ? e.push(o.translations[0]) : e.push(...o.translations);
|
|
344
|
+
const s = e.length > 0 ? Object.keys(e[0])[0] : "en", a = e.map((o) => JSON.stringify(o, null, 2).split(`
|
|
345
|
+
`).map((l) => ` ${l}`).join(`
|
|
227
346
|
`)).join(`,
|
|
228
|
-
`),
|
|
347
|
+
`), r = `
|
|
229
348
|
const uniqueTranslations = allTranslations.filter(
|
|
230
|
-
(translation, index, self) => index === self.findIndex((t) => t.${
|
|
349
|
+
(translation, index, self) => index === self.findIndex((t) => t.${s} === translation.${s})
|
|
231
350
|
);`;
|
|
232
351
|
return `const allTranslations = [
|
|
233
352
|
${a}
|
|
234
|
-
];${
|
|
353
|
+
];${r}
|
|
235
354
|
|
|
236
355
|
export default uniqueTranslations;
|
|
237
356
|
`;
|
|
238
357
|
}
|
|
239
|
-
function
|
|
240
|
-
return
|
|
358
|
+
function Q(t, n, e) {
|
|
359
|
+
return k(t, n, e);
|
|
241
360
|
}
|
|
242
|
-
async function
|
|
243
|
-
const
|
|
244
|
-
if (
|
|
361
|
+
async function tt(t) {
|
|
362
|
+
const n = [], e = Date.now(), s = await U(t.pattern);
|
|
363
|
+
if (s.length === 0)
|
|
245
364
|
return {
|
|
246
365
|
success: !0,
|
|
247
366
|
filesFound: 0,
|
|
248
367
|
translationsGenerated: 0,
|
|
249
368
|
errors: [],
|
|
250
|
-
outputPath:
|
|
369
|
+
outputPath: t.outputPath
|
|
251
370
|
};
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
if ((!o || o.length === 0) && a.filter(
|
|
259
|
-
(h) => !h.error && h.translations.length > 0
|
|
371
|
+
const a = await B(s);
|
|
372
|
+
for (const c of a)
|
|
373
|
+
c.error && n.push(c.error);
|
|
374
|
+
const r = V(a);
|
|
375
|
+
if ((!r || r.length === 0) && a.filter(
|
|
376
|
+
(p) => !p.error && p.translations.length > 0
|
|
260
377
|
).length === 0)
|
|
261
378
|
return {
|
|
262
379
|
success: !1,
|
|
263
|
-
filesFound:
|
|
380
|
+
filesFound: s.length,
|
|
264
381
|
translationsGenerated: 0,
|
|
265
|
-
errors:
|
|
382
|
+
errors: n.length > 0 ? n : [
|
|
266
383
|
{
|
|
267
|
-
file:
|
|
384
|
+
file: t.pattern,
|
|
268
385
|
message: "No valid translation files found",
|
|
269
386
|
type: "validation"
|
|
270
387
|
}
|
|
271
388
|
],
|
|
272
|
-
outputPath:
|
|
389
|
+
outputPath: t.outputPath
|
|
273
390
|
};
|
|
274
|
-
if (
|
|
275
|
-
const
|
|
276
|
-
if (
|
|
391
|
+
if (r && r.length > 0) {
|
|
392
|
+
const c = z(a, r);
|
|
393
|
+
if (n.push(...c), c.length > 0)
|
|
277
394
|
return {
|
|
278
395
|
success: !1,
|
|
279
|
-
filesFound:
|
|
396
|
+
filesFound: s.length,
|
|
280
397
|
translationsGenerated: 0,
|
|
281
|
-
errors:
|
|
282
|
-
outputPath:
|
|
398
|
+
errors: n,
|
|
399
|
+
outputPath: t.outputPath
|
|
283
400
|
};
|
|
284
401
|
}
|
|
285
|
-
const
|
|
286
|
-
for (const
|
|
287
|
-
!
|
|
288
|
-
const
|
|
289
|
-
|
|
290
|
-
|
|
402
|
+
const o = [];
|
|
403
|
+
for (const c of a)
|
|
404
|
+
!c.error && c.translations.length > 0 && o.push(...c.translations);
|
|
405
|
+
const u = t.referenceLanguage || (r == null ? void 0 : r[0]) || "en", f = X(
|
|
406
|
+
o,
|
|
407
|
+
u
|
|
291
408
|
);
|
|
292
|
-
let
|
|
293
|
-
const
|
|
294
|
-
(
|
|
409
|
+
let l;
|
|
410
|
+
const i = a.filter(
|
|
411
|
+
(c) => !c.error && c.translations.length > 0
|
|
295
412
|
);
|
|
296
|
-
switch (
|
|
413
|
+
switch (t.outputFormat) {
|
|
297
414
|
case "ts":
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
415
|
+
l = k(
|
|
416
|
+
i,
|
|
417
|
+
t.outputPath,
|
|
418
|
+
r || []
|
|
302
419
|
);
|
|
303
420
|
break;
|
|
304
421
|
case "tsx":
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
422
|
+
l = Q(
|
|
423
|
+
i,
|
|
424
|
+
t.outputPath,
|
|
425
|
+
r || []
|
|
309
426
|
);
|
|
310
427
|
break;
|
|
311
428
|
case "js":
|
|
312
|
-
|
|
429
|
+
l = K(i);
|
|
313
430
|
break;
|
|
314
431
|
default:
|
|
315
432
|
return {
|
|
316
433
|
success: !1,
|
|
317
|
-
filesFound:
|
|
434
|
+
filesFound: s.length,
|
|
318
435
|
translationsGenerated: 0,
|
|
319
436
|
errors: [
|
|
320
|
-
...
|
|
437
|
+
...n,
|
|
321
438
|
{
|
|
322
|
-
file:
|
|
323
|
-
message: `Unsupported output format: ${
|
|
439
|
+
file: t.outputPath,
|
|
440
|
+
message: `Unsupported output format: ${t.outputFormat}`,
|
|
324
441
|
type: "validation"
|
|
325
442
|
}
|
|
326
443
|
],
|
|
327
|
-
outputPath:
|
|
444
|
+
outputPath: t.outputPath
|
|
328
445
|
};
|
|
329
446
|
}
|
|
330
447
|
try {
|
|
331
|
-
const
|
|
332
|
-
await
|
|
333
|
-
} catch (
|
|
334
|
-
const
|
|
335
|
-
return
|
|
336
|
-
file:
|
|
337
|
-
message: `Failed to write output file: ${
|
|
448
|
+
const c = b(t.outputPath);
|
|
449
|
+
await E(c, { recursive: !0 }), await O(t.outputPath, l, "utf-8");
|
|
450
|
+
} catch (c) {
|
|
451
|
+
const p = c instanceof Error ? c.message : "Unknown error";
|
|
452
|
+
return n.push({
|
|
453
|
+
file: t.outputPath,
|
|
454
|
+
message: `Failed to write output file: ${p}`,
|
|
338
455
|
type: "file_system"
|
|
339
456
|
}), {
|
|
340
457
|
success: !1,
|
|
341
|
-
filesFound:
|
|
342
|
-
translationsGenerated:
|
|
343
|
-
errors:
|
|
344
|
-
outputPath:
|
|
458
|
+
filesFound: s.length,
|
|
459
|
+
translationsGenerated: f.length,
|
|
460
|
+
errors: n,
|
|
461
|
+
outputPath: t.outputPath
|
|
345
462
|
};
|
|
346
463
|
}
|
|
347
|
-
const
|
|
348
|
-
return
|
|
349
|
-
`⚠️ Generation took ${
|
|
464
|
+
const h = Date.now() - e;
|
|
465
|
+
return h > 1e3 && s.length < 100 && console.warn(
|
|
466
|
+
`⚠️ Generation took ${h}ms for ${s.length} files`
|
|
350
467
|
), {
|
|
351
|
-
success:
|
|
352
|
-
filesFound:
|
|
353
|
-
translationsGenerated:
|
|
354
|
-
errors:
|
|
355
|
-
outputPath:
|
|
468
|
+
success: n.length === 0,
|
|
469
|
+
filesFound: s.length,
|
|
470
|
+
translationsGenerated: f.length,
|
|
471
|
+
errors: n,
|
|
472
|
+
outputPath: t.outputPath
|
|
356
473
|
};
|
|
357
474
|
}
|
|
358
475
|
export {
|
|
359
|
-
|
|
476
|
+
tt as generate
|
|
360
477
|
};
|