mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
35 lines
723 B
TypeScript
35 lines
723 B
TypeScript
import Vue from 'vue';
|
|
import { deepAssign } from '../utils/deep-assign';
|
|
import defaultMessages from './lang/zh-CN';
|
|
|
|
declare module 'vue' {
|
|
interface VueConstructor {
|
|
util: {
|
|
defineReactive(obj: object, key: string, value: any): void;
|
|
};
|
|
}
|
|
}
|
|
|
|
const proto = Vue.prototype;
|
|
const { defineReactive } = Vue.util;
|
|
|
|
defineReactive(proto, '$vantLang', 'zh-CN');
|
|
defineReactive(proto, '$vantMessages', {
|
|
'zh-CN': defaultMessages
|
|
});
|
|
|
|
export default {
|
|
messages() {
|
|
return proto.$vantMessages[proto.$vantLang];
|
|
},
|
|
|
|
use(lang: string, messages?: object) {
|
|
proto.$vantLang = lang;
|
|
this.add({ [lang]: messages });
|
|
},
|
|
|
|
add(messages = {}) {
|
|
deepAssign(proto.$vantMessages, messages);
|
|
}
|
|
};
|