Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
赵月辉
/
fastgpt-migrated
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Unverified
Commit
64fde42c
authored
Sep 05, 2023
by
archer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
perf: default lang
parent
7a926b70
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
20 deletions
+21
-20
client/next-i18next.config.js
+2
-2
client/src/components/Language/index.tsx
+1
-12
client/src/utils/i18n.ts
+18
-6
No files found.
client/next-i18next.config.js
View file @
64fde42c
...
@@ -5,8 +5,8 @@
...
@@ -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
}
}
};
};
client/src/components/Language/index.tsx
View file @
64fde42c
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
();
...
...
client/src/utils/i18n.ts
View file @
64fde42c
...
@@ -6,6 +6,16 @@ export enum LangEnum {
...
@@ -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 = () => {
...
@@ -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
);
};
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment