feat(js入口文件): 调整接收lang参数的判断
This commit is contained in:
parent
3fb445534b
commit
ae11cfd5b2
15
src/main.js
15
src/main.js
@ -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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user