From d60dc3fcb23bd094f077a32976ee3efce9a0cf37 Mon Sep 17 00:00:00 2001 From: Jon Eugster Date: Wed, 27 Mar 2024 02:03:05 +0100 Subject: [PATCH] mark most of the game text for translation --- client/src/components/app_bar.tsx | 5 +++-- client/src/components/hints.tsx | 7 +++++-- client/src/components/infoview/main.tsx | 5 ++++- client/src/components/inventory.tsx | 2 +- client/src/components/level.tsx | 8 ++++---- client/src/components/popup/game_info.tsx | 7 ++++++- client/src/components/world_tree.tsx | 5 +++-- 7 files changed, 26 insertions(+), 13 deletions(-) diff --git a/client/src/components/app_bar.tsx b/client/src/components/app_bar.tsx index 37d2a19..37d55dd 100644 --- a/client/src/components/app_bar.tsx +++ b/client/src/components/app_bar.tsx @@ -214,6 +214,7 @@ export function WelcomeAppBar({pageNumber, setPageNumber, gameInfo, toggleImpres toggleInfo: any, togglePreferencesPopup: () => void; }) { + const { t } = useTranslation() const gameId = React.useContext(GameIdContext) const gameProgress = useAppSelector(selectProgress(gameId)) const {mobile} = React.useContext(PreferencesContext) @@ -225,7 +226,7 @@ export function WelcomeAppBar({pageNumber, setPageNumber, gameInfo, toggleImpres
- {!mobile && {gameInfo?.title}} + {!mobile && {t(gameInfo?.title, {ns: gameId})}}
{mobile && } @@ -288,7 +289,7 @@ export function LevelAppBar({isLoading, levelTitle, toggleImpressum, toggleInfo, {/* DESKTOP VERSION */}
- {worldTitle && `${t("World")}: ${worldTitle}`} + {worldTitle && `${t("World")}: ${t(worldTitle, {ns: gameId})}`}
{levelTitle} diff --git a/client/src/components/hints.tsx b/client/src/components/hints.tsx index c75bb2d..5fa5a47 100644 --- a/client/src/components/hints.tsx +++ b/client/src/components/hints.tsx @@ -5,22 +5,25 @@ import { DeletedChatContext, ProofContext } from "./infoview/context"; import { lastStepHasErrors } from "./infoview/goals"; import { Button } from "./button"; import { useTranslation } from "react-i18next"; +import { GameIdContext } from "../app"; /** Plug-in the variable names in a hint. We do this client-side to prepare * for i18n in the future. i.e. one should be able translate the `rawText` * and have the variables substituted just before displaying. */ function getHintText(hint: GameHint): string { + const gameId = React.useContext(GameIdContext) + let { t } = useTranslation() if (hint.rawText) { // Replace the variable names used in the hint with the ones used by the player // variable names are marked like `«{g}»` inside the text. - return hint.rawText.replaceAll(/«\{(.*?)\}»/g, ((_, v) => + return t(hint.rawText, {ns: gameId}).replaceAll(/«\{(.*?)\}»/g, ((_, v) => // `hint.varNames` contains tuples `[oldName, newName]` (hint.varNames.find(x => x[0] == v))[1])) } else { // hints created in the frontend do not have a `rawText` // TODO: `hint.text` could be removed in theory. - return hint.text + return t(hint.text, {ns: gameId}) } } diff --git a/client/src/components/infoview/main.tsx b/client/src/components/infoview/main.tsx index fa39b04..244f7e9 100644 --- a/client/src/components/infoview/main.tsx +++ b/client/src/components/infoview/main.tsx @@ -136,12 +136,15 @@ function DualEditorMain({ worldId, levelId, level, worldSize }: { worldId: strin * If `showLeanStatement` is true, it will additionally display the lean code. */ function ExerciseStatement({ data, showLeanStatement = false }) { + let { t } = useTranslation() + const gameId = React.useContext(GameIdContext) + if (!(data?.descrText || data?.descrFormat)) { return <> } return <>
{data?.descrText && - {(data?.displayName ? `**Theorem** \`${data?.displayName}\`: ` : '') + data?.descrText} + {(data?.displayName ? `**Theorem** \`${data?.displayName}\`: ` : '') + t(data?.descrText, {ns: gameId})} } {data?.descrFormat && showLeanStatement && diff --git a/client/src/components/inventory.tsx b/client/src/components/inventory.tsx index 676be72..a249289 100644 --- a/client/src/components/inventory.tsx +++ b/client/src/components/inventory.tsx @@ -140,7 +140,7 @@ export function Documentation({name, type, handleClose}) {

{doc.data?.displayName}

{doc.data?.statement}

{/* docstring: {doc.data?.docstring} */} - {doc.data?.content} + {t(doc.data?.content, {ns: gameId})}
} diff --git a/client/src/components/level.tsx b/client/src/components/level.tsx index b0582d4..260a196 100644 --- a/client/src/components/level.tsx +++ b/client/src/components/level.tsx @@ -173,11 +173,11 @@ function ChatPanel({lastLevel, visible = true}) { {proof?.completed && <>
- Level completed! 🎉 + {t("Level completed! 🎉")}
{level?.data?.conclusion?.trim() &&
- {level?.data?.conclusion} + {t(level?.data?.conclusion, {ns: gameId})}
} @@ -186,10 +186,10 @@ function ChatPanel({lastLevel, visible = true}) {
{proof?.completed && (lastLevel ? : ) } diff --git a/client/src/components/popup/game_info.tsx b/client/src/components/popup/game_info.tsx index 6d1898c..593c245 100644 --- a/client/src/components/popup/game_info.tsx +++ b/client/src/components/popup/game_info.tsx @@ -4,6 +4,8 @@ import * as React from 'react' import { Typography } from '@mui/material' import Markdown from '../markdown' +import { useTranslation } from 'react-i18next' +import { GameIdContext } from '../../app' /** Pop-up that is displaying the Game Info. * @@ -11,12 +13,15 @@ import Markdown from '../markdown' * controlled by the containing element. */ export function InfoPopup ({info, handleClose}: {info: string, handleClose: () => void}) { + let { t } = useTranslation() + const gameId = React.useContext(GameIdContext) + return
- {info} + {t(info, {ns: gameId})}
diff --git a/client/src/components/world_tree.tsx b/client/src/components/world_tree.tsx index 9fbe100..6e57a57 100644 --- a/client/src/components/world_tree.tsx +++ b/client/src/components/world_tree.tsx @@ -113,6 +113,7 @@ export function WorldIcon({world, title, position, completedLevels, difficulty, difficulty: number, worldSize: number }) { + const { t } = useTranslation() // See level icons. Match radius computed there minus `1.2*r` const N = Math.max(worldSize, NMIN) @@ -151,7 +152,7 @@ export function WorldIcon({world, title, position, completedLevels, difficulty, width={1.42*R} height={1.42*R} transform={"translate("+ -.71*R +","+ -.71*R +")"}>

- {title ? title : world} + {title ? t(title, {ns: gameId}) : world}

@@ -162,7 +163,7 @@ export function WorldIcon({world, title, position, completedLevels, difficulty, >

- {title ? title : world} + {title ? t(title, {ns: gameId}) : world}

}