@verbaly/compiler 0.64.0 → 0.65.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 +7 -3
- package/dist/{claude-CbKynSMc.js → claude--aMMLA-N.js} +2 -1
- package/dist/claude--aMMLA-N.js.map +1 -0
- package/dist/{claude-ByRATJ03.js → claude-arq_js_3.js} +2 -1
- package/dist/claude-arq_js_3.js.map +1 -0
- package/dist/cli.js +256 -59
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +24 -3
- package/dist/index.js +198 -46
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/dist/claude-ByRATJ03.js.map +0 -1
- package/dist/claude-CbKynSMc.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -49,6 +49,7 @@ interface TranslateResult {
|
|
|
49
49
|
failed: TranslateFailure[];
|
|
50
50
|
}
|
|
51
51
|
export declare function translateCatalogs(cfg: ResolvedConfig, catalogs: Catalogs, provider: TranslateProvider, options?: TranslateOptions): Promise<TranslateResult>;
|
|
52
|
+
export declare function mergeTranslations(cfg: ResolvedConfig, locale: string, translated: Catalog, keys: string[]): string[];
|
|
52
53
|
export declare function formatTranslateFailures(failed: TranslateFailure[]): string[];
|
|
53
54
|
export declare function resolveProvider(cfg: ResolvedConfig, model?: string): Promise<TranslateProvider>;
|
|
54
55
|
//#endregion
|
|
@@ -146,6 +147,7 @@ interface TaggedMessage {
|
|
|
146
147
|
interface UsedKey {
|
|
147
148
|
key: string;
|
|
148
149
|
file: string;
|
|
150
|
+
loose?: true;
|
|
149
151
|
}
|
|
150
152
|
interface StrayImport {
|
|
151
153
|
name: string;
|
|
@@ -165,7 +167,7 @@ export declare class MessageRegistry {
|
|
|
165
167
|
update(file: string, analysis: Analysis): void;
|
|
166
168
|
remove(file: string): void;
|
|
167
169
|
messages(): Map<string, TaggedMessage>;
|
|
168
|
-
usedKeys(): Map<string, string[]>;
|
|
170
|
+
usedKeys(strict?: boolean): Map<string, string[]>;
|
|
169
171
|
strayImports(): StrayImport[];
|
|
170
172
|
parseErrors(): {
|
|
171
173
|
file: string;
|
|
@@ -254,11 +256,17 @@ interface BrokenEntry {
|
|
|
254
256
|
severity: IssueSeverity;
|
|
255
257
|
issue: string;
|
|
256
258
|
}
|
|
259
|
+
interface ExtraEntry {
|
|
260
|
+
locale: string;
|
|
261
|
+
key: string;
|
|
262
|
+
files: string[];
|
|
263
|
+
}
|
|
257
264
|
interface CheckResult {
|
|
258
265
|
ok: boolean;
|
|
259
266
|
missing: MissingEntry[];
|
|
260
267
|
unknown: UnknownEntry[];
|
|
261
268
|
broken: BrokenEntry[];
|
|
269
|
+
extra: ExtraEntry[];
|
|
262
270
|
}
|
|
263
271
|
export declare function check(cfg: ResolvedConfig, catalogs: Catalogs, registry: MessageRegistry): CheckResult;
|
|
264
272
|
export declare function formatCheckResult(result: CheckResult, root?: string): string;
|
|
@@ -295,6 +303,14 @@ export declare function counted(count: number, noun: string, many?: string): str
|
|
|
295
303
|
//#region src/run.d.ts
|
|
296
304
|
export declare function formatCliError(error: unknown): string;
|
|
297
305
|
//#endregion
|
|
306
|
+
//#region src/watch.d.ts
|
|
307
|
+
interface TreeOptions {
|
|
308
|
+
keep?: string;
|
|
309
|
+
native?: boolean;
|
|
310
|
+
persistent?: boolean;
|
|
311
|
+
}
|
|
312
|
+
export declare function watchTree(root: string, options: TreeOptions, onFile: (file: string) => void): () => void;
|
|
313
|
+
//#endregion
|
|
298
314
|
//#region src/doctor.d.ts
|
|
299
315
|
interface DoctorEntry {
|
|
300
316
|
level: 'ok' | 'warn' | 'error';
|
|
@@ -322,9 +338,14 @@ interface InitResult {
|
|
|
322
338
|
host: Host | undefined;
|
|
323
339
|
configFile: string;
|
|
324
340
|
next: string[];
|
|
341
|
+
renamed: {
|
|
342
|
+
from: string;
|
|
343
|
+
to: string;
|
|
344
|
+
}[];
|
|
345
|
+
refused: string[];
|
|
325
346
|
}
|
|
326
347
|
type Host = 'nuxt' | 'next' | 'sveltekit' | 'astro' | 'vite' | 'webpack' | 'rspack' | 'rollup' | 'esbuild';
|
|
327
|
-
export declare function init(
|
|
348
|
+
export declare function init(input?: InitOptions): Promise<InitResult>;
|
|
328
349
|
//#endregion
|
|
329
350
|
//#region src/wrap.d.ts
|
|
330
351
|
interface WrapEntry {
|
|
@@ -381,5 +402,5 @@ interface RenderSiteResult {
|
|
|
381
402
|
export declare function renderSite(cfg: ResolvedConfig, options?: RenderSiteOptions): Promise<RenderSiteResult>;
|
|
382
403
|
export declare function formatRenderWarnings(result: RenderSiteResult, sourceLocale: string): string[];
|
|
383
404
|
//#endregion
|
|
384
|
-
export type { BrokenEntry, BundleConfig, Catalog, Catalogs, CheckResult, DoctorEntry, DoctorResult, Drafts, DtsOptions, GlossaryEntry, Host, InitOptions, InitResult, IssueSeverity, LocaleStatus, MissingEntry, PluginOptions, RedirectConfig, RenderConfig, RenderSiteOptions, RenderSiteResult, ResolvedConfig, RuntimeModuleOptions, StatusResult, StructureIssue, SyncResult, TransformResult, TranslateConfig, TranslateFailure, TranslateOptions, TranslateProgress, TranslateProvider, TranslateRequest, TranslateResult, UnknownEntry, VerbalyConfig, WrapBlocked, WrapEntry, WrapOptions, WrapResult, WrapSkip };
|
|
405
|
+
export type { BrokenEntry, BundleConfig, Catalog, Catalogs, CheckResult, DoctorEntry, DoctorResult, Drafts, DtsOptions, ExtraEntry, GlossaryEntry, Host, InitOptions, InitResult, IssueSeverity, LocaleStatus, MissingEntry, PluginOptions, RedirectConfig, RenderConfig, RenderSiteOptions, RenderSiteResult, ResolvedConfig, RuntimeModuleOptions, StatusResult, StructureIssue, SyncResult, TransformResult, TranslateConfig, TranslateFailure, TranslateOptions, TranslateProgress, TranslateProvider, TranslateRequest, TranslateResult, TreeOptions, UnknownEntry, VerbalyConfig, WrapBlocked, WrapEntry, WrapOptions, WrapResult, WrapSkip };
|
|
385
406
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { a as resolveConfig, i as loadConfigFile, o as targetLocales, r as loadConfig, t as findConfigFile } from "./config-DYlbHrPc.js";
|
|
2
|
-
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { existsSync, mkdirSync, readFileSync, readdirSync, rmSync, statSync, watch, writeFileSync } from "node:fs";
|
|
3
3
|
import { dirname, join, relative } from "node:path";
|
|
4
4
|
import { CATALOG_SCRIPT, LOCALE_STORAGE_KEY, RICH_TAGS, VOID_TAGS, alternateLinks, createVerbaly, flatten, localeDirection, normalizeLink, parse, parseIcu, parseTags, safeAttribute } from "verbaly";
|
|
5
5
|
import { glob } from "tinyglobby";
|
|
@@ -57,14 +57,17 @@ function loadCatalogs(cfg) {
|
|
|
57
57
|
function isNested(tree) {
|
|
58
58
|
return Object.values(tree).some((value) => typeof value === "object" && value !== null);
|
|
59
59
|
}
|
|
60
|
+
function group() {
|
|
61
|
+
return Object.create(null);
|
|
62
|
+
}
|
|
60
63
|
function nest(catalog) {
|
|
61
|
-
const tree =
|
|
64
|
+
const tree = group();
|
|
62
65
|
for (const [key, message] of Object.entries(catalog).sort(([a], [b]) => a < b ? -1 : 1)) {
|
|
63
66
|
const parts = key.split(".");
|
|
64
67
|
const leaf = parts[parts.length - 1];
|
|
65
68
|
let node = parts.length > 1 ? tree : void 0;
|
|
66
69
|
for (let i = 0; node && i < parts.length - 1; i++) {
|
|
67
|
-
const next = node[parts[i]] ??=
|
|
70
|
+
const next = node[parts[i]] ??= group();
|
|
68
71
|
node = typeof next === "object" && next !== null ? next : void 0;
|
|
69
72
|
}
|
|
70
73
|
if (node && typeof node[leaf] !== "object") node[leaf] = message;
|
|
@@ -73,7 +76,7 @@ function nest(catalog) {
|
|
|
73
76
|
return tree;
|
|
74
77
|
}
|
|
75
78
|
function sortTree(tree) {
|
|
76
|
-
const sorted =
|
|
79
|
+
const sorted = group();
|
|
77
80
|
for (const key of Object.keys(tree).sort()) {
|
|
78
81
|
const value = tree[key];
|
|
79
82
|
if (typeof value === "string") sorted[key] = value;
|
|
@@ -88,7 +91,7 @@ function isSorted(keys) {
|
|
|
88
91
|
function orderLike(tree, previous) {
|
|
89
92
|
const had = Object.keys(previous);
|
|
90
93
|
if (isSorted(had)) return sortTree(tree);
|
|
91
|
-
const out =
|
|
94
|
+
const out = group();
|
|
92
95
|
const take = (key) => {
|
|
93
96
|
const value = tree[key];
|
|
94
97
|
if (typeof value === "string") {
|
|
@@ -99,8 +102,8 @@ function orderLike(tree, previous) {
|
|
|
99
102
|
const before = previous[key];
|
|
100
103
|
out[key] = typeof before === "object" && before !== null ? orderLike(value, before) : sortTree(value);
|
|
101
104
|
};
|
|
102
|
-
for (const key of had) if (key
|
|
103
|
-
for (const key of Object.keys(tree).sort()) if (!(key
|
|
105
|
+
for (const key of had) if (Object.hasOwn(tree, key)) take(key);
|
|
106
|
+
for (const key of Object.keys(tree).sort()) if (!Object.hasOwn(previous, key)) take(key);
|
|
104
107
|
return out;
|
|
105
108
|
}
|
|
106
109
|
function serializeCatalog(catalog, nested = false, previous) {
|
|
@@ -218,9 +221,10 @@ var MessageRegistry = class {
|
|
|
218
221
|
}
|
|
219
222
|
return out;
|
|
220
223
|
}
|
|
221
|
-
usedKeys() {
|
|
224
|
+
usedKeys(strict = false) {
|
|
222
225
|
const out = /* @__PURE__ */ new Map();
|
|
223
226
|
for (const analysis of this.files.values()) for (const used of analysis.usedKeys) {
|
|
227
|
+
if (strict && used.loose) continue;
|
|
224
228
|
const files = out.get(used.key) ?? [];
|
|
225
229
|
if (!files.includes(used.file)) files.push(used.file);
|
|
226
230
|
out.set(used.key, files);
|
|
@@ -305,11 +309,8 @@ function analyze(code, file, options = {}) {
|
|
|
305
309
|
return;
|
|
306
310
|
}
|
|
307
311
|
if (!isTReference(callee, names)) return;
|
|
308
|
-
const
|
|
309
|
-
if (
|
|
310
|
-
key: first.value,
|
|
311
|
-
file
|
|
312
|
-
});
|
|
312
|
+
const key = staticString(args[0]);
|
|
313
|
+
if (key !== void 0) usedKeys.push(usedKey(key, file, args[0]));
|
|
313
314
|
} else if (node.type === "JSXElement") handleTrans(code, node, file, tagged, usedKeys, names);
|
|
314
315
|
});
|
|
315
316
|
return {
|
|
@@ -323,14 +324,28 @@ function collectDeclaredKeys(node, file, out) {
|
|
|
323
324
|
for (const property of node.properties) {
|
|
324
325
|
if (property.type !== "ObjectProperty") continue;
|
|
325
326
|
const value = property.value;
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
file
|
|
330
|
-
});
|
|
327
|
+
const key = staticString(value);
|
|
328
|
+
if (key !== void 0) {
|
|
329
|
+
if (key !== "") out.push(usedKey(key, file, value));
|
|
331
330
|
} else if (value.type === "ObjectExpression") collectDeclaredKeys(value, file, out);
|
|
332
331
|
}
|
|
333
332
|
}
|
|
333
|
+
function usedKey(key, file, node) {
|
|
334
|
+
return node?.type === "StringLiteral" ? {
|
|
335
|
+
key,
|
|
336
|
+
file
|
|
337
|
+
} : {
|
|
338
|
+
key,
|
|
339
|
+
file,
|
|
340
|
+
loose: true
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
function staticString(node) {
|
|
344
|
+
if (!node) return void 0;
|
|
345
|
+
if (node.type === "StringLiteral") return node.value;
|
|
346
|
+
if (node.type === "TemplateLiteral" && node.expressions.length === 0) return cookedValue(node.quasis[0]);
|
|
347
|
+
if (node.type === "JSXExpressionContainer") return staticString(node.expression);
|
|
348
|
+
}
|
|
334
349
|
const VERBALY_PACKAGE = /^(?:verbaly|@verbaly\/[\w-]+)$/;
|
|
335
350
|
function collectStrayImports(node, file, out) {
|
|
336
351
|
const source = node.source;
|
|
@@ -370,19 +385,16 @@ function handleTrans(code, node, file, tagged, usedKeys, names) {
|
|
|
370
385
|
});
|
|
371
386
|
if (idAttr) {
|
|
372
387
|
const value = idAttr.value;
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
if (attrs.length === 1 && children?.length) {
|
|
388
|
+
const id = staticString(value);
|
|
389
|
+
if (id === void 0) return;
|
|
390
|
+
if (value?.type === "StringLiteral" && attrs.length === 1 && children?.length) {
|
|
376
391
|
const built = buildTransMessage(code, children, names);
|
|
377
392
|
if (built?.text.trim()) {
|
|
378
393
|
push(id, built);
|
|
379
394
|
return;
|
|
380
395
|
}
|
|
381
396
|
}
|
|
382
|
-
usedKeys.push(
|
|
383
|
-
key: id,
|
|
384
|
-
file
|
|
385
|
-
});
|
|
397
|
+
usedKeys.push(usedKey(id, file, value));
|
|
386
398
|
return;
|
|
387
399
|
}
|
|
388
400
|
if (attrs.length > 0) return;
|
|
@@ -937,7 +949,7 @@ const NUMBER_FORMATS = /* @__PURE__ */ new Set([
|
|
|
937
949
|
const DATE_FORMATS = /* @__PURE__ */ new Set(["date", "time"]);
|
|
938
950
|
function collectParams(message) {
|
|
939
951
|
const out = /* @__PURE__ */ new Map();
|
|
940
|
-
visit(parse(message), out);
|
|
952
|
+
visit(parse(message, parseIcu), out);
|
|
941
953
|
return out;
|
|
942
954
|
}
|
|
943
955
|
function visit(nodes, out) {
|
|
@@ -1030,7 +1042,10 @@ ${loaders}
|
|
|
1030
1042
|
// raw catalog access: SSR integrations serialize it across the client boundary
|
|
1031
1043
|
export async function loadMessages(locale) {
|
|
1032
1044
|
if (locale === ${src}) return source;
|
|
1033
|
-
|
|
1045
|
+
// own entries only: a locale named constructor must be a miss, not the Object function
|
|
1046
|
+
const loader = Object.prototype.hasOwnProperty.call(localeLoaders, locale)
|
|
1047
|
+
? localeLoaders[locale]
|
|
1048
|
+
: undefined;
|
|
1034
1049
|
return loader ? (await loader()).default : {};
|
|
1035
1050
|
}
|
|
1036
1051
|
|
|
@@ -1154,6 +1169,20 @@ function writeDts(cfg, catalog, file) {
|
|
|
1154
1169
|
writeFileSync(file, content);
|
|
1155
1170
|
}
|
|
1156
1171
|
//#endregion
|
|
1172
|
+
//#region src/tag.ts
|
|
1173
|
+
function isLocaleTag(tag) {
|
|
1174
|
+
try {
|
|
1175
|
+
Intl.getCanonicalLocales(tag);
|
|
1176
|
+
return true;
|
|
1177
|
+
} catch {
|
|
1178
|
+
return false;
|
|
1179
|
+
}
|
|
1180
|
+
}
|
|
1181
|
+
function suggestTag(tag) {
|
|
1182
|
+
const near = tag.replace(/_/g, "-");
|
|
1183
|
+
return near !== tag && isLocaleTag(near) ? near : void 0;
|
|
1184
|
+
}
|
|
1185
|
+
//#endregion
|
|
1157
1186
|
//#region src/init.ts
|
|
1158
1187
|
const HOSTS = [
|
|
1159
1188
|
{
|
|
@@ -1242,10 +1271,38 @@ function configSource(options, typescript) {
|
|
|
1242
1271
|
if (typescript) return `import type { VerbalyConfig } from '@verbaly/compiler';\n\n${body} satisfies VerbalyConfig;\n`;
|
|
1243
1272
|
return `/** @type {import('@verbaly/compiler').VerbalyConfig} */\n${body};\n`;
|
|
1244
1273
|
}
|
|
1245
|
-
async function init(
|
|
1246
|
-
const root =
|
|
1274
|
+
async function init(input = {}) {
|
|
1275
|
+
const root = input.root ?? process.cwd();
|
|
1247
1276
|
const created = [];
|
|
1248
1277
|
const skipped = [];
|
|
1278
|
+
const renamed = [];
|
|
1279
|
+
const refused = [];
|
|
1280
|
+
const typed = input.locales?.flatMap((locale) => {
|
|
1281
|
+
if (isLocaleTag(locale)) return [locale];
|
|
1282
|
+
const near = suggestTag(locale);
|
|
1283
|
+
if (near) renamed.push({
|
|
1284
|
+
from: locale,
|
|
1285
|
+
to: near
|
|
1286
|
+
});
|
|
1287
|
+
else refused.push(locale);
|
|
1288
|
+
return near ? [near] : [];
|
|
1289
|
+
});
|
|
1290
|
+
const locales = typed && [...new Set(typed)];
|
|
1291
|
+
let sourceLocale = input.sourceLocale;
|
|
1292
|
+
if (sourceLocale !== void 0 && !isLocaleTag(sourceLocale)) {
|
|
1293
|
+
const near = suggestTag(sourceLocale);
|
|
1294
|
+
if (!near) throw new Error(`[verbaly] "${sourceLocale}" is not a locale tag: pass --source with one like en or pt-BR`);
|
|
1295
|
+
renamed.push({
|
|
1296
|
+
from: sourceLocale,
|
|
1297
|
+
to: near
|
|
1298
|
+
});
|
|
1299
|
+
sourceLocale = near;
|
|
1300
|
+
}
|
|
1301
|
+
const options = {
|
|
1302
|
+
...input,
|
|
1303
|
+
locales,
|
|
1304
|
+
sourceLocale
|
|
1305
|
+
};
|
|
1249
1306
|
const existing = findConfigFile(root);
|
|
1250
1307
|
const typescript = existsSync(join(root, "tsconfig.json"));
|
|
1251
1308
|
const configFile = existing ?? (typescript ? "verbaly.config.ts" : "verbaly.config.mjs");
|
|
@@ -1278,7 +1335,9 @@ async function init(options = {}) {
|
|
|
1278
1335
|
skipped,
|
|
1279
1336
|
host: host?.name,
|
|
1280
1337
|
configFile,
|
|
1281
|
-
next
|
|
1338
|
+
next,
|
|
1339
|
+
renamed,
|
|
1340
|
+
refused
|
|
1282
1341
|
};
|
|
1283
1342
|
}
|
|
1284
1343
|
//#endregion
|
|
@@ -1291,8 +1350,9 @@ function check(cfg, catalogs, registry) {
|
|
|
1291
1350
|
const flat = {};
|
|
1292
1351
|
for (const locale of cfg.locales) flat[locale] = flatten(catalogs[locale] ?? {});
|
|
1293
1352
|
const source = flat[cfg.sourceLocale] ?? {};
|
|
1353
|
+
const used = registry.usedKeys();
|
|
1294
1354
|
const unknown = [];
|
|
1295
|
-
for (const [key, files] of registry.usedKeys()) if (!(extracted.has(key) || cfg.locales.some((locale) => flat[locale]?.[key] !== void 0))) unknown.push({
|
|
1355
|
+
for (const [key, files] of registry.usedKeys(true)) if (!(extracted.has(key) || cfg.locales.some((locale) => flat[locale]?.[key] !== void 0))) unknown.push({
|
|
1296
1356
|
key,
|
|
1297
1357
|
files
|
|
1298
1358
|
});
|
|
@@ -1332,6 +1392,18 @@ function check(cfg, catalogs, registry) {
|
|
|
1332
1392
|
if (text) add(locale, key, validatePair(text, translated));
|
|
1333
1393
|
}
|
|
1334
1394
|
}
|
|
1395
|
+
const extra = [];
|
|
1396
|
+
for (const locale of cfg.locales) {
|
|
1397
|
+
if (locale === cfg.sourceLocale) continue;
|
|
1398
|
+
for (const key of Object.keys(flat[locale] ?? {})) {
|
|
1399
|
+
if (source[key] !== void 0 || extracted.has(key)) continue;
|
|
1400
|
+
extra.push({
|
|
1401
|
+
locale,
|
|
1402
|
+
key,
|
|
1403
|
+
files: used.get(key) ?? []
|
|
1404
|
+
});
|
|
1405
|
+
}
|
|
1406
|
+
}
|
|
1335
1407
|
return {
|
|
1336
1408
|
ok: gatePasses({
|
|
1337
1409
|
missing,
|
|
@@ -1340,7 +1412,8 @@ function check(cfg, catalogs, registry) {
|
|
|
1340
1412
|
}),
|
|
1341
1413
|
missing,
|
|
1342
1414
|
unknown,
|
|
1343
|
-
broken
|
|
1415
|
+
broken,
|
|
1416
|
+
extra
|
|
1344
1417
|
};
|
|
1345
1418
|
}
|
|
1346
1419
|
function formatCheckResult(result, root) {
|
|
@@ -1373,7 +1446,9 @@ function checkNextSteps(result, cliReachable = true) {
|
|
|
1373
1446
|
return steps.join("\n");
|
|
1374
1447
|
}
|
|
1375
1448
|
function formatCheckWarnings(result) {
|
|
1376
|
-
|
|
1449
|
+
const lines = result.broken.filter((entry) => entry.severity === "warning").map((entry) => ` [${entry.locale}] ${entry.key}: ${entry.issue}`);
|
|
1450
|
+
for (const entry of result.extra) lines.push(entry.files.length > 0 ? ` [${entry.locale}] ${entry.key}: only this translation has it, so the source language shows the key itself` : ` [${entry.locale}] ${entry.key}: only this translation has it, and no code reads it`);
|
|
1451
|
+
return lines.join("\n");
|
|
1377
1452
|
}
|
|
1378
1453
|
function truncate(text, max) {
|
|
1379
1454
|
return text.length > max ? text.slice(0, max - 1) + "…" : text;
|
|
@@ -1649,6 +1724,12 @@ async function doctor(cfg) {
|
|
|
1649
1724
|
ok("catalogs", `${counted(cfg.locales.length, "locale")} (${cfg.locales.join(", ")}) in ${rel(cfg.dir)}/${how}`);
|
|
1650
1725
|
}
|
|
1651
1726
|
}
|
|
1727
|
+
for (const locale of cfg.locales) {
|
|
1728
|
+
if (isLocaleTag(locale)) continue;
|
|
1729
|
+
const near = suggestTag(locale);
|
|
1730
|
+
const file = rel(join(cfg.dir, `${locale}.json`));
|
|
1731
|
+
warn("locales", `"${locale}" is not a locale tag, so numbers, dates and plurals in it format in a fallback`, near ? `rename it to ${near}: the file ${file} and your config` : `name it with a language tag like es or pt-BR, in ${file} and in your config`);
|
|
1732
|
+
}
|
|
1652
1733
|
const source = catalogs[cfg.sourceLocale];
|
|
1653
1734
|
if (source && Object.keys(source).length === 0) warn("source", `source catalog ${cfg.sourceLocale}.json is empty`, "write your first t`…` message and run `npx verbaly extract`");
|
|
1654
1735
|
const mirrors = cfg.render.site !== void 0 || Object.keys(cfg.render).length > 0;
|
|
@@ -1714,6 +1795,10 @@ async function doctor(cfg) {
|
|
|
1714
1795
|
const locales = [...new Set(broken.map((b) => b.locale))];
|
|
1715
1796
|
error("translations", `${counted(broken.length, "broken translation")} (${locales.join(", ")}): present but not rendering what the source renders`, "run `npx verbaly check` to read what each one lost");
|
|
1716
1797
|
}
|
|
1798
|
+
if (result.extra.length > 0) {
|
|
1799
|
+
const shown = result.extra.map((entry) => `${entry.locale}: ${entry.key}`);
|
|
1800
|
+
warn("extras", `a translation has ${counted(result.extra.length, "key")} the source catalog does not (${preview(shown)})`, scanning ? "add them to the source catalog if your code uses them, or run `npx verbaly extract --prune` to drop the rest" : "add them to the source catalog if your code uses them, or delete them from the translations");
|
|
1801
|
+
}
|
|
1717
1802
|
const warnings = result.broken.filter((entry) => entry.severity === "warning");
|
|
1718
1803
|
if (warnings.length > 0) warn("translations", `${counted(warnings.length, "structural warning")} (plural forms a language asks for)`, "run `npx verbaly check` to read them, they never fail the build");
|
|
1719
1804
|
if (result.ok) ok("translations", "all translations complete");
|
|
@@ -1843,6 +1928,19 @@ async function translateCatalogs(cfg, catalogs, provider, options = {}) {
|
|
|
1843
1928
|
function compare(a, b) {
|
|
1844
1929
|
return (a[0] ?? "").localeCompare(b[0] ?? "");
|
|
1845
1930
|
}
|
|
1931
|
+
function mergeTranslations(cfg, locale, translated, keys) {
|
|
1932
|
+
const source = readCatalog(cfg, cfg.sourceLocale);
|
|
1933
|
+
const current = readCatalog(cfg, locale);
|
|
1934
|
+
const written = [];
|
|
1935
|
+
for (const key of keys) {
|
|
1936
|
+
const text = translated[key];
|
|
1937
|
+
if (!source[key] || current[key] || !text) continue;
|
|
1938
|
+
current[key] = text;
|
|
1939
|
+
written.push(key);
|
|
1940
|
+
}
|
|
1941
|
+
if (written.length > 0) writeCatalog(cfg, locale, current);
|
|
1942
|
+
return written;
|
|
1943
|
+
}
|
|
1846
1944
|
function formatTranslateFailures(failed) {
|
|
1847
1945
|
const grouped = [];
|
|
1848
1946
|
for (const entry of failed) {
|
|
@@ -1858,7 +1956,7 @@ function formatTranslateFailures(failed) {
|
|
|
1858
1956
|
async function resolveProvider(cfg, model) {
|
|
1859
1957
|
const configured = cfg.translate.provider;
|
|
1860
1958
|
if (typeof configured === "function") return configured;
|
|
1861
|
-
const { claudeProvider } = await import("./claude-
|
|
1959
|
+
const { claudeProvider } = await import("./claude--aMMLA-N.js");
|
|
1862
1960
|
return claudeProvider({ model: model ?? cfg.translate.model });
|
|
1863
1961
|
}
|
|
1864
1962
|
function structureMatches(source, translated) {
|
|
@@ -2028,12 +2126,16 @@ function publicPath(rel) {
|
|
|
2028
2126
|
const path = `/${rel.replace(/(^|\/)index\.html$/, "$1")}`;
|
|
2029
2127
|
return path.length > 1 ? path.replace(/\/+$/, "") : path;
|
|
2030
2128
|
}
|
|
2129
|
+
function linkFor(links, name) {
|
|
2130
|
+
return links && Object.hasOwn(links, name) ? links[name] : void 0;
|
|
2131
|
+
}
|
|
2031
2132
|
function usedLinks(nodes, links) {
|
|
2032
2133
|
const out = {};
|
|
2033
2134
|
const walk = (list) => {
|
|
2034
2135
|
for (const node of list) {
|
|
2035
2136
|
if (typeof node === "string") continue;
|
|
2036
|
-
|
|
2137
|
+
const link = linkFor(links, node.name);
|
|
2138
|
+
if (link !== void 0) out[node.name] = link;
|
|
2037
2139
|
walk(node.children);
|
|
2038
2140
|
}
|
|
2039
2141
|
};
|
|
@@ -2117,7 +2219,7 @@ function injectAlternates(ms, html, alternates) {
|
|
|
2117
2219
|
if (head) ms.appendLeft(head.index, block);
|
|
2118
2220
|
}
|
|
2119
2221
|
function injectCatalog(ms, html, messages) {
|
|
2120
|
-
const json = JSON.stringify(messages).replace(/<\//g, "<\\/");
|
|
2222
|
+
const json = JSON.stringify(messages).replace(/<\//g, "<\\/").replace(/<!--/g, "\\u003c!--");
|
|
2121
2223
|
const tag = `<script ${CATALOG_SCRIPT} type="application/json">${json}<\/script>`;
|
|
2122
2224
|
const block = `${CATALOG_OPEN}${tag}${CATALOG_CLOSE}`;
|
|
2123
2225
|
const from = html.indexOf(CATALOG_OPEN);
|
|
@@ -2303,15 +2405,18 @@ function setAttribute(ms, html, chunkStart, openEnd, attrChunk, name, value) {
|
|
|
2303
2405
|
}
|
|
2304
2406
|
function richToHtml(nodes, allowed, links) {
|
|
2305
2407
|
let out = "";
|
|
2306
|
-
for (const node of nodes)
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2408
|
+
for (const node of nodes) {
|
|
2409
|
+
const link = typeof node === "string" ? void 0 : linkFor(links, node.name);
|
|
2410
|
+
if (typeof node === "string") out += escapeHtml(node);
|
|
2411
|
+
else if (link !== void 0) {
|
|
2412
|
+
const { href, target, rel } = normalizeLink(link);
|
|
2413
|
+
let attrs = href !== void 0 ? ` href="${escapeAttr(href)}"` : "";
|
|
2414
|
+
if (target) attrs += ` target="${escapeAttr(target)}"`;
|
|
2415
|
+
if (rel) attrs += ` rel="${escapeAttr(rel)}"`;
|
|
2416
|
+
out += `<a${attrs}>${richToHtml(node.children, allowed, links)}</a>`;
|
|
2417
|
+
} else if (allowed.has(node.name)) out += VOID.has(node.name) ? `<${node.name}>` : `<${node.name}>${richToHtml(node.children, allowed, links)}</${node.name}>`;
|
|
2418
|
+
else out += richToHtml(node.children, allowed, links);
|
|
2419
|
+
}
|
|
2315
2420
|
return out;
|
|
2316
2421
|
}
|
|
2317
2422
|
function escapeHtml(text) {
|
|
@@ -2324,6 +2429,53 @@ function decodeEntities(text) {
|
|
|
2324
2429
|
return text.replace(/"/g, "\"").replace(/'/g, "'").replace(/</g, "<").replace(/>/g, ">").replace(/&/g, "&");
|
|
2325
2430
|
}
|
|
2326
2431
|
//#endregion
|
|
2432
|
+
//#region src/watch.ts
|
|
2433
|
+
const NATIVE_TREE = process.platform === "darwin" || process.platform === "win32";
|
|
2434
|
+
function watchTree(root, options, onFile) {
|
|
2435
|
+
const watchers = /* @__PURE__ */ new Map();
|
|
2436
|
+
const close = (name) => {
|
|
2437
|
+
watchers.get(name)?.close();
|
|
2438
|
+
watchers.delete(name);
|
|
2439
|
+
};
|
|
2440
|
+
const open = (name, recursive, listener) => {
|
|
2441
|
+
const watcher = watch(join(root, name), {
|
|
2442
|
+
recursive,
|
|
2443
|
+
persistent: options.persistent ?? true
|
|
2444
|
+
}, listener);
|
|
2445
|
+
watcher.on("error", (error) => {
|
|
2446
|
+
close(name);
|
|
2447
|
+
console.warn(`[verbaly] stopped watching ${name || "the project"}:`, error);
|
|
2448
|
+
});
|
|
2449
|
+
watchers.set(name, watcher);
|
|
2450
|
+
};
|
|
2451
|
+
if (options.native ?? NATIVE_TREE) open("", true, (_event, file) => {
|
|
2452
|
+
if (file) onFile(file);
|
|
2453
|
+
});
|
|
2454
|
+
else {
|
|
2455
|
+
const sync = (name) => {
|
|
2456
|
+
close(name);
|
|
2457
|
+
if (name !== options.keep && (name === "node_modules" || name.startsWith("."))) return;
|
|
2458
|
+
try {
|
|
2459
|
+
if (!statSync(join(root, name)).isDirectory()) return;
|
|
2460
|
+
} catch {
|
|
2461
|
+
return;
|
|
2462
|
+
}
|
|
2463
|
+
open(name, true, (_event, file) => {
|
|
2464
|
+
if (file) onFile(`${name}/${file}`);
|
|
2465
|
+
});
|
|
2466
|
+
};
|
|
2467
|
+
open("", false, (_event, file) => {
|
|
2468
|
+
if (!file) return;
|
|
2469
|
+
sync(file);
|
|
2470
|
+
onFile(file);
|
|
2471
|
+
});
|
|
2472
|
+
for (const entry of readdirSync(root, { withFileTypes: true })) if (entry.isDirectory()) sync(entry.name);
|
|
2473
|
+
}
|
|
2474
|
+
return () => {
|
|
2475
|
+
for (const name of [...watchers.keys()]) close(name);
|
|
2476
|
+
};
|
|
2477
|
+
}
|
|
2478
|
+
//#endregion
|
|
2327
2479
|
//#region src/wrap.ts
|
|
2328
2480
|
const WRAP_ATTRS = /* @__PURE__ */ new Set([
|
|
2329
2481
|
"title",
|
|
@@ -2606,6 +2758,6 @@ function formatCliError(error) {
|
|
|
2606
2758
|
return message.startsWith("[verbaly]") ? message : `[verbaly] ${message}`;
|
|
2607
2759
|
}
|
|
2608
2760
|
//#endregion
|
|
2609
|
-
export { DRAFTS_FILE, LOCALE_MODULE_PREFIX, MessageRegistry, RESOLVED_VIRTUAL_ID, SOURCE_FILE_RE, check, clearDrafts, clientCatalogs, collectOrigins, counted, createSourceFilter, doctor, effectiveDrafts, extractProject, formatCheckResult, formatCheckWarnings, formatCliError, formatDoctorEntry, formatRenderWarnings, formatStatusResult, formatTranslateFailures, generateDts, generateLocaleModule, generateRuntimeModule, init, isTransformTarget, loadCatalogs, loadConfig, loadDrafts, loadVirtualModule, markDrafts, needsIcu, needsRelative, parseCatalog, pruneCatalogs, readCatalog, renderSite, resolveConfig, resolveProvider, resolveVirtualId, runBuildGate, saveDrafts, stableKey, status, syncCatalogs, targetLocales, transformCode, transformSource, translateCatalogs, validateMessage, validatePair, wrapProject, writeCatalog, writeDts };
|
|
2761
|
+
export { DRAFTS_FILE, LOCALE_MODULE_PREFIX, MessageRegistry, RESOLVED_VIRTUAL_ID, SOURCE_FILE_RE, check, clearDrafts, clientCatalogs, collectOrigins, counted, createSourceFilter, doctor, effectiveDrafts, extractProject, formatCheckResult, formatCheckWarnings, formatCliError, formatDoctorEntry, formatRenderWarnings, formatStatusResult, formatTranslateFailures, generateDts, generateLocaleModule, generateRuntimeModule, init, isTransformTarget, loadCatalogs, loadConfig, loadDrafts, loadVirtualModule, markDrafts, mergeTranslations, needsIcu, needsRelative, parseCatalog, pruneCatalogs, readCatalog, renderSite, resolveConfig, resolveProvider, resolveVirtualId, runBuildGate, saveDrafts, stableKey, status, syncCatalogs, targetLocales, transformCode, transformSource, translateCatalogs, validateMessage, validatePair, watchTree, wrapProject, writeCatalog, writeDts };
|
|
2610
2762
|
|
|
2611
2763
|
//# sourceMappingURL=index.js.map
|