mirror of
https://github.com/hansjone/mind-map.git
synced 2026-10-09 00:43:20 +08:00
feat: sync canvas toolbar locale with DSH zh/en
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
288ebf4c90
commit
d95f033d1f
6 changed files with 322 additions and 46 deletions
|
|
@ -1,8 +1,6 @@
|
|||
#!/usr/bin/env node
|
||||
/**
|
||||
* Fail the build if canvas UI CJK is corrupted or missing.
|
||||
* Root cause we guard against: Windows tools rewriting TopologyCanvas.tsx
|
||||
* with "?" for multibyte UTF-8, and Latin-1 middot 0xb7 breaking UTF-8.
|
||||
* Fail the build if canvas UI CJK/i18n tables are corrupted or incomplete.
|
||||
*/
|
||||
import { readFileSync, existsSync } from "node:fs";
|
||||
import { dirname, join } from "node:path";
|
||||
|
|
@ -26,59 +24,68 @@ function mustUtf8(rel) {
|
|||
}
|
||||
}
|
||||
|
||||
const requiredZh = ["选择", "平移", "连线", "单点", "整枝", "气泡", "卡片", "撤销", "未命名"];
|
||||
const requiredEn = [
|
||||
"Select",
|
||||
"Pan",
|
||||
"Link",
|
||||
"Node",
|
||||
"Branch",
|
||||
"Bubble",
|
||||
"Card",
|
||||
"Undo",
|
||||
"Untitled",
|
||||
];
|
||||
|
||||
const labels = mustUtf8("src/canvas-ui-text.ts");
|
||||
if (labels) {
|
||||
const required = [
|
||||
"选择",
|
||||
"平移",
|
||||
"连线",
|
||||
"单点",
|
||||
"整枝",
|
||||
"气泡",
|
||||
"卡片",
|
||||
"撤销",
|
||||
"未命名",
|
||||
];
|
||||
for (const s of required) {
|
||||
if (!labels.includes(s)) errors.push(`canvas-ui-text.ts missing: ${s}`);
|
||||
for (const s of requiredZh) {
|
||||
if (!labels.includes(s)) errors.push(`canvas-ui-text.ts missing zh: ${s}`);
|
||||
}
|
||||
for (const s of requiredEn) {
|
||||
if (!labels.includes(`"${s}"`) && !labels.includes(`'${s}'`)) {
|
||||
errors.push(`canvas-ui-text.ts missing en: ${s}`);
|
||||
}
|
||||
}
|
||||
if (!labels.includes("const zh:") && !labels.includes("const zh =")) {
|
||||
errors.push("canvas-ui-text.ts must define zh table");
|
||||
}
|
||||
if (!labels.includes("const en:") && !labels.includes("const en =")) {
|
||||
errors.push("canvas-ui-text.ts must define en table");
|
||||
}
|
||||
if (/^\s*\w+:\s*["']\?{2,}["']/m.test(labels)) {
|
||||
errors.push("canvas-ui-text.ts contains corrupted ?? string literals");
|
||||
}
|
||||
}
|
||||
|
||||
const hook = mustUtf8("src/useCanvasUi.ts");
|
||||
if (hook && !hook.includes("dsh-mind-map:locale")) {
|
||||
errors.push("useCanvasUi.ts must listen for dsh-mind-map:locale");
|
||||
}
|
||||
|
||||
const canvas = mustUtf8("src/TopologyCanvas.tsx");
|
||||
if (canvas) {
|
||||
// Toolbar / controls must use canvasUi — no inline ?? placeholders.
|
||||
const badUi = [
|
||||
...canvas.matchAll(/\["select",\s*"(\?+)"/g),
|
||||
...canvas.matchAll(/\["pan",\s*"(\?+)"/g),
|
||||
...canvas.matchAll(/\["link",\s*"(\?+)"/g),
|
||||
];
|
||||
if (badUi.length) {
|
||||
errors.push(
|
||||
"TopologyCanvas.tsx has corrupted tool labels (??). Use canvasUi from canvas-ui-text.ts",
|
||||
);
|
||||
errors.push("TopologyCanvas.tsx has corrupted tool labels (??)");
|
||||
}
|
||||
if (!canvas.includes("canvas-ui-text") && !canvas.includes("canvasUi")) {
|
||||
errors.push("TopologyCanvas.tsx must import canvasUi from canvas-ui-text.ts");
|
||||
if (!canvas.includes("useCanvasUi")) {
|
||||
errors.push("TopologyCanvas.tsx must use useCanvasUi()");
|
||||
}
|
||||
// Detect classic corruption: many consecutive ? inside quotes in JSX title/aria
|
||||
const titleQ = [...canvas.matchAll(/title=\{?["'](\?{2,})["']\}?/g)];
|
||||
if (titleQ.length >= 3) {
|
||||
errors.push(
|
||||
`TopologyCanvas.tsx looks CJK-corrupted (${titleQ.length} title="??" hits). Restore via canvasUi.`,
|
||||
);
|
||||
errors.push(`TopologyCanvas.tsx CJK-corrupted (${titleQ.length} title="??")`);
|
||||
}
|
||||
}
|
||||
|
||||
if (errors.length) {
|
||||
console.error("[check-canvas-cjk] FAILED:");
|
||||
for (const e of errors) console.error(" -", e);
|
||||
console.error(
|
||||
"Fix: edit src/canvas-ui-text.ts (UTF-8 only). Never pipe CJK through PowerShell Set-Content.",
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log("[check-canvas-cjk] OK");
|
||||
console.log("[check-canvas-cjk] OK (zh/en i18n)");
|
||||
|
|
|
|||
7
apps/web/scripts/verify-dist-i18n.py
Normal file
7
apps/web/scripts/verify-dist-i18n.py
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from pathlib import Path
|
||||
|
||||
js = next((Path(__file__).resolve().parents[1] / "dist" / "assets").glob("index-*.js")).read_text(
|
||||
encoding="utf-8"
|
||||
)
|
||||
print({k: (k in js) for k in ["选择", "Select", "平移", "Pan", "连线", "Link", "dsh-mind-map:locale"]})
|
||||
Loading…
Add table
Add a link
Reference in a new issue