Skip to content

Commit

Permalink
fixup! Make all strings translateable, translate to German
Browse files Browse the repository at this point in the history
  • Loading branch information
dbrgn committed May 24, 2024
1 parent 23947a5 commit 5d2276e
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 51 deletions.
30 changes: 30 additions & 0 deletions frontend/src/lib/flights.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import type {i18n as I18nextType} from 'i18next';

/**
* Return a verbose translated name for the specified flight.
*/
export function flightName(
flight: {
id: number;
number?: number;
launchAt?: string;
landingAt?: string;
},
i18n: I18nextType,
): string {
let name =
flight.number !== undefined
? i18n.t('flight.snippet--flight-with-number', {
number: flight.number,
})
: i18n.t('flight.snippet--flight-with-id', {id: flight.id});
if (flight.launchAt !== undefined) {
name += ' ';
name += i18n.t('flight.snippet--from', {location: flight.launchAt});
}
if (flight.landingAt !== undefined) {
name += ' ';
name += i18n.t('flight.snippet--to', {location: flight.landingAt});
}
return name;
}
91 changes: 46 additions & 45 deletions frontend/src/routes/flights/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import Flashes from '$lib/components/Flashes.svelte';
import MessageModal from '$lib/components/MessageModal.svelte';
import XContestSummary from '$lib/components/XContestSummary.svelte';
import {flightName} from '$lib/flights';
import {formatDate, formatDistance, formatDuration} from '$lib/formatters';
import {i18n} from '$lib/i18n';
import {addFlash} from '$lib/stores';
Expand All @@ -22,23 +23,15 @@
let deleting = false;
let deleteError: {type: 'authentication'} | {type: 'api-error'; message: string} | undefined;
function flightName(flight: FlightListItem): string {
let name = `Flight ${
flight.number !== undefined ? `${flight.number}` : `with ID ${flight.id}`
}`;
if (flight.launchAt !== undefined) {
const location = data.locations[flight.launchAt];
if (location !== undefined) {
name += ` from ${location.name}`;
}
}
if (flight.landingAt !== undefined) {
const location = data.locations[flight.landingAt];
if (location !== undefined) {
name += ` to ${location.name}`;
}
}
return name;
function flightListItemName(f: FlightListItem): string {
return flightName(
{
...f,
launchAt: f.launchAt === undefined ? undefined : data.locations[f.launchAt]?.name,
landingAt: f.landingAt === undefined ? undefined : data.locations[f.landingAt]?.name,
},
$i18n,
);
}
async function deleteFlight(): Promise<void> {
Expand All @@ -51,7 +44,9 @@
case 204:
// Success
addFlash({
message: `${flightName(flightToDelete)} successfully deleted`,
message: $i18n.t('flights.prose--delete-success', {
flight: flightListItemName(flightToDelete),
}),
severity: 'success',
icon: 'fa-trash-can',
});
Expand Down Expand Up @@ -99,25 +94,23 @@
<MessageModal
type="error"
title={$i18n.t('common.error--api-error')}
message="The flight could not be deleted due to an error on the server: {deleteError.message}"
message={$i18n.t('flights.error--delete-error', {message: deleteError.message})}
showClose={true}
on:closed={() => (deleteError = undefined)}
/>
{:else if flightToDelete !== undefined}
<DialogModal
title="Delete Flight"
message="Are you sure that you want to delete the flight &ldquo;{flightName(
flightToDelete,
)}&rdquo;?"
title={$i18n.t('flights.action--delete-flight')}
message={$i18n.t('flights.prose--delete-confirm', {flight: flightListItemName(flightToDelete)})}
dialogClass="is-danger"
>
<section slot="buttons">
<button class="button is-white" on:click={() => (flightToDelete = undefined)}
>No, cancel</button
>
<button class="button is-danger" disabled={deleting} on:click={() => void deleteFlight()}
>Yes, delete!</button
>
<button class="button is-white" on:click={() => (flightToDelete = undefined)}>
{$i18n.t('common.action--no-cancel')}
</button>
<button class="button is-danger" disabled={deleting} on:click={() => void deleteFlight()}>
{$i18n.t('common.action--yes-delete')}
</button>
</section>
</DialogModal>
{/if}
Expand All @@ -131,30 +124,34 @@

