mirror of
https://github.com/labring/FastGPT.git
synced 2025-10-21 19:42:07 +00:00
perf: default lang
This commit is contained in:
@@ -5,8 +5,8 @@
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
i18n: {
|
i18n: {
|
||||||
defaultLocale: 'en',
|
defaultLocale: 'zh',
|
||||||
locales: ['en', 'zh', 'zh-Hans'],
|
locales: ['en', 'zh', 'zh-Hans', 'zh-CN'],
|
||||||
localeDetection: false
|
localeDetection: false
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@@ -1,21 +1,10 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import { Menu, MenuButton, MenuItem, MenuList, MenuButtonProps } from '@chakra-ui/react';
|
import { Menu, MenuButton, MenuItem, MenuList, MenuButtonProps } from '@chakra-ui/react';
|
||||||
import { getLangStore, LangEnum, setLangStore } from '@/utils/i18n';
|
import { getLangStore, LangEnum, setLangStore, langMap } from '@/utils/i18n';
|
||||||
import MyIcon from '@/components/Icon';
|
import MyIcon from '@/components/Icon';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { useRouter } from 'next/router';
|
import { useRouter } from 'next/router';
|
||||||
|
|
||||||
const langMap = {
|
|
||||||
[LangEnum.en]: {
|
|
||||||
label: 'English',
|
|
||||||
icon: 'language_en'
|
|
||||||
},
|
|
||||||
[LangEnum.zh]: {
|
|
||||||
label: '简体中文',
|
|
||||||
icon: 'language_zh'
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const Language = (props: MenuButtonProps) => {
|
const Language = (props: MenuButtonProps) => {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { i18n } = useTranslation();
|
const { i18n } = useTranslation();
|
||||||
|
@@ -6,6 +6,16 @@ export enum LangEnum {
|
|||||||
'zh' = 'zh',
|
'zh' = 'zh',
|
||||||
'en' = 'en'
|
'en' = 'en'
|
||||||
}
|
}
|
||||||
|
export const langMap = {
|
||||||
|
[LangEnum.en]: {
|
||||||
|
label: 'English',
|
||||||
|
icon: 'language_en'
|
||||||
|
},
|
||||||
|
[LangEnum.zh]: {
|
||||||
|
label: '简体中文',
|
||||||
|
icon: 'language_zh'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
export const setLangStore = (value: `${LangEnum}`) => {
|
export const setLangStore = (value: `${LangEnum}`) => {
|
||||||
return Cookies.set(LANG_KEY, value, { expires: 7, sameSite: 'None', secure: true });
|
return Cookies.set(LANG_KEY, value, { expires: 7, sameSite: 'None', secure: true });
|
||||||
@@ -16,10 +26,12 @@ export const getLangStore = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const serviceSideProps = (content: any) => {
|
export const serviceSideProps = (content: any) => {
|
||||||
return serverSideTranslations(
|
const acceptLanguage = (content.req.headers['accept-language'] as string) || '';
|
||||||
content.req.cookies[LANG_KEY] || 'en',
|
const acceptLanguageList = acceptLanguage.split(/,|;/g);
|
||||||
undefined,
|
// @ts-ignore
|
||||||
null,
|
const firstLang = acceptLanguageList.find((lang) => langMap[lang]);
|
||||||
content.locales
|
|
||||||
);
|
const language = content.req.cookies[LANG_KEY] || firstLang || 'zh';
|
||||||
|
|
||||||
|
return serverSideTranslations(language, undefined, null, content.locales);
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user