Send the remaining interface text through the catalog and audit it

Phase 4f.

- scripts/i18nAudit.mjs runs in pnpm check. It fails for a key that the
  catalog does not have, a catalog key that the code does not use, and
  a row without all four languages.
- message() marks a key that a variable carries to the translation call
  later: table formats, formula errors, and browser status messages.
- 53 new rows with French, Japanese, and Simplified Chinese text for the
  status and error messages of the workbench, the tree, Settings, theme
  import, images, the built-in browser, and code blocks. The backlinks
  toggle now translates too.
- 13 unused rows are gone.
- Errors of the plugin API stay in English. docs/development.md has the
  rule in "Interface text".

pnpm check, pnpm test (350 of 350), and the full smoke suite pass,
except two tests that failed one time under load and passed on retry
and 3 of 3 times alone.
This commit is contained in:
Knotty Wyvern
2026-10-28 12:00:24 -07:00
parent 3e6bc5f088
commit e9c59f28de
28 changed files with 249 additions and 171 deletions
+15 -15
View File
@@ -354,7 +354,7 @@
expanded = folders;
}
async function copyText(text: string, label: string) {
async function copyText(text: string, done: string) {
try {
await navigator.clipboard.writeText(text);
} catch {
@@ -365,7 +365,7 @@
document.execCommand("copy");
area.remove();
}
onStatus?.(`Copied ${label}`);
onStatus?.(done);
}
async function persistMarks(change: (current: Marks) => Marks) {
@@ -416,7 +416,7 @@
await load(parentRel(from));
selectOnly(plan.to);
await focusTreePath(plan.to);
onStatus?.(`Renamed to ${plan.to}`);
onStatus?.($t("Renamed to {path}", { path: plan.to }));
} catch (err) {
error = err instanceof Error ? err.message : String(err);
} finally { moving = false; }
@@ -512,7 +512,7 @@
}
await load(parent);
if (workspaceRoot !== operationRoot) return;
onStatus?.(`Created ${rel}`);
onStatus?.($t("Created {path}", { path: rel }));
if (kind === "folder") {
startRename({ name: finalName, rel_path: rel, kind: "folder" });
} else {
@@ -554,7 +554,7 @@
const paths = new Map(entries.map(entry => [entry.rel_path, entry.rel_path]));
moving = true;
const result = await runTreeActions(place === "after" ? [...entries].reverse() : entries, async entry => {
if (workspaceRoot !== operationRoot) throw new Error("The workspace changed. File moves stopped.");
if (workspaceRoot !== operationRoot) throw new Error($t("The workspace changed. File moves stopped."));
const plan = planDrop(entry.rel_path, target, place, namesIn);
if (plan.action === "noop") return;
if (plan.action === "reorder") {
@@ -567,7 +567,7 @@
const next = moveMarks(current, plan.from, plan.to);
return { ...next, order: { ...next.order, [plan.fromParent]: plan.orderFrom, [plan.toParent]: plan.orderTo } };
});
if (!moved || workspaceRoot !== operationRoot) throw new Error("The workspace changed. File moves stopped.");
if (!moved || workspaceRoot !== operationRoot) throw new Error($t("The workspace changed. File moves stopped."));
moves.push({ from: plan.from, to: plan.to });
paths.set(plan.from, plan.to);
await load(plan.fromParent);
@@ -578,7 +578,7 @@
if (place === "inside") expanded = new Set([...expanded, destination]);
selection = { paths: new Set(paths.values()), anchor: paths.values().next().value ?? null };
error = result.failures.length ? result.failures.join("\n") : null;
onStatus?.(`Moved ${result.completed.length} of ${entries.length} items`);
onStatus?.($t("Moved {count} of {total} items", { count: result.completed.length, total: entries.length }));
if (moves.length || JSON.stringify(before.order) !== JSON.stringify(marks.order)) {
undoMoves = [...undoMoves, { moves, before, after: session.marks.snapshot() }];
redoMoves = [];
@@ -621,13 +621,13 @@
const applied: { from: string; to: string }[] = [];
try {
for (const move of redo ? batch.moves : [...batch.moves].reverse()) {
if (workspaceRoot !== operationRoot) throw new Error("The workspace changed. File moves stopped.");
if (workspaceRoot !== operationRoot) throw new Error($t("The workspace changed. File moves stopped."));
const from = redo ? move.from : move.to, to = redo ? move.to : move.from;
// The batch restores the marks after all moves, so each move leaves them alone.
if (!await session.rename(from, to, null) || workspaceRoot !== operationRoot) throw new Error("The workspace changed. File moves stopped.");
if (!await session.rename(from, to, null) || workspaceRoot !== operationRoot) throw new Error($t("The workspace changed. File moves stopped."));
applied.push({ from, to });
}
if (workspaceRoot !== operationRoot) throw new Error("The workspace changed. File moves stopped.");
if (workspaceRoot !== operationRoot) throw new Error($t("The workspace changed. File moves stopped."));
await persistMarks(current => replayMoveMarks(current, batch.before, batch.after, batch.moves, redo));
if (redo) { redoMoves = redoMoves.slice(0, -1); undoMoves = [...undoMoves, batch]; }
else { undoMoves = undoMoves.slice(0, -1); redoMoves = [...redoMoves, batch]; }
@@ -657,11 +657,11 @@
const moves: MoveBatch["moves"] = [];
moving = true;
const result = await runTreeActions(source.paths.map(rel_path => ({ rel_path, name: rel_path.split("/").pop()!, kind: "file" as const })), async entry => {
if (workspaceRoot !== operationRoot) throw new Error("The workspace changed. Paste stopped.");
if (workspaceRoot !== operationRoot) throw new Error($t("The workspace changed. Paste stopped."));
if (source.cut) {
const to = joinRel(parent, entry.name);
if (to === entry.rel_path) return;
if (!await session.rename(entry.rel_path, to) || workspaceRoot !== operationRoot) throw new Error("The workspace changed. Paste stopped.");
if (!await session.rename(entry.rel_path, to) || workspaceRoot !== operationRoot) throw new Error($t("The workspace changed. Paste stopped."));
moves.push({ from: entry.rel_path, to });
} else await workspaceCopy(entry.rel_path, parent, operationRoot);
});
@@ -677,7 +677,7 @@
const result = await runTreeActions(roots, entry => workspaceCopy(entry.rel_path));
for (const parent of new Set(roots.map(entry => parentRel(entry.rel_path)))) await load(parent);
error = result.failures.length ? result.failures.join("\n") : null;
onStatus?.(`Copied ${result.completed.length} of ${roots.length} items`);
onStatus?.($t("Copied {count} of {total} items", { count: result.completed.length, total: roots.length }));
}
// Delete moves items to the system trash. One file needs no confirmation, because the
@@ -838,7 +838,7 @@
label: multiple ? $t("Copy workspace paths") : $t("Copy workspace path"),
icon: "copy",
run: () => {
void copyText(entries.map(item => item.rel_path).join("\n"), multiple ? "workspace paths" : "workspace path");
void copyText(entries.map(item => item.rel_path).join("\n"), multiple ? $t("Copied workspace paths") : $t("Copied workspace path"));
},
},
{
@@ -849,7 +849,7 @@
void (async () => {
try {
const paths = await Promise.all(entries.map(item => workspaceAbsPath(item.rel_path)));
await copyText(paths.join("\n"), multiple ? "system paths" : "system path");
await copyText(paths.join("\n"), multiple ? $t("Copied system paths") : $t("Copied system path"));
} catch (err) {
error = err instanceof Error ? err.message : String(err);
}
+3 -2
View File
@@ -1,4 +1,5 @@
<script lang="ts">
import { t } from "$lib/i18n";
import { onMount } from "svelte";
import { isTauri } from "@tauri-apps/api/core";
import { getCurrentWindow } from "@tauri-apps/api/window";
@@ -11,7 +12,7 @@
let error = $state("");
function read() {
try { settings = readSettings(); }
catch { error = "Could not read your settings. Default settings apply until you save new settings."; }
catch { error = $t("Could not read your settings. Default settings apply until you save new settings."); }
}
onMount(() => {
read();
@@ -27,7 +28,7 @@
async function close() {
if (!isTauri()) { window.location.assign("/"); return; }
try { await getCurrentWindow().close(); }
catch (reason) { error = `Could not close settings: ${String(reason)}`; }
catch (reason) { error = $t("Could not close settings: {reason}", { reason: String(reason) }); }
}
</script>
+16 -16
View File
@@ -286,27 +286,27 @@
* The source tab closes only after this window accepts the tab.
*/
async function acceptTabTransfer(id: string, { index, startup = false }: { index?: number; startup?: boolean } = {}) {
if (!TAB_TRANSFER_ID.test(id)) throw new Error("Invalid tab transfer.");
if (!TAB_TRANSFER_ID.test(id)) throw new Error($t("Invalid tab transfer."));
const current = documents;
if (!workspace || !current || (switching && !startup)) throw new Error("Move tabs only between windows of the same workspace.");
if (!workspace || !current || (switching && !startup)) throw new Error($t("Move tabs only between windows of the same workspace."));
const payload = await takeTabTransfer(id, workspace.root);
let accepted = false;
try {
const transfer = parseTabTransfer(payload);
let path = "";
if ("buffer" in transfer) {
if (!current.importTab(transfer.buffer)) throw new Error("This tab is already open in this window. The source tab remains open.");
if (!current.importTab(transfer.buffer)) throw new Error($t("This tab is already open in this window. The source tab remains open."));
path = transfer.buffer.relPath;
if (!startup) selectTab(path);
} else {
// A new window starts its plugins after the workspace opens. Wait for them there.
const deadline = Date.now() + (startup ? 15000 : 0);
while (!await restorePluginTab(transfer.plugin as Parameters<typeof restorePluginTab>[0])) {
if (Date.now() >= deadline) throw new Error("Enable this tab's plugin before moving it to this window.");
if (Date.now() >= deadline) throw new Error($t("Enable this tab's plugin before moving it to this window."));
await new Promise(resolve => setTimeout(resolve, 100));
}
if (index !== undefined) {
if (!$pluginView || $pluginView.placement !== "editor") throw new Error("The plugin did not open this tab.");
if (!$pluginView || $pluginView.placement !== "editor") throw new Error($t("The plugin did not open this tab."));
path = `plugin:${$pluginView.key}`;
}
}
@@ -450,7 +450,7 @@
if (tab.plugin && await openPluginDocument(tab.path)) {
await tick();
const opened = $pluginEditors.find(view => view.document?.path === tab.path);
if (!opened) throw new Error("The plugin did not open this document.");
if (!opened) throw new Error($t("The plugin did not open this document."));
if (tab.pinned !== !!opened.pinned) pinPluginEditor(opened.key);
order.push(opened.key);
paths.set(tab.path, `plugin:${opened.key}`);
@@ -567,7 +567,7 @@
const offered = offerTabTransfer(token, workspace!.root, { ...("buffer" in tab ? { buffer: tab.buffer } : { plugin: pluginTabState(tab.plugin) }), reading });
// A drag cannot wait for the offer. Report a failed drag offer here. `detachTab` reports its own.
offered.catch(reason => { finish(false); if (!reportTimeout) error = String(reason); });
timer = setTimeout(() => { finish(); if (reportTimeout) error = "The new window did not accept the tab. The source tab remains open."; }, 30000);
timer = setTimeout(() => { finish(); if (reportTimeout) error = $t("The new window did not accept the tab. The source tab remains open."); }, 30000);
return { token, finish, offered };
} catch (reason) { finish(); throw reason; }
}
@@ -902,7 +902,7 @@
async function renameNoteTitle(id: string, title: string) {
const current = documents;
const note = current?.buffers.find(tab => tab.id === id);
if (!current || !note || switching) throw new Error("This note is no longer available.");
if (!current || !note || switching) throw new Error($t("This note is no longer available."));
const from = note.relPath;
const plan = planMarkdownTitleRename(from, title);
if (plan.action === "error") throw new Error(plan.message);
@@ -947,7 +947,7 @@
const targets = await session.linkTargets(origin, link.target, link.kind);
if ("ambiguous" in targets) throw new Error($t("More than one note matches {path}. Use its workspace path: {candidates}", { path: link.target, candidates: targets.ambiguous.join(", ") }));
for (const path of targets.paths) {
if (!valid()) throw new Error("The workspace changed. Open the link menu again.");
if (!valid()) throw new Error($t("The workspace changed. Open the link menu again."));
const parent = path.split("/").slice(0, -1).join("/");
let files: TreeEntry[];
try { files = await workspaceList(parent); } catch { continue; }
@@ -965,7 +965,7 @@
if (!typed || !valid()) return;
let to = typed.trim().replaceAll("\\", "/");
if (move) {
if (!to || to.startsWith("/") || to.split("/").some(part => !part || part === "." || part === "..") || /[<>:"|?*\u0000-\u001f]/.test(to)) throw new Error("Enter a relative workspace path without reserved characters.");
if (!to || to.startsWith("/") || to.split("/").some(part => !part || part === "." || part === "..") || /[<>:"|?*\u0000-\u001f]/.test(to)) throw new Error($t("Enter a relative workspace path without reserved characters."));
} else {
const plan = planRename(file.rel_path, to);
if (plan.action === "noop") return;
@@ -1071,18 +1071,18 @@
({ leftOpen, rightOpen, leftWidth, rightWidth, leftView } = layout);
if (transferredWindow) { leftOpen = false; rightOpen = false; }
layoutReady = true;
} catch { error = "Could not read your layout. Default layout applies for this window."; }
} catch { error = $t("Could not read your layout. Default layout applies for this window."); }
});
$effect(() => {
if (!layoutReady || transferredWindow) return;
try { saveWorkbenchLayout(localStorage, { leftOpen, rightOpen, leftWidth, rightWidth, leftView }); }
catch { error = "Could not save your layout. Layout changes apply for this window only."; }
catch { error = $t("Could not save your layout. Layout changes apply for this window only."); }
});
onMount(() => {
try { settings = readSettings(); }
catch { error = "Could not read your settings. Default settings apply until you save new settings."; }
catch { error = $t("Could not read your settings. Default settings apply until you save new settings."); }
error = takeSettingsNotice() ?? error;
settingsReady = true;
const stopSettings = onSettingsChange("general", () => { settings = readSettings(); });
@@ -1109,11 +1109,11 @@
}));
unlisteners.push(handlePluginDocumentRename(async (from, name) => {
const current = documents;
if (!current || switching) throw new Error("Open a workspace before renaming a document.");
if (!current || switching) throw new Error($t("Open a workspace before renaming a document."));
const plan = planDocumentTitleRename(from, name);
if (plan.action === "error") throw new Error(plan.message);
if (plan.action === "noop") return from;
if (!await session.rename(from, plan.to) || documents !== current) throw new Error("The workspace changed. Reopen the document.");
if (!await session.rename(from, plan.to) || documents !== current) throw new Error($t("The workspace changed. Reopen the document."));
return plan.to;
}));
unlisteners.push(guardPluginWrites(path => {
@@ -1365,7 +1365,7 @@
onRenameTitle={renameNoteTitle}
tableActions={{ onSearch: searchSelection, onExtract: (markdown, label, valid) => extractSelection(markdown, label, valid, pane.buffer) }}
linkActions={{
browser: browserContribution ? async target => { if (!await browserContribution?.open(target)) throw new Error("Could not open the app browser."); } : undefined,
browser: browserContribution ? async target => { if (!await browserContribution?.open(target)) throw new Error($t("Could not open the app browser.")); } : undefined,
defaultBrowser: target => openUrl(target),
workspaceItems: link => workspaceLinkItems(link, pane.buffer?.relPath ?? "", pane.id),
}}