P2 of docs/subsystems/plugin-runtime.md, the second page after Sessions.
- library.js and library.css move to assets/plugins/library/ (client.js,
library.css). The script registers with the kernel
(magpie.plugin("library")) and adds its page to the "page" slot. Its
hooks: open and relang load, redraw, close (its modal), dirty, discard.
What it set up at load (list scroll and resize, the modal's backdrop
and Escape, beforeunload, the stuck header, a quiet reload on focus)
runs in mount.
- app.js calls those through magpie.call instead of window.loadLibrary,
redrawLibrary, closeLibraryModal, libraryDirty and discardLibrary. It
no longer lists library in its title map, hide loop or OPEN_VIEWS; the
kernel's pages are in them.
- index.html: <main id="view-library"> goes, the kernel makes it.
library.css keeps its place in the cascade.
- The 560 strings only Library says move from i18n.js to
plugins/library/i18n.js (4 languages). i18n.js: 18826 → 16584 lines.
- plugins/library/library.go lists the client files.
- Tests that read i18n.js for a Library string read strings.cjs (i18n.js
and the plugins'): 8 library tests and mcp-editor-cancel,
mcp-oauth-app, mcp-signin-health. font-cascade, win-fonts and
assets_revalidate_test.go name the new paths.
- "Check again" stays in i18n.js: Library said it alone when the words
were split, and a5d72a095 (Settings' search keys) says it too since.
i18n-keys has a new test, "a plugin's words are its own": a key in a
plugin's i18n.js that any file outside the plugin's folder says fails
it, naming the file. It was red on this key, and search-keys.test.cjs
said "Check again" had no zh translation.
- docs: library.md, gui-shell.md, plugin-runtime.md.
Run, at this tree:
- 101 GUI test files touching Library, skills, MCP, the plugins, the
shell and every language (gui-de/ja/zh-tw, i18n-keys, page-width,
view-no-sideways, mobile-web, text-size, …): Chromium and WebKit, 4 at
a time, all green but one. text-size's "zh: 100% picked at the foot"
failed once in Chromium under load ("scrolled from 160 to 109 (max
115)"); it passed alone, 6 at once here and on origin/main 8f34bbcd1,
and at 6× and 12× CPU throttling. It's the Settings page, already
"fixed" by 50dd39104, so I filed it as #2058.
- After rebasing onto origin/main 75cbc7e1e: i18n-keys, search-keys,
library-mcp-tools, library-all, gui-de, mono-icon-redraw,
group-first-token, Chromium and WebKit, green.
- go test ./internal/gui/ ./internal/pluginrt/ ./plugins/...; gofmt;
go vet on darwin, GOOS=linux -tags nogui, GOOS=windows: clean.
64 lines
2.9 KiB
JavaScript
64 lines
2.9 KiB
JavaScript
// Run with Node's test runner; needs no browser. A key written twice in one
|
|
// language is a trap: the later one silently wins, so an edit to the first
|
|
// does nothing. Every key appears once per language, in i18n.js or in one
|
|
// plugin's i18n.js (strings.cjs), never in two of them, and a plugin's
|
|
// file says every one of its keys in every language.
|
|
const assert = require("node:assert/strict");
|
|
const { test } = require("node:test");
|
|
const { strings } = require("./strings.cjs");
|
|
|
|
test("no language has a key twice", () => {
|
|
const { files, twice } = strings();
|
|
for (const { file, src } of files) {
|
|
const body = file === "i18n.js" ? src.slice(0, src.indexOf("\n};")) : src;
|
|
let lang, seen;
|
|
body.split("\n").forEach((line, i) => {
|
|
const head = line.match(/^ "?([\w-]+)"?: \{/);
|
|
if (head) return void ((lang = head[1]), (seen = new Map()));
|
|
const key = line.match(/^ ("(?:[^"\\]|\\.)*")\s*:/);
|
|
if (!key || !lang) return;
|
|
if (seen.has(key[1])) twice.push(`${file} ${lang} ${key[1]}: lines ${seen.get(key[1])} and ${i + 1}`);
|
|
else seen.set(key[1], i + 1);
|
|
});
|
|
}
|
|
assert.deepEqual(twice, []);
|
|
});
|
|
|
|
test("a plugin's words are said in every language", () => {
|
|
for (const { file, dict } of strings().files.slice(1)) {
|
|
assert.deepEqual(Object.keys(dict).sort(), ["de", "ja", "zh", "zh-TW"], file);
|
|
const zh = Object.keys(dict.zh);
|
|
assert.ok(zh.length, `${file} says nothing`);
|
|
for (const lang of ["zh-TW", "ja", "de"]) assert.deepEqual(Object.keys(dict[lang]).sort(), [...zh].sort(), `${file} ${lang}`);
|
|
}
|
|
});
|
|
|
|
test("a plugin's words are its own", () => {
|
|
// A word the core or another plugin says too belongs in i18n.js: in a
|
|
// plugin's file, it is English wherever that plugin is off, and a
|
|
// word a later change starts saying elsewhere ("Check again", Library's
|
|
// and then Settings' search keys) went untranslated there
|
|
const fs = require("node:fs"), path = require("node:path");
|
|
const repo = path.resolve(__dirname, "../../.."), assets = path.join(repo, "internal/gui/assets");
|
|
const texts = [];
|
|
const walk = (d) => {
|
|
for (const e of fs.readdirSync(d, { withFileTypes: true })) {
|
|
const p = path.join(d, e.name);
|
|
if (e.isDirectory()) {
|
|
if (!["node_modules", ".git", "site", "tests", "testdata", "docs"].includes(e.name)) walk(p);
|
|
} else if (/\.(go|js|html|css)$/.test(e.name) && e.name !== "i18n.js") texts.push([p, fs.readFileSync(p, "utf8")]);
|
|
}
|
|
};
|
|
walk(repo);
|
|
const shared = [];
|
|
for (const { file, dict } of strings().files.slice(1)) {
|
|
const own = path.join(assets, path.dirname(file)) + path.sep;
|
|
const rest = texts.filter(([p]) => !p.startsWith(own));
|
|
for (const k of Object.keys(dict.zh)) {
|
|
const at = rest.find(([, s]) => s.includes(k) || s.includes(JSON.stringify(k).slice(1, -1)));
|
|
if (at) shared.push(`${file} ${JSON.stringify(k)}: ${path.relative(repo, at[0])} says it too`);
|
|
}
|
|
}
|
|
assert.deepEqual(shared, []);
|
|
});
|