From 80a7ad015442d52cb058863109af5980ee66b0d2 Mon Sep 17 00:00:00 2001 From: notmd Date: Sun, 22 Jan 2023 23:28:27 +0700 Subject: [PATCH] typesafe i18n --- website/public/locales/en/common.json | 1 + website/src/components/Faq.tsx | 4 ++-- website/src/pages/index.tsx | 2 +- website/src/pages/leaderboard.tsx | 12 ++++++------ website/types/i18next.d.ts | 15 +++++++++++++++ 5 files changed, 25 insertions(+), 9 deletions(-) create mode 100644 website/types/i18next.d.ts diff --git a/website/public/locales/en/common.json b/website/public/locales/en/common.json index 99edf6c3..d18e5d91 100644 --- a/website/public/locales/en/common.json +++ b/website/public/locales/en/common.json @@ -1,6 +1,7 @@ { "about": "About", "account_settings": "Account", + "admin_dashboard": "Admin Dashboard", "connect": "Connect", "conversational": "Conversational AI for everyone.", "dashboard": "Dashboard", diff --git a/website/src/components/Faq.tsx b/website/src/components/Faq.tsx index 55bb3585..46d5d19c 100644 --- a/website/src/components/Faq.tsx +++ b/website/src/components/Faq.tsx @@ -27,10 +27,10 @@ export function Faq() { return ( - {t(`faq_items.q${index}`)} + {t(`faq_items.q${index as 0}`)} - {t(`faq_items.a${index}`)} + {t(`faq_items.a${index as 0}`)} ); diff --git a/website/src/pages/index.tsx b/website/src/pages/index.tsx index 888c0d61..6ac7dd38 100644 --- a/website/src/pages/index.tsx +++ b/website/src/pages/index.tsx @@ -24,7 +24,7 @@ const Home = () => { <> {t("title")} - + diff --git a/website/src/pages/leaderboard.tsx b/website/src/pages/leaderboard.tsx index e413366f..7bb8e025 100644 --- a/website/src/pages/leaderboard.tsx +++ b/website/src/pages/leaderboard.tsx @@ -11,19 +11,19 @@ const Leaderboard = () => { return ( <> - {`${t("leaderboard")} - ${t("common:title")}`} + {`${t("leaderboard:leaderboard")} - ${t("common:title")}`} - {t("leaderboard")} + {t("leaderboard:leaderboard")} - {t("daily")} - {t("weekly")} - {t("monthly")} - {t("overall")} + {t("leaderboard:daily")} + {t("leaderboard:weekly")} + {t("leaderboard:monthly")} + {t("leaderboard:overall")} diff --git a/website/types/i18next.d.ts b/website/types/i18next.d.ts new file mode 100644 index 00000000..9c447c2c --- /dev/null +++ b/website/types/i18next.d.ts @@ -0,0 +1,15 @@ +import "i18next"; + +import type common from "../public/locales/en/common.json"; +import type index from "../public/locales/en/index.json"; +import type leaderboard from "../public/locales/en/leaderboard.json"; + +declare module "i18next" { + interface CustomTypeOptions { + resources: { + common: typeof common; + index: typeof index; + leaderboard: typeof leaderboard; + }; + } +}