import { FALLBACK_LANGUAGE, normalizeLanguage } from './locale.js' /** * Switch the signed-in user's language: the screen changes at once, then the choice is * saved to their profile (PATCH /api/auth/me {language}) through `save`, which the app * provides (its API client; @xenia/api from 2.5). Pass `language: null` to go back to * inheriting (device → venue), with `fallback` = the language to show then. * If saving fails the screen keeps the new language and the error is rethrown, so the * caller can say "changed here, not saved". */ export async function setUserLanguage(i18n, language, { save, fallback } = {}) { const lng = normalizeLanguage(language) if (language && !lng) throw new Error(`unsupported language "${language}"`) await i18n.changeLanguage(lng || normalizeLanguage(fallback) || FALLBACK_LANGUAGE) if (save) await save(lng ?? '') return i18n.language }