aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Corentin THOMASSET <corentin.thomasset74@gmail.com> 2023-09-03 22:07:45 +0200
committerGravatar GitHub <noreply@github.com> 2023-09-03 20:07:45 +0000
commit233d5565f6d4572b283d85d698de1822b3b6fc07 (patch)
tree5e7180278fa6b412f76c00beaa6ee5468b6e17cf
parent7ab9204e96e21050760cf3280197c139551829f5 (diff)
downloadit-tools-233d5565f6d4572b283d85d698de1822b3b6fc07.tar.gz
it-tools-233d5565f6d4572b283d85d698de1822b3b6fc07.tar.zst
it-tools-233d5565f6d4572b283d85d698de1822b3b6fc07.zip
refactor(i18n): merge tools scoped locales with global ones (#612)
-rw-r--r--src/pages/Home.page.vue2
-rw-r--r--src/plugins/i18n.plugin.ts24
-rw-r--r--vite.config.ts5
3 files changed, 25 insertions, 6 deletions
diff --git a/src/pages/Home.page.vue b/src/pages/Home.page.vue
index 49d90c6..5c7c3c4 100644
--- a/src/pages/Home.page.vue
+++ b/src/pages/Home.page.vue
@@ -49,7 +49,7 @@ const { t } = useI18n();
</transition>
<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-gi v-for="tool in toolStore.newTools" :key="tool.name">
<ToolCard :tool="tool" />
diff --git a/src/plugins/i18n.plugin.ts b/src/plugins/i18n.plugin.ts
index c38cdee..8e0b2d3 100644
--- a/src/plugins/i18n.plugin.ts
+++ b/src/plugins/i18n.plugin.ts
@@ -1,6 +1,22 @@
-import type { App } from 'vue';
+import type { Plugin } from 'vue';
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({
legacy: false,
@@ -8,8 +24,8 @@ const i18n = createI18n({
messages,
});
-export const i18nPlugin = {
- install: (app: App) => {
+export const i18nPlugin: Plugin = {
+ install: (app) => {
app.use(i18n);
},
};
diff --git a/vite.config.ts b/vite.config.ts
index 8e2e083..00f90c3 100644
--- a/vite.config.ts
+++ b/vite.config.ts
@@ -25,7 +25,7 @@ export default defineConfig({
runtimeOnly: true,
compositionOnly: true,
fullInstall: true,
- include: [resolve(__dirname, 'locales/**'), resolve(__dirname, 'src/tools/*/locales/**')],
+ include: [resolve(__dirname, 'locales/**')],
}),
AutoImport({
imports: [
@@ -106,4 +106,7 @@ export default defineConfig({
test: {
exclude: [...configDefaults.exclude, '**/*.e2e.spec.ts'],
},
+ build: {
+ target: 'esnext',
+ },
});