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';
|
|
|
|
|
|
|
|
const i18n = createI18n({
|
|
|
|
legacy: false,
|
2023-06-19 23:14:44 +02:00
|
|
|
locale: 'en',
|
2023-12-22 22:42:03 +08:00
|
|
|
fallbackLocale: 'en',
|
2023-06-19 23:14:44 +02:00
|
|
|
messages,
|
2023-06-18 14:11:38 +02:00
|
|
|
});
|
|
|
|
|
2023-09-03 22:07:45 +02:00
|
|
|
export const i18nPlugin: Plugin = {
|
|
|
|
install: (app) => {
|
2023-06-18 14:11:38 +02:00
|
|
|
app.use(i18n);
|
|
|
|
},
|
|
|
|
};
|
2023-10-22 16:23:00 +08:00
|
|
|
|
2024-02-21 17:58:57 +08:00
|
|
|
export const translate = function (localeKey: string, named: Record<string, unknown> = {}) {
|
2024-02-11 00:33:52 +01:00
|
|
|
const hasKey = i18n.global.te(localeKey, get(i18n.global.locale));
|
2024-02-21 17:58:57 +08:00
|
|
|
return hasKey ? i18n.global.t(localeKey, named) : localeKey;
|
2023-10-22 16:23:00 +08:00
|
|
|
};
|