@customyai/cli 0.7.2 → 0.10.1
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/CHANGELOG.md +76 -0
- package/LICENSE +2 -1
- package/README.md +77 -0
- package/dist/bin.cjs +6 -2
- package/dist/bin.mjs +5 -1
- package/dist/chunk-2A6WFLXS.cjs +235 -0
- package/dist/chunk-3M6ZLCSN.mjs +237 -0
- package/dist/chunk-57NNDUEX.mjs +3246 -0
- package/dist/chunk-6X3AX6PB.cjs +3266 -0
- package/dist/chunk-ABK4QQWW.cjs +244 -0
- package/dist/chunk-BYMLRMNS.mjs +27 -0
- package/dist/chunk-MFJL3NO5.cjs +31 -0
- package/dist/chunk-QKIF4C5R.mjs +226 -0
- package/dist/index.cjs +32 -11
- package/dist/index.d.cts +63 -1
- package/dist/index.d.ts +63 -1
- package/dist/index.mjs +2 -1
- package/dist/json-NETFQXLJ.mjs +67 -0
- package/dist/json-NSJMTBPP.cjs +70 -0
- package/dist/po-AKWHAYBL.mjs +387 -0
- package/dist/po-IJGMXNVY.cjs +394 -0
- package/dist/pseudo-CKYMJJBX.mjs +101 -0
- package/dist/pseudo-LBLMBD2T.cjs +106 -0
- package/dist/quality-6SEZNA6Q.cjs +207 -0
- package/dist/quality-ILK6IA5O.mjs +199 -0
- package/dist/xliff-DEJHB2SY.mjs +512 -0
- package/dist/xliff-DXICWMWC.cjs +518 -0
- package/package.json +9 -3
- package/dist/chunk-762M6SBX.mjs +0 -1098
- package/dist/chunk-TSPERSQL.cjs +0 -1113
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkMFJL3NO5_cjs = require('./chunk-MFJL3NO5.cjs');
|
|
4
|
+
var chunk2A6WFLXS_cjs = require('./chunk-2A6WFLXS.cjs');
|
|
5
|
+
var chunkABK4QQWW_cjs = require('./chunk-ABK4QQWW.cjs');
|
|
6
|
+
|
|
7
|
+
// src/vendor/i18n-tools/po.ts
|
|
8
|
+
var DEFAULT_PO_MAX_BYTES = 4 * 1024 * 1024;
|
|
9
|
+
var bad = (line, text) => {
|
|
10
|
+
throw new chunkMFJL3NO5_cjs.I18nToolsError("malformed-po", `${text} (l\xEDnea ${line})`);
|
|
11
|
+
};
|
|
12
|
+
var SIMPLE_ESC = { n: "\n", t: " ", r: "\r", "\\": "\\", '"': '"', a: "\x07", b: "\b", f: "\f", v: "\v" };
|
|
13
|
+
function parseQuoted(rest, line) {
|
|
14
|
+
let i = 0;
|
|
15
|
+
let out = "";
|
|
16
|
+
let count = 0;
|
|
17
|
+
for (; ; ) {
|
|
18
|
+
while (rest[i] === " " || rest[i] === " ") i += 1;
|
|
19
|
+
if (i >= rest.length) break;
|
|
20
|
+
if (rest[i] !== '"') return bad(line, "se esperaba una cadena entre comillas");
|
|
21
|
+
i += 1;
|
|
22
|
+
let closed = false;
|
|
23
|
+
while (i < rest.length) {
|
|
24
|
+
const c = rest[i];
|
|
25
|
+
if (c === '"') {
|
|
26
|
+
closed = true;
|
|
27
|
+
i += 1;
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
if (c !== "\\") {
|
|
31
|
+
out += c;
|
|
32
|
+
i += 1;
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
const e = rest[i + 1];
|
|
36
|
+
if (e === void 0) return bad(line, "escape incompleto");
|
|
37
|
+
if (Object.hasOwn(SIMPLE_ESC, e)) {
|
|
38
|
+
out += SIMPLE_ESC[e];
|
|
39
|
+
i += 2;
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
if (e >= "0" && e <= "7") {
|
|
43
|
+
let j = i + 1;
|
|
44
|
+
let digits = "";
|
|
45
|
+
while (digits.length < 3 && rest[j] !== void 0 && rest[j] >= "0" && rest[j] <= "7") {
|
|
46
|
+
digits += rest[j];
|
|
47
|
+
j += 1;
|
|
48
|
+
}
|
|
49
|
+
const v = Number.parseInt(digits, 8);
|
|
50
|
+
if (v > 255) return bad(line, "escape octal fuera de rango");
|
|
51
|
+
out += String.fromCharCode(v);
|
|
52
|
+
i = j;
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
if (e === "x") {
|
|
56
|
+
const m = /^[0-9A-Fa-f]{1,2}/.exec(rest.slice(i + 2));
|
|
57
|
+
if (!m) return bad(line, "escape \\x sin d\xEDgitos");
|
|
58
|
+
out += String.fromCharCode(Number.parseInt(m[0], 16));
|
|
59
|
+
i += 2 + m[0].length;
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
return bad(line, `escape desconocido \\${e}`);
|
|
63
|
+
}
|
|
64
|
+
if (!closed) return bad(line, "cadena sin cerrar");
|
|
65
|
+
count += 1;
|
|
66
|
+
}
|
|
67
|
+
if (count === 0) return bad(line, "se esperaba una cadena entre comillas");
|
|
68
|
+
return out;
|
|
69
|
+
}
|
|
70
|
+
function escapePo(s) {
|
|
71
|
+
let out = "";
|
|
72
|
+
for (const c of s) {
|
|
73
|
+
if (c === "\\") out += "\\\\";
|
|
74
|
+
else if (c === '"') out += '\\"';
|
|
75
|
+
else if (c === "\n") out += "\\n";
|
|
76
|
+
else if (c === " ") out += "\\t";
|
|
77
|
+
else if (c === "\r") out += "\\r";
|
|
78
|
+
else {
|
|
79
|
+
const cp = c.codePointAt(0) ?? 0;
|
|
80
|
+
out += cp < 32 || cp === 127 ? `\\${cp.toString(8).padStart(3, "0")}` : c;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return out;
|
|
84
|
+
}
|
|
85
|
+
function emitField(lines, prefix, keyword, value) {
|
|
86
|
+
if (!value.includes("\n")) {
|
|
87
|
+
lines.push(`${prefix}${keyword} "${escapePo(value)}"`);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
lines.push(`${prefix}${keyword} ""`);
|
|
91
|
+
let start = 0;
|
|
92
|
+
while (start < value.length) {
|
|
93
|
+
const nl = value.indexOf("\n", start);
|
|
94
|
+
const end = nl === -1 ? value.length : nl + 1;
|
|
95
|
+
lines.push(`${prefix}"${escapePo(value.slice(start, end))}"`);
|
|
96
|
+
start = end;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
var newDraft = () => ({ msgctxt: null, msgid: null, msgidPlural: null, msgstr: [], plainStr: false, tc: [], ec: [], refs: [], flags: [], prev: [], obsolete: false, started: false });
|
|
100
|
+
function parsePo(input, options = {}) {
|
|
101
|
+
const maxBytes = options.maxBytes ?? DEFAULT_PO_MAX_BYTES;
|
|
102
|
+
if (input.length > maxBytes || chunkMFJL3NO5_cjs.utf8ByteLength(input) > maxBytes) throw new chunkMFJL3NO5_cjs.I18nToolsError("too-large", `el archivo PO pasa de ${maxBytes} bytes`);
|
|
103
|
+
const text = (input.charCodeAt(0) === 65279 ? input.slice(1) : input).replace(/\r\n?/g, "\n");
|
|
104
|
+
const lines = text.split("\n");
|
|
105
|
+
const entries = [];
|
|
106
|
+
let headerComments = [];
|
|
107
|
+
let headers = [];
|
|
108
|
+
let headerSeen = false;
|
|
109
|
+
const seen = /* @__PURE__ */ new Set();
|
|
110
|
+
let cur = newDraft();
|
|
111
|
+
let field = null;
|
|
112
|
+
let curLine = 0;
|
|
113
|
+
const append = (kind, index, add, replace) => {
|
|
114
|
+
if (kind === "msgctxt") cur.msgctxt = replace ? add : (cur.msgctxt ?? "") + add;
|
|
115
|
+
else if (kind === "msgid") cur.msgid = replace ? add : (cur.msgid ?? "") + add;
|
|
116
|
+
else if (kind === "msgid_plural") cur.msgidPlural = replace ? add : (cur.msgidPlural ?? "") + add;
|
|
117
|
+
else cur.msgstr[index] = replace ? add : (cur.msgstr[index] ?? "") + add;
|
|
118
|
+
};
|
|
119
|
+
const finish = () => {
|
|
120
|
+
if (!cur.started) {
|
|
121
|
+
cur = newDraft();
|
|
122
|
+
field = null;
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
if (cur.msgid === null) bad(curLine, "entrada sin msgid");
|
|
126
|
+
const plural = cur.msgidPlural !== null;
|
|
127
|
+
let msgstr;
|
|
128
|
+
if (plural) {
|
|
129
|
+
if (cur.plainStr) bad(curLine, "una entrada con msgid_plural necesita msgstr[n]");
|
|
130
|
+
if (cur.msgstr.length === 0) bad(curLine, "falta msgstr[0]");
|
|
131
|
+
msgstr = [];
|
|
132
|
+
for (let k = 0; k < cur.msgstr.length; k += 1) {
|
|
133
|
+
const v = cur.msgstr[k];
|
|
134
|
+
if (v === void 0) return bad(curLine, `falta msgstr[${k}]`);
|
|
135
|
+
msgstr.push(v);
|
|
136
|
+
}
|
|
137
|
+
} else {
|
|
138
|
+
if (cur.msgstr.length !== 1 || !cur.plainStr) bad(curLine, "se esperaba un \xFAnico msgstr");
|
|
139
|
+
msgstr = [cur.msgstr[0] ?? ""];
|
|
140
|
+
}
|
|
141
|
+
const msgid = cur.msgid;
|
|
142
|
+
if (!headerSeen && cur.msgctxt === null && msgid === "" && !plural) {
|
|
143
|
+
headerSeen = true;
|
|
144
|
+
headerComments = cur.tc;
|
|
145
|
+
headers = [];
|
|
146
|
+
for (const raw of (msgstr[0] ?? "").split("\n")) {
|
|
147
|
+
if (raw === "") continue;
|
|
148
|
+
const colon = raw.indexOf(":");
|
|
149
|
+
if (colon <= 0) bad(curLine, `l\xEDnea de cabecera no v\xE1lida \xAB${raw}\xBB`);
|
|
150
|
+
headers.push({ name: raw.slice(0, colon), value: raw.slice(colon + 1).replace(/^[ \t]+/, "") });
|
|
151
|
+
}
|
|
152
|
+
} else {
|
|
153
|
+
const id = cur.msgctxt === null ? `n:${msgid}` : `c:${cur.msgctxt}${msgid}`;
|
|
154
|
+
if (seen.has(id)) throw new chunkMFJL3NO5_cjs.I18nToolsError("duplicate-entry", `entrada repetida \xAB${msgid}\xBB${cur.msgctxt !== null ? ` (contexto \xAB${cur.msgctxt}\xBB)` : ""}`);
|
|
155
|
+
seen.add(id);
|
|
156
|
+
entries.push({
|
|
157
|
+
msgctxt: cur.msgctxt,
|
|
158
|
+
msgid,
|
|
159
|
+
msgidPlural: cur.msgidPlural,
|
|
160
|
+
msgstr,
|
|
161
|
+
translatorComments: cur.tc,
|
|
162
|
+
extractedComments: cur.ec,
|
|
163
|
+
references: cur.refs,
|
|
164
|
+
flags: cur.flags,
|
|
165
|
+
previous: cur.prev,
|
|
166
|
+
obsolete: cur.obsolete
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
cur = newDraft();
|
|
170
|
+
field = null;
|
|
171
|
+
};
|
|
172
|
+
for (let ln = 0; ln < lines.length; ln += 1) {
|
|
173
|
+
curLine = ln + 1;
|
|
174
|
+
let line = lines[ln].trimStart();
|
|
175
|
+
if (line === "") {
|
|
176
|
+
finish();
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
let obsoleteLine = false;
|
|
180
|
+
if (line.startsWith("#~") && line[2] !== "|") {
|
|
181
|
+
obsoleteLine = true;
|
|
182
|
+
line = line.slice(2).trimStart();
|
|
183
|
+
if (line === "") continue;
|
|
184
|
+
}
|
|
185
|
+
if (line[0] === "#" && !obsoleteLine) {
|
|
186
|
+
if (field !== null && cur.msgstr.length > 0) finish();
|
|
187
|
+
const kind = line[1];
|
|
188
|
+
const body = line.slice(2);
|
|
189
|
+
const strip = (b) => b.startsWith(" ") ? b.slice(1) : b;
|
|
190
|
+
if (kind === void 0) cur.tc.push("");
|
|
191
|
+
else if (kind === " ") cur.tc.push(body);
|
|
192
|
+
else if (kind === ".") cur.ec.push(strip(body));
|
|
193
|
+
else if (kind === ":") cur.refs.push(strip(body));
|
|
194
|
+
else if (kind === ",") for (const f of body.split(",")) {
|
|
195
|
+
const t = f.trim();
|
|
196
|
+
if (t) cur.flags.push(t);
|
|
197
|
+
}
|
|
198
|
+
else if (kind === "|") cur.prev.push(strip(body));
|
|
199
|
+
else bad(curLine, `comentario no reconocido \xAB${line.slice(0, 2)}\xBB`);
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
if (line[0] === '"') {
|
|
203
|
+
if (field === null) bad(curLine, "cadena sin palabra clave");
|
|
204
|
+
append(field.kind, field.index, parseQuoted(line, curLine), false);
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
const m = /^(msgctxt|msgid_plural|msgid|msgstr)(?:\[(\d{1,3})\])?[ \t]*(.*)$/.exec(line);
|
|
208
|
+
if (!m) {
|
|
209
|
+
bad(curLine, `l\xEDnea no reconocida \xAB${line.slice(0, 30)}\xBB`);
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
const keyword = m[1];
|
|
213
|
+
const index = m[2] === void 0 ? 0 : Number.parseInt(m[2], 10);
|
|
214
|
+
if (m[2] !== void 0 && keyword !== "msgstr") bad(curLine, `${keyword} no lleva \xEDndice`);
|
|
215
|
+
if ((keyword === "msgctxt" || keyword === "msgid") && cur.msgstr.length > 0) finish();
|
|
216
|
+
const value = parseQuoted(m[3] ?? "", curLine);
|
|
217
|
+
cur.started = true;
|
|
218
|
+
if (obsoleteLine) cur.obsolete = true;
|
|
219
|
+
if (keyword === "msgstr") {
|
|
220
|
+
if (m[2] === void 0) {
|
|
221
|
+
if (cur.msgstr.length > 0) bad(curLine, "msgstr repetido");
|
|
222
|
+
cur.plainStr = true;
|
|
223
|
+
} else if (cur.plainStr) bad(curLine, "mezcla de msgstr y msgstr[n]");
|
|
224
|
+
if (cur.msgstr[index] !== void 0) bad(curLine, `msgstr[${index}] repetido`);
|
|
225
|
+
if (index > 99) bad(curLine, "\xEDndice de plural fuera de rango");
|
|
226
|
+
} else {
|
|
227
|
+
if (keyword === "msgctxt" && (cur.msgctxt !== null || cur.msgid !== null)) bad(curLine, "msgctxt fuera de lugar");
|
|
228
|
+
if (keyword === "msgid" && cur.msgid !== null) bad(curLine, "msgid repetido");
|
|
229
|
+
if (keyword === "msgid_plural" && (cur.msgid === null || cur.msgidPlural !== null)) bad(curLine, "msgid_plural fuera de lugar");
|
|
230
|
+
}
|
|
231
|
+
append(keyword, index, value, true);
|
|
232
|
+
field = { kind: keyword, index };
|
|
233
|
+
}
|
|
234
|
+
finish();
|
|
235
|
+
return { headerComments, headers, entries };
|
|
236
|
+
}
|
|
237
|
+
function stringifyPo(file) {
|
|
238
|
+
const blocks = [];
|
|
239
|
+
if (file.headers.length > 0 || file.headerComments.length > 0) {
|
|
240
|
+
const lines = [];
|
|
241
|
+
for (const c of file.headerComments) lines.push(c === "" ? "#" : `# ${c}`);
|
|
242
|
+
lines.push('msgid ""');
|
|
243
|
+
emitField(lines, "", "msgstr", file.headers.map((h) => `${h.name}: ${h.value}
|
|
244
|
+
`).join(""));
|
|
245
|
+
blocks.push(lines.join("\n"));
|
|
246
|
+
}
|
|
247
|
+
for (const e of file.entries) {
|
|
248
|
+
const lines = [];
|
|
249
|
+
for (const c of e.translatorComments) lines.push(c === "" ? "#" : `# ${c}`);
|
|
250
|
+
for (const c of e.extractedComments) lines.push(c === "" ? "#." : `#. ${c}`);
|
|
251
|
+
for (const c of e.references) lines.push(c === "" ? "#:" : `#: ${c}`);
|
|
252
|
+
if (e.flags.length > 0) lines.push(`#, ${e.flags.join(", ")}`);
|
|
253
|
+
for (const c of e.previous) lines.push(c === "" ? "#|" : `#| ${c}`);
|
|
254
|
+
const prefix = e.obsolete ? "#~ " : "";
|
|
255
|
+
if (e.msgctxt !== null) emitField(lines, prefix, "msgctxt", e.msgctxt);
|
|
256
|
+
emitField(lines, prefix, "msgid", e.msgid);
|
|
257
|
+
if (e.msgidPlural !== null) {
|
|
258
|
+
emitField(lines, prefix, "msgid_plural", e.msgidPlural);
|
|
259
|
+
e.msgstr.forEach((s, k) => emitField(lines, prefix, `msgstr[${k}]`, s));
|
|
260
|
+
} else emitField(lines, prefix, "msgstr", e.msgstr[0] ?? "");
|
|
261
|
+
blocks.push(lines.join("\n"));
|
|
262
|
+
}
|
|
263
|
+
return blocks.length === 0 ? "" : `${blocks.join("\n\n")}
|
|
264
|
+
`;
|
|
265
|
+
}
|
|
266
|
+
var poHeader = (file, name) => file.headers.find((h) => h.name.toLowerCase() === name.toLowerCase())?.value ?? null;
|
|
267
|
+
var PLURAL_VAR = "customy-plural-var: ";
|
|
268
|
+
var GETTEXT_FORMS = {
|
|
269
|
+
en: "nplurals=2; plural=(n != 1);",
|
|
270
|
+
de: "nplurals=2; plural=(n != 1);",
|
|
271
|
+
nl: "nplurals=2; plural=(n != 1);",
|
|
272
|
+
sv: "nplurals=2; plural=(n != 1);",
|
|
273
|
+
ja: "nplurals=1; plural=0;",
|
|
274
|
+
zh: "nplurals=1; plural=0;",
|
|
275
|
+
ko: "nplurals=1; plural=0;",
|
|
276
|
+
vi: "nplurals=1; plural=0;"
|
|
277
|
+
};
|
|
278
|
+
function asCanonicalPlural(message) {
|
|
279
|
+
const nodes = chunkABK4QQWW_cjs.parseIcu(message);
|
|
280
|
+
const n = nodes[0];
|
|
281
|
+
if (nodes.length !== 1 || !n || n.t !== "complex" || n.type !== "plural") return null;
|
|
282
|
+
const forms = n.options.map((o) => [o.selector, chunkABK4QQWW_cjs.unparseIcu(o.body)]);
|
|
283
|
+
if (forms.length === 0 || new Set(forms.map((f) => f[0])).size !== forms.length) return null;
|
|
284
|
+
return buildCanonicalPlural(n.name, forms) === message ? { name: n.name, forms } : null;
|
|
285
|
+
}
|
|
286
|
+
var buildCanonicalPlural = (name, forms) => `{${name}, plural,${forms.map(([sel, body]) => ` ${sel} {${body}}`).join("")}}`;
|
|
287
|
+
function catalogToPo(options) {
|
|
288
|
+
const { source, target } = options;
|
|
289
|
+
if (target && target.namespace !== source.namespace) throw new chunkMFJL3NO5_cjs.I18nToolsError("invalid-input", "origen y destino son de espacios de nombres distintos");
|
|
290
|
+
const trgLocale = target?.locale ?? options.targetLocale ?? null;
|
|
291
|
+
if (trgLocale !== null && !chunk2A6WFLXS_cjs.CATALOG_LOCALE.test(trgLocale)) throw new chunkMFJL3NO5_cjs.I18nToolsError("invalid-locale", `idioma de destino no v\xE1lido \xAB${trgLocale}\xBB`);
|
|
292
|
+
const gettext = options.pluralMode === "gettext";
|
|
293
|
+
const trgCats = trgLocale ? chunkABK4QQWW_cjs.pluralCategories(trgLocale) : null;
|
|
294
|
+
const headers = [
|
|
295
|
+
{ name: "Content-Type", value: "text/plain; charset=UTF-8" },
|
|
296
|
+
{ name: "Content-Transfer-Encoding", value: "8bit" }
|
|
297
|
+
];
|
|
298
|
+
if (trgLocale) headers.push({ name: "Language", value: trgLocale });
|
|
299
|
+
headers.push(
|
|
300
|
+
{ name: "X-Source-Language", value: source.locale },
|
|
301
|
+
{ name: "X-Customy-Catalog", value: chunk2A6WFLXS_cjs.CATALOG_DOC_VERSION },
|
|
302
|
+
{ name: "X-Customy-Namespace", value: source.namespace },
|
|
303
|
+
{ name: "X-Customy-Syntax", value: source.syntax }
|
|
304
|
+
);
|
|
305
|
+
if (gettext && trgLocale && trgCats) {
|
|
306
|
+
const forms = GETTEXT_FORMS[trgLocale.split("-")[0] ?? ""];
|
|
307
|
+
if (forms && forms.startsWith(`nplurals=${trgCats.length};`)) headers.push({ name: "Plural-Forms", value: forms });
|
|
308
|
+
headers.push({ name: "X-Customy-Plural-Categories", value: trgCats.join(",") });
|
|
309
|
+
}
|
|
310
|
+
const entries = [];
|
|
311
|
+
for (const key of Object.keys(source.messages).sort(chunkMFJL3NO5_cjs.compareCodeUnits)) {
|
|
312
|
+
if (!chunk2A6WFLXS_cjs.CATALOG_KEY.test(key)) throw new chunkMFJL3NO5_cjs.I18nToolsError("invalid-key", `clave no v\xE1lida \xAB${key}\xBB`);
|
|
313
|
+
const src = source.messages[key] ?? "";
|
|
314
|
+
const trg = target?.messages[key];
|
|
315
|
+
const ctx = options.contexts?.[key];
|
|
316
|
+
const extracted = ctx ? ctx.split("\n") : [];
|
|
317
|
+
let entry = {
|
|
318
|
+
msgctxt: key,
|
|
319
|
+
msgid: src,
|
|
320
|
+
msgidPlural: null,
|
|
321
|
+
msgstr: [trg ?? ""],
|
|
322
|
+
translatorComments: [],
|
|
323
|
+
extractedComments: extracted,
|
|
324
|
+
references: [],
|
|
325
|
+
flags: [],
|
|
326
|
+
previous: [],
|
|
327
|
+
obsolete: false
|
|
328
|
+
};
|
|
329
|
+
if (gettext && trgCats) {
|
|
330
|
+
const sp = asCanonicalPlural(src);
|
|
331
|
+
const sel = sp?.forms.map((f) => f[0]).join(",");
|
|
332
|
+
if (sp && sel === "one,other") {
|
|
333
|
+
const tp = trg === void 0 || trg === "" ? null : asCanonicalPlural(trg);
|
|
334
|
+
const tOk = trg === void 0 || trg === "" || tp !== null && tp.name === sp.name && tp.forms.map((f) => f[0]).join(",") === trgCats.join(",");
|
|
335
|
+
if (tOk) {
|
|
336
|
+
entry = {
|
|
337
|
+
...entry,
|
|
338
|
+
msgid: sp.forms[0][1],
|
|
339
|
+
msgidPlural: sp.forms[1][1],
|
|
340
|
+
msgstr: tp ? tp.forms.map((f) => f[1]) : trgCats.map(() => ""),
|
|
341
|
+
extractedComments: [`${PLURAL_VAR}${sp.name}`, ...extracted]
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
entries.push(entry);
|
|
347
|
+
}
|
|
348
|
+
return { headerComments: [], headers, entries };
|
|
349
|
+
}
|
|
350
|
+
function poToCatalogs(po, options = {}) {
|
|
351
|
+
const namespace = options.namespace ?? poHeader(po, "X-Customy-Namespace");
|
|
352
|
+
if (!namespace || !chunk2A6WFLXS_cjs.CATALOG_NAMESPACE.test(namespace)) throw new chunkMFJL3NO5_cjs.I18nToolsError("invalid-input", "falta un espacio de nombres v\xE1lido (X-Customy-Namespace u options.namespace)");
|
|
353
|
+
const sourceLocale = options.sourceLocale ?? poHeader(po, "X-Source-Language");
|
|
354
|
+
if (!sourceLocale || !chunk2A6WFLXS_cjs.CATALOG_LOCALE.test(sourceLocale)) throw new chunkMFJL3NO5_cjs.I18nToolsError("invalid-locale", "falta el idioma de origen (X-Source-Language u options.sourceLocale)");
|
|
355
|
+
const targetLocale = options.targetLocale ?? poHeader(po, "Language");
|
|
356
|
+
if (targetLocale && !chunk2A6WFLXS_cjs.CATALOG_LOCALE.test(targetLocale)) throw new chunkMFJL3NO5_cjs.I18nToolsError("invalid-locale", `idioma de destino no v\xE1lido \xAB${targetLocale}\xBB`);
|
|
357
|
+
const syntaxHeader = options.syntax ?? poHeader(po, "X-Customy-Syntax") ?? "icu1";
|
|
358
|
+
if (syntaxHeader !== "icu1" && syntaxHeader !== "mf2") throw new chunkMFJL3NO5_cjs.I18nToolsError("invalid-input", `sintaxis desconocida \xAB${syntaxHeader}\xBB`);
|
|
359
|
+
const catsHeader = poHeader(po, "X-Customy-Plural-Categories");
|
|
360
|
+
const cats = catsHeader ? catsHeader.split(",").map((c) => c.trim()).filter(Boolean) : targetLocale ? chunkABK4QQWW_cjs.pluralCategories(targetLocale) : [];
|
|
361
|
+
const sourceMessages = {};
|
|
362
|
+
const targetMessages = {};
|
|
363
|
+
const contexts = {};
|
|
364
|
+
const put = (into, key, value) => {
|
|
365
|
+
Object.defineProperty(into, key, { value, enumerable: true, writable: true, configurable: true });
|
|
366
|
+
};
|
|
367
|
+
for (const e of po.entries) {
|
|
368
|
+
if (e.obsolete) continue;
|
|
369
|
+
if (e.msgctxt === null || !chunk2A6WFLXS_cjs.CATALOG_KEY.test(e.msgctxt)) throw new chunkMFJL3NO5_cjs.I18nToolsError("invalid-key", `la entrada \xAB${e.msgid.slice(0, 40)}\xBB no trae una clave v\xE1lida en msgctxt`);
|
|
370
|
+
const key = e.msgctxt;
|
|
371
|
+
const varLine = e.extractedComments.find((c) => c.startsWith(PLURAL_VAR));
|
|
372
|
+
const ctxLines = e.extractedComments.filter((c) => !c.startsWith(PLURAL_VAR));
|
|
373
|
+
if (ctxLines.length > 0) put(contexts, key, ctxLines.join("\n"));
|
|
374
|
+
if (e.msgidPlural !== null) {
|
|
375
|
+
const name = varLine ? varLine.slice(PLURAL_VAR.length) : "count";
|
|
376
|
+
put(sourceMessages, key, buildCanonicalPlural(name, [["one", e.msgid], ["other", e.msgidPlural]]));
|
|
377
|
+
if (e.msgstr.length === cats.length && e.msgstr.every((s) => s !== "")) put(targetMessages, key, buildCanonicalPlural(name, cats.map((c, i) => [c, e.msgstr[i] ?? ""])));
|
|
378
|
+
} else {
|
|
379
|
+
put(sourceMessages, key, e.msgid);
|
|
380
|
+
const s = e.msgstr[0] ?? "";
|
|
381
|
+
if (s !== "") put(targetMessages, key, s);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
const source = { version: chunk2A6WFLXS_cjs.CATALOG_DOC_VERSION, namespace, locale: sourceLocale, syntax: syntaxHeader, messages: sourceMessages };
|
|
385
|
+
const target = targetLocale ? { version: chunk2A6WFLXS_cjs.CATALOG_DOC_VERSION, namespace, locale: targetLocale, syntax: syntaxHeader, messages: targetMessages } : null;
|
|
386
|
+
return { source, target, contexts };
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
exports.DEFAULT_PO_MAX_BYTES = DEFAULT_PO_MAX_BYTES;
|
|
390
|
+
exports.catalogToPo = catalogToPo;
|
|
391
|
+
exports.parsePo = parsePo;
|
|
392
|
+
exports.poHeader = poHeader;
|
|
393
|
+
exports.poToCatalogs = poToCatalogs;
|
|
394
|
+
exports.stringifyPo = stringifyPo;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { tokenizeIcu } from './chunk-3M6ZLCSN.mjs';
|
|
2
|
+
|
|
3
|
+
// src/vendor/i18n-tools/pseudo.ts
|
|
4
|
+
var ACCENTS = {
|
|
5
|
+
a: "\xE1",
|
|
6
|
+
b: "\u0180",
|
|
7
|
+
c: "\xE7",
|
|
8
|
+
d: "\u0111",
|
|
9
|
+
e: "\xE9",
|
|
10
|
+
f: "\u0192",
|
|
11
|
+
g: "\u011D",
|
|
12
|
+
h: "\u0125",
|
|
13
|
+
i: "\xED",
|
|
14
|
+
j: "\u0135",
|
|
15
|
+
k: "\u0137",
|
|
16
|
+
l: "\u013C",
|
|
17
|
+
m: "\u0271",
|
|
18
|
+
n: "\xF1",
|
|
19
|
+
o: "\xF3",
|
|
20
|
+
p: "\u01A5",
|
|
21
|
+
q: "\u01A3",
|
|
22
|
+
r: "\u0155",
|
|
23
|
+
s: "\u0161",
|
|
24
|
+
t: "\u0167",
|
|
25
|
+
u: "\xFA",
|
|
26
|
+
v: "\u1E7D",
|
|
27
|
+
w: "\u0175",
|
|
28
|
+
x: "\u1E8B",
|
|
29
|
+
y: "\xFD",
|
|
30
|
+
z: "\u017E",
|
|
31
|
+
A: "\xC1",
|
|
32
|
+
B: "\u0181",
|
|
33
|
+
C: "\xC7",
|
|
34
|
+
D: "\u0110",
|
|
35
|
+
E: "\xC9",
|
|
36
|
+
F: "\u0191",
|
|
37
|
+
G: "\u011C",
|
|
38
|
+
H: "\u0124",
|
|
39
|
+
I: "\xCD",
|
|
40
|
+
J: "\u0134",
|
|
41
|
+
K: "\u0136",
|
|
42
|
+
L: "\u013B",
|
|
43
|
+
M: "\u1E40",
|
|
44
|
+
N: "\xD1",
|
|
45
|
+
O: "\xD3",
|
|
46
|
+
P: "\u01A4",
|
|
47
|
+
Q: "\u01A2",
|
|
48
|
+
R: "\u0154",
|
|
49
|
+
S: "\u0160",
|
|
50
|
+
T: "\u0166",
|
|
51
|
+
U: "\xDA",
|
|
52
|
+
V: "\u1E7C",
|
|
53
|
+
W: "\u0174",
|
|
54
|
+
X: "\u1E8A",
|
|
55
|
+
Y: "\xDD",
|
|
56
|
+
Z: "\u017D"
|
|
57
|
+
};
|
|
58
|
+
var PSEUDO_PREFIX = "[!! ";
|
|
59
|
+
var PSEUDO_SUFFIX = " !!]";
|
|
60
|
+
var RLO = "\u202E";
|
|
61
|
+
var PDF = "\u202C";
|
|
62
|
+
var PAD = "~";
|
|
63
|
+
var URL_OR_EMAIL = /https?:\/\/[^\s]+|mailto:[^\s]+|[\w.+-]+@[\w-]+(?:\.[\w-]+)+/gu;
|
|
64
|
+
function accent(text) {
|
|
65
|
+
let out = "";
|
|
66
|
+
for (const ch of text) out += ACCENTS[ch] ?? ch;
|
|
67
|
+
return out;
|
|
68
|
+
}
|
|
69
|
+
function expandText(text, expansion) {
|
|
70
|
+
if (text.trim() === "") return text;
|
|
71
|
+
const lead = /^\s*/.exec(text)?.[0] ?? "";
|
|
72
|
+
const trail = /\s*$/.exec(text)?.[0] ?? "";
|
|
73
|
+
const core = text.slice(lead.length, text.length - trail.length);
|
|
74
|
+
const letters = [...core].length;
|
|
75
|
+
const extra = Math.ceil(letters * expansion);
|
|
76
|
+
return `${lead}${core}${PAD.repeat(extra)}${trail}`;
|
|
77
|
+
}
|
|
78
|
+
function transformText(text, expansion) {
|
|
79
|
+
let out = "";
|
|
80
|
+
let last = 0;
|
|
81
|
+
for (const m of text.matchAll(URL_OR_EMAIL)) {
|
|
82
|
+
const idx = m.index ?? 0;
|
|
83
|
+
out += accent(text.slice(last, idx)) + m[0];
|
|
84
|
+
last = idx + m[0].length;
|
|
85
|
+
}
|
|
86
|
+
out += accent(text.slice(last));
|
|
87
|
+
return expandText(out, expansion);
|
|
88
|
+
}
|
|
89
|
+
function pseudoLocalize(message, options = {}) {
|
|
90
|
+
const expansion = options.expansion ?? 0.4;
|
|
91
|
+
const tokens = tokenizeIcu(message);
|
|
92
|
+
let body = "";
|
|
93
|
+
for (const t of tokens) body += t.kind === "text" ? transformText(t.text, expansion) : t.raw;
|
|
94
|
+
if (options.markers !== false) body = `${options.prefix ?? PSEUDO_PREFIX}${body}${options.suffix ?? PSEUDO_SUFFIX}`;
|
|
95
|
+
return options.strategy === "rtl" ? `${RLO}${body}${PDF}` : body;
|
|
96
|
+
}
|
|
97
|
+
function pseudoLocalizeMessages(messages, options = {}) {
|
|
98
|
+
return Object.fromEntries(Object.keys(messages).map((k) => [k, pseudoLocalize(messages[k] ?? "", options)]));
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export { PSEUDO_PREFIX, PSEUDO_SUFFIX, pseudoLocalize, pseudoLocalizeMessages };
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkABK4QQWW_cjs = require('./chunk-ABK4QQWW.cjs');
|
|
4
|
+
|
|
5
|
+
// src/vendor/i18n-tools/pseudo.ts
|
|
6
|
+
var ACCENTS = {
|
|
7
|
+
a: "\xE1",
|
|
8
|
+
b: "\u0180",
|
|
9
|
+
c: "\xE7",
|
|
10
|
+
d: "\u0111",
|
|
11
|
+
e: "\xE9",
|
|
12
|
+
f: "\u0192",
|
|
13
|
+
g: "\u011D",
|
|
14
|
+
h: "\u0125",
|
|
15
|
+
i: "\xED",
|
|
16
|
+
j: "\u0135",
|
|
17
|
+
k: "\u0137",
|
|
18
|
+
l: "\u013C",
|
|
19
|
+
m: "\u0271",
|
|
20
|
+
n: "\xF1",
|
|
21
|
+
o: "\xF3",
|
|
22
|
+
p: "\u01A5",
|
|
23
|
+
q: "\u01A3",
|
|
24
|
+
r: "\u0155",
|
|
25
|
+
s: "\u0161",
|
|
26
|
+
t: "\u0167",
|
|
27
|
+
u: "\xFA",
|
|
28
|
+
v: "\u1E7D",
|
|
29
|
+
w: "\u0175",
|
|
30
|
+
x: "\u1E8B",
|
|
31
|
+
y: "\xFD",
|
|
32
|
+
z: "\u017E",
|
|
33
|
+
A: "\xC1",
|
|
34
|
+
B: "\u0181",
|
|
35
|
+
C: "\xC7",
|
|
36
|
+
D: "\u0110",
|
|
37
|
+
E: "\xC9",
|
|
38
|
+
F: "\u0191",
|
|
39
|
+
G: "\u011C",
|
|
40
|
+
H: "\u0124",
|
|
41
|
+
I: "\xCD",
|
|
42
|
+
J: "\u0134",
|
|
43
|
+
K: "\u0136",
|
|
44
|
+
L: "\u013B",
|
|
45
|
+
M: "\u1E40",
|
|
46
|
+
N: "\xD1",
|
|
47
|
+
O: "\xD3",
|
|
48
|
+
P: "\u01A4",
|
|
49
|
+
Q: "\u01A2",
|
|
50
|
+
R: "\u0154",
|
|
51
|
+
S: "\u0160",
|
|
52
|
+
T: "\u0166",
|
|
53
|
+
U: "\xDA",
|
|
54
|
+
V: "\u1E7C",
|
|
55
|
+
W: "\u0174",
|
|
56
|
+
X: "\u1E8A",
|
|
57
|
+
Y: "\xDD",
|
|
58
|
+
Z: "\u017D"
|
|
59
|
+
};
|
|
60
|
+
var PSEUDO_PREFIX = "[!! ";
|
|
61
|
+
var PSEUDO_SUFFIX = " !!]";
|
|
62
|
+
var RLO = "\u202E";
|
|
63
|
+
var PDF = "\u202C";
|
|
64
|
+
var PAD = "~";
|
|
65
|
+
var URL_OR_EMAIL = /https?:\/\/[^\s]+|mailto:[^\s]+|[\w.+-]+@[\w-]+(?:\.[\w-]+)+/gu;
|
|
66
|
+
function accent(text) {
|
|
67
|
+
let out = "";
|
|
68
|
+
for (const ch of text) out += ACCENTS[ch] ?? ch;
|
|
69
|
+
return out;
|
|
70
|
+
}
|
|
71
|
+
function expandText(text, expansion) {
|
|
72
|
+
if (text.trim() === "") return text;
|
|
73
|
+
const lead = /^\s*/.exec(text)?.[0] ?? "";
|
|
74
|
+
const trail = /\s*$/.exec(text)?.[0] ?? "";
|
|
75
|
+
const core = text.slice(lead.length, text.length - trail.length);
|
|
76
|
+
const letters = [...core].length;
|
|
77
|
+
const extra = Math.ceil(letters * expansion);
|
|
78
|
+
return `${lead}${core}${PAD.repeat(extra)}${trail}`;
|
|
79
|
+
}
|
|
80
|
+
function transformText(text, expansion) {
|
|
81
|
+
let out = "";
|
|
82
|
+
let last = 0;
|
|
83
|
+
for (const m of text.matchAll(URL_OR_EMAIL)) {
|
|
84
|
+
const idx = m.index ?? 0;
|
|
85
|
+
out += accent(text.slice(last, idx)) + m[0];
|
|
86
|
+
last = idx + m[0].length;
|
|
87
|
+
}
|
|
88
|
+
out += accent(text.slice(last));
|
|
89
|
+
return expandText(out, expansion);
|
|
90
|
+
}
|
|
91
|
+
function pseudoLocalize(message, options = {}) {
|
|
92
|
+
const expansion = options.expansion ?? 0.4;
|
|
93
|
+
const tokens = chunkABK4QQWW_cjs.tokenizeIcu(message);
|
|
94
|
+
let body = "";
|
|
95
|
+
for (const t of tokens) body += t.kind === "text" ? transformText(t.text, expansion) : t.raw;
|
|
96
|
+
if (options.markers !== false) body = `${options.prefix ?? PSEUDO_PREFIX}${body}${options.suffix ?? PSEUDO_SUFFIX}`;
|
|
97
|
+
return options.strategy === "rtl" ? `${RLO}${body}${PDF}` : body;
|
|
98
|
+
}
|
|
99
|
+
function pseudoLocalizeMessages(messages, options = {}) {
|
|
100
|
+
return Object.fromEntries(Object.keys(messages).map((k) => [k, pseudoLocalize(messages[k] ?? "", options)]));
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
exports.PSEUDO_PREFIX = PSEUDO_PREFIX;
|
|
104
|
+
exports.PSEUDO_SUFFIX = PSEUDO_SUFFIX;
|
|
105
|
+
exports.pseudoLocalize = pseudoLocalize;
|
|
106
|
+
exports.pseudoLocalizeMessages = pseudoLocalizeMessages;
|