mirror of
https://github.com/ant-design/ant-design.git
synced 2026-02-08 18:39:20 +08:00
docs: improve site locale detection (#56618)
* 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>
This commit is contained in:
23
.dumirc.ts
23
.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';
|
||||
})();
|
||||
`,
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user