@verbaly/compiler 0.23.0 → 0.25.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/README.md +3 -3
- package/dist/claude-C-ETlqsW.js.map +1 -1
- package/dist/cli.js +35 -13
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +26 -11
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -120,6 +120,7 @@ declare class MessageRegistry {
|
|
|
120
120
|
remove(file: string): void;
|
|
121
121
|
messages(): Map<string, TaggedMessage>;
|
|
122
122
|
usedKeys(): Map<string, string[]>;
|
|
123
|
+
origins(): Map<string, string[]>;
|
|
123
124
|
}
|
|
124
125
|
//#endregion
|
|
125
126
|
//#region src/check.d.ts
|
|
@@ -197,6 +198,7 @@ interface ExportOptions {
|
|
|
197
198
|
format?: ExportFormat;
|
|
198
199
|
out?: string;
|
|
199
200
|
missing?: boolean;
|
|
201
|
+
origins?: Record<string, string[]>;
|
|
200
202
|
}
|
|
201
203
|
interface ExportedFile {
|
|
202
204
|
locale: string;
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { parse } from "@babel/parser";
|
|
|
2
2
|
import { createHash } from "node:crypto";
|
|
3
3
|
import { existsSync, mkdirSync, readFileSync, readdirSync, rmSync, watch, writeFileSync } from "node:fs";
|
|
4
4
|
import { basename, dirname, join, relative, resolve } from "node:path";
|
|
5
|
-
import { RICH_TAGS, createVerbaly, parse as parse$1, parseTags,
|
|
5
|
+
import { RICH_TAGS, createVerbaly, localeDirection, normalizeLink, parse as parse$1, parseTags, safeAttribute } from "verbaly";
|
|
6
6
|
import { pathToFileURL } from "node:url";
|
|
7
7
|
import MagicString from "magic-string";
|
|
8
8
|
import { glob } from "tinyglobby";
|
|
@@ -918,6 +918,15 @@ var MessageRegistry = class {
|
|
|
918
918
|
}
|
|
919
919
|
return out;
|
|
920
920
|
}
|
|
921
|
+
origins() {
|
|
922
|
+
const out = this.usedKeys();
|
|
923
|
+
for (const analysis of this.files.values()) for (const msg of analysis.tagged) {
|
|
924
|
+
const files = out.get(msg.key) ?? [];
|
|
925
|
+
if (!files.includes(msg.file)) files.push(msg.file);
|
|
926
|
+
out.set(msg.key, files);
|
|
927
|
+
}
|
|
928
|
+
return out;
|
|
929
|
+
}
|
|
921
930
|
};
|
|
922
931
|
//#endregion
|
|
923
932
|
//#region src/extract.ts
|
|
@@ -1248,7 +1257,8 @@ function exportCatalogs(cfg, catalogs, options = {}) {
|
|
|
1248
1257
|
const all = Object.keys(source).filter((key) => source[key]).sort().map((key) => ({
|
|
1249
1258
|
key,
|
|
1250
1259
|
source: source[key],
|
|
1251
|
-
target: catalog[key] ?? ""
|
|
1260
|
+
target: catalog[key] ?? "",
|
|
1261
|
+
location: options.origins?.[key]
|
|
1252
1262
|
}));
|
|
1253
1263
|
const untranslated = all.filter((entry) => !entry.target);
|
|
1254
1264
|
const entries = options.missing ? untranslated : all;
|
|
@@ -1344,8 +1354,13 @@ function parseExchangeFile(file, localeOverride) {
|
|
|
1344
1354
|
throw new Error(`[verbaly] ${file}: unsupported format, expected .xlf, .xliff or .csv.`);
|
|
1345
1355
|
}
|
|
1346
1356
|
function toXliff(sourceLocale, locale, entries) {
|
|
1347
|
-
const units = entries.map(({ key, source, target }) => [
|
|
1357
|
+
const units = entries.map(({ key, source, target, location }) => [
|
|
1348
1358
|
` <unit id="${escapeXml(key)}">`,
|
|
1359
|
+
...location?.length ? [
|
|
1360
|
+
" <notes>",
|
|
1361
|
+
...location.map((file) => ` <note category="location">${escapeXml(file)}</note>`),
|
|
1362
|
+
" </notes>"
|
|
1363
|
+
] : [],
|
|
1349
1364
|
` <segment state="${target ? "translated" : "initial"}">`,
|
|
1350
1365
|
` <source>${escapeXml(source)}</source>`,
|
|
1351
1366
|
` <target>${escapeXml(target)}</target>`,
|
|
@@ -1395,8 +1410,8 @@ function unescapeXml(text) {
|
|
|
1395
1410
|
}
|
|
1396
1411
|
function toCsv(entries) {
|
|
1397
1412
|
return [
|
|
1398
|
-
"key,source,target",
|
|
1399
|
-
...entries.map(({ key, source, target }) => `${csvField(key)},${csvField(source)},${csvField(target)}`),
|
|
1413
|
+
"key,source,target,location",
|
|
1414
|
+
...entries.map(({ key, source, target, location }) => `${csvField(key)},${csvField(source)},${csvField(target)},${csvField(location?.join("; ") ?? "")}`),
|
|
1400
1415
|
""
|
|
1401
1416
|
].join("\r\n");
|
|
1402
1417
|
}
|
|
@@ -1545,6 +1560,7 @@ function renderHtml(html, options) {
|
|
|
1545
1560
|
const chunkStart = m.index + 1 + rawName.length;
|
|
1546
1561
|
if (tagName === "html" && options.setLang !== false) {
|
|
1547
1562
|
setAttribute(ms, html, chunkStart, openEnd, attrChunk, "lang", options.locale);
|
|
1563
|
+
setAttribute(ms, html, chunkStart, openEnd, attrChunk, "dir", localeDirection(options.locale));
|
|
1548
1564
|
continue;
|
|
1549
1565
|
}
|
|
1550
1566
|
const attrs = parseAttrs(attrChunk);
|
|
@@ -1574,12 +1590,13 @@ function renderHtml(html, options) {
|
|
|
1574
1590
|
if (attrMapRaw !== void 0) {
|
|
1575
1591
|
const map = parseArgs(attrMapRaw);
|
|
1576
1592
|
if (map) for (const [name, attrKey] of Object.entries(map)) {
|
|
1577
|
-
if (typeof attrKey !== "string"
|
|
1593
|
+
if (typeof attrKey !== "string") continue;
|
|
1578
1594
|
if (!v.has(attrKey)) {
|
|
1579
1595
|
missing.add(attrKey);
|
|
1580
1596
|
continue;
|
|
1581
1597
|
}
|
|
1582
|
-
|
|
1598
|
+
const value = safeAttribute(name, t(attrKey, args));
|
|
1599
|
+
if (value !== void 0) setAttribute(ms, html, chunkStart, openEnd, attrChunk, name, value);
|
|
1583
1600
|
}
|
|
1584
1601
|
}
|
|
1585
1602
|
}
|
|
@@ -1741,10 +1758,8 @@ function richToHtml(nodes, allowed, links) {
|
|
|
1741
1758
|
let out = "";
|
|
1742
1759
|
for (const node of nodes) if (typeof node === "string") out += escapeHtml(node);
|
|
1743
1760
|
else if (links?.[node.name] !== void 0) {
|
|
1744
|
-
const
|
|
1745
|
-
|
|
1746
|
-
const safe = safeHref(href);
|
|
1747
|
-
let attrs = safe !== void 0 ? ` href="${escapeAttr(safe)}"` : "";
|
|
1761
|
+
const { href, target, rel } = normalizeLink(links[node.name]);
|
|
1762
|
+
let attrs = href !== void 0 ? ` href="${escapeAttr(href)}"` : "";
|
|
1748
1763
|
if (target) attrs += ` target="${escapeAttr(target)}"`;
|
|
1749
1764
|
if (rel) attrs += ` rel="${escapeAttr(rel)}"`;
|
|
1750
1765
|
out += `<a${attrs}>${richToHtml(node.children, allowed, links)}</a>`;
|