mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-30 10:28:42 +00:00
Perf: i18n change and captcha code. (#2625)
* perf: send captcha check * perf: back router * perf: i18n init * perf: ui * i18n * perf: ui duration
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import { I18nNsType } from '@fastgpt/web/types/i18next';
|
||||
import { serverSideTranslations } from 'next-i18next/serverSideTranslations';
|
||||
|
||||
export const LANG_KEY = 'NEXT_LOCALE_LANG';
|
||||
export enum LangEnum {
|
||||
'zh' = 'zh',
|
||||
'en' = 'en'
|
||||
@@ -20,24 +19,3 @@ export const langMap = {
|
||||
export const serviceSideProps = (content: any, ns: I18nNsType = []) => {
|
||||
return serverSideTranslations(content.locale, ['common', 'error', ...ns], null, content.locales);
|
||||
};
|
||||
|
||||
export const getLng = (lng: string) => {
|
||||
return lng.split('-')[0];
|
||||
};
|
||||
export const change2DefaultLng = (currentLng: string) => {
|
||||
if (!navigator || !localStorage) return;
|
||||
if (localStorage.getItem(LANG_KEY)) return;
|
||||
const userLang = navigator.language;
|
||||
|
||||
if (userLang.includes(currentLng)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// currentLng not in userLang
|
||||
return getLng(userLang);
|
||||
};
|
||||
|
||||
export const setLngStore = (lng: string) => {
|
||||
if (!localStorage) return;
|
||||
localStorage.setItem(LANG_KEY, lng);
|
||||
};
|
||||
|
@@ -1,17 +1,14 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { clientInitData } from '@/web/common/system/staticData';
|
||||
import { useTranslation } from 'next-i18next';
|
||||
import { useRouter } from 'next/router';
|
||||
import { useSystemStore } from '@/web/common/system/useSystemStore';
|
||||
import type { FastGPTFeConfigsType } from '@fastgpt/global/common/system/types/index.d';
|
||||
import { change2DefaultLng, LangEnum, setLngStore } from '@/web/common/utils/i18n';
|
||||
import { useMemoizedFn, useMount } from 'ahooks';
|
||||
import { TrackEventName } from '../common/system/constants';
|
||||
|
||||
export const useInitApp = () => {
|
||||
const router = useRouter();
|
||||
const { hiId } = router.query as { hiId?: string };
|
||||
const { i18n } = useTranslation();
|
||||
const { loadGitStar, setInitd, feConfigs } = useSystemStore();
|
||||
const [scripts, setScripts] = useState<FastGPTFeConfigsType['scripts']>([]);
|
||||
const [title, setTitle] = useState(process.env.SYSTEM_NAME || 'AI');
|
||||
@@ -38,20 +35,8 @@ export const useInitApp = () => {
|
||||
setInitd();
|
||||
});
|
||||
|
||||
const initUserLanguage = useMemoizedFn(() => {
|
||||
// get default language
|
||||
|
||||
const targetLng =
|
||||
change2DefaultLng(i18n.language) ||
|
||||
(['zh', 'zh-CN'].includes(navigator.language) ? 'zh' : 'en');
|
||||
|
||||
setLngStore(targetLng);
|
||||
router.replace(router.asPath, undefined, { locale: targetLng });
|
||||
});
|
||||
|
||||
useMount(() => {
|
||||
initFetch();
|
||||
initUserLanguage();
|
||||
|
||||
const errorTrack = (event: ErrorEvent) => {
|
||||
window.umami?.track(TrackEventName.windowError, {
|
||||
|
Reference in New Issue
Block a user