feat(js入口文件): 调整接收lang参数的判断

This commit is contained in:
hzj 2025-11-27 14:58:37 +08:00
parent 3fb445534b
commit ae11cfd5b2

View File

@ -63,6 +63,15 @@ const queryParams = hashPath.split('?')[1]
const urlParams = queryParams ? new URLSearchParams(queryParams) : new URLSearchParams()
const langParam = urlParams.get('lang')
let finalLang = null // 最终使用的语言
if (langParam) {
if (langParam === 'en') {
finalLang = 'en'
} else if (langParam.startsWith('ar-')) {
finalLang = 'ar'
}
}
// 检查当前页面是否在固定英语的页面列表中
if (enPages.includes(currentPage)) {
// 强制设置为英语不受URL参数影响
@ -74,10 +83,10 @@ else if (arPages.includes(currentPage)) {
setLocale(langStore, 'ar')
}
// 对于其他页面如果有URL参数则按参数设置语言
else if (langParam) {
else if (finalLang) {
console.log('langParam', langParam)
setLocale(langStore, langParam)
console.log('finalLang', finalLang)
setLocale(langStore, finalLang)
}
initI18n(langStore)