From ae11cfd5b2905cc8cef0184c7b3cf65e832fd387 Mon Sep 17 00:00:00 2001 From: hzj <1304805162@qq.com> Date: Thu, 27 Nov 2025 14:58:37 +0800 Subject: [PATCH] =?UTF-8?q?feat(js=E5=85=A5=E5=8F=A3=E6=96=87=E4=BB=B6):?= =?UTF-8?q?=20=E8=B0=83=E6=95=B4=E6=8E=A5=E6=94=B6lang=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E7=9A=84=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main.js b/src/main.js index ecb0640..2e6a292 100644 --- a/src/main.js +++ b/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)