diff --git a/core/core-frontend/src/config/axios/service.ts b/core/core-frontend/src/config/axios/service.ts index 0fb7cb03db..84e7ddd3d9 100644 --- a/core/core-frontend/src/config/axios/service.ts +++ b/core/core-frontend/src/config/axios/service.ts @@ -14,7 +14,7 @@ import { useEmbedded } from '@/store/modules/embedded' import { useLinkStoreWithOut } from '@/store/modules/link' import { config } from './config' import { configHandler } from './refresh' -import { isMobile } from '@/utils/utils' +import { isMobile, getLocale } from '@/utils/utils' import { useRequestStoreWithOut } from '@/store/modules/request' type AxiosErrorWidthLoading = T & { config: { @@ -120,9 +120,9 @@ service.interceptors.request.use( } else if (embeddedStore.token) { ;(config.headers as AxiosRequestHeaders)['X-EMBEDDED-TOKEN'] = embeddedStore.token } - if (wsCache.get('user.language')) { - const key = wsCache.get('user.language') - const val = mapping[key] || key + const locale = getLocale() + if (locale) { + const val = mapping[locale] || locale ;(config.headers as AxiosRequestHeaders)['Accept-Language'] = val } diff --git a/core/core-frontend/src/store/modules/locale.ts b/core/core-frontend/src/store/modules/locale.ts index d86ad10664..4e90e50279 100644 --- a/core/core-frontend/src/store/modules/locale.ts +++ b/core/core-frontend/src/store/modules/locale.ts @@ -1,12 +1,10 @@ import { defineStore } from 'pinia' import { store } from '../index' -import { useCache } from '@/hooks/web/useCache' import type { LocaleDropdownType } from 'types/localeDropdown' import zhCn from 'element-plus-secondary/es/locale/lang/zh-cn' import en from 'element-plus-secondary/es/locale/lang/en' import tw from 'element-plus-secondary/es/locale/lang/zh-tw' - -const { wsCache } = useCache() +import { getLocale } from '@/utils/utils' const elLocaleMap = { 'zh-CN': zhCn, @@ -22,8 +20,8 @@ export const useLocaleStore = defineStore('locales', { state: (): LocaleState => { return { currentLocale: { - lang: wsCache.get('user.language') || 'zh-CN', - elLocale: elLocaleMap[wsCache.get('user.language') || 'zh-CN'] + lang: getLocale(), + elLocale: elLocaleMap[getLocale()] }, // 多语言 localeMap: [ diff --git a/core/core-frontend/src/utils/utils.ts b/core/core-frontend/src/utils/utils.ts index e5c8c52306..ab560fb2a3 100644 --- a/core/core-frontend/src/utils/utils.ts +++ b/core/core-frontend/src/utils/utils.ts @@ -218,3 +218,10 @@ export const formatExt = (num: number): number[] | null => { const reversedNumArray = reversedStr?.split('')?.map(Number) ?? [] return reversedNumArray } + +export const getBrowserLocale = () => { + return navigator.language +} +export const getLocale = () => { + return wsCache.get('user.language') || getBrowserLocale() || 'zh-CN' +} diff --git a/de-xpack b/de-xpack index 9b17aadb40..850e9137a8 160000 --- a/de-xpack +++ b/de-xpack @@ -1 +1 @@ -Subproject commit 9b17aadb40750bc71c0ddb816cc62d725a73b208 +Subproject commit 850e9137a80862404e0340f1937b96faf8526c99