mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
34 lines
724 B
JavaScript
34 lines
724 B
JavaScript
/* eslint-disable import/no-mutable-exports */
|
|
import Vue from 'vue';
|
|
import deepAssign from '../utils/deep-assign';
|
|
import defaultMessages from './lang/zh-CN';
|
|
|
|
let lang = 'zh-CN';
|
|
const proto = Vue.prototype;
|
|
const messages = { [lang]: defaultMessages };
|
|
|
|
const locale = {
|
|
install() {
|
|
if (proto.$vantLang) {
|
|
return;
|
|
}
|
|
Vue.util.defineReactive(proto, '$vantLang', lang);
|
|
Vue.util.defineReactive(proto, '$vantMessages', messages);
|
|
},
|
|
|
|
use(newLang, messages) {
|
|
lang = newLang;
|
|
proto.$vantLang = lang;
|
|
this.add({ [lang]: messages });
|
|
},
|
|
|
|
add(messages = {}) {
|
|
deepAssign(proto.$vantMessages, messages);
|
|
}
|
|
};
|
|
|
|
locale.install();
|
|
|
|
export default locale;
|
|
export { lang, messages };
|