Skip to content

Commit fa878fb

Browse files
author
Lena Emme
committed
fix translation mapping in admin panel
1 parent 3b027ad commit fa878fb

File tree

6 files changed

+32
-22
lines changed

6 files changed

+32
-22
lines changed

src/components/database/editableEntry.svelte

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<script lang="ts">
22
import type { Entry } from "$models/entry.model"
33
4-
import { academicTitleMapping } from "$lib/entryMappings"
4+
import { academicTitleMapping, makeTranslatedMapping, subjectMapping, offerMapping, attributeMapping, accessibleMapping, typeMapping } from "$lib/entryMappings"
55
66
import axios from "axios"
77
import { getObjChanges, replaceFields } from "$lib/utils"
8-
import { t } from "$lib/localization"
8+
import { t, tEntry } from "$lib/localization"
99
import { popupOk, popupError } from "$components/popup.svelte"
1010
1111
import EditableInputField from "$components/database/editableInputField.svelte"
@@ -21,8 +21,6 @@
2121
import XIcon from "lucide-icons-svelte/x.svelte"
2222
import LinkIcon from "lucide-icons-svelte/link.svelte"
2323
24-
const { subjectMapping, typeMapping, offerMapping, attributeMapping, accessibleMapping } = t("entryMapping");
25-
2624
let edit: boolean = false;
2725
export let entry: Entry = null;
2826
@@ -139,7 +137,7 @@
139137
<div class="auto-grid">
140138
<div class="header">
141139
<EditableInputField label="Name des Eintrags" bind:value={ _entry.name } { edit } />
142-
<EditableSelectField label="Kategorie" bind:value={ _entry.type } mapping={ typeMapping } { edit } />
140+
<EditableSelectField label="Kategorie" bind:value={ _entry.type } mapping={ makeTranslatedMapping(typeMapping, tEntry("typeMapping")) } { edit } />
143141
<EditableCheckbox label="Blockiert" bind:checked={ _entry.blocked } { edit } class="narrow"/>
144142
<EditableCheckbox label="Freigeschaltet" bind:checked={ _entry.approved } { edit } class="narrow"/>
145143
</div>
@@ -168,7 +166,7 @@
168166
<span class="group-title"> Kontaktdaten </span>
169167

170168
<div class="sub-grid">
171-
<EditableSelectField label="Titel" bind:value={ _entry.academicTitle } mapping={ academicTitleMapping } nullMapping="Kein Titel" { edit } />
169+
<EditableSelectField label="Titel" bind:value={ _entry.academicTitle } mapping={ makeTranslatedMapping(academicTitleMapping, tEntry("academicTitleMapping")) } nullMapping="Kein Titel" { edit } />
172170
<EditableInputField label="Vorname" bind:value={ _entry.firstName } { edit } />
173171
<EditableInputField label="Nachname" bind:value={ _entry.lastName } { edit } />
174172

@@ -185,19 +183,19 @@
185183
</div>
186184

187185
<div class="sub-grid">
188-
<EditableRadioList label="Angebote" bind:value={ _entry.meta.offers } mapping={ offerMapping[_entry.type] } { edit } />
189-
<EditableRadioList label="Attribute" bind:value={ _entry.meta.attributes } mapping={ attributeMapping[_entry.type] } { edit } />
186+
<EditableRadioList label="Angebote" bind:value={ _entry.meta.offers } mapping={ makeTranslatedMapping(offerMapping[_entry.type], tEntry("offerMapping")) } { edit } />
187+
<EditableRadioList label="Attribute" bind:value={ _entry.meta.attributes } mapping={ makeTranslatedMapping(attributeMapping[_entry.type], tEntry("attributeMapping")) } { edit } />
190188
</div>
191189

192190
<div class="sub-grid">
193191
<EditableInputField label="Besonderheiten" bind:value={ _entry.meta.specials } { edit } />
194192
<EditableInputField label="Mindestalter" number bind:value={ _entry.meta.minAge } { edit } />
195193

196194
{#if subjectMapping[_entry.type]}
197-
<EditableSelectField label="Fachrichtung" bind:value={ _entry.meta.subject } mapping={ subjectMapping[_entry.type] } { edit } />
195+
<EditableSelectField label="Fachrichtung" bind:value={ _entry.meta.subject } mapping={ makeTranslatedMapping(subjectMapping[_entry.type], tEntry("subjectMapping")) } { edit } />
198196
{/if}
199197

200-
<EditableSelectField label="Barrierefrei" bind:value={ _entry.accessible } mapping={ accessibleMapping } { edit } />
198+
<EditableSelectField label="Barrierefrei" bind:value={ _entry.accessible } mapping={ makeTranslatedMapping(accessibleMapping, tEntry("accessibleMapping")) } { edit } />
201199
</div>
202200

203201
<div class="sub-grid grid-full-width">

src/components/entry/entry.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
navigator.share({ url });
5151
} else {
5252
navigator.clipboard.writeText(window.location.origin + url);
53-
popupOk(t("errors.copiedLinktToClipboard"));
53+
popupOk(t("infos.copiedLinkToClipboard"));
5454
}
5555
}
5656
</script>

src/components/forms/submitForm.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@
207207
<Select bind:value={ newEntry.meta.subject } required>
208208
<option value="" disabled selected> { t("submitForm.selectSubject") } </option>
209209

210-
{#each subjectMapping as subject}
210+
{#each subjectMapping[newEntry.type] as subject}
211211
<option value={ subject }> { tEntry("subjectMapping")[subject] } </option>
212212
{/each}
213213
</Select>

src/lib/entryMappings.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,21 +148,33 @@ export const offerMapping = {
148148
]
149149
} as const;
150150

151-
export const subjectMapping = [
152-
"therapist",
153-
"psychologist",
154-
"naturopath",
155-
"other"
156-
] as const;
151+
export const subjectMapping = {
152+
therapist: [
153+
"therapist",
154+
"psychologist",
155+
"naturopath",
156+
"other"
157+
]
158+
};
157159

158160
export const accessibleMapping = [
159161
"unknown",
160162
"yes",
161163
"no"
162-
] as const;
164+
];
163165

164166
export const academicTitleMapping = [
165167
"dr",
166168
"prof",
167169
"prof_dr"
168-
]
170+
]
171+
172+
export function makeTranslatedMapping(mapping: string[], translation: Record<string, string>) {
173+
let m = {};
174+
175+
for (const key of mapping) {
176+
m[key] = translation[key];
177+
}
178+
179+
return m;
180+
}

src/locales/de.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@
313313
},
314314
"infos": {
315315
"copiedToClipboard": "Text in die Zwischenablage kopiert!",
316-
"copiedLinktToClipboard": "Link in die Zwischenablage kopiert!"
316+
"copiedLinkToClipboard": "Link in die Zwischenablage kopiert!"
317317
},
318318
"altTexts": {
319319
"contribute": "Mehrere Hände beschriften einen Papierbogen",

src/locales/en.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@
313313
},
314314
"infos": {
315315
"copiedToClipboard": "Text copied to clipboard!",
316-
"copiedLinktToClipboard": "Link copied to clipboard!"
316+
"copiedLinkToClipboard": "Link copied to clipboard!"
317317
},
318318
"altTexts": {
319319
"contribute": "Several hands writing a sheet of paper",

0 commit comments

Comments
 (0)