From 6d71b88010eab4b275e97810b681b2e15ab176b2 Mon Sep 17 00:00:00 2001 From: Paul Bienkowski Date: Sun, 12 Mar 2023 12:57:05 +0100 Subject: [PATCH] Translate region frontend --- frontend/src/components/RegionStats/index.tsx | 94 +++++++++---------- frontend/src/pages/MapPage/LayerSidebar.tsx | 4 +- frontend/src/pages/MapPage/RegionInfo.tsx | 26 +++-- frontend/src/translations/de.yaml | 13 +++ frontend/src/translations/en.yaml | 13 +++ frontend/src/translations/fr.yaml | 13 +++ 6 files changed, 95 insertions(+), 68 deletions(-) diff --git a/frontend/src/components/RegionStats/index.tsx b/frontend/src/components/RegionStats/index.tsx index 5dac6b8..6aafa1e 100644 --- a/frontend/src/components/RegionStats/index.tsx +++ b/frontend/src/components/RegionStats/index.tsx @@ -1,46 +1,36 @@ -import React, { useState, useCallback } from "react"; -import { pickBy } from "lodash"; -import { - Loader, - Statistic, - Pagination, - Segment, - Header, - Menu, - Table, - Icon, -} from "semantic-ui-react"; -import { useObservable } from "rxjs-hooks"; -import { of, from, concat, combineLatest } from "rxjs"; -import { map, switchMap, distinctUntilChanged } from "rxjs/operators"; -import { Duration, DateTime } from "luxon"; +import React, {useState, useCallback} from 'react' +import {pickBy} from 'lodash' +import {Loader, Statistic, Pagination, Segment, Header, Menu, Table, Icon} from 'semantic-ui-react' +import {useObservable} from 'rxjs-hooks' +import {of, from, concat, combineLatest} from 'rxjs' +import {map, switchMap, distinctUntilChanged} from 'rxjs/operators' +import {Duration, DateTime} from 'luxon' -import api from "api"; +import api from 'api' +import {useTranslation} from 'react-i18next' function formatDuration(seconds) { return ( Duration.fromMillis((seconds ?? 0) * 1000) - .as("hours") - .toFixed(1) + " h" - ); + .as('hours') + .toFixed(1) + ' h' + ) } export default function Stats() { - const [page, setPage] = useState(1); - const PER_PAGE = 10; + const {t} = useTranslation() + const [page, setPage] = useState(1) + const PER_PAGE = 10 const stats = useObservable( - () => - of(null).pipe( - switchMap(() => concat(of(null), from(api.get("/stats/regions")))) - ), + () => of(null).pipe(switchMap(() => concat(of(null), from(api.get('/stats/regions'))))), null - ); + ) - const pageCount = stats ? Math.ceil(stats.length / PER_PAGE) : 1; + const pageCount = stats ? Math.ceil(stats.length / PER_PAGE) : 1 return ( <> -
Top Regions
+
{t('RegionStats.title')}
@@ -48,36 +38,36 @@ export default function Stats() { - Region name - Event count + {t('RegionStats.regionName')} + {t('RegionStats.eventCount')} - {stats - ?.slice((page - 1) * PER_PAGE, page * PER_PAGE) - ?.map((area) => ( - - {area.name} - {area.overtaking_event_count} - - ))} + {stats?.slice((page - 1) * PER_PAGE, page * PER_PAGE)?.map((area) => ( + + {area.name} + {area.overtaking_event_count} + + ))} - {pageCount > 1 && - - - setPage(data.activePage as number)} - /> - - - } + {pageCount > 1 && ( + + + + setPage(data.activePage as number)} + /> + + + + )}
- ); + ) } diff --git a/frontend/src/pages/MapPage/LayerSidebar.tsx b/frontend/src/pages/MapPage/LayerSidebar.tsx index 0120bc3..7dcf698 100644 --- a/frontend/src/pages/MapPage/LayerSidebar.tsx +++ b/frontend/src/pages/MapPage/LayerSidebar.tsx @@ -72,12 +72,12 @@ function LayerSidebar({ onChange={() => setMapConfigFlag('obsRegions.show', !showRegions)} /> {showRegions && ( <> - Color regions based on event count + {t('MapPage.sidebar.obsRegions.colorByEventCount')}
-
{region.properties.name || "Unnamed region"}
+
{region.properties.name || t('MapPage.regionInfo.unnamedRegion')}
@@ -17,17 +18,14 @@ export default function RegionInfo({ region, mapInfoPortal, onClose }) { - Number of events + {t('MapPage.regionInfo.eventCount')} {region.properties.overtaking_event_count ?? 0} - ); + ) return content && mapInfoPortal - ? createPortal( -
{content}
, - mapInfoPortal - ) - : null; + ? createPortal(
{content}
, mapInfoPortal) + : null } diff --git a/frontend/src/translations/de.yaml b/frontend/src/translations/de.yaml index 0097b68..a0f42ff 100644 --- a/frontend/src/translations/de.yaml +++ b/frontend/src/translations/de.yaml @@ -158,6 +158,10 @@ MapPage: obsEvents: title: Überholvorgänge + obsRegions: + title: Regionen + colorByEventCount: Regionen eingefärbt nach Anzahl Überholungen + filters: title: Filter needsLogin: Filter sind ohne Login nicht verfügbar. @@ -203,6 +207,10 @@ MapPage: west: westwärts northWest: nordwestwärts + regionInfo: + unnamedRegion: Unbenannte Region + eventCount: Anzahl Überholungen + SettingsPage: title: Einstellungen @@ -343,3 +351,8 @@ TrackEditor: vorhanden bleiben. **Nutze diese Funktion mit Bedacht und auf dein eigenes Risiko.** + +RegionStats: + title: Top-Regionen + regionName: Region + eventCount: Anzahl Überholungen diff --git a/frontend/src/translations/en.yaml b/frontend/src/translations/en.yaml index 15c4aeb..14de675 100644 --- a/frontend/src/translations/en.yaml +++ b/frontend/src/translations/en.yaml @@ -164,6 +164,10 @@ MapPage: obsEvents: title: Event points + obsRegions: + title: Regions + colorByEventCount: Color regions are based on event count + filters: title: Filters needsLogin: No filters available without login. @@ -208,6 +212,10 @@ MapPage: west: west bound northWest: north-west bound + regionInfo: + unnamedRegion: Unnamed region + eventCount: Event count + SettingsPage: title: Settings @@ -342,3 +350,8 @@ TrackEditor: later. **Use at your own risk.** + +RegionStats: + title: Top regions + regionName: Region name + eventCount: Event count diff --git a/frontend/src/translations/fr.yaml b/frontend/src/translations/fr.yaml index 7248f70..6367382 100644 --- a/frontend/src/translations/fr.yaml +++ b/frontend/src/translations/fr.yaml @@ -164,6 +164,10 @@ MapPage: obsEvents: title: Points d'événement + obsRegions: + title: Régions + colorByEventCount: Couleurs des régions sont basées sur le nombre d'événements + filters: title: Filtres needsLogin: Aucun filtre disponible sans être connecté. @@ -208,6 +212,10 @@ MapPage: west: Ouest northWest: Nord-Ouest + regionInfo: + unnamedRegion: Région sans nom + eventCount: Nombre de dépassements + SettingsPage: title: Paramètres @@ -343,3 +351,8 @@ TrackEditor: ou les rendez anonymes plus tard. **Utilisation à vos risques et périls.** + +RegionStats: + title: Top régions + regionName: Nom de la région + eventCount: Nombre de dépassements