From 24e0e38b4af7126a98ea93da2159f50dc79be884 Mon Sep 17 00:00:00 2001 From: "Ibrahima G. Coulibaly" Date: Sun, 13 Jul 2025 15:39:12 +0100 Subject: [PATCH] fix: tsc --- .idea/workspace.xml | 42 +++++++++--------------------- @types/i18n.d.ts | 28 ++------------------ src/components/ToolLayout.tsx | 10 ++++--- src/i18n/index.ts | 31 ++++++++++------------ src/pages/tools/audio/i18n/en.json | 3 +++ src/tools/defineTool.tsx | 9 ++++--- 6 files changed, 43 insertions(+), 80 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index b51b1b6..648248c 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -6,27 +6,11 @@ + + - - - - - - - - - - - - - - - - - - - + diff --git a/@types/i18n.d.ts b/@types/i18n.d.ts index 7238ada..efd6ca1 100644 --- a/@types/i18n.d.ts +++ b/@types/i18n.d.ts @@ -1,33 +1,9 @@ // types/i18next.d.ts import 'i18next'; -import enGlobal from '../src/i18n/en.json'; -import enList from '../src/pages/tools/list/i18n/en.json'; -import enString from '../src/pages/tools/string/i18n/en.json'; -import enCsv from '../src/pages/tools/csv/i18n/en.json'; -import enJson from '../src/pages/tools/json/i18n/en.json'; -import enPdf from '../src/pages/tools/pdf/i18n/en.json'; -import enImage from '../src/pages/tools/image/i18n/en.json'; -import enAudio from '../src/pages/tools/audio/i18n/en.json'; -import enVideo from '../src/pages/tools/video/i18n/en.json'; -import enNumber from '../src/pages/tools/number/i18n/en.json'; -import enTime from '../src/pages/tools/time/i18n/en.json'; -import enXml from '../src/pages/tools/xml/i18n/en.json'; +import { resources } from '../src/i18n'; declare module 'i18next' { interface CustomTypeOptions { - resources: { - translation: typeof enGlobal; - list: typeof enList; - string: typeof enString; - csv: typeof enCsv; - json: typeof enJson; - pdf: typeof enPdf; - image: typeof enImage; - audio: typeof enAudio; - video: typeof enVideo; - number: typeof enNumber; - time: typeof enTime; - xml: typeof enXml; - }; + resources: (typeof resources)['en']; } } diff --git a/src/components/ToolLayout.tsx b/src/components/ToolLayout.tsx index b628461..63eee44 100644 --- a/src/components/ToolLayout.tsx +++ b/src/components/ToolLayout.tsx @@ -8,6 +8,8 @@ import { getToolsByCategory } from '@tools/index'; import { capitalizeFirstLetter } from '../utils/string'; import { IconifyIcon } from '@iconify/react'; import { useTranslation } from 'react-i18next'; +import { ToolCategory } from '@tools/defineTool'; +import { FullI18nKey } from '../i18n'; export default function ToolLayout({ children, @@ -20,12 +22,12 @@ export default function ToolLayout({ title: string; description: string; icon?: IconifyIcon | string; - type: string; + type: ToolCategory; children: ReactNode; i18n?: { - name: string; - description: string; - shortDescription: string; + name: FullI18nKey; + description: FullI18nKey; + shortDescription: FullI18nKey; }; }) { const { t } = useTranslation(); diff --git a/src/i18n/index.ts b/src/i18n/index.ts index dd54037..82bc088 100644 --- a/src/i18n/index.ts +++ b/src/i18n/index.ts @@ -1,4 +1,4 @@ -import i18n from 'i18next'; +import i18n, { ParseKeys } from 'i18next'; import { initReactI18next } from 'react-i18next'; import enGlobal from './en.json'; import hiGlobal from './hi.json'; @@ -33,7 +33,7 @@ const locizeOptions = { version: 'latest' }; // Merge translations for demonstration; in a real app, use namespaces -const resources = { +export const resources = { en: { translation: enGlobal, list: enList, @@ -62,21 +62,18 @@ const resources = { time: hiTime, xml: hiXml } -}; +} as const; -i18n - // .use(Backend) - .use(initReactI18next) - .init({ - resources, - lng: 'en', - fallbackLng: 'en', - interpolation: { - escapeValue: false - }, - backend: locizeOptions, - saveMissing: true, // Send missing keys to Locize - updateMissing: true // Update keys in Locize - }); +export type I18nNamespaces = keyof (typeof resources)['en']; +export type FullI18nKey = `${string}:${ParseKeys}`; + +i18n.use(Backend).use(initReactI18next).init({ + resources, + lng: 'en', + fallbackLng: 'en', + backend: locizeOptions, + saveMissing: true, // Send missing keys to Locize + updateMissing: true // Update keys in Locize +}); export default i18n; diff --git a/src/pages/tools/audio/i18n/en.json b/src/pages/tools/audio/i18n/en.json index 6ff32d5..2e2ec8c 100644 --- a/src/pages/tools/audio/i18n/en.json +++ b/src/pages/tools/audio/i18n/en.json @@ -13,6 +13,9 @@ } }, "changeSpeed": { + "title": "Change audio speed", + "description": "Change the playback speed of audio files. Speed up or slow down audio while maintaining pitch.", + "shortDescription": "Change the speed of audio files", "newAudioSpeed": "New Audio Speed", "speedDescription": "Default multiplier: 2 means 2x faster", "outputFormat": "Output Format", diff --git a/src/tools/defineTool.tsx b/src/tools/defineTool.tsx index 8721017..0955200 100644 --- a/src/tools/defineTool.tsx +++ b/src/tools/defineTool.tsx @@ -1,6 +1,7 @@ import ToolLayout from '../components/ToolLayout'; import React, { JSXElementConstructor, LazyExoticComponent } from 'react'; import { IconifyIcon } from '@iconify/react'; +import { FullI18nKey } from '../i18n'; export interface ToolMeta { path: string; @@ -12,10 +13,10 @@ export interface ToolMeta { shortDescription: string; longDescription?: string; i18n?: { - name: string; - description: string; - shortDescription: string; - longDescription?: string; + name: FullI18nKey; + description: FullI18nKey; + shortDescription: FullI18nKey; + longDescription?: FullI18nKey; }; }