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.
69 lines
3.0 KiB
TypeScript
69 lines
3.0 KiB
TypeScript
import { afterEach, describe, expect, it } from "vitest";
|
|
import { isLocalisedName, mailboxDisplayName, mailboxDisplayPath } from "@/lib/mailboxName";
|
|
import { setCatalog, type Catalog } from "@/lib/i18n";
|
|
import type { Mailbox } from "@/jmap/types";
|
|
|
|
/**
|
|
* Stalwart names the standard folders once, at account creation, and never
|
|
* renames them — so a German reader on an English-provisioned account would
|
|
* otherwise see "Deleted Items" in an otherwise German app. The role is what
|
|
* lets ihasmail say "Papierkorb" without writing anything to the server.
|
|
*/
|
|
const de: Catalog = {
|
|
strings: { Inbox: "Posteingang", "Deleted Items": "Papierkorb", Drafts: "Entwürfe" },
|
|
plurals: {},
|
|
};
|
|
const mb = (id: string, name: string, role: string | null = null, parentId: string | null = null) =>
|
|
({ id, name, role, parentId } as unknown as Mailbox);
|
|
|
|
afterEach(() => setCatalog("en", { strings: {}, plurals: {} }));
|
|
|
|
describe("mailboxDisplayName", () => {
|
|
it("is the server's name until a catalogue says otherwise", () => {
|
|
expect(mailboxDisplayName(mb("1", "Deleted Items", "trash"))).toBe("Deleted Items");
|
|
});
|
|
|
|
it("follows the interface language for a folder carrying a role", () => {
|
|
setCatalog("de", de);
|
|
expect(mailboxDisplayName(mb("1", "Deleted Items", "trash"))).toBe("Papierkorb");
|
|
expect(mailboxDisplayName(mb("2", "Inbox", "inbox"))).toBe("Posteingang");
|
|
});
|
|
|
|
it("leaves a folder somebody made alone", () => {
|
|
// "Newsletters" is their word. Translating it would name a folder they
|
|
// never created, and it would not match what any other client shows.
|
|
setCatalog("de", de);
|
|
expect(mailboxDisplayName(mb("3", "Newsletters"))).toBe("Newsletters");
|
|
expect(mailboxDisplayName(mb("4", "Work", "subscribed"))).toBe("Work");
|
|
});
|
|
|
|
it("survives a missing mailbox rather than printing undefined", () => {
|
|
expect(mailboxDisplayName(null)).toBe("");
|
|
expect(mailboxDisplayName(undefined)).toBe("");
|
|
});
|
|
});
|
|
|
|
describe("isLocalisedName", () => {
|
|
it("tells an editor when the name on screen is not the server's", () => {
|
|
// A rename box prefilled with "Papierkorb" would rename the folder to that
|
|
// the moment somebody pressed Save — a real change made by accident.
|
|
expect(isLocalisedName(mb("1", "Deleted Items", "trash"))).toBe(true);
|
|
expect(isLocalisedName(mb("2", "Newsletters"))).toBe(false);
|
|
expect(isLocalisedName(mb("3", "Work", "subscribed"))).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe("mailboxDisplayPath", () => {
|
|
it("localises each part that has a role and leaves the rest", () => {
|
|
setCatalog("de", de);
|
|
const all = { a: mb("a", "Inbox", "inbox"), b: mb("b", "Projects", null, "a") };
|
|
expect(mailboxDisplayPath(all.b!, all)).toBe("Posteingang / Projects");
|
|
});
|
|
|
|
it("stops rather than looping on a parent cycle", () => {
|
|
// A malformed tree from the server must not hang the folder picker.
|
|
const all: Record<string, Mailbox> = { a: mb("a", "A", null, "b"), b: mb("b", "B", null, "a") };
|
|
expect(mailboxDisplayPath(all.a!, all)).toBe("B / A");
|
|
});
|
|
});
|