mirror of
https://github.com/youzan/vant.git
synced 2025-10-20 18:54:24 +00:00
Docs: add English language support (#170)
* feat: support lang entry build * feat: vant support lang switch * move lang iframe-router to utils & fix router link bug * add en-US config && add some translation * chang async. to async_ (support superman cdn) * add layout translation * change nav style * upgrade zan-doc * fix: doc config * upgrade zan-doc && remove useless code * fix changelog generate path
This commit is contained in:
@@ -1,43 +1,67 @@
|
||||
import docConfig from './doc.config';
|
||||
import { getLang } from './utils/lang';
|
||||
import DemoList from './components/demo-list';
|
||||
import componentDocs from '../examples-dist/entry-docs';
|
||||
import componentDemos from '../examples-dist/entry-demos';
|
||||
import './iframe-router';
|
||||
|
||||
const navs = docConfig['zh-CN'].nav;
|
||||
import './utils/iframe-router';
|
||||
|
||||
const registerRoute = (isExample) => {
|
||||
const route = [{
|
||||
path: '/',
|
||||
redirect: to => {
|
||||
return `/${getLang()}/`;
|
||||
}
|
||||
}, {
|
||||
path: '*',
|
||||
redirect: '/'
|
||||
redirect: to => {
|
||||
return `/${getLang()}/`;
|
||||
}
|
||||
}];
|
||||
|
||||
navs.forEach(nav => {
|
||||
if (isExample && !nav.showInMobile) {
|
||||
return;
|
||||
Object.keys(docConfig).forEach((lang, index) => {
|
||||
if (isExample) {
|
||||
route.push({
|
||||
path: `/${lang}`,
|
||||
component: DemoList,
|
||||
meta: { lang }
|
||||
});
|
||||
} else {
|
||||
route.push({
|
||||
path: `/${lang}`,
|
||||
redirect: `/${lang}/component/quickstart`
|
||||
});
|
||||
}
|
||||
|
||||
if (nav.groups) {
|
||||
nav.groups.forEach(group => {
|
||||
group.list.forEach(addRoute);
|
||||
});
|
||||
} else if (nav.children) {
|
||||
nav.children.forEach(addRoute);
|
||||
} else {
|
||||
addRoute(nav);
|
||||
const navs = docConfig[lang].nav || [];
|
||||
navs.forEach(nav => {
|
||||
if (isExample && !nav.showInMobile) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (nav.groups) {
|
||||
nav.groups.forEach(group => {
|
||||
group.list.forEach(page => addRoute(page, lang));
|
||||
});
|
||||
} else if (nav.children) {
|
||||
nav.children.forEach(page => addRoute(page, lang));
|
||||
} else {
|
||||
addRoute(nav, lang);
|
||||
}
|
||||
});
|
||||
|
||||
function addRoute(page, lang) {
|
||||
const { path } = page;
|
||||
if (path) {
|
||||
const name = lang + '/' + path.replace('/', '');
|
||||
route.push({
|
||||
path: `/${lang}/component${path}`,
|
||||
component: isExample ? componentDemos[name] : componentDocs[name],
|
||||
meta: { lang }
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
function addRoute(page) {
|
||||
const { path } = page;
|
||||
if (path) {
|
||||
const name = path.replace('/', '');
|
||||
route.push({
|
||||
path: '/component' + path,
|
||||
component: isExample ? componentDemos[name] : componentDocs[name]
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return route;
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user