Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(frontend): Add language support for English and Deutsch #50

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
},
"dependencies": {
"autoprefixer": "^10.4.19",
"i18next": "^23.11.4",
"md-to-pdf": "^5.2.4",
"postcss": "^8.4.38",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-i18next": "^14.1.1",
"react-router-dom": "^6.23.0",
"tailwindcss": "^3.4.3"
},
Expand All @@ -29,6 +31,7 @@
"@commitlint/config-conventional": "^19.2.2",
"@commitlint/format": "^19.3.0",
"@eslint/eslintrc": "^3.0.2",
"@types/i18next-browser-languagedetector": "^3.0.0",
"@types/react": "^18.2.66",
"@types/react-dom": "^18.2.22",
"@typescript-eslint/eslint-plugin": "^7.7.1",
Expand Down
21 changes: 20 additions & 1 deletion src/components/home-page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,26 @@
import React from 'react';
import { useTranslation } from 'react-i18next';

const Homepage: React.FC = () => {
return <h2>Home</h2>;
const { t, i18n } = useTranslation();

const changeLanguage = (event: React.ChangeEvent<HTMLSelectElement>) => {
const selectedLanguage = event.target.value;
i18n.changeLanguage(selectedLanguage);
};

return (
<>
<h1>Home</h1>
<div>
<select onChange={changeLanguage} value={i18n.language}>
<option value="en">English</option>
<option value="de">Deutsch</option>
</select>
</div>
<div>{t('welcome')}</div>
</>
);
};

export default Homepage;
26 changes: 26 additions & 0 deletions src/i18n.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import i18n from 'i18next';
import { initReactI18next } from 'react-i18next';
import LanguageDetector from 'i18next-browser-languagedetector';
import enJSon from './i18n/en.json';
import deJSon from './i18n/de.json';

i18n
.use(LanguageDetector)
.use(initReactI18next)
.init({
fallbackLng: 'en',
debug: true,
interpolation: {
escapeValue: false,
},
resources: {
en: {
translation: enJSon,
},
de: {
translation: deJSon,
},
},
});

export default i18n;
3 changes: 3 additions & 0 deletions src/i18n/de.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"welcome": "Willkommen bei Lynx-Scanner"
}
3 changes: 3 additions & 0 deletions src/i18n/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"welcome": "Welcome to the Lynx-Scanner"
}
11 changes: 8 additions & 3 deletions src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import React from 'react';
import ReactDOM from 'react-dom/client';
import { App } from './app.tsx';

import { I18nextProvider } from 'react-i18next';
import i18n from './i18n';
import './index.scss';

