diff --git a/frontend/packages/common/src/components/aoplatform/LanguageSetting.tsx b/frontend/packages/common/src/components/aoplatform/LanguageSetting.tsx
index 90a20efa..adc69330 100644
--- a/frontend/packages/common/src/components/aoplatform/LanguageSetting.tsx
+++ b/frontend/packages/common/src/components/aoplatform/LanguageSetting.tsx
@@ -4,48 +4,48 @@ import { Icon } from '@iconify/react/dist/iconify.js'
import { Button, Dropdown } from 'antd'
import { memo, useEffect, useMemo } from 'react'
+const LanguageItems = [
+ {
+ key: 'en-US',
+ label: (
+
+ ),
+ title: 'English'
+ },
+ {
+ key: 'ja-JP',
+ label: (
+
+ ),
+ title: '日本語'
+ },
+ {
+ key: 'zh-TW',
+ label: (
+
+ ),
+ title: '繁體中文'
+ },
+ {
+ key: 'zh-CN',
+ label: (
+
+ ),
+ title: '简体中文'
+ }
+]
const LanguageSetting = ({ mode = 'light' }: { mode?: 'dark' | 'light' }) => {
const { dispatch, state } = useGlobalContext()
- const items = [
- {
- key: 'en-US',
- label: (
-
- ),
- title: 'English'
- },
- {
- key: 'ja-JP',
- label: (
-
- ),
- title: '日本語'
- },
- {
- key: 'zh-TW',
- label: (
-
- ),
- title: '繁體中文'
- },
- {
- key: 'zh-CN',
- label: (
-
- ),
- title: '简体中文'
- }
- ]
- const langLabel = useMemo(() => items.find((item) => item?.key === state.language)?.title, [state.language])
+ const langLabel = useMemo(() => LanguageItems.find((item) => item?.key === state.language)?.title, [state.language])
useEffect(() => {
const savedLang = i18n.language || sessionStorage.getItem('i18nextLng')
@@ -53,17 +53,17 @@ const LanguageSetting = ({ mode = 'light' }: { mode?: 'dark' | 'light' }) => {
dispatch({ type: 'UPDATE_LANGUAGE', language: savedLang })
} else if (!savedLang) {
const browserLang = navigator.language
- const supportedLang = items.find((item) => item.key === browserLang) ? browserLang : 'zh-CN'
+ const supportedLang = LanguageItems.find((item) => item.key === browserLang) ? browserLang : 'zh-CN'
+ if (state.language === supportedLang) return
dispatch({ type: 'UPDATE_LANGUAGE', language: supportedLang })
i18n.changeLanguage(supportedLang)
}
}, [])
-
return (
{
const { key } = e
diff --git a/frontend/packages/common/src/contexts/GlobalStateContext.tsx b/frontend/packages/common/src/contexts/GlobalStateContext.tsx
index da730fa6..31fbb1d4 100644
--- a/frontend/packages/common/src/contexts/GlobalStateContext.tsx
+++ b/frontend/packages/common/src/contexts/GlobalStateContext.tsx
@@ -342,7 +342,7 @@ export const GlobalProvider: FC<{ children: ReactNode }> = ({ children }) => {
updateDate: '2024-07-01',
powered: 'Powered by https://apipark.com',
mainPage: '/guide/page',
- language: 'en-US',
+ language: sessionStorage.getItem('i18nextLng') || 'en-US',
pluginsLoaded: false
})
const [accessData, setAccessData] = useState