it-tools/src/plugins/i18n.plugin.ts
2024-02-11 00:33:52 +01:00

21 lines
517 B
TypeScript

import messages from '@intlify/unplugin-vue-i18n/messages';
import { get } from '@vueuse/core';
import type { Plugin } from 'vue';
import { createI18n } from 'vue-i18n';
const i18n = createI18n({
legacy: false,
locale: 'en',
messages,
});
export const i18nPlugin: Plugin = {
install: (app) => {
app.use(i18n);
},
};
export const translate = function (localeKey: string) {
const hasKey = i18n.global.te(localeKey, get(i18n.global.locale));
return hasKey ? i18n.global.t(localeKey) : localeKey;
};