Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"scripts": {
"dev": "astro dev",
"og": "node scripts/og.mjs",
"build": "node scripts/i18n-check.mjs && node scripts/og.mjs && astro build && node scripts/sitemap-lastmod.mjs dist && node scripts/seo-audit.mjs dist && node scripts/sales-lens-check.mjs dist && node scripts/card-words.mjs dist && node scripts/voice-gate.mjs dist",
"build": "node scripts/i18n-check.test.mjs && node scripts/i18n-check.mjs && node scripts/og.mjs && astro build && node scripts/sitemap-lastmod.mjs dist && node scripts/seo-audit.mjs dist && node scripts/sales-lens-check.mjs dist && node scripts/card-words.mjs dist && node scripts/voice-gate.mjs dist",
"preview": "astro preview",
"audit": "node scripts/seo-audit.mjs dist && node scripts/sales-lens-check.mjs dist && node scripts/card-words.mjs dist && node scripts/voice-gate.mjs dist"
},
Expand Down
17 changes: 11 additions & 6 deletions scripts/i18n-check.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { existsSync, readFileSync, readdirSync } from 'node:fs';
import { fileURLToPath } from 'node:url';
import { dirname, join } from 'node:path';

const root = join(dirname(fileURLToPath(import.meta.url)), '..');
const root = process.env.I18N_CHECK_ROOT || join(dirname(fileURLToPath(import.meta.url)), '..');
const dir = join(root, 'src', 'i18n');
const load = (c) => JSON.parse(readFileSync(join(dir, `${c}.json`), 'utf8'));

