From 1def9d7cd5386e8c22121d53e2cc05c025e74899 Mon Sep 17 00:00:00 2001 From: Leander Furumo Date: Sun, 22 Jun 2025 02:20:27 +0200 Subject: [PATCH] add support for translated match descriptions --- src/app/components/GuessesList.tsx | 48 +++++++++++++++++++----------- src/app/types.ts | 1 + 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/src/app/components/GuessesList.tsx b/src/app/components/GuessesList.tsx index 4191e0c..deb46b9 100644 --- a/src/app/components/GuessesList.tsx +++ b/src/app/components/GuessesList.tsx @@ -1,3 +1,5 @@ +import { useLanguage } from "@/LanguageContext"; +import { translations } from "@/translations"; import type { Match } from "@/types"; import React from "react"; @@ -5,22 +7,34 @@ interface GuessesListProps { matches: Match[]; } -const GuessesList: React.FC = ({ matches }) => ( - -); +const GuessesList: React.FC = ({ matches }) => { + const { language } = useLanguage(); + const t = translations[language]; + + const getDescription = (match: Match) => { + if (match.translationKey) { + return t[match.translationKey as keyof typeof t]; + } + return match.description; + }; + + return ( +
    + {[...matches].reverse().map((match, idx) => ( +
  • +

    {match.name ?? match.input}

    +

    {getDescription(match)}

    +
  • + ))} +
+ ); +}; export default GuessesList; diff --git a/src/app/types.ts b/src/app/types.ts index 94e80bc..31fcf13 100644 --- a/src/app/types.ts +++ b/src/app/types.ts @@ -2,6 +2,7 @@ export interface Match { input: string; name: string | undefined; description: string | undefined; + translationKey?: string; correct: boolean; }