From 4dc35000b103cbb3bc77e5372da870955b4b473c Mon Sep 17 00:00:00 2001 From: QdabuliuQ <69883552+QdabuliuQ@users.noreply.github.com> Date: Fri, 16 Jan 2026 09:37:26 +0800 Subject: [PATCH] docs: improve site locale detection (#56618) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(Site): improve changelog header styles and locale detection * style: fix link and button style conflicts in typography * style: modify style file * style: reset typography mixins.ts file --------- Co-authored-by: 遇见同学 <1875694521@qq.com> --- .dumirc.ts | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/.dumirc.ts b/.dumirc.ts index 5f64b7d49e..cfde6f212b 100644 --- a/.dumirc.ts +++ b/.dumirc.ts @@ -160,18 +160,27 @@ export default defineConfig({ } // 首页无视链接里面的语言设置 https://github.com/ant-design/ant-design/issues/4552 - if (pathname === '/' || pathname === '/index-cn') { - const lang = - (window.localStorage && localStorage.getItem('locale')) || - ((navigator.language || navigator.browserLanguage).toLowerCase() === 'zh-cn' + const normalizedPathname = pathname || '/'; + if (normalizedPathname === '/' || normalizedPathname === '/index-cn') { + let lang; + if (window.localStorage) { + const antLocale = localStorage.getItem('ANT_LOCAL_TYPE_KEY'); + // 尝试解析 JSON,因为可能是被序列化后存储的 "en-US" / en-US https://github.com/ant-design/ant-design/issues/56606 + try { + lang = antLocale ? JSON.parse(antLocale) : localStorage.getItem('locale'); + } catch (e) { + lang = antLocale ? antLocale : localStorage.getItem('locale'); + } + } + lang = lang || ((navigator.language || navigator.browserLanguage).toLowerCase() === 'zh-cn' ? 'zh-CN' : 'en-US'); // safari is 'zh-cn', while other browser is 'zh-CN'; - if ((lang === 'zh-CN') !== isZhCN(pathname)) { - location.pathname = getLocalizedPathname(pathname, lang === 'zh-CN'); + if ((lang === 'zh-CN') !== isZhCN(normalizedPathname)) { + location.pathname = getLocalizedPathname(normalizedPathname, lang === 'zh-CN'); } } - document.documentElement.className += isZhCN(pathname) ? 'zh-cn' : 'en-us'; + document.documentElement.className += isZhCN(normalizedPathname) ? 'zh-cn' : 'en-us'; })(); `, ],