提交 fcc7b18d 编写于 作者: D DCloud_LXH

feat: remember language

上级 f6c43394
......@@ -171,7 +171,10 @@ export const navbarLanguage = {
},
{
text: 'English',
link: 'https://en.uniapp.dcloud.io/'
link: 'https://en.uniapp.dcloud.io/',
click() {
localStorage.setItem(window.__UNI_DOCS_ZH_KEY__ || 'unidocs-zh-language', 'en')
}
}
]
}
\ No newline at end of file
const { host, pathname } = location
var { host, pathname } = location
var LOCAL_ZH = 'zh'
var LOCAL_EN = 'en'
var website_ZH_host = 'uniapp.dcloud.net.cn'
var website_EN_host = 'en.uniapp.dcloud.io'
var website_ZH = 'https://' + website_ZH_host;
var website_EN = 'https://' + website_EN_host;
window.__UNI_DOCS_ZH_KEY__ = 'unidocs-zh-language'
if (host === 'uniapp.dcloud.io') {
var website_ZH = 'https://uniapp.dcloud.net.cn';
var website_EN = 'https://en.uniapp.dcloud.io';
var localStorageLanguage = localStorage.getItem(window.__UNI_DOCS_ZH_KEY__)
if (localStorageLanguage) {
switch (localStorageLanguage) {
case LOCAL_ZH:
if (host !== website_ZH_host) {
window.location.href = website_ZH + pathname;
}
break;
case LOCAL_EN:
if (host !== website_EN_host) {
window.location.href = website_EN + pathname;
}
break;
default:
break;
}
} else {
var website_finally =
navigator.language.indexOf('zh') !== -1
? website_ZH
: website_EN;
window.location.href = website_finally + pathname;
}
}
\ No newline at end of file
......@@ -31,6 +31,6 @@
},
"dependencies": {
"@docsearch/js": "^3.1.0",
"vuepress-theme-uni-app-test": "^1.2.1"
"vuepress-theme-uni-app-test": "^1.2.2"
}
}
\ No newline at end of file
......@@ -8503,10 +8503,10 @@ vuepress-theme-uni-app-test@^1.2.0:
vuepress-plugin-juejin-style-copy "^1.0.4"
vuepress-theme-uni-app-test "^1.1.9"
vuepress-theme-uni-app-test@^1.2.1:
version "1.2.1"
resolved "https://registry.yarnpkg.com/vuepress-theme-uni-app-test/-/vuepress-theme-uni-app-test-1.2.1.tgz#e18b97bb6bd72bd40432260e014562a04081a245"
integrity sha512-BYeiRRUWi5hR9yNOBlsrrC47/XGCOi7+a0Km1ebKE/IrIw5uCIpyQt1XEU9HXdmtDfFBH3Wu0ecQ/W2R4clvUw==
vuepress-theme-uni-app-test@^1.2.2:
version "1.2.2"
resolved "https://registry.yarnpkg.com/vuepress-theme-uni-app-test/-/vuepress-theme-uni-app-test-1.2.2.tgz#a570cda549d6082d300a8ec53eb65cbaafb96e9b"
integrity sha512-ciw6DyfTc8czeq0KzGtx9SLUzuxGv6ZD60spb/ODoa6LYxXqXlYpnDtilPmxcQDKAISRv246w3MWFt74rxayaA==
dependencies:
"@vuepress/plugin-back-to-top" "^1.9.5"
"@vuepress/theme-default" "^1.8.2"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册