From 0a5111e4b0fa0f6687c65997af59753b82093563 Mon Sep 17 00:00:00 2001 From: johnnyjoy Date: Sat, 7 Dec 2024 12:16:38 +0800 Subject: [PATCH] chore: update i18n types definition --- web/src/types/utils/nestedKeyOf.types.ts | 3 --- web/src/utils/i18n.ts | 5 ++++- 2 files changed, 4 insertions(+), 4 deletions(-) delete mode 100644 web/src/types/utils/nestedKeyOf.types.ts diff --git a/web/src/types/utils/nestedKeyOf.types.ts b/web/src/types/utils/nestedKeyOf.types.ts deleted file mode 100644 index 472f7f4d3..000000000 --- a/web/src/types/utils/nestedKeyOf.types.ts +++ /dev/null @@ -1,3 +0,0 @@ -export type NestedKeyOf = K extends keyof T & (string | number) - ? `${K}` | (T[K] extends object ? `${K}.${NestedKeyOf}` : never) - : never; diff --git a/web/src/utils/i18n.ts b/web/src/utils/i18n.ts index ca9434393..9e6bf97a3 100644 --- a/web/src/utils/i18n.ts +++ b/web/src/utils/i18n.ts @@ -2,7 +2,6 @@ import { FallbackLngObjList } from "i18next"; import { useTranslation } from "react-i18next"; import i18n, { locales, TLocale } from "@/i18n"; import enTranslation from "@/locales/en.json"; -import type { NestedKeyOf } from "@/types/utils/nestedKeyOf.types"; export const findNearestMatchedLanguage = (language: string): Locale => { if (locales.includes(language as TLocale)) { @@ -33,6 +32,10 @@ export const findNearestMatchedLanguage = (language: string): Locale => { return (i18n.store.options.fallbackLng as FallbackLngObjList).default[0] as Locale; }; +type NestedKeyOf = K extends keyof T & (string | number) + ? `${K}` | (T[K] extends object ? `${K}.${NestedKeyOf}` : never) + : never; + // Represents the keys of nested translation objects. export type Translations = NestedKeyOf;