Merge pull request #887 from notmd/typesafe_i18n

Typesafe i18n
This commit is contained in:
Keith Stevens
2023-01-23 21:53:53 +09:00
committed by GitHub
7 changed files with 26 additions and 15 deletions
+1
View File
@@ -1,6 +1,7 @@
{
"about": "About",
"account_settings": "Account",
"admin_dashboard": "Admin Dashboard",
"connect": "Connect",
"conversational": "Conversational AI for everyone.",
"dashboard": "Dashboard",
+2 -2
View File
@@ -27,10 +27,10 @@ export function Faq() {
return (
<ListItem className="space-y-10" key={`question_${index}`}>
<Text as="h3" className={`text-lg font-semibold leading-6 ${headingColorClass}`}>
{t(`faq_items.q${index}`)}
{t(`faq_items.q${index as 0}`)}
</Text>
<Text as="p" className={`mt-4 text-sm ${textColorClass}`}>
{t(`faq_items.a${index}`)}
{t(`faq_items.a${index as 0}`)}
</Text>
</ListItem>
);
@@ -20,7 +20,6 @@ import React, { ElementType, useCallback } from "react";
interface MenuOption {
name: string;
href: string;
desc: string;
icon: ElementType;
isExternal: boolean;
}
@@ -40,21 +39,18 @@ export function UserMenu() {
{
name: t("dashboard"),
href: "/dashboard",
desc: t("dashboard"),
icon: Layout,
isExternal: false,
},
{
name: t("account_settings"),
href: "/account",
desc: t("account_settings"),
icon: Settings,
isExternal: false,
},
{
name: t("report_a_bug"),
href: "https://github.com/LAION-AI/Open-Assistant/issues/new/choose",
desc: t("report_a_bug"),
icon: AlertTriangle,
isExternal: true,
},
@@ -64,7 +60,6 @@ export function UserMenu() {
options.unshift({
name: t("admin_dashboard"),
href: "/admin",
desc: t("admin_dashboard"),
icon: Shield,
isExternal: false,
});
+1 -1
View File
@@ -1,7 +1,7 @@
import { Flex } from "@chakra-ui/react";
import Head from "next/head";
import { useTranslation } from "next-i18next";
import { useEffect, useMemo, useState } from "react";
import { useTranslation } from "react-i18next";
import { LeaderboardTable, TaskOption, WelcomeCard } from "src/components/Dashboard";
import { getDashboardLayout } from "src/components/Layout";
import { TaskCategory } from "src/components/Tasks/TaskTypes";
+1 -1
View File
@@ -24,7 +24,7 @@ const Home = () => {
<>
<Head>
<title>{t("title")}</title>
<meta name="description" content={t("description")} />
<meta name="description" content={t("index:description")} />
</Head>
<Box as="main" className="oa-basic-theme">
<Hero />
+6 -6
View File
@@ -11,19 +11,19 @@ const Leaderboard = () => {
return (
<>
<Head>
<title>{`${t("leaderboard")} - ${t("common:title")}`}</title>
<title>{`${t("leaderboard:leaderboard")} - ${t("common:title")}`}</title>
<meta name="description" content="Leaderboard Rankings" charSet="UTF-8" />
</Head>
<Box display="flex" flexDirection="column">
<Heading fontSize="2xl" fontWeight="bold" pb="4">
{t("leaderboard")}
{t("leaderboard:leaderboard")}
</Heading>
<Tabs isFitted isLazy>
<TabList>
<Tab>{t("daily")}</Tab>
<Tab>{t("weekly")}</Tab>
<Tab>{t("monthly")}</Tab>
<Tab>{t("overall")}</Tab>
<Tab>{t("leaderboard:daily")}</Tab>
<Tab>{t("leaderboard:weekly")}</Tab>
<Tab>{t("leaderboard:monthly")}</Tab>
<Tab>{t("leaderboard:overall")}</Tab>
</TabList>
<TabPanels>
+15
View File
@@ -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;
};
}
}