Skip to content

Commit 1375316

Browse files
committed
feat: translations
1 parent b5baf99 commit 1375316

File tree

5 files changed

+42
-17
lines changed

5 files changed

+42
-17
lines changed

frontend/app/header/header.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { useAtom } from "jotai";
1818

1919
import GlobalState from "../GlobalState";
2020
import { useNavigate } from "react-router";
21+
import { useTranslation } from 'node_modules/react-i18next';
2122

2223
const Header = () => {
2324
const [locationModalState, setLocationModalState] = useAtom(GlobalState.locationModalState);
@@ -26,9 +27,10 @@ const Header = () => {
2627
const [globalLoginModal, setGlobalLoginModal] = useAtom(GlobalState.loginModalState);
2728
const [globalWebWorkerRefState, setGlobalWebWorkerRefState] = useAtom(GlobalState.webWorkerRefState);
2829
const navigate = useNavigate();
30+
const { t } = useTranslation();
2931

3032
const logout = (event: FormEvent) => {
31-
console.log("Logout ",event);
33+
//console.log("Logout ",event);
3234
setJwtTokenState('');
3335
globalWebWorkerRefState?.postMessage({jwtToken: '', newNotificationUrl: ''});
3436
setGlobalWebWorkerRefState(null);
@@ -44,10 +46,10 @@ const Header = () => {
4446
}
4547

4648
return <div className={styles.headerBase}>
47-
<span>Cheap Gas</span>
48-
<Button variant="outlined" onClick={logout} className={styles.headerButton}>Logout</Button>
49-
<Button variant="outlined" onClick={location} className={styles.headerButton}>Location</Button>
50-
<Button variant="outlined" onClick={targetPrice} className={styles.headerButton}>Target Price</Button>
49+
<span>{t('header.title')}</span>
50+
<Button variant="outlined" onClick={logout} className={styles.headerButton}>{t('common.logout')}</Button>
51+
<Button variant="outlined" onClick={location} className={styles.headerButton}>{t('header.location')}</Button>
52+
<Button variant="outlined" onClick={targetPrice} className={styles.headerButton}>{t('header.targetPrice')}</Button>
5153
</div>
5254
}
5355

frontend/app/i18n/en/translation.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,23 @@
1212
"password": "Password",
1313
"login": "Login",
1414
"signin": "Sign In"
15+
},
16+
"header": {
17+
"title": "Cheap Gas",
18+
"location": "Location",
19+
"targetPrice": "Target Price"
20+
},
21+
"location": {
22+
"setLocation": "Set your location",
23+
"searchRadius": "Search Radius (km)",
24+
"postalCode": "Postal Code",
25+
"getLocation": "Get Location"
26+
},
27+
"targetPrice": {
28+
"setTargetPrice": "Set your target prices",
29+
"diesel": "Target Price Diesel",
30+
"e5": "Target Price E5",
31+
"e10": "Target Price E10"
1532
}
33+
1634
}

frontend/app/location-modal/location-modal.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ import { fetchLocation, postLocationRadius } from "../service/http-client";
2020
import { type PostCodeLocation } from "../model/location";
2121
import { type UserRequest } from "../model/user";
2222
import { useAtom } from "jotai";
23+
import { useTranslation } from 'node_modules/react-i18next';
2324

2425
const LocationModal = () => {
2526
let controller: AbortController | null = null;
27+
const { t } = useTranslation();
2628
const [open, setOpen] = useState(false);
2729
const [searchRadius, setSearchRadius] = useState(0);
2830
const [longitude, setLongitude] = useState(0);
@@ -144,23 +146,23 @@ const LocationModal = () => {
144146
renderInput={(params) => <TextField {...params} label="Locations" onChange={handleChange} />}
145147
></Autocomplete>
146148
<div>
147-
<h3>Longitude: {longitude}</h3>
148-
<h3>Latitude: {latitude}</h3>
149-
<h3>Postcode: {postCode}</h3>
149+
<h3>{t('location.longitude')}: {longitude}</h3>
150+
<h3>{t('location.latitude')}: {latitude}</h3>
151+
<h3>{t('location.postalCode')}: {postCode}</h3>
150152
</div>
151153
<TextField
152154
autoFocus
153155
margin="dense"
154156
value={searchRadius}
155157
onChange={handleSearchRadiusChange}
156-
label="Search Radius"
158+
label={t('location.searchRadius')}
157159
type="string"
158160
fullWidth
159161
variant="standard"/>
160162
<div>
161-
<Button type="submit">Ok</Button>
162-
<Button onClick={handleCancel}>Cancel</Button>
163-
<Button className={styles.toright} onClick={handleGetLocation}>Get Location</Button>
163+
<Button type="submit">{t('common.ok')}</Button>
164+
<Button onClick={handleCancel}>{t('common.cancel')}</Button>
165+
<Button className={styles.toright} onClick={handleGetLocation}>{t('location.getLocation')}</Button>
164166
</div>
165167
</Box>
166168
</DialogContent>

frontend/app/main-container/main-container.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ function MainContainer() {
3131
const [globalUserUuidState, setGlobalUserUuidState] = useAtom(GlobalState.userUuidState);
3232
const navigate = useNavigate();
3333

34+
3435
useEffect(() => {
3536
if((!globalJwtTokenState || !globalUserUuidState || globalJwtTokenState.length < 10 || globalUserUuidState.length < 10)) {
3637
navigate('/');

frontend/app/target-price-modal/target-price-modal.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ import { useState, useMemo, type ChangeEventHandler, type FormEvent } from "reac
1717
import { postTargetPrices } from "../service/http-client";
1818
import { type UserRequest } from "../model/user";
1919
import { useAtom } from 'jotai';
20+
import { useTranslation } from 'node_modules/react-i18next';
2021

2122

2223
const TargetPriceModal = () => {
2324
let controller: AbortController | null = null;
25+
const { t } = useTranslation();
2426
const [targetDiesel, setTargetDiesel] = useState('0');
2527
const [targetE5, setTargetE5] = useState('0');
2628
const [targetE10, setTargetE10] = useState('0');
@@ -100,7 +102,7 @@ const TargetPriceModal = () => {
100102
margin="dense"
101103
value={targetDiesel}
102104
onChange={handleTargetDieselChange}
103-
label="Targetprice Diesel"
105+
label={t('targetPrice.diesel')}
104106
type="string"
105107
fullWidth
106108
variant="standard" />
@@ -109,7 +111,7 @@ const TargetPriceModal = () => {
109111
margin="dense"
110112
value={targetE5}
111113
onChange={handleTargetE5Change}
112-
label="Targetprice E5"
114+
label={t('targetPrice.e5')}
113115
type="string"
114116
fullWidth
115117
variant="standard" />
@@ -118,14 +120,14 @@ const TargetPriceModal = () => {
118120
margin="dense"
119121
value={targetE10}
120122
onChange={handleTargetE10Change}
121-
label="Targetprice E10"
123+
label={t('targetPrice.e10')}
122124
type="string"
123125
fullWidth
124126
variant="standard" />
125127
</div>
126128
<div>
127-
<Button type="submit">Ok</Button>
128-
<Button onClick={handleCancel}>Cancel</Button>
129+
<Button type="submit">{t('common.ok')}</Button>
130+
<Button onClick={handleCancel}>{t('common.cancel')}</Button>
129131
</div>
130132
</Box>
131133
</DialogContent>

0 commit comments

Comments
 (0)