import { resolveLocale, type Locale } from '@wellformed/shared'; /** * The language a request's browser asks for. * * Inside a workspace the workspace's own locale answers, and this is never * consulted. It matters at the edges, where there is no workspace to ask: the * language a brand-new workspace opens in, and the language of mail sent to * someone who is locked out and has no session at all. * * The q-weights are ignored: browsers already send the list in preference * order, and parsing weights buys nothing but a place for a malformed header * to matter. An absent or unreadable header falls through to English. */ export function localeFromHeader(header: string | undefined): Locale { if (!header) return resolveLocale([]); const tags = header .split(',') .map((part) => part.split(';')[0]?.trim() ?? '') .filter(Boolean); return resolveLocale(tags); }