<Flashes bind:this={flashes} />

<h2 class="title is-2">Your Flights</h2>
<h2 class="title is-2">{$i18n.t('flights.title--your-flights')}</h2>

<section>
<p class="content">
You've logged {data.flights.length} flight{data.flights.length === 1 ? '' : 's'} so far!
{$i18n.t('flights.prose--flight-log-count', {count: data.flights.length})}
</p>

<p class="content" style="display: flex; justify-content: space-between;">
<a href="/flights/add/" class="button is-primary">Add flight</a>
<a href="/flights/import/csv/" class="button is-light">Import from CSV</a>
<a href="/flights/add/" class="button is-primary">
{$i18n.t('flights.action--add-flight')}
</a>
<a href="/flights/import/csv/" class="button is-light"
>{$i18n.t('flights.action--import-csv')}</a
>
</p>

<table class="table is-fullwidth is-striped is-hoverable">
<thead>
<tr>
<th>#</th>
<th>Date</th>
<th>Glider</th>
<th>Launch</th>
<th>Landing</th>
<th>Duration</th>
<th>GPS Distance</th>
<th>XContest</th>
<th>Actions</th>
<th>{$i18n.t('flights.column--date')}</th>
<th>{$i18n.t('flights.column--glider')}</th>
<th>{$i18n.t('flights.column--launch')}</th>
<th>{$i18n.t('flights.column--landing')}</th>
<th>{$i18n.t('flights.column--duration')}</th>
<th>{$i18n.t('flights.column--track-distance')}</th>
<th>{$i18n.t('flights.column--xcontest')}</th>
<th>{$i18n.t('flights.column--actions')}</th>
</tr>
</thead>
<tbody>
Expand Down Expand Up @@ -200,28 +197,32 @@
/>
</td>
<td>
<a class="icon" title="View Flight" href="/flights/{flight.id}/">
<a
class="icon"
title={$i18n.t('flights.action--view-flight')}
href="/flights/{flight.id}/"
>
<i class="fa-solid fa-eye"></i>
</a>
<a
class="icon"
title="Edit Flight"
title={$i18n.t('flights.action--edit-flight')}
href="/flights/{flight.id}/edit/"
data-sveltekit-preload-data="tap"
>
<i class="fa-solid fa-pen-square"></i>
</a>
<button
class="icon has-text-danger"
title="Delete Flight"
title={$i18n.t('flights.action--delete-flight')}
on:click={() => (flightToDelete = flight)}
>
<i class="fa-solid fa-trash-alt"></i>
</button>
{#if flight.hasIgc}
<a
class="icon"
title="Download IGC"
title={$i18n.t('flights.action--download-igc')}
href="/api/v1/flights/{flight.id}/igc/"
data-sveltekit-reload
>
Expand Down
6 changes: 2 additions & 4 deletions frontend/src/routes/flights/[id]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import CountryFlag from '$lib/components/CountryFlag.svelte';
import Flashes from '$lib/components/Flashes.svelte';
import XContestSummary from '$lib/components/XContestSummary.svelte';
import {flightName} from '$lib/flights';
import {formatDate, formatDistance, formatDuration, formatTime} from '$lib/formatters';
import {i18n} from '$lib/i18n';
Expand Down Expand Up @@ -29,10 +30,7 @@
<Flashes />

<h2 class="title is-2">
Flight
{#if flight.number}#{flight.number}{/if}
{#if launchAt}from {launchAt.name}{/if}
{#if landingAt}to {landingAt.name}{/if}
{flightName({...flight, launchAt: launchAt?.name, landingAt: landingAt?.name}, $i18n)}
</h2>

<div class="is-flex is-justify-content-space-between mb-5">
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/routes/gliders/[id]/edit/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

<GliderForm glider={data.glider}>
<h2 slot="title" class="title is-2">
{$i18n.t('glider.title--edit-glider', 'Edit glider: {manufacturer} {model}', {
{$i18n.t('glider.title--edit-glider', {
manufacturer: data.glider.manufacturer,
model: data.glider.model,
})}
Expand Down
29 changes: 28 additions & 1 deletion frontend/src/translations/de/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,33 @@
"hint--required-fields": "Benötigte Felder",
"unit--m-asl": "m"
},
"flight": {
"snippet--flight-with-id": "Flug mit ID {id}",
"snippet--flight-with-number": "Flug {number}",
"snippet--from": "von {location}",
"snippet--to": "nach {location}"
},
"flights": {
"action--add-flight": "Flug hinzufügen",
"action--delete-flight": "Flug löschen",
"action--download-igc": "IGC-Datei herunterladen",
"action--edit-flight": "Flug bearbeiten",
"action--import-csv": "CSV-Import",
"action--view-flight": "Flug ansehen",
"column--actions": "Aktionen",
"column--date": "Datum",
"column--duration": "Dauer",
"column--glider": "Fluggerät",
"column--landing": "Landeplatz",
"column--launch": "Startplatz",
"column--track-distance": "Tracklänge",
"column--xcontest": "XContest",
"error--delete-error": "Der Flug konnte aufgrund eines Serverfehlers nicht gelöscht werden: {message}",
"prose--delete-confirm": "Bist du sicher, dass du den {flight} löschen möchtest?",
"prose--delete-success": "{flight} erfolgreich gelöscht",
"prose--flight-log-count": "Du hast bisher {count, plural, =1 {# Flug} other {# Flüge}} gemacht!",
"title--your-flights": "Deine Flüge"
},
"glider": {
"error--add-error": "Das Fluggerät konnte aufgrund eines Serverfehlers nicht hinzugefügt werden: {message}",
"error--update-error": "Das Fluggerät konnte aufgrund eines Serverfehlers nicht aktualisiert werden: {message}",
Expand Down Expand Up @@ -92,7 +119,7 @@
},
"layout": {
"contact": "Kontakt",
"issue-tracker": "Issue Tracker",
"issue-tracker": "Issue-Tracker",
"privacy-policy": "Datenschutzerklärung",
"sourcecode": "Quellcode",
"welcome": "Willkommen, {name}!"
Expand Down
27 changes: 27 additions & 0 deletions frontend/src/translations/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,33 @@
"hint--required-fields": "Required fields",
"unit--m-asl": "m ASL"
},
"flight": {
"snippet--flight-with-id": "Flight with ID {id}",
"snippet--flight-with-number": "Flight {number}",
"snippet--from": "from {location}",
"snippet--to": "to {location}"
},
"flights": {
"action--add-flight": "Add flight",
"action--delete-flight": "Delete Flight",
"action--download-igc": "Download IGC",
"action--edit-flight": "Edit Flight",
"action--import-csv": "Import from CSV",
"action--view-flight": "View Flight",
"column--actions": "Actions",
"column--date": "Date",
"column--duration": "Duration",
"column--glider": "Glider",
"column--landing": "Landing",
"column--launch": "Launch",
"column--track-distance": "Track Distance",
"column--xcontest": "XContest",
"error--delete-error": "The flight could not be deleted due to an error on the server: {message}",
"prose--delete-confirm": "Are you sure that you want to delete {flight}?",
"prose--delete-success": "{flight} successfully deleted",
"prose--flight-log-count": "You've logged {count, plural, =1 {# flight} other {# flights}} so far!",
"title--your-flights": "Your Flights"
},
"glider": {
"error--add-error": "The glider could not be added due to an error on the server: {message}",
"error--update-error": "The glider could not be updated due to an error on the server: {message}",
Expand Down

0 comments on commit 5d2276e

Please sign in to comment.