// Maps a system-mail message (lifecycle hook) to its i18n title key. // Kept as a typed helper so the thread-list and detail panes pick the // same title even when the body templates evolve. import type { TranslationKey } from "$lib/i18n/index.svelte"; import type { MailMessage } from "../../../api/diplomail"; const KEYWORDS: Array<{ test: RegExp; key: TranslationKey }> = [ { test: /game[._ ]paused/i, key: "game.mail.system.game_paused.title" }, { test: /game[._ ]cancelled|cancelled/i, key: "game.mail.system.game_cancelled.title" }, { test: /membership[._ ]removed|kicked/i, key: "game.mail.system.membership_removed.title" }, { test: /membership[._ ]blocked|blocked/i, key: "game.mail.system.membership_blocked.title" }, ]; /** * systemTitleKey returns the localised title key for a system mail * row. The lobby renders these messages through templated subjects; * the UI matches on the subject to pick a canonical title regardless * of language. Falls back to a generic system-mail title when no * pattern matches. */ export function systemTitleKey(message: MailMessage): TranslationKey { const subject = message.subject ?? ""; for (const { test, key } of KEYWORDS) { if (test.test(subject)) { return key; } } return "game.mail.system.generic.title"; }