mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-04-20 06:55:06 -04:00
refactor(i18n): merge tools scoped locales with global ones (#612)
This commit is contained in:
parent
7ab9204e96
commit
233d5565f6
3 changed files with 25 additions and 6 deletions
|
@ -49,7 +49,7 @@ const { t } = useI18n();
|
||||||
</transition>
|
</transition>
|
||||||
|
|
||||||
<div v-if="toolStore.newTools.length > 0">
|
<div v-if="toolStore.newTools.length > 0">
|
||||||
<n-h3>{{ t('home.categories.newestTools', 'Newest tools') }}</n-h3>
|
<n-h3>{{ t('home.categories.newestTools') }}</n-h3>
|
||||||
<n-grid x-gap="12" y-gap="12" cols="1 400:2 800:3 1200:4 2000:8">
|
<n-grid x-gap="12" y-gap="12" cols="1 400:2 800:3 1200:4 2000:8">
|
||||||
<n-gi v-for="tool in toolStore.newTools" :key="tool.name">
|
<n-gi v-for="tool in toolStore.newTools" :key="tool.name">
|
||||||
<ToolCard :tool="tool" />
|
<ToolCard :tool="tool" />
|
||||||
|
|
|
@ -1,6 +1,22 @@
|
||||||
import type { App } from 'vue';
|
import type { Plugin } from 'vue';
|
||||||
import { createI18n } from 'vue-i18n';
|
import { createI18n } from 'vue-i18n';
|
||||||
import messages from '@intlify/unplugin-vue-i18n/messages';
|
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),
|
||||||
|
);
|
||||||
|
|
||||||
const i18n = createI18n({
|
const i18n = createI18n({
|
||||||
legacy: false,
|
legacy: false,
|
||||||
|
@ -8,8 +24,8 @@ const i18n = createI18n({
|
||||||
messages,
|
messages,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const i18nPlugin = {
|
export const i18nPlugin: Plugin = {
|
||||||
install: (app: App) => {
|
install: (app) => {
|
||||||
app.use(i18n);
|
app.use(i18n);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -25,7 +25,7 @@ export default defineConfig({
|
||||||
runtimeOnly: true,
|
runtimeOnly: true,
|
||||||
compositionOnly: true,
|
compositionOnly: true,
|
||||||
fullInstall: true,
|
fullInstall: true,
|
||||||
include: [resolve(__dirname, 'locales/**'), resolve(__dirname, 'src/tools/*/locales/**')],
|
include: [resolve(__dirname, 'locales/**')],
|
||||||
}),
|
}),
|
||||||
AutoImport({
|
AutoImport({
|
||||||
imports: [
|
imports: [
|
||||||
|
@ -106,4 +106,7 @@ export default defineConfig({
|
||||||
test: {
|
test: {
|
||||||
exclude: [...configDefaults.exclude, '**/*.e2e.spec.ts'],
|
exclude: [...configDefaults.exclude, '**/*.e2e.spec.ts'],
|
||||||
},
|
},
|
||||||
|
build: {
|
||||||
|
target: 'esnext',
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue