Skip to content

Commit a56997b

Browse files
committed
feat: add translation
1 parent 06c4a65 commit a56997b

File tree

5 files changed

+36
-16
lines changed

5 files changed

+36
-16
lines changed

frontend/app/i18n/config.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212
*/
1313
import i18next from 'i18next';
1414
import { initReactI18next } from 'react-i18next';
15+
import LanguageDetector from 'i18next-browser-languagedetector';
1516
import translation from './en/translation.json';
1617

17-
i18next.use(initReactI18next).init({
18-
lng: 'en', // if you're using a language detector, do not define the lng option
18+
i18next.use(initReactI18next).use(LanguageDetector).init({
19+
supportedLngs: ['de', 'en'],
20+
fallbackLng: 'en',
1921
debug: true,
2022
resources: {
2123
en: {
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
{
22
"common": {
33
"ok": "OK",
4-
"cancel": "Cancel"
4+
"cancel": "Cancel",
5+
"message": "Message"
6+
},
7+
"login": {
8+
"username": "Username",
9+
"password": "Password",
10+
"login": "Login",
11+
"signin": "Sign In"
512
}
613
}

frontend/app/login/login.tsx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export function Login() {
6666
const [password1, setPassword1] = useState('');
6767
const [password2, setPassword2] = useState('');
6868
const [responseMsg, setResponseMsg] = useState('');
69-
const [activeTab, setActiveTab] = useState(0);
69+
const [activeTab, setActiveTab] = useState(0);
7070

7171
const handleChangeUsername: ChangeEventHandler<HTMLInputElement> = (event) => {
7272
setUserName(event.currentTarget.value as string);
@@ -155,8 +155,8 @@ export function Login() {
155155
return (<Dialog open={globalLoginModal} onClose={handleClose} className="backDrop">
156156
<DialogContent>
157157
<Tabs value={activeTab} onChange={handleTabChange} aria-label="basic tabs example">
158-
<Tab label="Login" {...a11yProps(0)} />
159-
<Tab label="Singin" {...a11yProps(1)} />
158+
<Tab label={t('login.login')} {...a11yProps(0)} />
159+
<Tab label={t('login.signin')} {...a11yProps(1)} />
160160
</Tabs>
161161
<TabPanel value={activeTab} index={0}>
162162
<Box
@@ -171,7 +171,7 @@ export function Login() {
171171
value={userName}
172172
onChange={handleChangeUsername}
173173
id="userName"
174-
label="user name"
174+
label={t('login.username')}
175175
type="string"
176176
fullWidth
177177
variant="standard"
@@ -182,7 +182,7 @@ export function Login() {
182182
value={password1}
183183
onChange={handleChangePassword1}
184184
id="password1"
185-
label="password"
185+
label={t('login.password')}
186186
type="password"
187187
fullWidth
188188
variant="standard"
@@ -193,7 +193,7 @@ export function Login() {
193193
</div>
194194
<div className={styles.responseMsg}>
195195
{[responseMsg].filter(value => !!value).map((value, index) =>
196-
<span key={index}>Message: {value}</span>
196+
<span key={index}>{t('common.message')}: {value}</span>
197197
)}
198198
</div>
199199
</Box>
@@ -211,7 +211,7 @@ export function Login() {
211211
value={userName}
212212
onChange={handleChangeUsername}
213213
id="userName"
214-
label="user name"
214+
label={t('login.username')}
215215
type="string"
216216
fullWidth
217217
variant="standard"
@@ -222,7 +222,7 @@ export function Login() {
222222
value={password1}
223223
onChange={handleChangePassword1}
224224
id="password1"
225-
label="password"
225+
label={t('login.password')}
226226
type="password"
227227
fullWidth
228228
variant="standard"
@@ -233,18 +233,18 @@ export function Login() {
233233
value={password2}
234234
onChange={handleChangePassword2}
235235
id="password2"
236-
label="password"
236+
label={t('login.password')}
237237
type="password"
238238
fullWidth
239239
variant="standard"
240240
/>
241241
<div>
242-
<Button type="submit">Ok</Button>
243-
<Button onClick={handleCancel}>Cancel</Button>
242+
<Button type="submit">{t('common.ok')}</Button>
243+
<Button onClick={handleCancel}>{t('common.cancel')}</Button>
244244
</div>
245245
<div className={styles.responseMsg}>
246246
{[responseMsg].filter(value => !!value).map((value, index) =>
247-
<span key={index}>Message: {value}</span>
247+
<span key={index}>{t('common.message')}: {value}</span>
248248
)}
249249
</div>
250250
</Box>

frontend/package-lock.json

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"@mui/material": "^7.3.4",
2020
"@react-router/node": "^7.9.2",
2121
"@react-router/serve": "^7.9.2",
22+
"i18next-browser-languagedetector": "^8.2.0",
2223
"isbot": "^5.1.31",
2324
"jotai": "^2.15.0",
2425
"nano": "^11.0.3",
@@ -35,10 +36,10 @@
3536
"@types/node": "^22",
3637
"@types/react": "^19.1.13",
3738
"@types/react-dom": "^19.1.9",
38-
"tailwindcss": "^4.1.13",
3939
"cpy-cli": "^5.0.0",
4040
"mkdirp": "^3.0.0",
4141
"rimraf": "^5.0.0",
42+
"tailwindcss": "^4.1.13",
4243
"typescript": "^5.9.2",
4344
"vite": "^7.1.11",
4445
"vite-tsconfig-paths": "^5.1.4"

0 commit comments

Comments
 (0)