Files
SnapOtter/scripts/i18n/lib/validate.mjs
T
SnapOtterandGitHub 00b651c9f8 feat(i18n): 21-language pipeline, landing/docs/API wiring, landing+API translations
Shared Claude Code translation pipeline (scripts/i18n, no API key) plus Astro/VitePress/Scalar i18n wiring. Landing and API reference translated into all 20 languages; docs i18n wiring + English source anchors. The translated docs markdown (apps/docs/<locale>/**, 3,620 files) follows in a companion PR because it exceeds GitHub's per-PR CI file limit.
2026-07-11 13:01:55 +08:00

22 lines
856 B
JavaScript

// scripts/i18n/lib/validate.mjs
import { countStructures, TOKEN_RE } from "./mask.mjs";
/**
* Assert that the translated text preserved the source's markdown structure.
* Runs on the FINAL (restored) translation, so no mask tokens should remain.
* @param {string} source
* @param {string} translated
* @returns {{ ok: boolean, errors: string[] }}
*/
export function validate(source, translated) {
const errors = [];
const a = countStructures(source);
const b = countStructures(translated);
for (const key of /** @type {const} */ (["fences", "inlineCode", "links", "placeholders"])) {
if (a[key] !== b[key]) errors.push(`${key} count changed: ${a[key]} -> ${b[key]}`);
}
TOKEN_RE.lastIndex = 0;
if (TOKEN_RE.test(translated)) errors.push("unrestored mask token remained in output");
return { ok: errors.length === 0, errors };
}