ReactDOM.createRoot(document.getElementById('root')!).render(
const rootElement = document.getElementById('root') as HTMLElement;
const root = ReactDOM.createRoot(rootElement);
root.render(
<React.StrictMode>
<App />
<I18nextProvider i18n={i18n}>
<App />
</I18nextProvider>
</React.StrictMode>
);
48 changes: 48 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1114,6 +1114,13 @@
dependencies:
regenerator-runtime "^0.14.0"

"@babel/runtime@^7.23.9":
version "7.24.5"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.24.5.tgz#230946857c053a36ccc66e1dd03b17dd0c4ed02c"
integrity sha512-Nms86NXrsaeU9vbBJKni6gXiEXZ4CVpYVzEjDH9Sb8vmZ3UljyA1GSOJl/6LGPO8EHLuSF9H+IxNXHPX8QHJ4g==
dependencies:
regenerator-runtime "^0.14.0"

"@babel/template@^7.22.15", "@babel/template@^7.24.0":
version "7.24.0"
resolved "https://registry.npmjs.org/@babel/template/-/template-7.24.0.tgz"
Expand Down Expand Up @@ -1769,6 +1776,13 @@
resolved "https://registry.npmjs.org/@types/estree/-/estree-1.0.5.tgz"
integrity sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw==

"@types/i18next-browser-languagedetector@^3.0.0":
version "3.0.0"
resolved "https://registry.yarnpkg.com/@types/i18next-browser-languagedetector/-/i18next-browser-languagedetector-3.0.0.tgz#5117c813488ec5515f316fd0bbc32e4d03dbaf86"
integrity sha512-jCIazV+0MyFB/re4i+HdqkNLNIWahcVztIPyDoBM2KjrFIhzGyvpclel7ma6xhbm+PvidTDY0eXcFRCO+2QOhQ==
dependencies:
i18next-browser-languagedetector "*"

"@types/json-schema@*", "@types/json-schema@^7.0.15", "@types/json-schema@^7.0.9":
version "7.0.15"
resolved "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.15.tgz"
Expand Down Expand Up @@ -3961,6 +3975,13 @@ highlight.js@^11.7.0:
resolved "https://registry.yarnpkg.com/highlight.js/-/highlight.js-11.9.0.tgz#04ab9ee43b52a41a047432c8103e2158a1b8b5b0"
integrity sha512-fJ7cW7fQGCYAkgv4CPfwFHrfd/cLS4Hau96JuJ+ZTOWhjnhoeN1ub1tFmALm/+lW5z4WCAuAV9bm05AP0mS6Gw==

html-parse-stringify@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/html-parse-stringify/-/html-parse-stringify-3.0.1.tgz#dfc1017347ce9f77c8141a507f233040c59c55d2"
integrity sha512-KknJ50kTInJ7qIScF3jeaFRpMpE8/lfiTdzf/twXyPBLAGrLRTmkz3AdTnKeh40X8k9L2fdYwEp/42WGXIRGcg==
dependencies:
void-elements "3.1.0"

html-tags@^3.3.1:
version "3.3.1"
resolved "https://registry.yarnpkg.com/html-tags/-/html-tags-3.3.1.tgz#a04026a18c882e4bba8a01a3d39cfe465d40b5ce"
Expand Down Expand Up @@ -3992,6 +4013,20 @@ husky@^9.0.11:
resolved "https://registry.npmjs.org/husky/-/husky-9.0.11.tgz"
integrity sha512-AB6lFlbwwyIqMdHYhwPe+kjOC3Oc5P3nThEoW/AaO2BX3vJDjWPFxYLxokUZOo6RNX20He3AaT8sESs9NJcmEw==

i18next-browser-languagedetector@*:
version "7.2.1"
resolved "https://registry.yarnpkg.com/i18next-browser-languagedetector/-/i18next-browser-languagedetector-7.2.1.tgz#1968196d437b4c8db847410c7c33554f6c448f6f"
integrity sha512-h/pM34bcH6tbz8WgGXcmWauNpQupCGr25XPp9cZwZInR9XHSjIFDYp1SIok7zSPsTOMxdvuLyu86V+g2Kycnfw==
dependencies:
"@babel/runtime" "^7.23.2"

i18next@^23.11.4:
version "23.11.4"
resolved "https://registry.yarnpkg.com/i18next/-/i18next-23.11.4.tgz#3f0e620fd2cff3825324191615d0ab0a1eec3baf"
integrity sha512-CCUjtd5TfaCl+mLUzAA0uPSN+AVn4fP/kWCYt/hocPUwusTpMVczdrRyOBUwk6N05iH40qiKx6q1DoNJtBIwdg==
dependencies:
"@babel/runtime" "^7.23.2"

iconv-lite@^0.6.3:
version "0.6.3"
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.6.3.tgz#a52f80bf38da1952eb5c681790719871a1a72501"
Expand Down Expand Up @@ -5384,6 +5419,14 @@ react-dom@^18.2.0:
loose-envify "^1.1.0"
scheduler "^0.23.0"

react-i18next@^14.1.1:
version "14.1.1"
resolved "https://registry.yarnpkg.com/react-i18next/-/react-i18next-14.1.1.tgz#3d942a99866555ae3552c40f9fddfa061e29d7f3"
integrity sha512-QSiKw+ihzJ/CIeIYWrarCmXJUySHDwQr5y8uaNIkbxoGRm/5DukkxZs+RPla79IKyyDPzC/DRlgQCABHtrQuQQ==
dependencies:
"@babel/runtime" "^7.23.9"
html-parse-stringify "^3.0.1"

react-is@^16.13.1:
version "16.13.1"
resolved "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz"
Expand Down Expand Up @@ -6493,6 +6536,11 @@ vite@^5.2.0:
optionalDependencies:
fsevents "~2.3.3"

[email protected]:
version "3.1.0"
resolved "https://registry.yarnpkg.com/void-elements/-/void-elements-3.1.0.tgz#614f7fbf8d801f0bb5f0661f5b2f5785750e4f09"
integrity sha512-Dhxzh5HZuiHQhbvTW9AMetFfBHDMYpo23Uo9btPXgdYP+3T5S+p+jgNy7spra+veYhBP2dCSgxR/i2Y02h5/6w==

vscode-oniguruma@^1.7.0:
version "1.7.0"
resolved "https://registry.npmjs.org/vscode-oniguruma/-/vscode-oniguruma-1.7.0.tgz"
Expand Down
Loading