Guard language switching failures (#1002)

This commit is contained in:
ZacharyZcR
2026-07-10 08:01:48 +08:00
committed by GitHub
parent 57effd2405
commit d908d9dc57
6 changed files with 80 additions and 37 deletions
+6 -6
View File
@@ -41,7 +41,7 @@ import type { SSOProviderPublic } from "@/types/index";
import { ElectronServerConfig as ServerConfigComponent } from "@/auth/ElectronServerConfig";
import { ElectronLoginForm } from "@/auth/ElectronLoginForm";
import { Checkbox } from "@/components/checkbox";
import i18n from "@/i18n/i18n";
import { changeAppLanguage, normalizeLanguageCode } from "@/i18n/i18n";
import {
removeSilentSigninFromSearch,
shouldTriggerSilentSignin,
@@ -238,14 +238,14 @@ export function Auth({ onLogin }: AuthProps) {
const [confirmNewPassword, setConfirmNewPassword] = useState("");
const [resetTempToken, setResetTempToken] = useState("");
const [language, setLanguage] = useState(
() => localStorage.getItem("i18nextLng") ?? "en",
const [language, setLanguage] = useState(() =>
normalizeLanguageCode(localStorage.getItem("i18nextLng")),
);
function handleLanguageChange(code: string) {
setLanguage(code);
localStorage.setItem("i18nextLng", code);
i18n.changeLanguage(code);
void changeAppLanguage(code)
.then((language) => setLanguage(language))
.catch(() => {});
}
const [registrationAllowed, setRegistrationAllowed] = useState(true);