@fluenti/cli 0.1.2 → 0.1.3
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/catalog.d.ts +6 -2
- package/dist/catalog.d.ts.map +1 -1
- package/dist/cli.cjs +18 -6
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +411 -236
- package/dist/cli.js.map +1 -1
- package/dist/compile-BJdEF9QX.js +357 -0
- package/dist/compile-BJdEF9QX.js.map +1 -0
- package/dist/compile-d4Q8bND5.cjs +16 -0
- package/dist/compile-d4Q8bND5.cjs.map +1 -0
- package/dist/compile.d.ts +16 -1
- package/dist/compile.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/init.d.ts +24 -0
- package/dist/init.d.ts.map +1 -0
- package/dist/json-format.d.ts.map +1 -1
- package/dist/migrate.d.ts +36 -0
- package/dist/migrate.d.ts.map +1 -1
- package/dist/po-format.d.ts.map +1 -1
- package/dist/stats-format.d.ts +20 -0
- package/dist/stats-format.d.ts.map +1 -0
- package/dist/translate.d.ts +4 -0
- package/dist/translate.d.ts.map +1 -1
- package/dist/tsx-extractor-DZrY1LMS.js +268 -0
- package/dist/tsx-extractor-DZrY1LMS.js.map +1 -0
- package/dist/tsx-extractor-LEAVCuX9.cjs +2 -0
- package/dist/tsx-extractor-LEAVCuX9.cjs.map +1 -0
- package/dist/tsx-extractor.d.ts.map +1 -1
- package/dist/vue-extractor-BlHc3vzt.cjs +3 -0
- package/dist/vue-extractor-BlHc3vzt.cjs.map +1 -0
- package/dist/vue-extractor-iUl6SUkv.js +210 -0
- package/dist/vue-extractor-iUl6SUkv.js.map +1 -0
- package/package.json +2 -2
- package/dist/compile-DK1UYkah.cjs +0 -13
- package/dist/compile-DK1UYkah.cjs.map +0 -1
- package/dist/compile-DuHUSzlx.js +0 -747
- package/dist/compile-DuHUSzlx.js.map +0 -1
package/dist/compile-DuHUSzlx.js
DELETED
|
@@ -1,747 +0,0 @@
|
|
|
1
|
-
import { parse as e } from "@vue/compiler-sfc";
|
|
2
|
-
import { createMessageId as t, isSourceNode as n, parseSourceModule as r, walkSourceAst as i } from "@fluenti/core/internal";
|
|
3
|
-
import { hashMessage as a, parse as o } from "@fluenti/core";
|
|
4
|
-
import * as s from "gettext-parser";
|
|
5
|
-
//#region src/tsx-extractor.ts
|
|
6
|
-
var c = new Set([
|
|
7
|
-
"@fluenti/react",
|
|
8
|
-
"@fluenti/vue",
|
|
9
|
-
"@fluenti/solid",
|
|
10
|
-
"@fluenti/next/__generated"
|
|
11
|
-
]);
|
|
12
|
-
function l(e) {
|
|
13
|
-
let t = e.trim();
|
|
14
|
-
if (/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(t)) return t;
|
|
15
|
-
if (/^[a-zA-Z_$][a-zA-Z0-9_$.]*$/.test(t) && !t.endsWith(".")) {
|
|
16
|
-
let e = t.split(".");
|
|
17
|
-
return e[e.length - 1];
|
|
18
|
-
}
|
|
19
|
-
let n = t.match(/^([a-zA-Z_$][a-zA-Z0-9_$.]*)\s*\(/);
|
|
20
|
-
return n ? n[1].replace(/\./g, "_") : "";
|
|
21
|
-
}
|
|
22
|
-
function u(e, t) {
|
|
23
|
-
let n = "", r = 0;
|
|
24
|
-
for (let i = 0; i < e.length; i++) {
|
|
25
|
-
if (n += e[i], i >= t.length) continue;
|
|
26
|
-
let a = l(t[i]);
|
|
27
|
-
if (a === "") {
|
|
28
|
-
n += `{arg${r}}`, r++;
|
|
29
|
-
continue;
|
|
30
|
-
}
|
|
31
|
-
n += `{${a}}`;
|
|
32
|
-
}
|
|
33
|
-
return n;
|
|
34
|
-
}
|
|
35
|
-
function d(e, t, n) {
|
|
36
|
-
if (!e.message) return;
|
|
37
|
-
let r = n.loc?.start.line ?? 1, i = (n.loc?.start.column ?? 0) + 1;
|
|
38
|
-
return {
|
|
39
|
-
id: e.id,
|
|
40
|
-
message: e.message,
|
|
41
|
-
...e.context === void 0 ? {} : { context: e.context },
|
|
42
|
-
...e.comment === void 0 ? {} : { comment: e.comment },
|
|
43
|
-
origin: {
|
|
44
|
-
file: t,
|
|
45
|
-
line: r,
|
|
46
|
-
column: i
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
function f(e) {
|
|
51
|
-
if (e.message) return {
|
|
52
|
-
id: e.id ?? t(e.message, e.context),
|
|
53
|
-
message: e.message,
|
|
54
|
-
...e.context === void 0 ? {} : { context: e.context },
|
|
55
|
-
...e.comment === void 0 ? {} : { comment: e.comment }
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
function p(e) {
|
|
59
|
-
if (e.type === "StringLiteral") return f({ message: e.value });
|
|
60
|
-
if (e.type === "TemplateLiteral") {
|
|
61
|
-
let t = e;
|
|
62
|
-
return t.expressions.length === 0 ? f({ message: t.quasis.map((e) => e.value.cooked ?? e.value.raw).join("") }) : void 0;
|
|
63
|
-
}
|
|
64
|
-
if (e.type !== "ObjectExpression") return;
|
|
65
|
-
let t = {};
|
|
66
|
-
for (let n of e.properties) {
|
|
67
|
-
if (n.type !== "ObjectProperty") continue;
|
|
68
|
-
let e = n;
|
|
69
|
-
if (e.computed || !E(e.key)) continue;
|
|
70
|
-
let r = e.key.name;
|
|
71
|
-
if (![
|
|
72
|
-
"id",
|
|
73
|
-
"message",
|
|
74
|
-
"context",
|
|
75
|
-
"comment"
|
|
76
|
-
].includes(r)) continue;
|
|
77
|
-
let i = g(e.value);
|
|
78
|
-
i !== void 0 && (t[r] = i);
|
|
79
|
-
}
|
|
80
|
-
if (t.message) return f(t);
|
|
81
|
-
}
|
|
82
|
-
function ee(e) {
|
|
83
|
-
let t = [
|
|
84
|
-
"zero",
|
|
85
|
-
"one",
|
|
86
|
-
"two",
|
|
87
|
-
"few",
|
|
88
|
-
"many",
|
|
89
|
-
"other"
|
|
90
|
-
], n = e.value ?? e.count ?? "count", r = [], i = e.offset;
|
|
91
|
-
for (let n of t) {
|
|
92
|
-
let t = e[n];
|
|
93
|
-
if (t === void 0) continue;
|
|
94
|
-
let i = n === "zero" ? "=0" : n;
|
|
95
|
-
r.push(`${i} {${t}}`);
|
|
96
|
-
}
|
|
97
|
-
return r.length === 0 ? "" : `{${n}, plural, ${i ? `offset:${i} ` : ""}${r.join(" ")}}`;
|
|
98
|
-
}
|
|
99
|
-
function m(e) {
|
|
100
|
-
let t = 0;
|
|
101
|
-
function n(e) {
|
|
102
|
-
let r = "";
|
|
103
|
-
for (let i of e) {
|
|
104
|
-
if (i.type === "JSXText") {
|
|
105
|
-
r += h(i.value);
|
|
106
|
-
continue;
|
|
107
|
-
}
|
|
108
|
-
if (i.type === "JSXElement") {
|
|
109
|
-
let e = t++, a = n(i.children);
|
|
110
|
-
if (a === void 0) return;
|
|
111
|
-
r += `<${e}>${a}</${e}>`;
|
|
112
|
-
continue;
|
|
113
|
-
}
|
|
114
|
-
if (i.type === "JSXFragment") {
|
|
115
|
-
let e = n(i.children);
|
|
116
|
-
if (e === void 0) return;
|
|
117
|
-
r += e;
|
|
118
|
-
continue;
|
|
119
|
-
}
|
|
120
|
-
if (i.type === "JSXExpressionContainer") {
|
|
121
|
-
let e = i.expression;
|
|
122
|
-
if (e.type === "StringLiteral") {
|
|
123
|
-
r += e.value;
|
|
124
|
-
continue;
|
|
125
|
-
}
|
|
126
|
-
if (e.type === "NumericLiteral") {
|
|
127
|
-
r += String(e.value);
|
|
128
|
-
continue;
|
|
129
|
-
}
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
return r;
|
|
134
|
-
}
|
|
135
|
-
let r = n(e);
|
|
136
|
-
if (r !== void 0) return r.replace(/\s+/g, " ").trim() || void 0;
|
|
137
|
-
}
|
|
138
|
-
function h(e) {
|
|
139
|
-
return e.replace(/\s+/g, " ");
|
|
140
|
-
}
|
|
141
|
-
function g(e) {
|
|
142
|
-
if (e.type === "StringLiteral") return e.value;
|
|
143
|
-
if (e.type === "NumericLiteral") return String(e.value);
|
|
144
|
-
if (e.type === "JSXExpressionContainer") return g(e.expression);
|
|
145
|
-
if (e.type === "TemplateLiteral") {
|
|
146
|
-
let t = e;
|
|
147
|
-
if (t.expressions.length === 0) return t.quasis.map((e) => e.value.cooked ?? e.value.raw).join("");
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
function _(e, t) {
|
|
151
|
-
if (!(e.start == null || e.end == null)) return e.type === "JSXExpressionContainer" ? _(e.expression, t) : t.slice(e.start, e.end).trim();
|
|
152
|
-
}
|
|
153
|
-
function v(e, t) {
|
|
154
|
-
for (let n of e.attributes) {
|
|
155
|
-
if (n.type !== "JSXAttribute") continue;
|
|
156
|
-
let e = n;
|
|
157
|
-
if (e.name.type === "JSXIdentifier" && e.name.name === t) return e;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
function te(e, t) {
|
|
161
|
-
let n = {};
|
|
162
|
-
for (let r of [
|
|
163
|
-
"id",
|
|
164
|
-
"value",
|
|
165
|
-
"count",
|
|
166
|
-
"offset",
|
|
167
|
-
"zero",
|
|
168
|
-
"one",
|
|
169
|
-
"two",
|
|
170
|
-
"few",
|
|
171
|
-
"many",
|
|
172
|
-
"other"
|
|
173
|
-
]) {
|
|
174
|
-
let i = v(e, r);
|
|
175
|
-
if (!i?.value) continue;
|
|
176
|
-
let a = g(i.value);
|
|
177
|
-
if (a !== void 0) {
|
|
178
|
-
n[r] = a;
|
|
179
|
-
continue;
|
|
180
|
-
}
|
|
181
|
-
let o = _(i.value, t);
|
|
182
|
-
o !== void 0 && (r === "value" || r === "count" || r === "offset") && (n[r] = o);
|
|
183
|
-
}
|
|
184
|
-
return n;
|
|
185
|
-
}
|
|
186
|
-
function ne(e, n) {
|
|
187
|
-
let r = u(n.quasi.quasis.map((e) => e.value.cooked ?? e.value.raw), n.quasi.expressions.map((t) => t.start == null || t.end == null ? "" : e.slice(t.start, t.end)));
|
|
188
|
-
return {
|
|
189
|
-
id: t(r),
|
|
190
|
-
message: r
|
|
191
|
-
};
|
|
192
|
-
}
|
|
193
|
-
function y(e) {
|
|
194
|
-
let t = /* @__PURE__ */ new Set(), n = Array.isArray(e.body) ? e.body : [];
|
|
195
|
-
for (let e of n) if (x(e) && c.has(e.source.value)) for (let n of e.specifiers) S(n) && C(n) === "t" && t.add(n.local.name);
|
|
196
|
-
return t;
|
|
197
|
-
}
|
|
198
|
-
function b(e, n) {
|
|
199
|
-
let a = r(e);
|
|
200
|
-
if (!a) return [];
|
|
201
|
-
let o = [], s = y(a);
|
|
202
|
-
return i(a, (r) => {
|
|
203
|
-
if (r.type === "TaggedTemplateExpression") {
|
|
204
|
-
let t = r;
|
|
205
|
-
if (E(t.tag) && (t.tag.name === "t" || s.has(t.tag.name))) {
|
|
206
|
-
if (t.quasi.expressions.length > 0) return;
|
|
207
|
-
let r = d(ne(e, t), n, t);
|
|
208
|
-
r && o.push(r);
|
|
209
|
-
}
|
|
210
|
-
return;
|
|
211
|
-
}
|
|
212
|
-
if (r.type === "CallExpression") {
|
|
213
|
-
let e = r;
|
|
214
|
-
if (E(e.callee) && (e.callee.name === "t" || s.has(e.callee.name))) {
|
|
215
|
-
if (s.has(e.callee.name) && e.arguments[0]?.type !== "ObjectExpression") return;
|
|
216
|
-
let t = e.arguments[0] ? p(e.arguments[0]) : void 0, r = t ? d(t, n, e) : void 0;
|
|
217
|
-
r && o.push(r);
|
|
218
|
-
}
|
|
219
|
-
return;
|
|
220
|
-
}
|
|
221
|
-
if (r.type !== "JSXElement") return;
|
|
222
|
-
let i = r, a = i.openingElement, c = w(a.name);
|
|
223
|
-
if (c === "Trans") {
|
|
224
|
-
let e = v(a, "message"), t = v(a, "id"), r = v(a, "context"), s = v(a, "comment"), c = e?.value ? T({
|
|
225
|
-
id: t?.value ? g(t.value) : void 0,
|
|
226
|
-
message: g(e.value),
|
|
227
|
-
context: r?.value ? g(r.value) : void 0,
|
|
228
|
-
comment: s?.value ? g(s.value) : void 0
|
|
229
|
-
}) : T({
|
|
230
|
-
id: t?.value ? g(t.value) : void 0,
|
|
231
|
-
message: m(i.children),
|
|
232
|
-
context: r?.value ? g(r.value) : void 0,
|
|
233
|
-
comment: s?.value ? g(s.value) : void 0
|
|
234
|
-
}), l = c ? d(c, n, i) : void 0;
|
|
235
|
-
l && o.push(l);
|
|
236
|
-
return;
|
|
237
|
-
}
|
|
238
|
-
if (c === "Plural") {
|
|
239
|
-
let r = te(a, e), s = ee(r);
|
|
240
|
-
if (!s) return;
|
|
241
|
-
let c = d({
|
|
242
|
-
id: r.id ?? t(s),
|
|
243
|
-
message: s
|
|
244
|
-
}, n, i);
|
|
245
|
-
c && o.push(c);
|
|
246
|
-
}
|
|
247
|
-
}), o;
|
|
248
|
-
}
|
|
249
|
-
function x(e) {
|
|
250
|
-
return n(e) && e.type === "ImportDeclaration";
|
|
251
|
-
}
|
|
252
|
-
function S(e) {
|
|
253
|
-
return n(e) && e.type === "ImportSpecifier";
|
|
254
|
-
}
|
|
255
|
-
function C(e) {
|
|
256
|
-
if (e.imported.type === "Identifier") return e.imported.name;
|
|
257
|
-
if (e.imported.type === "StringLiteral") return e.imported.value;
|
|
258
|
-
}
|
|
259
|
-
function w(e) {
|
|
260
|
-
if (e.type === "JSXIdentifier") return String(e.name);
|
|
261
|
-
}
|
|
262
|
-
function T(e) {
|
|
263
|
-
let t = {};
|
|
264
|
-
return e.id !== void 0 && (t.id = e.id), e.message !== void 0 && (t.message = e.message), e.context !== void 0 && (t.context = e.context), e.comment !== void 0 && (t.comment = e.comment), f(t);
|
|
265
|
-
}
|
|
266
|
-
function E(e) {
|
|
267
|
-
return n(e) && e.type === "Identifier";
|
|
268
|
-
}
|
|
269
|
-
//#endregion
|
|
270
|
-
//#region src/vue-extractor.ts
|
|
271
|
-
var D = 1, O = 2, k = 7, A = 6;
|
|
272
|
-
function j(e) {
|
|
273
|
-
return e.filter((e) => e.type === O).map((e) => (e.content ?? "").trim()).join("");
|
|
274
|
-
}
|
|
275
|
-
function M(e, t) {
|
|
276
|
-
let n = e.split("|").map((e) => e.trim()), r = [
|
|
277
|
-
"one",
|
|
278
|
-
"other",
|
|
279
|
-
"zero",
|
|
280
|
-
"few",
|
|
281
|
-
"many"
|
|
282
|
-
], i = [];
|
|
283
|
-
if (n.length === 2) i.push(`one {${n[0]}}`), i.push(`other {${n[1]}}`);
|
|
284
|
-
else for (let e = 0; e < n.length && e < r.length; e++) i.push(`${r[e]} {${n[e]}}`);
|
|
285
|
-
return `{${t}, plural, ${i.join(" ")}}`;
|
|
286
|
-
}
|
|
287
|
-
function N(e) {
|
|
288
|
-
let t = e.count ?? "count", n = [
|
|
289
|
-
"zero",
|
|
290
|
-
"one",
|
|
291
|
-
"two",
|
|
292
|
-
"few",
|
|
293
|
-
"many",
|
|
294
|
-
"other"
|
|
295
|
-
], r = [], i = e.offset;
|
|
296
|
-
for (let t of n) if (e[t] !== void 0) {
|
|
297
|
-
let n = t === "zero" ? "=0" : t;
|
|
298
|
-
r.push(`${n} {${e[t]}}`);
|
|
299
|
-
}
|
|
300
|
-
return r.length === 0 ? "" : `{${t}, plural, ${i ? `offset:${i} ` : ""}${r.join(" ")}}`;
|
|
301
|
-
}
|
|
302
|
-
function P(e, n, r) {
|
|
303
|
-
if (e.type === D) {
|
|
304
|
-
let i = e.props?.find((e) => e.type === k && I(e) === "t");
|
|
305
|
-
if (i) {
|
|
306
|
-
let a = new Set(["plural"]), o = (i.modifiers ?? []).map((e) => typeof e == "string" ? e : e.content), s = o.includes("plural"), c = o.filter((e) => !a.has(e)), l = i.arg?.content, u = l ? [l, ...c].join(".") : void 0, d = j(e.children ?? []);
|
|
307
|
-
if (s) {
|
|
308
|
-
let e = M(d, i.exp?.content ?? "count"), a = u ?? t(e);
|
|
309
|
-
r.push({
|
|
310
|
-
id: a,
|
|
311
|
-
message: e,
|
|
312
|
-
origin: {
|
|
313
|
-
file: n,
|
|
314
|
-
line: i.loc.start.line,
|
|
315
|
-
column: i.loc.start.column
|
|
316
|
-
}
|
|
317
|
-
});
|
|
318
|
-
} else if (d) {
|
|
319
|
-
let e = u ?? t(d);
|
|
320
|
-
r.push({
|
|
321
|
-
id: e,
|
|
322
|
-
message: d,
|
|
323
|
-
origin: {
|
|
324
|
-
file: n,
|
|
325
|
-
line: i.loc.start.line,
|
|
326
|
-
column: i.loc.start.column
|
|
327
|
-
}
|
|
328
|
-
});
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
if (e.tag === "Trans") {
|
|
332
|
-
let i = e.props?.find((e) => e.type === A && I(e) === "message"), a = e.props?.find((e) => e.type === A && I(e) === "id"), o = e.props?.find((e) => e.type === A && I(e) === "context"), s = e.props?.find((e) => e.type === A && I(e) === "comment"), c = o?.value?.content, l = s?.value?.content;
|
|
333
|
-
if (i?.value) {
|
|
334
|
-
let o = i.value.content, s = a?.value?.content ?? t(o, c);
|
|
335
|
-
r.push({
|
|
336
|
-
id: s,
|
|
337
|
-
message: o,
|
|
338
|
-
...c === void 0 ? {} : { context: c },
|
|
339
|
-
...l === void 0 ? {} : { comment: l },
|
|
340
|
-
origin: {
|
|
341
|
-
file: n,
|
|
342
|
-
line: e.loc.start.line,
|
|
343
|
-
column: e.loc.start.column
|
|
344
|
-
}
|
|
345
|
-
});
|
|
346
|
-
} else if (e.children && e.children.length > 0) {
|
|
347
|
-
let i = F(e.children);
|
|
348
|
-
if (i.message) {
|
|
349
|
-
let o = a?.value?.content ?? t(i.message, c);
|
|
350
|
-
r.push({
|
|
351
|
-
id: o,
|
|
352
|
-
message: i.message,
|
|
353
|
-
...c === void 0 ? {} : { context: c },
|
|
354
|
-
...l === void 0 ? {} : { comment: l },
|
|
355
|
-
origin: {
|
|
356
|
-
file: n,
|
|
357
|
-
line: e.loc.start.line,
|
|
358
|
-
column: e.loc.start.column
|
|
359
|
-
}
|
|
360
|
-
});
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
if (e.tag === "Plural") {
|
|
365
|
-
let i = {}, a, o;
|
|
366
|
-
for (let t of e.props ?? []) t.type === A && t.value && (i[I(t)] = t.value.content), t.type === k && I(t) === "bind" && t.arg?.content === "value" && t.exp && (a = t.exp.content), t.type === k && I(t) === "bind" && t.arg?.content === "offset" && t.exp && (o = t.exp.content);
|
|
367
|
-
let s = a ?? i.count ?? "count", c = o ?? i.offset, l = N({
|
|
368
|
-
...i,
|
|
369
|
-
count: s,
|
|
370
|
-
...c === void 0 ? {} : { offset: c }
|
|
371
|
-
});
|
|
372
|
-
if (l) {
|
|
373
|
-
let a = i.id ?? t(l);
|
|
374
|
-
r.push({
|
|
375
|
-
id: a,
|
|
376
|
-
message: l,
|
|
377
|
-
origin: {
|
|
378
|
-
file: n,
|
|
379
|
-
line: e.loc.start.line,
|
|
380
|
-
column: e.loc.start.column
|
|
381
|
-
}
|
|
382
|
-
});
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
if (e.children) for (let t of e.children) P(t, n, r);
|
|
387
|
-
}
|
|
388
|
-
function F(e) {
|
|
389
|
-
let t = 0, n = !1;
|
|
390
|
-
return {
|
|
391
|
-
message: e.map((e) => {
|
|
392
|
-
if (e.type === O) return (e.content ?? "").trim() ? e.content ?? "" : "";
|
|
393
|
-
if (e.type === D && e.tag) {
|
|
394
|
-
n = !0;
|
|
395
|
-
let r = t++;
|
|
396
|
-
return `<${r}>${F(e.children ?? []).message}</${r}>`;
|
|
397
|
-
}
|
|
398
|
-
return "";
|
|
399
|
-
}).join("").trim(),
|
|
400
|
-
hasElements: n
|
|
401
|
-
};
|
|
402
|
-
}
|
|
403
|
-
function I(e) {
|
|
404
|
-
return typeof e.name == "string" ? e.name : e.name.content;
|
|
405
|
-
}
|
|
406
|
-
function L(e, t) {
|
|
407
|
-
let n = [], r = /\{\{([\s\S]*?)\}\}/g, i;
|
|
408
|
-
for (; (i = r.exec(e)) !== null;) {
|
|
409
|
-
let r = i[1]?.trim();
|
|
410
|
-
if (!r) continue;
|
|
411
|
-
let a = b(r, t);
|
|
412
|
-
if (a.length === 0) continue;
|
|
413
|
-
let o = e.slice(0, i.index).split("\n").length - 1;
|
|
414
|
-
for (let e of a) n.push({
|
|
415
|
-
...e,
|
|
416
|
-
origin: {
|
|
417
|
-
...e.origin,
|
|
418
|
-
line: e.origin.line + o
|
|
419
|
-
}
|
|
420
|
-
});
|
|
421
|
-
}
|
|
422
|
-
return n;
|
|
423
|
-
}
|
|
424
|
-
function R(t, n) {
|
|
425
|
-
let r = [], { descriptor: i } = e(t, { filename: n });
|
|
426
|
-
if (i.template?.ast && P(i.template.ast, n, r), i.template?.content) {
|
|
427
|
-
let e = b(i.template.content, n), t = i.template.loc.start.line - 1, a = new Set(r.map((e) => e.id));
|
|
428
|
-
for (let n of e) a.has(n.id) || r.push({
|
|
429
|
-
...n,
|
|
430
|
-
origin: {
|
|
431
|
-
...n.origin,
|
|
432
|
-
line: n.origin.line + t
|
|
433
|
-
}
|
|
434
|
-
});
|
|
435
|
-
let o = L(i.template.content, n);
|
|
436
|
-
for (let e of o) a.has(e.id) || r.push({
|
|
437
|
-
...e,
|
|
438
|
-
origin: {
|
|
439
|
-
...e.origin,
|
|
440
|
-
line: e.origin.line + t
|
|
441
|
-
}
|
|
442
|
-
});
|
|
443
|
-
}
|
|
444
|
-
if (i.scriptSetup?.content) {
|
|
445
|
-
let e = b(i.scriptSetup.content, n), t = i.scriptSetup.loc.start.line - 1;
|
|
446
|
-
for (let n of e) r.push({
|
|
447
|
-
...n,
|
|
448
|
-
origin: {
|
|
449
|
-
...n.origin,
|
|
450
|
-
line: n.origin.line + t
|
|
451
|
-
}
|
|
452
|
-
});
|
|
453
|
-
}
|
|
454
|
-
if (i.script?.content) {
|
|
455
|
-
let e = b(i.script.content, n), t = i.script.loc.start.line - 1;
|
|
456
|
-
for (let n of e) r.push({
|
|
457
|
-
...n,
|
|
458
|
-
origin: {
|
|
459
|
-
...n.origin,
|
|
460
|
-
line: n.origin.line + t
|
|
461
|
-
}
|
|
462
|
-
});
|
|
463
|
-
}
|
|
464
|
-
return r;
|
|
465
|
-
}
|
|
466
|
-
//#endregion
|
|
467
|
-
//#region src/catalog.ts
|
|
468
|
-
function z(e, t) {
|
|
469
|
-
let n = new Set(t.map((e) => e.id)), r = /* @__PURE__ */ new Set(), i = {}, a = 0, o = 0, s = 0;
|
|
470
|
-
for (let n of t) {
|
|
471
|
-
let t = e[n.id], s = t ? void 0 : B(e, n, r), c = `${n.origin.file}:${n.origin.line}`, l = t ?? s?.entry;
|
|
472
|
-
s && r.add(s.id), l ? (i[n.id] = {
|
|
473
|
-
...l,
|
|
474
|
-
message: n.message ?? l.message,
|
|
475
|
-
context: n.context,
|
|
476
|
-
comment: n.comment,
|
|
477
|
-
origin: c,
|
|
478
|
-
obsolete: !1
|
|
479
|
-
}, o++) : (i[n.id] = {
|
|
480
|
-
message: n.message,
|
|
481
|
-
context: n.context,
|
|
482
|
-
comment: n.comment,
|
|
483
|
-
origin: c
|
|
484
|
-
}, a++);
|
|
485
|
-
}
|
|
486
|
-
for (let [t, r] of Object.entries(e)) n.has(t) || (i[t] = {
|
|
487
|
-
...r,
|
|
488
|
-
obsolete: !0
|
|
489
|
-
}, s++);
|
|
490
|
-
return {
|
|
491
|
-
catalog: i,
|
|
492
|
-
result: {
|
|
493
|
-
added: a,
|
|
494
|
-
unchanged: o,
|
|
495
|
-
obsolete: s
|
|
496
|
-
}
|
|
497
|
-
};
|
|
498
|
-
}
|
|
499
|
-
function B(e, t, n) {
|
|
500
|
-
if (!t.context) return;
|
|
501
|
-
let r = `${t.origin.file}:${t.origin.line}`;
|
|
502
|
-
for (let [i, a] of Object.entries(e)) if (!n.has(i) && a.context === void 0 && a.message === t.message && V(a.origin, r)) return {
|
|
503
|
-
id: i,
|
|
504
|
-
entry: a
|
|
505
|
-
};
|
|
506
|
-
}
|
|
507
|
-
function V(e, t) {
|
|
508
|
-
return e ? e === t ? !0 : H(e) === H(t) : !1;
|
|
509
|
-
}
|
|
510
|
-
function H(e) {
|
|
511
|
-
return e.match(/^(.*):\d+$/)?.[1] ?? e;
|
|
512
|
-
}
|
|
513
|
-
//#endregion
|
|
514
|
-
//#region src/json-format.ts
|
|
515
|
-
function U(e) {
|
|
516
|
-
let t = JSON.parse(e), n = {};
|
|
517
|
-
for (let [e, r] of Object.entries(t)) if (typeof r == "object" && r) {
|
|
518
|
-
let t = r;
|
|
519
|
-
n[e] = {
|
|
520
|
-
message: typeof t.message == "string" ? t.message : void 0,
|
|
521
|
-
context: typeof t.context == "string" ? t.context : void 0,
|
|
522
|
-
comment: typeof t.comment == "string" ? t.comment : void 0,
|
|
523
|
-
translation: typeof t.translation == "string" ? t.translation : void 0,
|
|
524
|
-
origin: typeof t.origin == "string" ? t.origin : void 0,
|
|
525
|
-
obsolete: typeof t.obsolete == "boolean" ? t.obsolete : void 0
|
|
526
|
-
};
|
|
527
|
-
}
|
|
528
|
-
return n;
|
|
529
|
-
}
|
|
530
|
-
function W(e) {
|
|
531
|
-
let t = {};
|
|
532
|
-
for (let [n, r] of Object.entries(e)) {
|
|
533
|
-
let e = {};
|
|
534
|
-
r.message !== void 0 && (e.message = r.message), r.context !== void 0 && (e.context = r.context), r.comment !== void 0 && (e.comment = r.comment), r.translation !== void 0 && (e.translation = r.translation), r.origin !== void 0 && (e.origin = r.origin), r.obsolete && (e.obsolete = !0), t[n] = e;
|
|
535
|
-
}
|
|
536
|
-
return JSON.stringify(t, null, 2) + "\n";
|
|
537
|
-
}
|
|
538
|
-
//#endregion
|
|
539
|
-
//#region src/po-format.ts
|
|
540
|
-
var G = "fluenti-id:";
|
|
541
|
-
function re(e) {
|
|
542
|
-
let t = s.po.parse(e), n = {}, r = t.translations ?? {};
|
|
543
|
-
for (let [e, t] of Object.entries(r)) for (let [r, i] of Object.entries(t)) {
|
|
544
|
-
if (!r) continue;
|
|
545
|
-
let t = e || i.msgctxt || void 0, o = i.msgstr?.[0] ?? void 0, s = i.comments?.reference ?? void 0, c = i.comments?.flag?.includes("fuzzy") ?? !1, { comment: l, customId: u, sourceMessage: d } = q(i.comments?.extracted), f = d && a(d, t) === r ? d : void 0, p = u ?? (f ? r : a(r, t));
|
|
546
|
-
n[p] = {
|
|
547
|
-
message: f ?? r,
|
|
548
|
-
...t === void 0 ? {} : { context: t },
|
|
549
|
-
...l === void 0 ? {} : { comment: l },
|
|
550
|
-
...o ? { translation: o } : {},
|
|
551
|
-
...s === void 0 ? {} : { origin: s },
|
|
552
|
-
...c ? { obsolete: c } : {}
|
|
553
|
-
};
|
|
554
|
-
}
|
|
555
|
-
return n;
|
|
556
|
-
}
|
|
557
|
-
function K(e) {
|
|
558
|
-
let t = { "": { "": {
|
|
559
|
-
msgid: "",
|
|
560
|
-
msgstr: ["Content-Type: text/plain; charset=UTF-8\n"]
|
|
561
|
-
} } };
|
|
562
|
-
for (let [n, r] of Object.entries(e)) {
|
|
563
|
-
let e = {
|
|
564
|
-
msgid: r.message ?? n,
|
|
565
|
-
...r.context === void 0 ? {} : { msgctxt: r.context },
|
|
566
|
-
msgstr: [r.translation ?? ""]
|
|
567
|
-
}, i = {};
|
|
568
|
-
r.origin && (i.reference = r.origin);
|
|
569
|
-
let a = Y(n, r.message ?? n, r.context, r.comment);
|
|
570
|
-
a && (i.extracted = a), r.obsolete && (i.flag = "fuzzy"), (i.reference || i.extracted || i.flag) && (e.comments = i);
|
|
571
|
-
let o = r.context ?? "";
|
|
572
|
-
t[o] ??= {}, t[o][e.msgid] = e;
|
|
573
|
-
}
|
|
574
|
-
let n = {
|
|
575
|
-
headers: { "Content-Type": "text/plain; charset=UTF-8" },
|
|
576
|
-
translations: t
|
|
577
|
-
};
|
|
578
|
-
return s.po.compile(n).toString();
|
|
579
|
-
}
|
|
580
|
-
function q(e) {
|
|
581
|
-
if (!e) return {};
|
|
582
|
-
let t = e.split("\n").map((e) => e.trim()).filter(Boolean), n, r, i = [];
|
|
583
|
-
for (let e of t) {
|
|
584
|
-
if (e.startsWith(G)) {
|
|
585
|
-
n = e.slice(11).trim() || void 0;
|
|
586
|
-
continue;
|
|
587
|
-
}
|
|
588
|
-
if (e.startsWith("msg`") && e.endsWith("`")) {
|
|
589
|
-
r = e.slice(4, -1);
|
|
590
|
-
continue;
|
|
591
|
-
}
|
|
592
|
-
if (e.startsWith("Trans: ")) {
|
|
593
|
-
r = J(e.slice(7));
|
|
594
|
-
continue;
|
|
595
|
-
}
|
|
596
|
-
i.push(e);
|
|
597
|
-
}
|
|
598
|
-
return {
|
|
599
|
-
...i.length > 0 ? { comment: i.join("\n") } : {},
|
|
600
|
-
...n ? { customId: n } : {},
|
|
601
|
-
...r ? { sourceMessage: r } : {}
|
|
602
|
-
};
|
|
603
|
-
}
|
|
604
|
-
function J(e) {
|
|
605
|
-
let t = [], n = 0;
|
|
606
|
-
return e.replace(/<\/?([a-zA-Z][\w-]*)>/g, (e, r) => {
|
|
607
|
-
let i = r;
|
|
608
|
-
if (e.startsWith("</")) {
|
|
609
|
-
for (let e = t.length - 1; e >= 0; e--) {
|
|
610
|
-
let n = t[e];
|
|
611
|
-
if (n?.tag === i) return t.splice(e, 1), `</${n.index}>`;
|
|
612
|
-
}
|
|
613
|
-
return e;
|
|
614
|
-
}
|
|
615
|
-
let a = n++;
|
|
616
|
-
return t.push({
|
|
617
|
-
tag: i,
|
|
618
|
-
index: a
|
|
619
|
-
}), `<${a}>`;
|
|
620
|
-
});
|
|
621
|
-
}
|
|
622
|
-
function Y(e, t, n, r) {
|
|
623
|
-
let i = [];
|
|
624
|
-
return r && i.push(r), e !== a(t, n) && i.push(`${G} ${e}`), i.length > 0 ? i.join("\n") : void 0;
|
|
625
|
-
}
|
|
626
|
-
//#endregion
|
|
627
|
-
//#region src/compile.ts
|
|
628
|
-
var X = /\{(\w+)\}/g;
|
|
629
|
-
function ie(e) {
|
|
630
|
-
return X.test(e);
|
|
631
|
-
}
|
|
632
|
-
function Z(e) {
|
|
633
|
-
return e.replace(/\\/g, "\\\\").replace(/'/g, "\\'").replace(/\n/g, "\\n").replace(/\r/g, "\\r");
|
|
634
|
-
}
|
|
635
|
-
function ae(e) {
|
|
636
|
-
return e.replace(/\\/g, "\\\\").replace(/`/g, "\\`").replace(/\$\{/g, "\\${").replace(/\n/g, "\\n").replace(/\r/g, "\\r");
|
|
637
|
-
}
|
|
638
|
-
function oe(e) {
|
|
639
|
-
return e.replace(X, (e, t) => `\${v.${t}}`);
|
|
640
|
-
}
|
|
641
|
-
var se = /\{(\w+),\s*(plural|select|selectordinal)\s*,/;
|
|
642
|
-
function ce(e) {
|
|
643
|
-
return se.test(e);
|
|
644
|
-
}
|
|
645
|
-
function Q(e, t) {
|
|
646
|
-
if (e.length === 0) return "''";
|
|
647
|
-
let n = e.map((e) => le(e, t));
|
|
648
|
-
return n.length === 1 ? n[0] : n.join(" + ");
|
|
649
|
-
}
|
|
650
|
-
function le(e, t) {
|
|
651
|
-
switch (e.type) {
|
|
652
|
-
case "text": return `'${Z(e.value)}'`;
|
|
653
|
-
case "variable": return e.name === "#" ? "String(__c)" : `String(v.${e.name} ?? '{${e.name}}')`;
|
|
654
|
-
case "plural": return $(e, t);
|
|
655
|
-
case "select": return ue(e, t);
|
|
656
|
-
case "function": return `String(v.${e.variable} ?? '')`;
|
|
657
|
-
}
|
|
658
|
-
}
|
|
659
|
-
function $(e, t) {
|
|
660
|
-
let n = e.offset ?? 0, r = n ? `(v.${e.variable} - ${n})` : `v.${e.variable}`, i = [];
|
|
661
|
-
i.push("((c) => { const __c = c; ");
|
|
662
|
-
let a = Object.keys(e.options).filter((e) => e.startsWith("="));
|
|
663
|
-
if (a.length > 0) for (let n of a) {
|
|
664
|
-
let r = n.slice(1), a = Q(e.options[n], t);
|
|
665
|
-
i.push(`if (c === ${r}) return ${a}; `);
|
|
666
|
-
}
|
|
667
|
-
let o = Object.keys(e.options).filter((e) => !e.startsWith("="));
|
|
668
|
-
if (o.length > 1 || o.length === 1 && o[0] !== "other") {
|
|
669
|
-
i.push(`const __cat = new Intl.PluralRules('${t}').select(c); `);
|
|
670
|
-
for (let n of o) {
|
|
671
|
-
if (n === "other") continue;
|
|
672
|
-
let r = Q(e.options[n], t);
|
|
673
|
-
i.push(`if (__cat === '${n}') return ${r}; `);
|
|
674
|
-
}
|
|
675
|
-
}
|
|
676
|
-
let s = e.options.other ? Q(e.options.other, t) : "''";
|
|
677
|
-
return i.push(`return ${s}; `), i.push(`})(${r})`), i.join("");
|
|
678
|
-
}
|
|
679
|
-
function ue(e, t) {
|
|
680
|
-
let n = [];
|
|
681
|
-
n.push("((s) => { ");
|
|
682
|
-
let r = Object.keys(e.options).filter((e) => e !== "other");
|
|
683
|
-
for (let i of r) {
|
|
684
|
-
let r = Q(e.options[i], t);
|
|
685
|
-
n.push(`if (s === '${Z(i)}') return ${r}; `);
|
|
686
|
-
}
|
|
687
|
-
let i = e.options.other ? Q(e.options.other, t) : "''";
|
|
688
|
-
return n.push(`return ${i}; `), n.push(`})(String(v.${e.variable} ?? ''))`), n.join("");
|
|
689
|
-
}
|
|
690
|
-
function de(e, t, n, r) {
|
|
691
|
-
let i = [];
|
|
692
|
-
i.push("// @fluenti/compiled v1");
|
|
693
|
-
let s = [], c = 0, l = [];
|
|
694
|
-
for (let u of n) {
|
|
695
|
-
let n = `_${a(u)}`, d = e[u], f = fe(d, u, t, r);
|
|
696
|
-
if (f === void 0) i.push(`/* @__PURE__ */ export const ${n} = undefined`), l.push(u);
|
|
697
|
-
else if (ce(f)) {
|
|
698
|
-
let e = Q(o(f), t);
|
|
699
|
-
i.push(`/* @__PURE__ */ export const ${n} = (v) => ${e}`), c++;
|
|
700
|
-
} else if (ie(f)) {
|
|
701
|
-
let e = oe(ae(f));
|
|
702
|
-
i.push(`/* @__PURE__ */ export const ${n} = (v) => \`${e}\``), c++;
|
|
703
|
-
} else i.push(`/* @__PURE__ */ export const ${n} = '${Z(f)}'`), c++;
|
|
704
|
-
s.push({
|
|
705
|
-
id: u,
|
|
706
|
-
exportName: n
|
|
707
|
-
});
|
|
708
|
-
}
|
|
709
|
-
if (s.length === 0) return {
|
|
710
|
-
code: "// @fluenti/compiled v1\n// empty catalog\nexport default {}\n",
|
|
711
|
-
stats: {
|
|
712
|
-
compiled: 0,
|
|
713
|
-
missing: []
|
|
714
|
-
}
|
|
715
|
-
};
|
|
716
|
-
i.push(""), i.push("export default {");
|
|
717
|
-
for (let { id: e, exportName: t } of s) i.push(` '${Z(e)}': ${t},`);
|
|
718
|
-
return i.push("}"), i.push(""), {
|
|
719
|
-
code: i.join("\n"),
|
|
720
|
-
stats: {
|
|
721
|
-
compiled: c,
|
|
722
|
-
missing: l
|
|
723
|
-
}
|
|
724
|
-
};
|
|
725
|
-
}
|
|
726
|
-
function fe(e, t, n, r) {
|
|
727
|
-
let i = r ?? n;
|
|
728
|
-
if (e) {
|
|
729
|
-
if (e.translation !== void 0 && e.translation.length > 0) return e.translation;
|
|
730
|
-
if (n === i) return e.message ?? t;
|
|
731
|
-
}
|
|
732
|
-
}
|
|
733
|
-
function pe(e, t) {
|
|
734
|
-
let n = [];
|
|
735
|
-
n.push(`export const locales = ${JSON.stringify(e)}`), n.push(""), n.push("export const loaders = {");
|
|
736
|
-
for (let t of e) n.push(` '${Z(t)}': () => import('./${t}.js'),`);
|
|
737
|
-
return n.push("}"), n.push(""), n.join("\n");
|
|
738
|
-
}
|
|
739
|
-
function me(e) {
|
|
740
|
-
let t = /* @__PURE__ */ new Set();
|
|
741
|
-
for (let n of Object.values(e)) for (let [e, r] of Object.entries(n)) r.obsolete || t.add(e);
|
|
742
|
-
return [...t].sort();
|
|
743
|
-
}
|
|
744
|
-
//#endregion
|
|
745
|
-
export { K as a, z as c, re as i, R as l, de as n, U as o, pe as r, W as s, me as t, b as u };
|
|
746
|
-
|
|
747
|
-
//# sourceMappingURL=compile-DuHUSzlx.js.map
|