mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
26 lines
547 B
TypeScript
26 lines
547 B
TypeScript
import { ref } from 'vue';
|
|
import { deepAssign } from '../utils/deep-assign';
|
|
import defaultMessages from './lang/zh-CN';
|
|
|
|
type Messages = Record<string, Record<string, any>>;
|
|
|
|
const lang = ref('zh-CN');
|
|
const messages = ref<Messages>({
|
|
'zh-CN': defaultMessages,
|
|
});
|
|
|
|
export default {
|
|
messages() {
|
|
return messages.value[lang.value];
|
|
},
|
|
|
|
use(newLang: string, newMessages?: object) {
|
|
lang.value = newLang;
|
|
this.add({ [newLang]: newMessages });
|
|
},
|
|
|
|
add(newMessages = {}) {
|
|
deepAssign(messages.value, newMessages);
|
|
},
|
|
};
|