2024-02-11 00:33:52 +01:00
|
|
|
import messages from '@intlify/unplugin-vue-i18n/messages';
|
|
|
|
import { get } from '@vueuse/core';
|
2023-09-03 22:07:45 +02:00
|
|
|
import type { Plugin } from 'vue';
|
2023-06-18 14:11:38 +02:00
|
|
|
import { createI18n } from 'vue-i18n';
|
|
|
|
|
2024-04-21 02:55:19 +08:00
|
|
|
// const i18n = createI18n({
|
|
|
|
// legacy: false,
|
|
|
|
// locale: 'en',
|
|
|
|
// messages,
|
|
|
|
// });
|
2023-06-18 14:11:38 +02:00
|
|
|
|
2023-09-03 22:07:45 +02:00
|
|
|
export const i18nPlugin: Plugin = {
|
|
|
|
install: (app) => {
|
2024-04-21 02:55:19 +08:00
|
|
|
const i18n = createI18n({
|
|
|
|
legacy: false,
|
|
|
|
locale: 'zh',
|
|
|
|
messages,
|
|
|
|
});
|
2023-06-18 14:11:38 +02:00
|
|
|
app.use(i18n);
|
|
|
|
},
|
|
|
|
};
|
2023-10-22 16:23:00 +08:00
|
|
|
|
2024-04-21 02:55:19 +08:00
|
|
|
export const i18n = createI18n({
|
|
|
|
legacy: false,
|
|
|
|
locale: 'zh',
|
|
|
|
messages,
|
|
|
|
});
|
|
|
|
|
2023-10-22 16:23:00 +08:00
|
|
|
export const translate = function (localeKey: string) {
|
2024-02-11 00:33:52 +01:00
|
|
|
const hasKey = i18n.global.te(localeKey, get(i18n.global.locale));
|
2023-10-22 16:23:00 +08:00
|
|
|
return hasKey ? i18n.global.t(localeKey) : localeKey;
|
|
|
|
};
|