#!/usr/bin/env node /** * I18n Regression Protection Script * * This script checks for: * 1. Hardcoded Chinese text in dashboard HTML/JS * 2. Missing translation keys in locale files * 3. Keys present in one locale but not the other * * Usage: node check-i18n.js * Exit code: 0 if all checks pass, 1 if violations found */ import fs from 'fs'; import path from 'path'; import { fileURLToPath } from 'url'; const __dirname = path.dirname(fileURLToPath(import.meta.url)); const RED = '\x1b[31m'; const GREEN = '\x1b[32m'; const YELLOW = '\x1b[33m'; const RESET = '\x1b[0m'; let exitCode = 0; let violations = 0; function logError(msg) { console.log(`${RED}✗${RESET} ${msg}`); violations++; exitCode = 1; } function logWarn(msg) { console.log(`${YELLOW}⚠${RESET} ${msg}`); } function logOk(msg) { console.log(`${GREEN}✓${RESET} ${msg}`); } // Chinese character regex const CHINESE_REGEX = /[\u4e00-\u9fff]/; // Patterns that are allowed to contain Chinese (whitelisted) const WHITELIST_PATTERNS = [ /data-i18n(?:-[\w-]+)?=/, // i18n attributes are ok /id="(?:mobile-)?lang-indicator"/, // compact language toggle label /indicator\.textContent\s*=/, // compact language toggle label /\/\/.*/, // comments /https?:\/\//, // URLs /windsurf\.com/, // windsurf domain /firebase/, // Firebase references ]; function isWhitelisted(line) { return WHITELIST_PATTERNS.some(p => p.test(line)); } // ---- Check #8 helpers: hardcoded English literals in the App region for hardcoded English string literals // that reach the user. Returns [{ kind, text, line }]. Deliberately conservative: // tuned to 0 findings on the current index.html so any hit is a genuine regression. // Not exported: this module runs checks + process.exit() at load, so it must not // be imported. Check #8 is exercised via subprocess in test/check-i18n.test.js. function scanScriptRegionForEnglish(htmlContent) { const bodyStart = htmlContent.indexOf('
'); const scriptStart = htmlContent.indexOf('