mirror of
https://github.com/xxxsf/vue3-h5-template.git
synced 2025-04-05 04:12:45 +08:00
33 lines
719 B
TypeScript
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;
|
|
}
|