From 81b66d31701ed4a2231aabaa94738efbe4c496bb Mon Sep 17 00:00:00 2001 From: Maurice Date: Sat, 28 Nov 2026 00:30:01 +0100 Subject: [PATCH] fix(native): keep a chosen language on the app sign-in screen The sign-in screen in the app now speaks the device language only when no language was chosen before, so the screen and the signed-in session match what the next launch shows. --- client/src/pages/login/useLogin.native.test.tsx | 14 +++++++++++--- client/src/pages/login/useLogin.ts | 10 +++++----- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/client/src/pages/login/useLogin.native.test.tsx b/client/src/pages/login/useLogin.native.test.tsx index 352d6a7b3..a7c43a1bf 100644 --- a/client/src/pages/login/useLogin.native.test.tsx +++ b/client/src/pages/login/useLogin.native.test.tsx @@ -1,4 +1,4 @@ -// FE-LOGIN-NATIVE-001 to FE-LOGIN-NATIVE-011: useLogin inside the iOS/Android app +// FE-LOGIN-NATIVE-001 to FE-LOGIN-NATIVE-012: useLogin inside the iOS/Android app import { startAuthentication } from '@simplewebauthn/browser'; import { http, HttpResponse } from 'msw'; import React from 'react'; @@ -166,8 +166,7 @@ describe('useLogin in the native app', () => { expect(result.current.showTakeoff).toBe(false); }); - it('FE-LOGIN-NATIVE-009: speaks the device language, over a language once picked on this page', async () => { - localStorage.setItem('app_language', 'fr'); + it('FE-LOGIN-NATIVE-009: speaks the device language when no language was chosen', async () => { deviceLanguages(['de-DE', 'en-US']); renderLogin(); await waitFor(() => expect(useSettingsStore.getState().settings.language).toBe('de')); @@ -190,4 +189,13 @@ describe('useLogin in the native app', () => { await waitFor(() => expect(mockNavigate).toHaveBeenCalledWith('/'), { timeout: 2500 }); expect(document.documentElement.hasAttribute('data-app-handover')).toBe(true); }); + + it('FE-LOGIN-NATIVE-012: keeps a language once picked on this page over the device language', async () => { + localStorage.setItem('app_language', 'fr'); + useSettingsStore.setState((state) => ({ settings: { ...state.settings, language: 'fr' } })); + deviceLanguages(['de-DE', 'en-US']); + const { result } = renderLogin(); + await waitFor(() => expect(result.current.appConfig).not.toBeNull()); + expect(useSettingsStore.getState().settings.language).toBe('fr'); + }); }); diff --git a/client/src/pages/login/useLogin.ts b/client/src/pages/login/useLogin.ts index 42b718253..ba76b0b87 100644 --- a/client/src/pages/login/useLogin.ts +++ b/client/src/pages/login/useLogin.ts @@ -300,16 +300,16 @@ export function useLogin() { // 2. Browser/OS language (navigator.languages) // 3. Server default (DEFAULT_LANGUAGE env var) // 4. 'en' → hardcoded fallback already in store - // Inside the iOS and Android app the sign-in screen has no language menu: it - // speaks the device's language, as the address screen before it does, and - // English where TREK has no translation for it. The account's own language - // takes over once signed in. + // Inside the iOS and Android app the sign-in screen has no language menu: unless + // a language was chosen before, it speaks the device's language, as the address + // screen before it does, and English where TREK has no translation for it. The + // account's own language takes over once signed in. useEffect(() => { + if (hasStoredLanguage()) return if (nativeApp) { setLanguageTransient(detectBrowserLanguage() ?? 'en') return } - if (hasStoredLanguage()) return const detected = detectBrowserLanguage() if (detected) {