Skip to content

Commit

Permalink
Merge pull request #203 from JiechengZhao/main
Browse files Browse the repository at this point in the history
add next_i18n
  • Loading branch information
joneugster authored Mar 23, 2024
2 parents a9447a7 + 830bffa commit c24efb1
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 1 deletion.
9 changes: 8 additions & 1 deletion client/src/components/landing_page.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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
Expand Down
36 changes: 36 additions & 0 deletions client/src/i18n.ts
Original file line number Diff line number Diff line change
@@ -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 change: 1 addition & 0 deletions client/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';



Expand Down
61 changes: 61 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@
"cytoscape-klay": "^3.1.4",
"debounce": "^1.2.1",
"express": "^4.18.2",
"i18next": "^23.10.1",
"lean4-infoview": "https://gitpkg.now.sh/leanprover/vscode-lean4/lean4-infoview?de0062c",
"lean4web": "github:hhu-adam/lean4web#414d9e62638a392fca278761b4c61a1d2e138bc7",
"octokit": "^3.1.2",
"path-browserify": "^1.0.1",
"react": "^18.2.0",
"react-country-flag": "^3.1.0",
"react-dom": "^18.2.0",
"react-i18next": "^14.1.0",
"react-markdown": "^8.0.4",
"react-native": "^0.72.3",
"react-redux": "^8.0.5",
Expand Down

0 comments on commit c24efb1

Please sign in to comment.