diff --git a/docs/markdown/intro.en-US.md b/docs/markdown/home.en-US.md similarity index 100% rename from docs/markdown/intro.en-US.md rename to docs/markdown/home.en-US.md diff --git a/docs/markdown/intro.zh-CN.md b/docs/markdown/home.zh-CN.md similarity index 100% rename from docs/markdown/intro.zh-CN.md rename to docs/markdown/home.zh-CN.md diff --git a/packages/vant-cli/site/common/locales.js b/packages/vant-cli/site/common/locales.js new file mode 100644 index 000000000..bb5661e41 --- /dev/null +++ b/packages/vant-cli/site/common/locales.js @@ -0,0 +1,30 @@ +const ZH_CN = 'zh-CN'; +const EN_US = 'en-US'; +const CACHE_KEY = 'vant-cli-lang'; + +let currentLang = ZH_CN; + +export function getLang() { + return currentLang; +} + +export function setLang(lang) { + currentLang = lang; + localStorage.setItem(CACHE_KEY, lang); +} + +export function setDefaultLang(langFromConfig) { + const cached = localStorage.getItem(CACHE_KEY); + + if (cached) { + currentLang = cached; + return; + } + + if (navigator.language && navigator.language.indexOf('zh-') !== -1) { + currentLang = ZH_CN; + return; + } + + currentLang = langFromConfig || EN_US; +} diff --git a/packages/vant-cli/site/desktop/App.vue b/packages/vant-cli/site/desktop/App.vue index a5db140fa..c61ff6d26 100644 --- a/packages/vant-cli/site/desktop/App.vue +++ b/packages/vant-cli/site/desktop/App.vue @@ -10,21 +10,38 @@ import VanDoc from './components'; import { config } from 'site-desktop-shared'; +function getPublicPath() { + const { site } = config.build || {}; + + if (process.env.NODE_ENV === 'production') { + return (site && site.publicPath) || '/'; + } + + return '/'; +} + export default { components: { VanDoc }, data() { - const { site } = config.build || {}; - const isProd = process.env.NODE_ENV === 'production'; - const prodPublicPath = (site && site.publicPath) || '/'; - const publicPath = isProd ? prodPublicPath : '/'; - return { - config: config.site, - simulator: `${publicPath}mobile.html${location.hash}` + simulator: `${getPublicPath()}mobile.html${location.hash}` }; + }, + + computed: { + config() { + const { locales } = config.site; + + if (locales) { + const { lang } = this.$route.meta; + return locales[lang]; + } + + return config.site; + } } }; @@ -32,7 +49,7 @@ export default {