it-tools/src/plugins/i18n.plugin.ts

22 lines
517 B
TypeScript
Raw Normal View History

import messages from '@intlify/unplugin-vue-i18n/messages';
import { get } from '@vueuse/core';
import type { Plugin } from 'vue';
2023-06-18 14:11:38 +02:00
import { createI18n } from 'vue-i18n';
const i18n = createI18n({
legacy: false,
locale: 'en',
messages,
2023-06-18 14:11:38 +02:00
});
export const i18nPlugin: Plugin = {
install: (app) => {
2023-06-18 14:11:38 +02:00
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;
};