feat(i18n): 增强管理端多语言支持,优化语言初始化与恢复逻辑

This commit is contained in:
2026-05-25 14:53:15 +08:00
parent ddedef824e
commit 84bf924378
4 changed files with 56 additions and 9 deletions

View File

@@ -13,13 +13,29 @@ type ProvidersProps = {
children: ReactNode;
};
function applyStoredAdminLanguage() {
const locale = hydrateAdminUiLocale();
if (!locale) {
return;
}
const current = i18n.resolvedLanguage ?? i18n.language;
if (locale !== current) {
void i18n.changeLanguage(locale);
}
}
function AdminSessionHydrator() {
useEffect(() => {
const locale = hydrateAdminUiLocale();
if (locale && i18n.resolvedLanguage !== locale) {
void i18n.changeLanguage(locale);
if (i18n.isInitialized) {
applyStoredAdminLanguage();
} else {
i18n.on("initialized", applyStoredAdminLanguage);
}
useAdminSessionStore.getState().rehydrate();
return () => {
i18n.off("initialized", applyStoredAdminLanguage);
};
}, []);
return null;