Add react_i18n

This commit is contained in:
Hydrogenbear
2024-03-21 18:11:17 +08:00
parent e07570181c
commit cb711205a2
7 changed files with 110 additions and 1 deletions
+8 -1
View File
@@ -1,5 +1,6 @@
import * as React from 'react';
import { useNavigate, Link } from "react-router-dom";
import { useTranslation } from 'react-i18next';
import '@fontsource/roboto/300.css';
import '@fontsource/roboto/400.css';
@@ -138,14 +139,20 @@ function LandingPage() {
"trequetrum/lean4game-logic",
]
let allTiles = allGames.map((gameId) => (useGetGameInfoQuery({game: `g/${gameId}`}).data?.tile))
const { t, i18n } = useTranslation();
return <div className="landing-page">
<header style={{backgroundImage: `url(${bgImage})`}}>
<nav>
<GithubIcon url="https://github.com/leanprover-community/lean4game"/>
</nav>
<div>
<button onClick={() => i18n.changeLanguage("en")}>{flag["English"]}</button>
<button onClick={() => i18n.changeLanguage("fr")}>{flag["French"]}</button>
{/* Add more buttons for other languages as needed */}
</div>
<div id="main-title">
<h1>Lean Game Server</h1>
<h1>{t("Lean Game Server")}</h1>
<p>
A repository of learning games for the
proof assistant <a target="_blank" href="https://leanprover-community.github.io/">Lean</a> <i>(Lean 4)</i> and
+36
View File
@@ -0,0 +1,36 @@
import i18n from "i18next";
import { initReactI18next } from "react-i18next";
// the translations
// (tip move them in a JSON file and import them,
// or even better, manage them separated from your code: https://react.i18next.com/guides/multiple-translation-files)
const resources = {
en: {
translation: {
"Welcome to React": "Welcome to React and react-i18next",
"Lean Game Server": "Lean Game Server translated"
}
},
fr: {
translation: {
"Welcome to React": "Bienvenue à React et react-i18next",
"Lean Game Server": "Lean Game Server French"
}
}
};
i18n
.use(initReactI18next) // passes i18n down to react-i18next
.init({
resources,
lng: "en", // language to use, more information here: https://www.i18next.com/overview/configuration-options#languages-namespaces-resources
// you can use the i18n.changeLanguage function to change the language manually: https://www.i18next.com/overview/api#changelanguage
// if you're using a language detector, do not define the lng option
interpolation: {
escapeValue: false // react already safes from xss
}
});
export default i18n;
+1
View File
@@ -9,6 +9,7 @@ import ErrorPage from './components/error_page'
import Welcome from './components/welcome'
import LandingPage from './components/landing_page'
import Level from './components/level'
import './i18n';