feat(admin): enhance login form with language switcher and update script handling

- Added AdminLanguageSwitcher to the login form for improved language selection.
- Replaced inline script with next/script component for better performance and safety in layout.tsx.
- Updated language initialization logic to ensure consistent SSR and client rendering.
This commit is contained in:
2026-05-26 09:57:05 +08:00
parent f080e6ba8e
commit fbe385666a
3 changed files with 11 additions and 12 deletions

View File

@@ -6,7 +6,6 @@ import { initReactI18next } from "react-i18next";
import {
adminHtmlLang,
applyAdminUiLocale,
getStoredAdminUiLocale,
hydrateAdminUiLocale,
type AdminApiLocale,
} from "@/lib/admin-locale";
@@ -124,16 +123,9 @@ export function normalizeAdminLanguage(lang: string | undefined): AdminLanguage
}
function getInitialAdminLanguage(): AdminLanguage {
if (typeof window === "undefined") {
return ADMIN_DEFAULT_LANGUAGE;
}
const stored = getStoredAdminUiLocale();
if (stored) {
return stored;
}
return normalizeAdminLanguage(document.documentElement.lang);
// Keep SSR and first client render aligned to avoid hydration mismatch.
// Stored locale is applied after mount in `Providers`.
return ADMIN_DEFAULT_LANGUAGE;
}
function syncAdminLanguage(lang: AdminLanguage): void {