Expand Down Expand Up @@ -203,11 +203,16 @@ for (const { code } of codes) {
const x = parse(readFileSync(join(here, `${e.id}.md`), 'utf8'), `${path}/${e.id}.md`);
if (!x) continue;
if (x.fm.lang !== path || `${x.fm.product}/${x.fm.version}` !== e.id) err(code, label, 'front matter lang, product or version does not match its path');
if (shape(e) !== shape(x)) err(code, label, `structure differs (highlights/breaking/headings/list items/table rows/code blocks): ${shape(e)} vs ${shape(x)}`);
if (fences(e.body).join('\n') !== fences(x.body).join('\n')) err(code, label, 'a code block differs from the English');
if (spans(e) !== spans(x)) err(code, label, 'its `code` spans differ from the English');
if (urls(e) !== urls(x)) err(code, label, 'a link or URL differs from the English');
if (versions(e) !== versions(x)) err(code, label, 'a version number differs from the English');
// An English entry rewritten after its translations were made carries `english_rewrite: true` in its front matter.
// Its structure, code spans, links and version numbers are free to differ from the translations; every other check below
// still runs, and an entry without the flag is held to all of them.
if (e.fm.english_rewrite !== 'true') {
if (shape(e) !== shape(x)) err(code, label, `structure differs (highlights/breaking/headings/list items/table rows/code blocks): ${shape(e)} vs ${shape(x)}`);
if (fences(e.body).join('\n') !== fences(x.body).join('\n')) err(code, label, 'a code block differs from the English');
if (spans(e) !== spans(x)) err(code, label, 'its `code` spans differ from the English');
if (urls(e) !== urls(x)) err(code, label, 'a link or URL differs from the English');
if (versions(e) !== versions(x)) err(code, label, 'a version number differs from the English');
}
const v = [x.fm.summary, ...x.fm.highlights, ...x.fm.breaking, x.body].join('\n');
if (/[–—]/.test(v)) err(code, label, 'has an em or en dash');
if (!x.fm.summary.trim() || x.fm.highlights.some((h) => !h.trim())) err(code, label, 'has an empty summary or highlight');
Expand Down
52 changes: 52 additions & 0 deletions scripts/i18n-check.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Proves the english_rewrite flag in scripts/i18n-check.mjs on a throwaway copy of the repo with two release entries:
// node scripts/i18n-check.test.mjs
// A flagged English entry whose code spans, links, versions and structure differ from its translations passes; the same
// entry without the flag fails on each of those checks; a flagged entry still fails the checks the flag does not cover.
import { cpSync, mkdtempSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join, dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import { spawnSync } from 'node:child_process';

const repo = join(dirname(fileURLToPath(import.meta.url)), '..');
const codes = [...readFileSync(join(repo, 'src/i18n/locales.ts'), 'utf8').matchAll(/\{ code: '([^']+)', path: '([^']*)'/g)].map((m) => ({ code: m[1], path: m[2] })).filter((l) => l.code !== 'en');

const fm = (lines) => ['---', ...lines, '---', ''].join('\n');
const old = (extra = []) => fm(['product: flow', 'version: "9.9.9"', 'date: 2026-12-01', 'published: true', 'summary: "Old copy that mentions `old-span` and version 9.9.8 in its summary."', 'highlights:', ' - "One highlight."', ' - "Two highlights."', 'breaking: []', ...extra]) +
'Old body for HotLoop Flow with `old-span` and 9.9.8.\n\n## What changed\n\n- One\n- Two\n\nSee [notes](https://example.com/old).\n';
const rewrite = (extra) => fm(['product: flow', 'version: "9.9.9"', 'date: 2026-12-01', 'published: true', 'summary: "New sales copy for HotLoop Flow."', 'highlights:', ' - "Only one highlight."', 'breaking: []', ...extra]) +
'New body with no spans, no links and no versions.\n';
const translation = (lang) => fm([`lang: ${lang}`, 'product: flow', 'version: "9.9.9"', 'summary: "Old copy that mentions `old-span` and version 9.9.8 in its summary, translated."', 'highlights:', ' - "One highlight, translated."', ' - "Two highlights, translated."', 'breaking: []']) +
'Old body for HotLoop Flow with `old-span` and 9.9.8, translated.\n\n## What changed\n\n- One\n- Two\n\nSee [notes](https://example.com/old).\n';

function run(english) {
const root = mkdtempSync(join(tmpdir(), 'i18n-check-'));
try {
for (const p of ['src/i18n', 'src/data', 'src/lib/products.ts', 'astro.config.mjs', 'scripts/i18n-check.mjs']) cpSync(join(repo, p), join(root, p), { recursive: true });
mkdirSync(join(root, 'src/content/releases/flow'), { recursive: true });
writeFileSync(join(root, 'src/content/releases/flow/9.9.9.md'), english);
for (const { code, path } of codes) {
mkdirSync(join(root, 'src/content/releases-i18n', path, 'flow'), { recursive: true });
writeFileSync(join(root, 'src/content/releases-i18n', path, 'flow/9.9.9.md'), translation(path));
}
const r = spawnSync('node', [join(root, 'scripts/i18n-check.mjs')], { encoding: 'utf8', env: { ...process.env, I18N_CHECK_ROOT: root } });
return { status: r.status, out: (r.stdout || '') + (r.stderr || '') };
} finally { rmSync(root, { recursive: true, force: true }); }
}
const releaseErrors = (out) => out.split('\n').filter((l) => /release flow\/9\.9\.9/.test(l));
const fail = (m) => { console.error('FAIL ' + m); process.exitCode = 1; };

const plain = run(rewrite([]));
const kinds = ['structure differs', 'code` spans differ', 'link or URL differs', 'version number differs'];
for (const k of kinds) if (!releaseErrors(plain.out).some((l) => l.includes(k))) fail(`unflagged rewrite should fail on "${k}"`);

const flagged = run(rewrite(['english_rewrite: true']));
if (releaseErrors(flagged.out).length) fail('flagged rewrite should pass, got: ' + releaseErrors(flagged.out).slice(0, 3).join(' | '));

// the flag does not cover the other checks: a flagged entry whose summary is a dash-bearing copy of nothing still needs its translations.
const oldFlagged = run(old(['english_rewrite: true']));
if (releaseErrors(oldFlagged.out).length) fail('flagged entry that still matches its translations should pass');
const missing = run(rewrite(['english_rewrite: true']).replace('version: "9.9.9"', 'version: "9.9.8"'));
if (!missing.out.includes('has no translation')) fail('flagged entry with no translation should still fail on the missing translation');

if (!process.exitCode) console.log('i18n-check.test: ok (flagged rewrite passes, unflagged fails on structure, code spans, links and versions, missing translations still fail)');
3 changes: 3 additions & 0 deletions src/content.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ const releases = defineCollection({
summary: z.string().min(20),
highlights: z.array(z.string()).min(1),
breaking: z.array(z.string()).default([]),
// Set on an English entry rewritten after its translations were made: i18n-check then skips the structure, code span,
// link and version comparisons for that entry. The page never shows it.
english_rewrite: z.boolean().optional(),
}),
});

Expand Down