mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-27 16:33:49 +00:00
feat: i18n
This commit is contained in:
@@ -8,11 +8,12 @@ import { theme } from '@/constants/theme';
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
||||
import NProgress from 'nprogress'; //nprogress module
|
||||
import Router from 'next/router';
|
||||
import { clientInitData, feConfigs } from '@/store/static';
|
||||
import { appWithTranslation } from 'next-i18next';
|
||||
import { setLangStore } from '@/utils/i18n';
|
||||
|
||||
import 'nprogress/nprogress.css';
|
||||
import '@/styles/reset.scss';
|
||||
import { clientInitData, feConfigs } from '@/store/static';
|
||||
import { NextPageContext } from 'next';
|
||||
import { useGlobalStore } from '@/store/global';
|
||||
|
||||
//Binding events.
|
||||
Router.events.on('routeChangeStart', () => NProgress.start());
|
||||
@@ -30,14 +31,9 @@ const queryClient = new QueryClient({
|
||||
}
|
||||
});
|
||||
|
||||
function App({ Component, pageProps, isPc }: AppProps & { isPc?: boolean; response: any }) {
|
||||
function App({ Component, pageProps }: AppProps) {
|
||||
const [googleClientVerKey, setGoogleVerKey] = useState<string>();
|
||||
const [baiduTongji, setBaiduTongji] = useState<string>();
|
||||
const { initIsPc } = useGlobalStore();
|
||||
|
||||
// if (isPc !== undefined) {
|
||||
// initIsPc(isPc);
|
||||
// }
|
||||
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
@@ -47,12 +43,14 @@ function App({ Component, pageProps, isPc }: AppProps & { isPc?: boolean; respon
|
||||
setGoogleVerKey(googleClientVerKey);
|
||||
setBaiduTongji(baiduTongji);
|
||||
})();
|
||||
|
||||
setLangStore('en');
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
<title>{feConfigs?.systemTitle || 'AI知识库'}</title>
|
||||
<title>{feConfigs?.systemTitle || 'FastAI'}</title>
|
||||
<meta name="description" content="Embedding + LLM, Build AI knowledge base" />
|
||||
<meta
|
||||
name="viewport"
|
||||
@@ -85,12 +83,4 @@ function App({ Component, pageProps, isPc }: AppProps & { isPc?: boolean; respon
|
||||
);
|
||||
}
|
||||
|
||||
App.getInitialProps = async ({ ctx }: { ctx: NextPageContext }) => {
|
||||
const reg = /mobile/gi;
|
||||
|
||||
const isPc = !reg.test(ctx.req?.headers?.['user-agent'] || '');
|
||||
|
||||
return { isPc };
|
||||
};
|
||||
|
||||
export default App;
|
||||
export default appWithTranslation(App);
|
||||
|
@@ -4,6 +4,8 @@ import { useRouter } from 'next/router';
|
||||
import { useGlobalStore } from '@/store/global';
|
||||
import { beianText } from '@/store/static';
|
||||
import { feConfigs } from '@/store/static';
|
||||
import { serviceSideProps } from '@/utils/i18n';
|
||||
import { useTranslation } from 'next-i18next';
|
||||
|
||||
import styles from './index.module.scss';
|
||||
import axios from 'axios';
|
||||
@@ -11,6 +13,7 @@ import MyIcon from '@/components/Icon';
|
||||
|
||||
const Home = () => {
|
||||
const router = useRouter();
|
||||
const { t } = useTranslation();
|
||||
const { inviterId } = router.query as { inviterId: string };
|
||||
const { isPc } = useGlobalStore();
|
||||
const [star, setStar] = useState(1500);
|
||||
@@ -157,9 +160,11 @@ const Home = () => {
|
||||
<Flex
|
||||
flexDirection={'column'}
|
||||
alignItems={'center'}
|
||||
justifyContent={'center'}
|
||||
mt={'22vh'}
|
||||
position={'absolute'}
|
||||
userSelect={'none'}
|
||||
textAlign={'center'}
|
||||
>
|
||||
<Image src="/icon/logo2.png" w={['70px', '120px']} h={['70px', '120px']} alt={''}></Image>
|
||||
<Box
|
||||
@@ -171,10 +176,10 @@ const Home = () => {
|
||||
{feConfigs?.systemTitle || 'AI知识库'}
|
||||
</Box>
|
||||
<Box className={styles.textlg} fontWeight={'bold'} fontSize={['30px', '50px']}>
|
||||
可视化 AI 编排
|
||||
{t('home.Visual AI orchestration')}
|
||||
</Box>
|
||||
<Box className={styles.textlg} fontWeight={'bold'} fontSize={['30px', '50px']}>
|
||||
快速搭建 AI 问答库
|
||||
{t('home.Quickly build AI question and answer library')}
|
||||
</Box>
|
||||
|
||||
<Flex flexDirection={['column', 'row']} my={5}>
|
||||
@@ -205,7 +210,7 @@ const Home = () => {
|
||||
py={[2, 3]}
|
||||
onClick={() => router.push(`/app/list`)}
|
||||
>
|
||||
立即开始
|
||||
{t('home.Start Now')}
|
||||
</Button>
|
||||
</Flex>
|
||||
</Flex>
|
||||
@@ -227,4 +232,12 @@ const Home = () => {
|
||||
);
|
||||
};
|
||||
|
||||
export async function getServerSideProps(content: any) {
|
||||
return {
|
||||
props: {
|
||||
...(await serviceSideProps(content))
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export default Home;
|
||||
|
29
client/src/utils/i18n.ts
Normal file
29
client/src/utils/i18n.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { serverSideTranslations } from 'next-i18next/serverSideTranslations';
|
||||
import Cookies from 'js-cookie';
|
||||
|
||||
export const LANG_KEY = 'NEXT_LOCALE_LANG';
|
||||
export enum LangEnum {
|
||||
'zh' = 'zh',
|
||||
'en' = 'en'
|
||||
}
|
||||
|
||||
export const setLangStore = (value: `${LangEnum}`) => {
|
||||
return Cookies.set(LANG_KEY, value, { expires: 7, sameSite: 'None', secure: true });
|
||||
};
|
||||
|
||||
export const getLangStore = () => {
|
||||
return Cookies.get(LANG_KEY) || LangEnum.zh;
|
||||
};
|
||||
|
||||
export const removeLangStore = () => {
|
||||
Cookies.remove(LANG_KEY);
|
||||
};
|
||||
|
||||
export const serviceSideProps = (content: any) => {
|
||||
return serverSideTranslations(
|
||||
content.req.cookies[LANG_KEY] || 'en',
|
||||
undefined,
|
||||
null,
|
||||
content.locales
|
||||
);
|
||||
};
|
Reference in New Issue
Block a user