[new feature] add i18n support (#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
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
import Vue from 'vue';
|
||||
import get from '../utils/get';
|
||||
import camelize from '../utils/camelize';
|
||||
import deepAssign from '../utils/deep-assign';
|
||||
import defaultMessages from './lang/zh-CN';
|
||||
|
||||
// component mixin
|
||||
const i18n = {
|
||||
computed: {
|
||||
$t() {
|
||||
const { name } = this.$options;
|
||||
const prefix = name ? camelize(name) + '.' : '';
|
||||
const messages = this.$vantMessages[this.$vantLang];
|
||||
|
||||
return (path, ...args) => {
|
||||
const message = get(messages, prefix + path) || get(messages, path);
|
||||
return typeof message === 'function' ? message.apply(null, args) : message;
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const proto = Vue.prototype;
|
||||
const defaultLang = 'zh-CN';
|
||||
const locale = {
|
||||
i18n,
|
||||
|
||||
init() {
|
||||
Vue.util.defineReactive(proto, '$vantLang', defaultLang);
|
||||
Vue.util.defineReactive(proto, '$vantMessages', { [defaultLang]: defaultMessages });
|
||||
},
|
||||
|
||||
use(lang, messages) {
|
||||
proto.$vantLang = lang;
|
||||
this.add({ [lang]: messages });
|
||||
},
|
||||
|
||||
add(messages = {}) {
|
||||
deepAssign(proto.$vantMessages, messages);
|
||||
}
|
||||
};
|
||||
|
||||
locale.init();
|
||||
export default locale;
|
||||
export { i18n };
|
||||
@@ -0,0 +1,68 @@
|
||||
export default {
|
||||
confirm: 'Confirm',
|
||||
cancel: 'Cancel',
|
||||
save: 'Save',
|
||||
complete: 'Complete',
|
||||
vanAddressEdit: {
|
||||
areaTitle: 'Area',
|
||||
areaWrong: 'Please select the correct receiving area',
|
||||
areaEmpty: 'Please select a receiving area',
|
||||
nameEmpty: 'Name can not be empty',
|
||||
nameOverlimit: 'Name length exceeds limit',
|
||||
telWrong: 'Wrong format of phone number',
|
||||
addressOverlimit: 'The length of the address can not exceed 200 characters',
|
||||
addressEmpty: 'Address can not be empty',
|
||||
postalEmpty: 'Wrong postal code',
|
||||
defaultAddress: 'Set as the default address',
|
||||
deleteAddress: 'Delete the address',
|
||||
confirmDelete: 'Are you sure you want to delete this address?',
|
||||
label: {
|
||||
name: 'Receiver',
|
||||
tel: 'Phone',
|
||||
postal: 'Postal'
|
||||
},
|
||||
placeholder: {
|
||||
name: 'Receiver name',
|
||||
tel: 'Phone',
|
||||
postal: 'Postal code (optional)',
|
||||
province: 'Province',
|
||||
city: 'City',
|
||||
county: 'County'
|
||||
}
|
||||
},
|
||||
vanAddressEditDetail: {
|
||||
label: {
|
||||
address: 'Address'
|
||||
},
|
||||
placeholder: {
|
||||
address: 'Address'
|
||||
}
|
||||
},
|
||||
vanContactCard: {
|
||||
name: 'Name',
|
||||
tel: 'Phone',
|
||||
addText: 'Add contact info'
|
||||
},
|
||||
vanContactList: {
|
||||
name: 'Name',
|
||||
tel: 'Phone',
|
||||
addText: 'Add new contact'
|
||||
},
|
||||
vanContactEdit: {
|
||||
name: 'Name',
|
||||
namePlaceholder: 'Name',
|
||||
nameEmpty: 'Name can not be empty',
|
||||
nameOverlimit: 'Name length exceeds limit',
|
||||
tel: 'Phone',
|
||||
telPlaceholder: 'Phone',
|
||||
telInvalid: 'Malformed phone number',
|
||||
save: 'Save',
|
||||
delete: 'Delete',
|
||||
confirmDelete: 'Are you sure you want to delete this contact?'
|
||||
},
|
||||
vanPullRefresh: {
|
||||
pullingText: 'Pull to refresh...',
|
||||
loosingText: 'Loose to refresh...',
|
||||
loadingText: 'Loading...'
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,72 @@
|
||||
export default {
|
||||
confirm: '确认',
|
||||
cancel: '取消',
|
||||
save: '保存',
|
||||
complete: '完成',
|
||||
vanAddressEdit: {
|
||||
areaTitle: '收件地区',
|
||||
addressText: '收货',
|
||||
areaWrong: '请选择正确的收件地区',
|
||||
areaEmpty: '请选择收件地区',
|
||||
nameEmpty: '请填写名字',
|
||||
nameOverlimit: '名字过长,请重新输入',
|
||||
telWrong: '请填写正确的手机号码或电话号码',
|
||||
addressOverlimit: '详细地址不能超过200个字符',
|
||||
addressEmpty: '请填写详细地址',
|
||||
postalEmpty: '邮政编码格式不正确',
|
||||
defaultAddress: text => `设为默认${text}地址`,
|
||||
deleteAddress: text => `删除${text}地址`,
|
||||
confirmDelete: text => `确定要删除这个${text}地址么`,
|
||||
label: {
|
||||
name: text => `${text}人`,
|
||||
tel: '联系电话',
|
||||
postal: '邮政编码'
|
||||
},
|
||||
placeholder: {
|
||||
name: '名字',
|
||||
tel: '手机或固定电话',
|
||||
postal: '邮政编码(选填)',
|
||||
province: '选择省',
|
||||
city: '选择市',
|
||||
county: '选择区'
|
||||
}
|
||||
},
|
||||
vanAddressEditDetail: {
|
||||
label: {
|
||||
address: '详细地址'
|
||||
},
|
||||
placeholder: {
|
||||
address: '如街道、楼层、门牌号等'
|
||||
}
|
||||
},
|
||||
vanContactCard: {
|
||||
name: '联系人',
|
||||
tel: '联系电话',
|
||||
addText: '添加订单联系人信息'
|
||||
},
|
||||
vanContactList: {
|
||||
name: '联系人',
|
||||
tel: '联系电话',
|
||||
addText: '新建联系人'
|
||||
},
|
||||
vanContactEdit: {
|
||||
name: '联系人',
|
||||
namePlaceholder: '名字',
|
||||
nameEmpty: '请填写名字',
|
||||
nameOverlimit: '名字过长,请重新输入',
|
||||
tel: '联系电话',
|
||||
telPlaceholder: '手机或固定电话',
|
||||
telInvalid: '请填写正确的手机号码或电话号码',
|
||||
save: '保存',
|
||||
delete: '删除联系人',
|
||||
confirmDelete: '确定要删除这个联系人么'
|
||||
},
|
||||
vanPicker: {
|
||||
confirm: '完成'
|
||||
},
|
||||
vanPullRefresh: {
|
||||
pullingText: '下拉即可刷新...',
|
||||
loosingText: '释放即可刷新...',
|
||||
loadingText: '加载中...'
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user