90f0424de2
CI / changes (pull_request) Successful in 2s
CI / unit (pull_request) Has been skipped
CI / integration (pull_request) Has been skipped
CI / ui (pull_request) Successful in 53s
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Successful in 1m18s
The UI language follows the device (the local choice / system guess) and is deliberately not overridden from the account, but the advertising banner and out-of-app push routing are resolved server-side from preferred_language. A saved device choice the account had not recorded — picked while a guest, or differing from the Telegram system-language seed — left the banner (and pushes) in the wrong language until a Settings change rewrote preferred_language. On profile load (adoptSession and the in-place link path) push the saved local choice to the account when it differs (new pure helper languageNeedsServerSync; no-op for guests and when already equal), so the banner and pushes match the visible UI from the first open. Unit-tested.
23 lines
1.3 KiB
TypeScript
23 lines
1.3 KiB
TypeScript
// 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;
|
|
}
|