Answering "can we ask Stalwart to serve German folder names": no, and it would not help if we could. The account locale exists in `x:AccountSettings`, and ihasmail already reads it -- that is what "Your mail server reports German" comes from -- but writing it needs `sysAccountSettingsSet`, which the built-in user role does not carry; only an admin could. And even then it would change nothing, because folder names are stored data written once when the account is provisioned. No server renames them afterwards; every other client has them mapped. The role is the way through. JMAP tags the standard folders and ihasmail already trusts the role over the name everywhere it matters, so the *displayed* name can follow the interface language with nothing written to the server. A folder somebody made and called "Newsletters" keeps that name: those are their words, and translating them would name a folder they never created. The cost is real and worth stating: Thunderbird on the same account still shows "Deleted Items", because that is what the folder is called. Inside ihasmail it stays consistent -- everything that names a folder goes through one function, including the "moved to …" toast, which exists precisely so that message does not name somewhere the reader cannot find. Renaming still edits the server's own name, never the localised one. Three things fell out of it. The message list refreshed for ever after a language change, which is the one somebody noticed. The root keys its tree on the language version, so a publish remounts everything; remounting re-runs the effect that loads the account's settings, which calls applyLang, which called setCatalog again -- with an identical tag and an identical catalogue -- and publishing that non-change went round again. setCatalog now returns early when nothing changed. Measured rather than assumed: three consecutive five-second windows with no JMAP calls at all, against a pre-change count that never settled. Calendar months and weekdays stayed English, because formatting locale and interface language are separate settings and only the first feeds Intl. Keeping them separate is right -- German dates with an English interface is a real preference -- but somebody who picks German and is shown "September" has not got what they asked for. A chosen interface language now joins the *automatic* chain ahead of the server and the browser. Setting a formatting locale explicitly still wins, and English is not counted, so an English interface on a German browser keeps German dates exactly as before. And the Archive folder read "Archivieren", which is the verb. English uses one word for the button and the folder; German does not, and neither does "Important", which is also a priority tag. tc(context, source) keys the catalogue on both and falls back to the plain English, which was right in English all along -- the gettext approach, including the control character as separator so no real string can collide. The catalogue checker needed teaching about tc() twice: first it reported the eight contextual entries as stale, then it asked for the plain fallbacks as though they were a second obligation. A check that reports work which does not exist gets switched off, which is worse than not having one.
85 lines
4.4 KiB
JavaScript
85 lines
4.4 KiB
JavaScript
#!/usr/bin/env node
|
|
/*
|
|
* Check a catalogue against the strings the code actually asks for.
|
|
*
|
|
* Two failures, and only one of them is visible without this.
|
|
*
|
|
* A *missing* key renders English. That is the designed fallback and shows up
|
|
* as an untranslated word on screen, which somebody will eventually notice.
|
|
*
|
|
* A *stale* key -- one whose English no longer exists, usually because it was
|
|
* mistyped when the catalogue was written -- is silent. The translation sits
|
|
* in the file looking correct, is never looked up, and the app renders English
|
|
* for ever. Nothing warns, because a catalogue is only ever read by key.
|
|
*/
|
|
import ts from "typescript";
|
|
import { readFileSync, globSync } from "node:fs";
|
|
|
|
const wanted = new Set();
|
|
for (const file of globSync("web/src/**/*.{ts,tsx}").filter((f) => !f.includes("__tests__") && !f.includes("/locales/"))) {
|
|
const src = ts.createSourceFile(file, readFileSync(file, "utf8"), ts.ScriptTarget.Latest, true, ts.ScriptKind.TSX);
|
|
const visit = (n) => {
|
|
/*
|
|
* Labels held in a constant and translated where they render -- t(s.label)
|
|
* -- reach t() as a variable, so there is no literal for this to find and
|
|
* every one of them looked "stale". They are collected from the constants
|
|
* instead: a `label:` property, or a value in an object of them. Without
|
|
* this the stale check cried wolf 33 times and would have been switched
|
|
* off, which is the only outcome worse than not having it.
|
|
*/
|
|
if (ts.isPropertyAssignment(n) && n.name.getText(src) === "label" && ts.isStringLiteral(n.initializer)) wanted.add(n.initializer.text);
|
|
if (ts.isVariableDeclaration(n) && ts.isIdentifier(n.name) && /_LABELS?$/.test(n.name.text)) {
|
|
const walk = (x) => { if (ts.isStringLiteral(x)) wanted.add(x.text); ts.forEachChild(x, walk); };
|
|
if (n.initializer) walk(n.initializer);
|
|
}
|
|
if (ts.isCallExpression(n) && ts.isIdentifier(n.expression)) {
|
|
const fn = n.expression.text, a0 = n.arguments[0];
|
|
if ((fn === "t" || fn === "translate" || fn === "tNode") && a0 && ts.isStringLiteral(a0)) wanted.add(a0.text);
|
|
// tc(context, source) keys the catalogue on both, joined by the same
|
|
// control character tc() uses. Without this the contextual entries all
|
|
// looked stale, which is the checker's own false alarm rather than a
|
|
// catalogue problem.
|
|
if (fn === "tc" && a0 && ts.isStringLiteral(a0) && n.arguments[1] && ts.isStringLiteral(n.arguments[1])) {
|
|
// Only the contextual key is required. The plain one is tc()'s
|
|
// fallback, not a second obligation -- asking for both would report
|
|
// work that does not exist.
|
|
wanted.add(`${a0.text}\u0004${n.arguments[1].text}`);
|
|
}
|
|
if (fn === "plural" && n.arguments[1] && ts.isObjectLiteralExpression(n.arguments[1])) {
|
|
for (const p of n.arguments[1].properties) {
|
|
if (ts.isPropertyAssignment(p) && p.name.getText(src) === "other" && ts.isStringLiteral(p.initializer)) wanted.add(p.initializer.text);
|
|
}
|
|
}
|
|
}
|
|
ts.forEachChild(n, visit);
|
|
};
|
|
visit(src);
|
|
}
|
|
|
|
let failed = false;
|
|
for (const file of globSync("web/src/locales/*.ts")) {
|
|
const tag = file.split("/").pop().replace(".ts", "");
|
|
const src = ts.createSourceFile(file, readFileSync(file, "utf8"), ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
|
|
const have = new Set();
|
|
const visit = (n) => {
|
|
if (ts.isPropertyAssignment(n) && ts.isStringLiteral(n.name)) have.add(n.name.text);
|
|
ts.forEachChild(n, visit);
|
|
};
|
|
visit(src);
|
|
const stale = [...have].filter((k) => !wanted.has(k) && !["one", "other", "few", "many", "zero", "two"].includes(k));
|
|
const missing = [...wanted].filter((k) => !have.has(k));
|
|
const pct = Math.round(((wanted.size - missing.length) / wanted.size) * 100);
|
|
console.log(`${tag}: ${wanted.size - missing.length}/${wanted.size} translated (${pct}%), ${missing.length} falling back to English`);
|
|
if (stale.length) {
|
|
failed = true;
|
|
console.log(`\n ${stale.length} STALE key(s) — translated but never looked up, so they do nothing:`);
|
|
for (const k of stale.slice(0, 25)) console.log(` ${JSON.stringify(k)}`);
|
|
if (stale.length > 25) console.log(` …and ${stale.length - 25} more`);
|
|
}
|
|
if (process.argv.includes("--missing")) {
|
|
console.log(`\n missing:`);
|
|
for (const k of missing) console.log(` ${JSON.stringify(k)}`);
|
|
}
|
|
}
|
|
if (failed && process.argv.includes("--check")) process.exit(1);
|