mirror of
https://github.com/labring/FastGPT.git
synced 2025-08-02 12:48:30 +00:00
feat: i18n
This commit is contained in:
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