2024-04-07 17:41:29 +08:00
|
|
|
import i18next from '@/locales/config';
|
|
|
|
import { App, ConfigProvider, ConfigProviderProps } from 'antd';
|
|
|
|
import enUS from 'antd/locale/en_US';
|
|
|
|
import zhCN from 'antd/locale/zh_CN';
|
|
|
|
import React, { ReactNode, useEffect, useState } from 'react';
|
|
|
|
import storage from './utils/authorizationUtil';
|
|
|
|
|
|
|
|
type Locale = ConfigProviderProps['locale'];
|
|
|
|
|
|
|
|
const RootProvider = ({ children }: React.PropsWithChildren) => {
|
|
|
|
const getLocale = (lng: string) => (lng === 'zh' ? zhCN : enUS);
|
|
|
|
|
|
|
|
const [locale, setLocal] = useState<Locale>(getLocale(storage.getLanguage()));
|
|
|
|
|
|
|
|
i18next.on('languageChanged', function (lng: string) {
|
|
|
|
storage.setLanguage(lng);
|
|
|
|
setLocal(getLocale(lng));
|
|
|
|
});
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
i18next.changeLanguage(storage.getLanguage());
|
|
|
|
}, [locale]);
|
2024-01-29 15:02:27 +08:00
|
|
|
|
2024-04-02 15:44:09 +08:00
|
|
|
return (
|
|
|
|
<ConfigProvider
|
|
|
|
theme={{
|
2024-03-20 18:20:42 +08:00
|
|
|
token: {
|
|
|
|
fontFamily: 'Inter',
|
|
|
|
},
|
2024-04-02 15:44:09 +08:00
|
|
|
}}
|
2024-04-07 17:41:29 +08:00
|
|
|
locale={locale}
|
2024-04-02 15:44:09 +08:00
|
|
|
>
|
2024-04-07 17:41:29 +08:00
|
|
|
<App> {children}</App>
|
2024-04-02 15:44:09 +08:00
|
|
|
</ConfigProvider>
|
2024-03-20 18:20:42 +08:00
|
|
|
);
|
2024-04-07 17:41:29 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
export function rootContainer(container: ReactNode) {
|
|
|
|
return <RootProvider>{container}</RootProvider>;
|
2024-01-29 15:02:27 +08:00
|
|
|
}
|