// Interface-language reconciliation. Kept out of app.svelte.ts (a runes module that the // node-env Vitest layer cannot import) so the decision is unit-testable. import type { Locale } from './i18n/catalog'; import type { Profile } from './model'; /** * languageNeedsServerSync reports whether the durable account's `preferred_language` should be * rewritten to the chosen interface `locale`. It is true only for a real (non-guest) account * whose stored language differs from the locale; guests keep only the client-side preference, * and an already-matching account is a no-op. * * The UI language follows the device (the local choice / system guess), but the advertising * banner and out-of-app push routing are resolved server-side from `preferred_language`. A saved * device choice the account has not yet recorded — picked while a guest, or differing from the * Telegram system-language seed — would otherwise leave the banner and pushes in the wrong * language until the next Settings change. Both the Settings control and the on-load reconciler * gate their write on this. */ export function languageNeedsServerSync(profile: Profile | null | undefined, locale: Locale): boolean { return !!profile && !profile.isGuest && profile.preferredLanguage !== locale; }