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';
|
2023-09-03 22:07:45 +02:00
|
|
|
import baseMessages from '@intlify/unplugin-vue-i18n/messages';
|
|
|
|
import _ from 'lodash';
|
|
|
|
import { parse as parseYaml } from 'yaml';
|
|
|
|
|
|
|
|
const i18nFiles = import.meta.glob('../tools/*/locales/**.yml', { as: 'raw' });
|
|
|
|
|
|
|
|
const messagesByTools = await Promise.all(_.map(i18nFiles, async (fileDescriptor, path) => {
|
|
|
|
const [, locale] = path.match(/\.\/tools\/.*?\/locales\/(.*)\.ya?ml$/i) ?? [];
|
|
|
|
const content = parseYaml(await fileDescriptor());
|
|
|
|
|
|
|
|
return { [locale]: content };
|
|
|
|
}));
|
|
|
|
|
|
|
|
const messages = _.merge(
|
|
|
|
baseMessages,
|
|
|
|
_.merge({}, ...messagesByTools),
|
|
|
|
);
|
2023-06-18 14:11:38 +02:00
|
|
|
|
|
|
|
const i18n = createI18n({
|
|
|
|
legacy: false,
|
2023-06-19 23:14:44 +02:00
|
|
|
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) => {
|
2023-06-18 14:11:38 +02:00
|
|
|
app.use(i18n);
|
|
|
|
},
|
|
|
|
};
|