initSetI18n.ts
627 Bytes
import { LangEnum } from '@/enums/styleEnum'
import { useLangStore } from '@/store/modules/langStore/langStore'
import { getUrlSearch } from '@/utils'
import { useI18n } from 'vue-i18n'
/**
* * 页面初始化就执行设置语言,浏览器地址栏判断
*/
export const initSetI18n = () => {
const localeKey = getUrlSearch('locale')
const { locale } = useI18n()
const langStore = useLangStore()
const initSetValue = (value: LangEnum) => {
locale.value = value
langStore.changeLang(value)
}
if (localeKey === 'zh_CN') {
initSetValue(LangEnum.ZH)
} else {
initSetValue(LangEnum.EN)
}
}