@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,207 @@
|
|
|
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/quality.ts
|
|
8
|
+
var DEFAULT_SEVERITY = {
|
|
9
|
+
"empty-target": "error",
|
|
10
|
+
"invalid-message": "error",
|
|
11
|
+
"source-invalid": "warning",
|
|
12
|
+
"variables-missing": "error",
|
|
13
|
+
"variables-extra": "error",
|
|
14
|
+
"plural-missing-category": "error",
|
|
15
|
+
"plural-unused-category": "warning",
|
|
16
|
+
"plural-lost": "warning",
|
|
17
|
+
"select-option-mismatch": "warning",
|
|
18
|
+
"length-too-long": "warning",
|
|
19
|
+
"length-too-short": "warning",
|
|
20
|
+
"html-mismatch": "error",
|
|
21
|
+
"double-space": "warning",
|
|
22
|
+
"leading-space": "warning",
|
|
23
|
+
"trailing-space": "warning",
|
|
24
|
+
"glossary-required": "error",
|
|
25
|
+
"glossary-forbidden": "error",
|
|
26
|
+
"glossary-keep": "error",
|
|
27
|
+
"number-mismatch": "warning",
|
|
28
|
+
"url-mismatch": "error",
|
|
29
|
+
"untranslated": "info",
|
|
30
|
+
"missing-translation": "warning",
|
|
31
|
+
"extra-key": "info"
|
|
32
|
+
};
|
|
33
|
+
var baseLang = (locale) => locale.split("-")[0]?.toLowerCase() ?? "";
|
|
34
|
+
var codePoints = (s) => {
|
|
35
|
+
let n = 0;
|
|
36
|
+
for (const _ of s) n += 1;
|
|
37
|
+
return n;
|
|
38
|
+
};
|
|
39
|
+
var escapeRe = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
40
|
+
var diffMultiset = (a, b) => {
|
|
41
|
+
const count = /* @__PURE__ */ new Map();
|
|
42
|
+
for (const x of a) count.set(x, (count.get(x) ?? 0) + 1);
|
|
43
|
+
const extra = [];
|
|
44
|
+
for (const x of b) {
|
|
45
|
+
const c = count.get(x) ?? 0;
|
|
46
|
+
if (c > 0) count.set(x, c - 1);
|
|
47
|
+
else extra.push(x);
|
|
48
|
+
}
|
|
49
|
+
const missing = [];
|
|
50
|
+
for (const [x, c] of count) for (let i = 0; i < c; i += 1) missing.push(x);
|
|
51
|
+
return { missing: missing.sort(chunkMFJL3NO5_cjs.compareCodeUnits), extra: extra.sort(chunkMFJL3NO5_cjs.compareCodeUnits) };
|
|
52
|
+
};
|
|
53
|
+
var TAG = /<(\/?)([A-Za-z][A-Za-z0-9-]*)(?:\s[^<>]*)?(\/?)>/g;
|
|
54
|
+
function extractHtmlTags(text) {
|
|
55
|
+
return [...text.matchAll(TAG)].map((m) => `${m[1] ?? ""}${(m[2] ?? "").toLowerCase()}${m[3] ?? ""}`);
|
|
56
|
+
}
|
|
57
|
+
var URL_RE = /(?:https?:\/\/|mailto:|www\.)[^\s<>"'`]+/giu;
|
|
58
|
+
var EMAIL_RE = /[\w.+-]+@[\w-]+(?:\.[\w-]+)+/gu;
|
|
59
|
+
function extractUrls(text) {
|
|
60
|
+
const urls = [...text.matchAll(URL_RE)].map((m) => m[0].replace(/[.,;:!?)\]}]+$/u, ""));
|
|
61
|
+
const rest = text.replace(URL_RE, " ");
|
|
62
|
+
return [...urls, ...[...rest.matchAll(EMAIL_RE)].map((m) => m[0])];
|
|
63
|
+
}
|
|
64
|
+
var ZEROS = [1632, 1776, 2406, 2534, 2662, 2790, 2918, 3046, 3174, 3302, 3430, 3664, 3792, 3872, 4160, 65296];
|
|
65
|
+
function asciiDigit(ch) {
|
|
66
|
+
const cp = ch.codePointAt(0) ?? 0;
|
|
67
|
+
if (cp >= 48 && cp <= 57) return ch;
|
|
68
|
+
for (const z of ZEROS) if (cp >= z && cp < z + 10) return String(cp - z);
|
|
69
|
+
return "";
|
|
70
|
+
}
|
|
71
|
+
var NUMBER_RE = /\p{Nd}{1,3}(?:[\u00A0\u202F.,'\u2019]\p{Nd}{3})+(?:[.,]\p{Nd}+)?|\p{Nd}+(?:[.,]\p{Nd}+)?/gu;
|
|
72
|
+
function extractNumbers(text) {
|
|
73
|
+
const clean = text.replace(URL_RE, " ").replace(EMAIL_RE, " ");
|
|
74
|
+
return [...clean.matchAll(NUMBER_RE)].map((m) => [...m[0]].map(asciiDigit).join("")).filter((d) => d !== "");
|
|
75
|
+
}
|
|
76
|
+
var NO_BOUNDARY_SCRIPT = /[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Thai}]/u;
|
|
77
|
+
function termRegex(term, caseSensitive, wholeWord) {
|
|
78
|
+
const boundary = wholeWord && !NO_BOUNDARY_SCRIPT.test(term);
|
|
79
|
+
const body = escapeRe(term.trim());
|
|
80
|
+
return new RegExp(boundary ? `(?<![\\p{L}\\p{N}_])${body}(?![\\p{L}\\p{N}_])` : body, caseSensitive ? "u" : "iu");
|
|
81
|
+
}
|
|
82
|
+
function glossaryFindings(source, target, entries, locale, emit) {
|
|
83
|
+
const src = chunkABK4QQWW_cjs.plainText(source);
|
|
84
|
+
const trg = chunkABK4QQWW_cjs.plainText(target);
|
|
85
|
+
for (const e of entries) {
|
|
86
|
+
if (e.locale && baseLang(e.locale) !== baseLang(locale)) continue;
|
|
87
|
+
if (e.term.trim() === "") continue;
|
|
88
|
+
const whole = e.wholeWord !== false;
|
|
89
|
+
const inSource = termRegex(e.term, e.caseSensitive ?? e.doNotTranslate === true, whole).test(src);
|
|
90
|
+
if (!inSource) continue;
|
|
91
|
+
if (e.doNotTranslate && !termRegex(e.term, e.caseSensitive ?? true, whole).test(trg)) {
|
|
92
|
+
emit("glossary-keep", `\xAB${e.term}\xBB no se traduce y debe aparecer tal cual en el destino`, { term: e.term });
|
|
93
|
+
}
|
|
94
|
+
const required = e.translation === void 0 ? [] : typeof e.translation === "string" ? [e.translation] : e.translation;
|
|
95
|
+
if (required.length > 0 && !required.some((t) => termRegex(t, e.caseSensitive ?? false, whole).test(trg))) {
|
|
96
|
+
emit("glossary-required", `\xAB${e.term}\xBB debe traducirse como ${required.map((t) => `\xAB${t}\xBB`).join(" o ")}`, { term: e.term, expected: [...required] });
|
|
97
|
+
}
|
|
98
|
+
for (const f of e.forbidden ?? []) {
|
|
99
|
+
if (f.trim() !== "" && termRegex(f, e.caseSensitive ?? false, whole).test(trg)) emit("glossary-forbidden", `\xAB${f}\xBB est\xE1 prohibido para \xAB${e.term}\xBB`, { term: e.term, forbidden: f });
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
function checkTranslation(source, target, options, key) {
|
|
104
|
+
const findings = [];
|
|
105
|
+
const emit = (code, message, detail) => {
|
|
106
|
+
const override = options.severities?.[code];
|
|
107
|
+
if (override === "off") return;
|
|
108
|
+
findings.push({ severity: override ?? DEFAULT_SEVERITY[code], code, message, ...key !== void 0 ? { key } : {}, locale: options.locale, ...detail ? { detail } : {} });
|
|
109
|
+
};
|
|
110
|
+
if (target === "") {
|
|
111
|
+
if (source !== "") emit("empty-target", "la traducci\xF3n est\xE1 vac\xEDa");
|
|
112
|
+
return findings;
|
|
113
|
+
}
|
|
114
|
+
const srcAnalysis = chunk2A6WFLXS_cjs.analyzeMessage(source);
|
|
115
|
+
const trgAnalysis = chunk2A6WFLXS_cjs.analyzeMessage(target);
|
|
116
|
+
if (!srcAnalysis.ok) emit("source-invalid", `el mensaje de origen no es ICU v\xE1lido: ${srcAnalysis.error ?? ""}`);
|
|
117
|
+
if (!trgAnalysis.ok && (srcAnalysis.ok || trgAnalysis.error !== srcAnalysis.error)) emit("invalid-message", `la traducci\xF3n no es un mensaje ICU v\xE1lido: ${trgAnalysis.error ?? ""}`, { error: trgAnalysis.error ?? "" });
|
|
118
|
+
if (srcAnalysis.ok && trgAnalysis.ok) {
|
|
119
|
+
const { missing, extra } = diffMultiset(srcAnalysis.params, trgAnalysis.params);
|
|
120
|
+
if (missing.length > 0) emit("variables-missing", `faltan variables del origen: ${missing.map((v) => `{${v}}`).join(", ")}`, { variables: missing });
|
|
121
|
+
if (extra.length > 0) emit("variables-extra", `variables que el origen no tiene: ${extra.map((v) => `{${v}}`).join(", ")}`, { variables: extra });
|
|
122
|
+
}
|
|
123
|
+
const srcComplex = chunkABK4QQWW_cjs.collectComplex(source);
|
|
124
|
+
const trgComplex = chunkABK4QQWW_cjs.collectComplex(target);
|
|
125
|
+
for (const c of trgComplex) {
|
|
126
|
+
if (c.type === "select") continue;
|
|
127
|
+
const cats = chunkABK4QQWW_cjs.pluralCategories(options.locale, c.type === "plural" ? "cardinal" : "ordinal");
|
|
128
|
+
const present = new Set(c.selectors);
|
|
129
|
+
const missing = cats.filter((cat) => !present.has(cat));
|
|
130
|
+
const unused = c.selectors.filter((s) => !s.startsWith("=") && !cats.includes(s));
|
|
131
|
+
if (missing.length > 0) emit("plural-missing-category", `\xAB${c.name}\xBB (${c.type}) no trae las categor\xEDas de ${options.locale}: ${missing.join(", ")}`, { variable: c.name, missing });
|
|
132
|
+
if (unused.length > 0) emit("plural-unused-category", `\xAB${c.name}\xBB (${c.type}) trae categor\xEDas que ${options.locale} no usa: ${unused.join(", ")}`, { variable: c.name, unused });
|
|
133
|
+
}
|
|
134
|
+
for (const s of srcComplex) {
|
|
135
|
+
if (s.type === "select") {
|
|
136
|
+
const t = trgComplex.find((x) => x.type === "select" && x.name === s.name);
|
|
137
|
+
if (t) {
|
|
138
|
+
const { missing, extra } = diffMultiset(s.selectors, t.selectors);
|
|
139
|
+
if (missing.length > 0 || extra.length > 0) emit("select-option-mismatch", `las opciones de select \xAB${s.name}\xBB difieren del origen`, { variable: s.name, missing, extra });
|
|
140
|
+
}
|
|
141
|
+
} else if (!trgComplex.some((x) => x.type === s.type && x.name === s.name)) {
|
|
142
|
+
emit("plural-lost", `el origen tiene un ${s.type} sobre \xAB${s.name}\xBB y el destino no`, { variable: s.name });
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
const lr = options.lengthRatio ?? {};
|
|
146
|
+
const sLen = codePoints(chunkABK4QQWW_cjs.plainText(source, ""));
|
|
147
|
+
const tLen = codePoints(chunkABK4QQWW_cjs.plainText(target, ""));
|
|
148
|
+
if (sLen >= (lr.minSourceLength ?? 8) && sLen > 0) {
|
|
149
|
+
const ratio = tLen / sLen;
|
|
150
|
+
const rounded = Math.round(ratio * 100) / 100;
|
|
151
|
+
if (ratio > (lr.max ?? 1.8)) emit("length-too-long", `la traducci\xF3n es ${rounded}\xD7 el origen (m\xE1ximo ${lr.max ?? 1.8}\xD7)`, { ratio: rounded, sourceLength: sLen, targetLength: tLen });
|
|
152
|
+
else if (ratio < (lr.min ?? 0.3)) emit("length-too-short", `la traducci\xF3n es ${rounded}\xD7 el origen (m\xEDnimo ${lr.min ?? 0.3}\xD7)`, { ratio: rounded, sourceLength: sLen, targetLength: tLen });
|
|
153
|
+
}
|
|
154
|
+
const tags = diffMultiset(extractHtmlTags(source), extractHtmlTags(target));
|
|
155
|
+
if (tags.missing.length > 0 || tags.extra.length > 0) {
|
|
156
|
+
emit("html-mismatch", `las etiquetas HTML no coinciden (faltan: ${tags.missing.join(" ") || "\u2014"}; sobran: ${tags.extra.join(" ") || "\u2014"})`, { missing: tags.missing, extra: tags.extra });
|
|
157
|
+
}
|
|
158
|
+
if (/ {2,}/.test(target) && !/ {2,}/.test(source)) emit("double-space", "la traducci\xF3n tiene espacios dobles");
|
|
159
|
+
const lead = (s) => /^\s*/.exec(s)?.[0] ?? "";
|
|
160
|
+
const trail = (s) => /\s*$/.exec(s)?.[0] ?? "";
|
|
161
|
+
if (lead(source) !== lead(target)) emit("leading-space", "los espacios al principio no coinciden con el origen");
|
|
162
|
+
if (trail(source) !== trail(target)) emit("trailing-space", "los espacios al final no coinciden con el origen");
|
|
163
|
+
if (options.glossary && options.glossary.length > 0) glossaryFindings(source, target, options.glossary, options.locale, emit);
|
|
164
|
+
const srcPlain = chunkABK4QQWW_cjs.plainText(source);
|
|
165
|
+
const trgPlain = chunkABK4QQWW_cjs.plainText(target);
|
|
166
|
+
const urls = diffMultiset(extractUrls(srcPlain), extractUrls(trgPlain));
|
|
167
|
+
if (urls.missing.length > 0 || urls.extra.length > 0) emit("url-mismatch", `las URL no coinciden (faltan: ${urls.missing.join(" ") || "\u2014"}; sobran: ${urls.extra.join(" ") || "\u2014"})`, { missing: urls.missing, extra: urls.extra });
|
|
168
|
+
const nums = diffMultiset(extractNumbers(srcPlain), extractNumbers(trgPlain));
|
|
169
|
+
if (nums.missing.length > 0 || nums.extra.length > 0) emit("number-mismatch", `los n\xFAmeros no coinciden (faltan: ${nums.missing.join(" ") || "\u2014"}; sobran: ${nums.extra.join(" ") || "\u2014"})`, { missing: nums.missing, extra: nums.extra });
|
|
170
|
+
const sameLang = options.sourceLocale !== void 0 && baseLang(options.sourceLocale) === baseLang(options.locale);
|
|
171
|
+
if (target === source && !sameLang && (srcPlain.match(/\p{L}/gu)?.length ?? 0) >= 4) emit("untranslated", "la traducci\xF3n es id\xE9ntica al origen");
|
|
172
|
+
return findings;
|
|
173
|
+
}
|
|
174
|
+
function checkCatalog(source, target, options = {}) {
|
|
175
|
+
const opts = { ...options, locale: options.locale ?? target.locale, sourceLocale: options.sourceLocale ?? source.locale };
|
|
176
|
+
const findings = [];
|
|
177
|
+
const structural = (code, message, key) => {
|
|
178
|
+
const override = opts.severities?.[code];
|
|
179
|
+
if (override !== "off") findings.push({ severity: override ?? DEFAULT_SEVERITY[code], code, message, key, locale: opts.locale });
|
|
180
|
+
};
|
|
181
|
+
for (const key of Object.keys(source.messages).sort(chunkMFJL3NO5_cjs.compareCodeUnits)) {
|
|
182
|
+
const t = target.messages[key];
|
|
183
|
+
if (t === void 0) {
|
|
184
|
+
structural("missing-translation", "falta la traducci\xF3n", key);
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
findings.push(...checkTranslation(source.messages[key] ?? "", t, opts, key));
|
|
188
|
+
}
|
|
189
|
+
for (const key of Object.keys(target.messages).sort(chunkMFJL3NO5_cjs.compareCodeUnits)) {
|
|
190
|
+
if (source.messages[key] === void 0) structural("extra-key", "la clave no existe en el origen", key);
|
|
191
|
+
}
|
|
192
|
+
return findings;
|
|
193
|
+
}
|
|
194
|
+
var hasErrors = (findings) => findings.some((f) => f.severity === "error");
|
|
195
|
+
var countBySeverity = (findings) => {
|
|
196
|
+
const out = { error: 0, warning: 0, info: 0 };
|
|
197
|
+
for (const f of findings) out[f.severity] += 1;
|
|
198
|
+
return out;
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
exports.checkCatalog = checkCatalog;
|
|
202
|
+
exports.checkTranslation = checkTranslation;
|
|
203
|
+
exports.countBySeverity = countBySeverity;
|
|
204
|
+
exports.extractHtmlTags = extractHtmlTags;
|
|
205
|
+
exports.extractNumbers = extractNumbers;
|
|
206
|
+
exports.extractUrls = extractUrls;
|
|
207
|
+
exports.hasErrors = hasErrors;
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { compareCodeUnits } from './chunk-BYMLRMNS.mjs';
|
|
2
|
+
import { analyzeMessage } from './chunk-QKIF4C5R.mjs';
|
|
3
|
+
import { collectComplex, pluralCategories, plainText } from './chunk-3M6ZLCSN.mjs';
|
|
4
|
+
|
|
5
|
+
// src/vendor/i18n-tools/quality.ts
|
|
6
|
+
var DEFAULT_SEVERITY = {
|
|
7
|
+
"empty-target": "error",
|
|
8
|
+
"invalid-message": "error",
|
|
9
|
+
"source-invalid": "warning",
|
|
10
|
+
"variables-missing": "error",
|
|
11
|
+
"variables-extra": "error",
|
|
12
|
+
"plural-missing-category": "error",
|
|
13
|
+
"plural-unused-category": "warning",
|
|
14
|
+
"plural-lost": "warning",
|
|
15
|
+
"select-option-mismatch": "warning",
|
|
16
|
+
"length-too-long": "warning",
|
|
17
|
+
"length-too-short": "warning",
|
|
18
|
+
"html-mismatch": "error",
|
|
19
|
+
"double-space": "warning",
|
|
20
|
+
"leading-space": "warning",
|
|
21
|
+
"trailing-space": "warning",
|
|
22
|
+
"glossary-required": "error",
|
|
23
|
+
"glossary-forbidden": "error",
|
|
24
|
+
"glossary-keep": "error",
|
|
25
|
+
"number-mismatch": "warning",
|
|
26
|
+
"url-mismatch": "error",
|
|
27
|
+
"untranslated": "info",
|
|
28
|
+
"missing-translation": "warning",
|
|
29
|
+
"extra-key": "info"
|
|
30
|
+
};
|
|
31
|
+
var baseLang = (locale) => locale.split("-")[0]?.toLowerCase() ?? "";
|
|
32
|
+
var codePoints = (s) => {
|
|
33
|
+
let n = 0;
|
|
34
|
+
for (const _ of s) n += 1;
|
|
35
|
+
return n;
|
|
36
|
+
};
|
|
37
|
+
var escapeRe = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
38
|
+
var diffMultiset = (a, b) => {
|
|
39
|
+
const count = /* @__PURE__ */ new Map();
|
|
40
|
+
for (const x of a) count.set(x, (count.get(x) ?? 0) + 1);
|
|
41
|
+
const extra = [];
|
|
42
|
+
for (const x of b) {
|
|
43
|
+
const c = count.get(x) ?? 0;
|
|
44
|
+
if (c > 0) count.set(x, c - 1);
|
|
45
|
+
else extra.push(x);
|
|
46
|
+
}
|
|
47
|
+
const missing = [];
|
|
48
|
+
for (const [x, c] of count) for (let i = 0; i < c; i += 1) missing.push(x);
|
|
49
|
+
return { missing: missing.sort(compareCodeUnits), extra: extra.sort(compareCodeUnits) };
|
|
50
|
+
};
|
|
51
|
+
var TAG = /<(\/?)([A-Za-z][A-Za-z0-9-]*)(?:\s[^<>]*)?(\/?)>/g;
|
|
52
|
+
function extractHtmlTags(text) {
|
|
53
|
+
return [...text.matchAll(TAG)].map((m) => `${m[1] ?? ""}${(m[2] ?? "").toLowerCase()}${m[3] ?? ""}`);
|
|
54
|
+
}
|
|
55
|
+
var URL_RE = /(?:https?:\/\/|mailto:|www\.)[^\s<>"'`]+/giu;
|
|
56
|
+
var EMAIL_RE = /[\w.+-]+@[\w-]+(?:\.[\w-]+)+/gu;
|
|
57
|
+
function extractUrls(text) {
|
|
58
|
+
const urls = [...text.matchAll(URL_RE)].map((m) => m[0].replace(/[.,;:!?)\]}]+$/u, ""));
|
|
59
|
+
const rest = text.replace(URL_RE, " ");
|
|
60
|
+
return [...urls, ...[...rest.matchAll(EMAIL_RE)].map((m) => m[0])];
|
|
61
|
+
}
|
|
62
|
+
var ZEROS = [1632, 1776, 2406, 2534, 2662, 2790, 2918, 3046, 3174, 3302, 3430, 3664, 3792, 3872, 4160, 65296];
|
|
63
|
+
function asciiDigit(ch) {
|
|
64
|
+
const cp = ch.codePointAt(0) ?? 0;
|
|
65
|
+
if (cp >= 48 && cp <= 57) return ch;
|
|
66
|
+
for (const z of ZEROS) if (cp >= z && cp < z + 10) return String(cp - z);
|
|
67
|
+
return "";
|
|
68
|
+
}
|
|
69
|
+
var NUMBER_RE = /\p{Nd}{1,3}(?:[\u00A0\u202F.,'\u2019]\p{Nd}{3})+(?:[.,]\p{Nd}+)?|\p{Nd}+(?:[.,]\p{Nd}+)?/gu;
|
|
70
|
+
function extractNumbers(text) {
|
|
71
|
+
const clean = text.replace(URL_RE, " ").replace(EMAIL_RE, " ");
|
|
72
|
+
return [...clean.matchAll(NUMBER_RE)].map((m) => [...m[0]].map(asciiDigit).join("")).filter((d) => d !== "");
|
|
73
|
+
}
|
|
74
|
+
var NO_BOUNDARY_SCRIPT = /[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Thai}]/u;
|
|
75
|
+
function termRegex(term, caseSensitive, wholeWord) {
|
|
76
|
+
const boundary = wholeWord && !NO_BOUNDARY_SCRIPT.test(term);
|
|
77
|
+
const body = escapeRe(term.trim());
|
|
78
|
+
return new RegExp(boundary ? `(?<![\\p{L}\\p{N}_])${body}(?![\\p{L}\\p{N}_])` : body, caseSensitive ? "u" : "iu");
|
|
79
|
+
}
|
|
80
|
+
function glossaryFindings(source, target, entries, locale, emit) {
|
|
81
|
+
const src = plainText(source);
|
|
82
|
+
const trg = plainText(target);
|
|
83
|
+
for (const e of entries) {
|
|
84
|
+
if (e.locale && baseLang(e.locale) !== baseLang(locale)) continue;
|
|
85
|
+
if (e.term.trim() === "") continue;
|
|
86
|
+
const whole = e.wholeWord !== false;
|
|
87
|
+
const inSource = termRegex(e.term, e.caseSensitive ?? e.doNotTranslate === true, whole).test(src);
|
|
88
|
+
if (!inSource) continue;
|
|
89
|
+
if (e.doNotTranslate && !termRegex(e.term, e.caseSensitive ?? true, whole).test(trg)) {
|
|
90
|
+
emit("glossary-keep", `\xAB${e.term}\xBB no se traduce y debe aparecer tal cual en el destino`, { term: e.term });
|
|
91
|
+
}
|
|
92
|
+
const required = e.translation === void 0 ? [] : typeof e.translation === "string" ? [e.translation] : e.translation;
|
|
93
|
+
if (required.length > 0 && !required.some((t) => termRegex(t, e.caseSensitive ?? false, whole).test(trg))) {
|
|
94
|
+
emit("glossary-required", `\xAB${e.term}\xBB debe traducirse como ${required.map((t) => `\xAB${t}\xBB`).join(" o ")}`, { term: e.term, expected: [...required] });
|
|
95
|
+
}
|
|
96
|
+
for (const f of e.forbidden ?? []) {
|
|
97
|
+
if (f.trim() !== "" && termRegex(f, e.caseSensitive ?? false, whole).test(trg)) emit("glossary-forbidden", `\xAB${f}\xBB est\xE1 prohibido para \xAB${e.term}\xBB`, { term: e.term, forbidden: f });
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
function checkTranslation(source, target, options, key) {
|
|
102
|
+
const findings = [];
|
|
103
|
+
const emit = (code, message, detail) => {
|
|
104
|
+
const override = options.severities?.[code];
|
|
105
|
+
if (override === "off") return;
|
|
106
|
+
findings.push({ severity: override ?? DEFAULT_SEVERITY[code], code, message, ...key !== void 0 ? { key } : {}, locale: options.locale, ...detail ? { detail } : {} });
|
|
107
|
+
};
|
|
108
|
+
if (target === "") {
|
|
109
|
+
if (source !== "") emit("empty-target", "la traducci\xF3n est\xE1 vac\xEDa");
|
|
110
|
+
return findings;
|
|
111
|
+
}
|
|
112
|
+
const srcAnalysis = analyzeMessage(source);
|
|
113
|
+
const trgAnalysis = analyzeMessage(target);
|
|
114
|
+
if (!srcAnalysis.ok) emit("source-invalid", `el mensaje de origen no es ICU v\xE1lido: ${srcAnalysis.error ?? ""}`);
|
|
115
|
+
if (!trgAnalysis.ok && (srcAnalysis.ok || trgAnalysis.error !== srcAnalysis.error)) emit("invalid-message", `la traducci\xF3n no es un mensaje ICU v\xE1lido: ${trgAnalysis.error ?? ""}`, { error: trgAnalysis.error ?? "" });
|
|
116
|
+
if (srcAnalysis.ok && trgAnalysis.ok) {
|
|
117
|
+
const { missing, extra } = diffMultiset(srcAnalysis.params, trgAnalysis.params);
|
|
118
|
+
if (missing.length > 0) emit("variables-missing", `faltan variables del origen: ${missing.map((v) => `{${v}}`).join(", ")}`, { variables: missing });
|
|
119
|
+
if (extra.length > 0) emit("variables-extra", `variables que el origen no tiene: ${extra.map((v) => `{${v}}`).join(", ")}`, { variables: extra });
|
|
120
|
+
}
|
|
121
|
+
const srcComplex = collectComplex(source);
|
|
122
|
+
const trgComplex = collectComplex(target);
|
|
123
|
+
for (const c of trgComplex) {
|
|
124
|
+
if (c.type === "select") continue;
|
|
125
|
+
const cats = pluralCategories(options.locale, c.type === "plural" ? "cardinal" : "ordinal");
|
|
126
|
+
const present = new Set(c.selectors);
|
|
127
|
+
const missing = cats.filter((cat) => !present.has(cat));
|
|
128
|
+
const unused = c.selectors.filter((s) => !s.startsWith("=") && !cats.includes(s));
|
|
129
|
+
if (missing.length > 0) emit("plural-missing-category", `\xAB${c.name}\xBB (${c.type}) no trae las categor\xEDas de ${options.locale}: ${missing.join(", ")}`, { variable: c.name, missing });
|
|
130
|
+
if (unused.length > 0) emit("plural-unused-category", `\xAB${c.name}\xBB (${c.type}) trae categor\xEDas que ${options.locale} no usa: ${unused.join(", ")}`, { variable: c.name, unused });
|
|
131
|
+
}
|
|
132
|
+
for (const s of srcComplex) {
|
|
133
|
+
if (s.type === "select") {
|
|
134
|
+
const t = trgComplex.find((x) => x.type === "select" && x.name === s.name);
|
|
135
|
+
if (t) {
|
|
136
|
+
const { missing, extra } = diffMultiset(s.selectors, t.selectors);
|
|
137
|
+
if (missing.length > 0 || extra.length > 0) emit("select-option-mismatch", `las opciones de select \xAB${s.name}\xBB difieren del origen`, { variable: s.name, missing, extra });
|
|
138
|
+
}
|
|
139
|
+
} else if (!trgComplex.some((x) => x.type === s.type && x.name === s.name)) {
|
|
140
|
+
emit("plural-lost", `el origen tiene un ${s.type} sobre \xAB${s.name}\xBB y el destino no`, { variable: s.name });
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
const lr = options.lengthRatio ?? {};
|
|
144
|
+
const sLen = codePoints(plainText(source, ""));
|
|
145
|
+
const tLen = codePoints(plainText(target, ""));
|
|
146
|
+
if (sLen >= (lr.minSourceLength ?? 8) && sLen > 0) {
|
|
147
|
+
const ratio = tLen / sLen;
|
|
148
|
+
const rounded = Math.round(ratio * 100) / 100;
|
|
149
|
+
if (ratio > (lr.max ?? 1.8)) emit("length-too-long", `la traducci\xF3n es ${rounded}\xD7 el origen (m\xE1ximo ${lr.max ?? 1.8}\xD7)`, { ratio: rounded, sourceLength: sLen, targetLength: tLen });
|
|
150
|
+
else if (ratio < (lr.min ?? 0.3)) emit("length-too-short", `la traducci\xF3n es ${rounded}\xD7 el origen (m\xEDnimo ${lr.min ?? 0.3}\xD7)`, { ratio: rounded, sourceLength: sLen, targetLength: tLen });
|
|
151
|
+
}
|
|
152
|
+
const tags = diffMultiset(extractHtmlTags(source), extractHtmlTags(target));
|
|
153
|
+
if (tags.missing.length > 0 || tags.extra.length > 0) {
|
|
154
|
+
emit("html-mismatch", `las etiquetas HTML no coinciden (faltan: ${tags.missing.join(" ") || "\u2014"}; sobran: ${tags.extra.join(" ") || "\u2014"})`, { missing: tags.missing, extra: tags.extra });
|
|
155
|
+
}
|
|
156
|
+
if (/ {2,}/.test(target) && !/ {2,}/.test(source)) emit("double-space", "la traducci\xF3n tiene espacios dobles");
|
|
157
|
+
const lead = (s) => /^\s*/.exec(s)?.[0] ?? "";
|
|
158
|
+
const trail = (s) => /\s*$/.exec(s)?.[0] ?? "";
|
|
159
|
+
if (lead(source) !== lead(target)) emit("leading-space", "los espacios al principio no coinciden con el origen");
|
|
160
|
+
if (trail(source) !== trail(target)) emit("trailing-space", "los espacios al final no coinciden con el origen");
|
|
161
|
+
if (options.glossary && options.glossary.length > 0) glossaryFindings(source, target, options.glossary, options.locale, emit);
|
|
162
|
+
const srcPlain = plainText(source);
|
|
163
|
+
const trgPlain = plainText(target);
|
|
164
|
+
const urls = diffMultiset(extractUrls(srcPlain), extractUrls(trgPlain));
|
|
165
|
+
if (urls.missing.length > 0 || urls.extra.length > 0) emit("url-mismatch", `las URL no coinciden (faltan: ${urls.missing.join(" ") || "\u2014"}; sobran: ${urls.extra.join(" ") || "\u2014"})`, { missing: urls.missing, extra: urls.extra });
|
|
166
|
+
const nums = diffMultiset(extractNumbers(srcPlain), extractNumbers(trgPlain));
|
|
167
|
+
if (nums.missing.length > 0 || nums.extra.length > 0) emit("number-mismatch", `los n\xFAmeros no coinciden (faltan: ${nums.missing.join(" ") || "\u2014"}; sobran: ${nums.extra.join(" ") || "\u2014"})`, { missing: nums.missing, extra: nums.extra });
|
|
168
|
+
const sameLang = options.sourceLocale !== void 0 && baseLang(options.sourceLocale) === baseLang(options.locale);
|
|
169
|
+
if (target === source && !sameLang && (srcPlain.match(/\p{L}/gu)?.length ?? 0) >= 4) emit("untranslated", "la traducci\xF3n es id\xE9ntica al origen");
|
|
170
|
+
return findings;
|
|
171
|
+
}
|
|
172
|
+
function checkCatalog(source, target, options = {}) {
|
|
173
|
+
const opts = { ...options, locale: options.locale ?? target.locale, sourceLocale: options.sourceLocale ?? source.locale };
|
|
174
|
+
const findings = [];
|
|
175
|
+
const structural = (code, message, key) => {
|
|
176
|
+
const override = opts.severities?.[code];
|
|
177
|
+
if (override !== "off") findings.push({ severity: override ?? DEFAULT_SEVERITY[code], code, message, key, locale: opts.locale });
|
|
178
|
+
};
|
|
179
|
+
for (const key of Object.keys(source.messages).sort(compareCodeUnits)) {
|
|
180
|
+
const t = target.messages[key];
|
|
181
|
+
if (t === void 0) {
|
|
182
|
+
structural("missing-translation", "falta la traducci\xF3n", key);
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
findings.push(...checkTranslation(source.messages[key] ?? "", t, opts, key));
|
|
186
|
+
}
|
|
187
|
+
for (const key of Object.keys(target.messages).sort(compareCodeUnits)) {
|
|
188
|
+
if (source.messages[key] === void 0) structural("extra-key", "la clave no existe en el origen", key);
|
|
189
|
+
}
|
|
190
|
+
return findings;
|
|
191
|
+
}
|
|
192
|
+
var hasErrors = (findings) => findings.some((f) => f.severity === "error");
|
|
193
|
+
var countBySeverity = (findings) => {
|
|
194
|
+
const out = { error: 0, warning: 0, info: 0 };
|
|
195
|
+
for (const f of findings) out[f.severity] += 1;
|
|
196
|
+
return out;
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
export { checkCatalog, checkTranslation, countBySeverity, extractHtmlTags, extractNumbers, extractUrls, hasErrors };
|