xushunfa459 bb8a597e19 update
2022-06-30 19:27:52 +08:00

33 lines
719 B
TypeScript

import { AnyObject } from '/#/global';
import { createI18n } from 'vue-i18n';
export function loadLang() {
const context = import.meta.globEager('./lang/*.ts');
const messages: AnyObject = {};
const langs = Object.keys(context);
for (const key of langs) {
if (key === './index.ts') return;
const lang = context[key].lang;
const name = key.replace(/(\.\/lang\/|\.ts)/g, '');
messages[name] = lang;
}
return messages;
}
export const i18n = createI18n({
// globalInjection: true,
// legacy: false,
locale: 'zh-cn',
fallbackLocale: 'zh-cn',
messages: loadLang(),
});
export const i18nt = i18n.global.t;
export function setLang(locale: string) {
i18n.global.locale = locale;
}