feat(i18n): 增强管理端多语言支持,优化语言初始化与恢复逻辑
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user