From 233d5565f6d4572b283d85d698de1822b3b6fc07 Mon Sep 17 00:00:00 2001 From: Corentin THOMASSET Date: Sun, 3 Sep 2023 22:07:45 +0200 Subject: [PATCH 1/2] refactor(i18n): merge tools scoped locales with global ones (#612) --- src/pages/Home.page.vue | 2 +- src/plugins/i18n.plugin.ts | 24 ++++++++++++++++++++---- vite.config.ts | 5 ++++- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/pages/Home.page.vue b/src/pages/Home.page.vue index 49d90c67..5c7c3c4f 100644 --- a/src/pages/Home.page.vue +++ b/src/pages/Home.page.vue @@ -49,7 +49,7 @@ const { t } = useI18n();
- {{ t('home.categories.newestTools', 'Newest tools') }} + {{ t('home.categories.newestTools') }} diff --git a/src/plugins/i18n.plugin.ts b/src/plugins/i18n.plugin.ts index c38cdee1..8e0b2d33 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 8e2e0836..00f90c33 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', + }, }); From 8a30b6bdb3c48138f8e015739a0189c87ee4a451 Mon Sep 17 00:00:00 2001 From: Mark Townsend <63235752+whackablemole@users.noreply.github.com> Date: Mon, 4 Sep 2023 13:51:04 +0100 Subject: [PATCH 2/2] refactor(spelling): minor corrections to phrasing/spelling (#596) * Minor corrections to phrasing/spelling. * Corrected 'millennia'. * Corrected tests. --------- Co-authored-by: Corentin THOMASSET --- .../date-time-converter.vue | 2 +- .../password-strength-analyser.e2e.spec.ts | 2 +- .../password-strength-analyser.service.ts | 24 +++++++++---------- src/tools/uuid-generator/index.ts | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/tools/date-time-converter/date-time-converter.vue b/src/tools/date-time-converter/date-time-converter.vue index 88fa6012..241c9cf6 100644 --- a/src/tools/date-time-converter/date-time-converter.vue +++ b/src/tools/date-time-converter/date-time-converter.vue @@ -146,7 +146,7 @@ function formatDateUsingFormatter(formatter: (date: Date) => string, date?: Date { const crackDuration = await page.getByTestId('crack-duration').textContent(); - expect(crackDuration).toEqual('15,091 milleniums, 3 centurys'); + expect(crackDuration).toEqual('15,091 millennia, 3 centuries'); }); }); diff --git a/src/tools/password-strength-analyser/password-strength-analyser.service.ts b/src/tools/password-strength-analyser/password-strength-analyser.service.ts index d639b223..aa281848 100644 --- a/src/tools/password-strength-analyser/password-strength-analyser.service.ts +++ b/src/tools/password-strength-analyser/password-strength-analyser.service.ts @@ -19,20 +19,20 @@ function getHumanFriendlyDuration({ seconds }: { seconds: number }) { } const timeUnits = [ - { unit: 'millenium', secondsInUnit: 31536000000, format: prettifyExponentialNotation }, - { unit: 'century', secondsInUnit: 3153600000 }, - { unit: 'decade', secondsInUnit: 315360000 }, - { unit: 'year', secondsInUnit: 31536000 }, - { unit: 'month', secondsInUnit: 2592000 }, - { unit: 'week', secondsInUnit: 604800 }, - { unit: 'day', secondsInUnit: 86400 }, - { unit: 'hour', secondsInUnit: 3600 }, - { unit: 'minute', secondsInUnit: 60 }, - { unit: 'second', secondsInUnit: 1 }, + { unit: 'millenium', secondsInUnit: 31536000000, format: prettifyExponentialNotation, plural: 'millennia' }, + { unit: 'century', secondsInUnit: 3153600000, plural: 'centuries' }, + { unit: 'decade', secondsInUnit: 315360000, plural: 'decades' }, + { unit: 'year', secondsInUnit: 31536000, plural: 'years' }, + { unit: 'month', secondsInUnit: 2592000, plural: 'months' }, + { unit: 'week', secondsInUnit: 604800, plural: 'weeks' }, + { unit: 'day', secondsInUnit: 86400, plural: 'days' }, + { unit: 'hour', secondsInUnit: 3600, plural: 'hours' }, + { unit: 'minute', secondsInUnit: 60, plural: 'minutes' }, + { unit: 'second', secondsInUnit: 1, plural: 'seconds' }, ]; return _.chain(timeUnits) - .map(({ unit, secondsInUnit, format = _.identity }) => { + .map(({ unit, secondsInUnit, plural, format = _.identity }) => { const quantity = Math.floor(seconds / secondsInUnit); seconds %= secondsInUnit; @@ -41,7 +41,7 @@ function getHumanFriendlyDuration({ seconds }: { seconds: number }) { } const formattedQuantity = format(quantity); - return `${formattedQuantity} ${unit}${quantity > 1 ? 's' : ''}`; + return `${formattedQuantity} ${quantity > 1 ? plural : unit}`; }) .compact() .take(2) diff --git a/src/tools/uuid-generator/index.ts b/src/tools/uuid-generator/index.ts index 2b4b3d34..ae5ae0da 100644 --- a/src/tools/uuid-generator/index.ts +++ b/src/tools/uuid-generator/index.ts @@ -5,7 +5,7 @@ export const tool = defineTool({ name: 'UUIDs v4 generator', path: '/uuid-generator', description: - 'A universally unique identifier (UUID) is a 128-bit number used to identify information in computer systems. The number of possible UUIDs is 16^32, which is 2^128 or about 3.4x10^38 (which is a lot !).', + 'A Universally Unique Identifier (UUID) is a 128-bit number used to identify information in computer systems. The number of possible UUIDs is 16^32, which is 2^128 or about 3.4x10^38 (which is a lot!).', keywords: ['uuid', 'v4', 'random', 'id', 'alphanumeric', 'identity', 'token', 'string', 'identifier', 'unique'], component: () => import('./uuid-generator.vue'), icon: Fingerprint,