forked from youzan/vant
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[new feature] add i18n support (youzan#310)
* fix: Tabbar icon line-height * [new feature] progress add showPivot prop * [new feature] TabItem support vue-router * [new feature] update document header style * [Doc] add toast english ducoment * [new feature] add i18n support * feat: Extract demos from markdown * feat: Base components demos * [new feature] complete demo extract & translate * [fix] text cases * fix: add deepAssign test cases * fix: changelog detail * [new feature] AddressEdit support i18n
- Loading branch information
1 parent
05abf0d
commit d8b6ad7
Showing
210 changed files
with
5,563 additions
and
5,530 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,83 +1,110 @@ | ||
var Components = require('./get-components')(); | ||
var fs = require('fs'); | ||
var render = require('json-templater/string'); | ||
var uppercamelcase = require('uppercamelcase'); | ||
var path = require('path'); | ||
|
||
var OUTPUT_PATH = path.join(__dirname, '../../packages/index.js'); | ||
var IMPORT_TEMPLATE = 'import {{name}} from \'./{{package}}\';'; | ||
var ISNTALL_COMPONENT_TEMPLATE = ' {{name}}'; | ||
var MAIN_TEMPLATE = `{{include}} | ||
const version = '{{version}}'; | ||
const Components = require('./get-components')(); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const uppercamelize = require('uppercamelcase'); | ||
const version = process.env.VERSION || require('../../package.json').version; | ||
const tips = '// This file is auto gererated by build/bin/build-entry.js'; | ||
|
||
function buildVantEntry() { | ||
const uninstallComponents = [ | ||
'Lazyload', | ||
'Waterfall', | ||
'Dialog', | ||
'Toast', | ||
'ImagePreview', | ||
'Locale' | ||
]; | ||
|
||
const importList = Components.map(name => `import ${uppercamelize(name)} from './${name}';`); | ||
const exportList = Components.map(name => `${uppercamelize(name)}`); | ||
const intallList = exportList.filter(name => !~uninstallComponents.indexOf(uppercamelize(name))); | ||
const content = `${tips} | ||
${importList.join('\n')} | ||
const version = '${version}'; | ||
const components = [ | ||
{{components}} | ||
${intallList.join(',\n ')} | ||
]; | ||
const install = function(Vue) { | ||
if (install.installed) return; | ||
const install = Vue => { | ||
components.forEach(component => { | ||
Vue.component(component.name, component); | ||
}); | ||
}; | ||
/* istanbul ignore if */ | ||
if (typeof window !== 'undefined' && window.Vue) { | ||
install(window.Vue); | ||
} | ||
export { | ||
install, | ||
version, | ||
{{list}} | ||
${exportList.join(',\n ')} | ||
}; | ||
export default { | ||
install, | ||
version | ||
}; | ||
`; | ||
|
||
delete Components.font; | ||
fs.writeFileSync(path.join(__dirname, '../../packages/index.js'), content); | ||
} | ||
|
||
var includeComponentTemplate = []; | ||
var installTemplate = []; | ||
var listTemplate = []; | ||
function buildDemoEntry() { | ||
const dir = path.join(__dirname, '../../docs/demos/views'); | ||
const demos = fs.readdirSync(dir) | ||
.filter(name => ~name.indexOf('.vue')) | ||
.map(name => name.replace('.vue', '')) | ||
.map(name => `'${name}': r => require.ensure([], () => r(wrapper(require('./views/${name}'), '${name}')), '${name}')`); | ||
|
||
Components.forEach(name => { | ||
var componentName = uppercamelcase(name); | ||
const content = `${tips} | ||
import './common'; | ||
includeComponentTemplate.push(render(IMPORT_TEMPLATE, { | ||
name: componentName, | ||
package: name | ||
})); | ||
function wrapper(component, name) { | ||
component = component.default; | ||
component.name = 'demo-' + name; | ||
return component; | ||
} | ||
if ([ | ||
// directives | ||
'Lazyload', | ||
'Waterfall', | ||
export default { | ||
${demos.join(',\n ')} | ||
}; | ||
`; | ||
fs.writeFileSync(path.join(dir, '../index.js'), content); | ||
} | ||
|
||
// services | ||
'Dialog', | ||
'Toast', | ||
'ImagePreview' | ||
].indexOf(componentName) === -1) { | ||
installTemplate.push(render(ISNTALL_COMPONENT_TEMPLATE, { | ||
name: componentName, | ||
component: name | ||
})); | ||
} | ||
|
||
listTemplate.push(` ${componentName}`); | ||
}); | ||
|
||
var template = render(MAIN_TEMPLATE, { | ||
include: includeComponentTemplate.join('\n'), | ||
list: listTemplate.join(',\n'), | ||
components: installTemplate.join(',\n') || ' ', | ||
version: process.env.VERSION || require('../../package.json').version | ||
}); | ||
|
||
fs.writeFileSync(OUTPUT_PATH, template); | ||
console.log('[build entry] DONE:' + OUTPUT_PATH); | ||
function buildDocsEntry() { | ||
const dir = path.join(__dirname, '../../docs/markdown'); | ||
const cnDocs = fs.readdirSync(path.join(dir, 'zh-CN')).map(name => 'zh-CN/' + name); | ||
const enDocs = fs.readdirSync(path.join(dir, 'en-US')).map(name => 'en-US/' + name); | ||
const docs = [...cnDocs, ...enDocs] | ||
.filter(name => name.indexOf('.md') !== -1) | ||
.map(name => name.replace('.md', '')) | ||
.map(name => `'${name}': wrapper(r => require.ensure([], () => r(require('./${name}.md')), '${name}'))`); | ||
|
||
const content = `${tips} | ||
import progress from 'nprogress'; | ||
import 'nprogress/nprogress.css'; | ||
function wrapper(component) { | ||
return function(r) { | ||
progress.start(); | ||
component(r).then(() => { | ||
progress.done(); | ||
}).catch(() => { | ||
progress.done(); | ||
}); | ||
}; | ||
} | ||
export default { | ||
${docs.join(',\n ')} | ||
}; | ||
`; | ||
fs.writeFileSync(path.join(dir, './index.js'), content); | ||
} | ||
|
||
buildVantEntry(); | ||
buildDemoEntry(); | ||
buildDocsEntry(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/** | ||
* Demo Common Mixin && i18n | ||
*/ | ||
|
||
import Vue from 'vue'; | ||
import { Locale, Toast, Dialog } from 'packages'; | ||
import { DemoBlock, DemoSection } from 'vant-doc'; | ||
import camelize from 'packages/utils/camelize'; | ||
|
||
const demoBaseMixin = { | ||
beforeCreate() { | ||
const { name, i18n } = this.$options; | ||
if (name && i18n) { | ||
const formattedI18n = {}; | ||
const camelizedName = camelize(name); | ||
Object.keys(i18n).forEach(key => { | ||
formattedI18n[key] = { [camelizedName]: i18n[key] }; | ||
}); | ||
Locale.add(formattedI18n); | ||
} | ||
} | ||
}; | ||
|
||
window.Toast = Toast; | ||
window.Dialog = Dialog; | ||
Vue.mixin(Locale.i18n); | ||
Vue.mixin(demoBaseMixin); | ||
Vue.component('demo-block', DemoBlock); | ||
Vue.component('demo-section', DemoSection); | ||
|
||
Locale.add({ | ||
'zh-CN': { | ||
red: '红色', | ||
orange: '橙色', | ||
yellow: '黄色', | ||
tab: '标签', | ||
tag: '标签', | ||
desc: '描述信息', | ||
back: '返回', | ||
title: '标题', | ||
status: '状态', | ||
button: '按钮', | ||
option: '选项', | ||
search: '搜索', | ||
content: '内容', | ||
custom: '自定义', | ||
loading: '加载状态', | ||
disabled: '禁用状态', | ||
basicUsage: '基础用法', | ||
advancedUsage: '高级用法' | ||
}, | ||
'en-US': { | ||
red: 'Red', | ||
orange: 'Orange', | ||
yellow: 'Yellow', | ||
tab: 'Tab', | ||
tag: 'Tag', | ||
desc: 'Description', | ||
back: 'Back', | ||
title: 'Title', | ||
status: 'Status', | ||
button: 'Button', | ||
option: 'Option', | ||
search: 'Search', | ||
content: 'Content', | ||
custom: 'Custom', | ||
loading: 'Loading', | ||
disabled: 'Disabled', | ||
basicUsage: 'Basic Usage', | ||
advancedUsage: 'Advanced Usage' | ||
} | ||
}); |
Oops, something went wrong.