mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
docs: demo locale messages
This commit is contained in:
parent
5531eea674
commit
d9cedca9a8
@ -3,6 +3,7 @@ import Locale from '../../src/locale';
|
|||||||
import { get } from '../../src/utils';
|
import { get } from '../../src/utils';
|
||||||
import { camelize } from '../../src/utils/format/string';
|
import { camelize } from '../../src/utils/format/string';
|
||||||
|
|
||||||
|
// helper for demo locales
|
||||||
Vue.mixin({
|
Vue.mixin({
|
||||||
computed: {
|
computed: {
|
||||||
$t() {
|
$t() {
|
||||||
@ -15,9 +16,24 @@ Vue.mixin({
|
|||||||
return typeof message === 'function' ? message(...args) : message;
|
return typeof message === 'function' ? message(...args) : message;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
beforeCreate() {
|
||||||
|
const { i18n, name } = this.$options;
|
||||||
|
if (i18n) {
|
||||||
|
const locales = {};
|
||||||
|
const camelizedName = camelize(name);
|
||||||
|
|
||||||
|
Object.keys(i18n).forEach(key => {
|
||||||
|
locales[key] = { [camelizedName]: i18n[key] };
|
||||||
|
});
|
||||||
|
|
||||||
|
Locale.add(locales);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// add some basic locale messages
|
||||||
Locale.add({
|
Locale.add({
|
||||||
'zh-CN': {
|
'zh-CN': {
|
||||||
add: '增加',
|
add: '增加',
|
||||||
|
@ -13,14 +13,13 @@ import {
|
|||||||
type DemoItem = {
|
type DemoItem = {
|
||||||
name: string;
|
name: string;
|
||||||
path: string;
|
path: string;
|
||||||
|
component: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
function genInstall() {
|
function genInstall() {
|
||||||
return `import Vue from 'vue';
|
return `import Vue from 'vue';
|
||||||
import PackageEntry from './package-entry';
|
import PackageEntry from './package-entry';
|
||||||
import './package-style';
|
import './package-style';
|
||||||
|
|
||||||
Vue.use(PackageEntry);
|
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,6 +35,12 @@ function genExports(demos: DemoItem[]) {
|
|||||||
.join(',\n ')}\n};`;
|
.join(',\n ')}\n};`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getSetName(demos: DemoItem[]) {
|
||||||
|
return demos
|
||||||
|
.map(item => `${item.name}.name = 'demo-${item.component}';`)
|
||||||
|
.join('\n');
|
||||||
|
}
|
||||||
|
|
||||||
function genConfig(demos: DemoItem[]) {
|
function genConfig(demos: DemoItem[]) {
|
||||||
const vantConfig = getVantConfig();
|
const vantConfig = getVantConfig();
|
||||||
const demoNames = demos.map(item => decamelize(item.name, '-'));
|
const demoNames = demos.map(item => decamelize(item.name, '-'));
|
||||||
@ -66,14 +71,22 @@ function genConfig(demos: DemoItem[]) {
|
|||||||
function genCode(components: string[]) {
|
function genCode(components: string[]) {
|
||||||
const demos = components
|
const demos = components
|
||||||
.map(component => ({
|
.map(component => ({
|
||||||
|
component,
|
||||||
name: pascalize(component),
|
name: pascalize(component),
|
||||||
path: join(SRC_DIR, component, 'demo/index.vue')
|
path: join(SRC_DIR, component, 'demo/index.vue')
|
||||||
}))
|
}))
|
||||||
.filter(item => existsSync(item.path));
|
.filter(item => existsSync(item.path));
|
||||||
|
|
||||||
return `${genInstall()}\n${genImports(demos)}\n\n${genExports(
|
return `${genInstall()}
|
||||||
demos
|
${genImports(demos)}
|
||||||
)}\n${genConfig(demos)}\n`;
|
|
||||||
|
Vue.use(PackageEntry);
|
||||||
|
|
||||||
|
${getSetName(demos)}
|
||||||
|
|
||||||
|
${genExports(demos)}
|
||||||
|
${genConfig(demos)}
|
||||||
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function genSiteMobileShared() {
|
export function genSiteMobileShared() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user