Fixed an issue where refreshing the login page caused the language settings to become invalid. #249 (#250)

### What problem does this PR solve?

Fixed an issue where refreshing the login page caused the language
settings to become invalid.

Issue link: #249

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
balibabu
2024-04-08 10:41:03 +08:00
committed by GitHub
parent c829799474
commit d0a1ffe6e2
8 changed files with 26 additions and 22 deletions

View File

@ -1,4 +1,4 @@
import i18next from '@/locales/config';
import { default as i18n, default as i18next } from '@/locales/config';
import { App, ConfigProvider, ConfigProviderProps } from 'antd';
import enUS from 'antd/locale/en_US';
import zhCN from 'antd/locale/zh_CN';
@ -18,8 +18,12 @@ const RootProvider = ({ children }: React.PropsWithChildren) => {
});
useEffect(() => {
i18next.changeLanguage(storage.getLanguage());
}, [locale]);
// Because the language is saved in the backend, a token is required to obtain the api. However, the login page cannot obtain the language through the getUserInfo api, so the language needs to be saved in localstorage.
const lng = storage.getLanguage();
if (lng) {
i18n.changeLanguage(lng);
}
}, []);
return (
<ConfigProvider