Add a Swedish interface with a per-person language switch

A small translation system (the English text is its own key, so anything
without a Swedish entry stays English) and a Language switch in the user menu,
saved on the account (users.language) and following the browser when no choice
has been made. Swedish covers the menu, shared parts (search, tables, dialogs,
relative times), the sign-in page and the everyday pages: Dashboard, Alerts,
Servers, Updates, Maintenance, My work, Coming up, To do, Integrations and the
display settings. Server-written messages stay English for now.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
bobbanandClaude Sonnet 5.5 committed 2026-11-12 21:49:49 +01:00
1 parent e7f23ba13f
commit 645816d5a8
168 files changed
+12142 -1422

No files matched your search

+2
View File
@@ -32,6 +32,8 @@ export const users = sqliteTable("users", {
// The address of the picture the identity provider gave for this person (the OIDC "picture" claim), as of their last sign-in. Only an address:
// nothing is fetched from it unless Settings → Sign-in → Profile pictures allows it, and then only by this server, never by the browser.
pictureUrl: text("picture_url"),
// The language this person chose for the interface: "en" or "sv". Null: they have not chosen, so the browser's language decides. Follows them to any browser.
language: text("language"),
});
// ─── Audit log ──────────────────────────────────────────────────────────────
+17 -2
View File
@@ -11,6 +11,13 @@ import { getSettings } from "../services/settingsStore.js";
export const meRouter = Router();
/** The languages the interface is written in. */
export const LANGUAGES = ["en", "sv"] as const;
export type Language = (typeof LANGUAGES)[number];
/** What is stored, read back as a language; anything else is "no choice yet". */
export const parseLanguage = (stored: string | null | undefined): Language | null => (LANGUAGES as readonly string[]).includes(stored ?? "") ? (stored as Language) : null;
/** The most pages anyone can pin: enough for a working set, not a second menu. */
export const MAX_FAVORITES = 24;
@@ -40,9 +47,9 @@ export function parseDashboardLayout(stored: string | null): DashboardLayout {
meRouter.get("/", requireAuth, asyncHandler(async (req, res) => {
const me = req.currentUser!;
const { id, email, name, role, oidcSub, favorites, dashboardLayout, serverPageLayout } = me;
const { id, email, name, role, oidcSub, favorites, dashboardLayout, serverPageLayout, language } = me;
const avatarUrl = avatarUrlFor(me, (await getSettings()).profilePictures);
res.json({ user: { id, sub: oidcSub, email, name, role, avatarUrl, favorites: parseFavorites(favorites), dashboard: parseDashboardLayout(dashboardLayout), serverPage: parsePageLayout(serverPageLayout) } });
res.json({ user: { id, sub: oidcSub, email, name, role, avatarUrl, favorites: parseFavorites(favorites), dashboard: parseDashboardLayout(dashboardLayout), serverPage: parsePageLayout(serverPageLayout), language: parseLanguage(language) } });
}));
// Paths inside the app only: a slash, then letters, digits, dashes, underscores and further slashes — and, for a saved view of a page,
@@ -93,6 +100,14 @@ export function parsePageLayout(stored: string | null): PageLayout {
}
}
// The language of the signed-in person's interface: "en" or "sv", or null to go back to following the browser. Only ever their own.
meRouter.put("/language", requireAuth, asyncHandler(async (req, res) => {
const parsed = z.object({ language: z.enum(LANGUAGES).nullable() }).safeParse(req.body);
if (!parsed.success) return res.status(400).json({ error: "invalid_body", message: "Choose en or sv, or null for the browser's language." });
await db.update(users).set({ language: parsed.data.language }).where(eq(users.id, req.currentUser!.id));
res.json({ language: parsed.data.language });
}));
// Replaces the signed-in person's pinned pages. Only ever their own.
meRouter.put("/favorites", requireAuth, asyncHandler(async (req, res) => {
const parsed = favoritesSchema.safeParse(req.body);