Merge pull request #13819 from dataease/pr@dev-v2@oerf_i18n

perf: 无用户信息场景使用浏览器默认语言
This commit is contained in:
fit2cloud-chenyw 2024-12-04 15:16:13 +08:00 committed by GitHub
commit 76321fff6f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 15 additions and 10 deletions

View File

@ -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> = 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
}

View File

@ -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: [

View File

@ -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'
}

@ -1 +1 @@
Subproject commit 9b17aadb40750bc71c0ddb816cc62d725a73b208
Subproject commit 850e9137a80862404e0340f1937b96faf8526c99