feat: Speiseplan-Inhalte variabel mehrsprachig (Teil 2)
Gerichtnamen, Essenszeiten und Allergen-/Zusatzstoff-Bezeichnungen sind jetzt genauso dynamisch mehrsprachig wie die Bedienoberfläche aus v1.10.0, statt fest auf Englisch/Polnisch begrenzt zu sein. Neue Übersetzungstabellen ersetzen die alten name_en/name_pl-Spalten, DeepL-Auto-Übersetzung und CSV-Import/-Export unterstützen jetzt beliebig viele aktive Sprachen.
This commit is contained in:
@@ -7,13 +7,12 @@ import { useCallback, useEffect, useState } from "react";
|
||||
import { formatMessage } from "@/lib/i18n/shared";
|
||||
import { localized } from "@/lib/types";
|
||||
import type { Section } from "@/lib/types";
|
||||
import { useDict, useLocale } from "@/components/i18n/LocaleProvider";
|
||||
import { useDict, useLanguages, useLocale } from "@/components/i18n/LocaleProvider";
|
||||
|
||||
interface SectionForm {
|
||||
key: string | null; // null = neue Essenszeit
|
||||
label: string;
|
||||
labelEn: string;
|
||||
labelPl: string;
|
||||
translations: Record<string, string>;
|
||||
timeFrom: string;
|
||||
timeTo: string;
|
||||
}
|
||||
@@ -21,8 +20,7 @@ interface SectionForm {
|
||||
const EMPTY_FORM: SectionForm = {
|
||||
key: null,
|
||||
label: "",
|
||||
labelEn: "",
|
||||
labelPl: "",
|
||||
translations: {},
|
||||
timeFrom: "",
|
||||
timeTo: "",
|
||||
};
|
||||
@@ -35,6 +33,7 @@ function splitTimeRange(range: string): { from: string; to: string } {
|
||||
export default function SectionManager() {
|
||||
const dict = useDict();
|
||||
const locale = useLocale();
|
||||
const languages = useLanguages().filter((l) => l.code !== "de");
|
||||
const [sections, setSections] = useState<Section[]>([]);
|
||||
const [form, setForm] = useState<SectionForm | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
@@ -61,9 +60,8 @@ export default function SectionManager() {
|
||||
if (!label || !form.timeFrom || !form.timeTo) return;
|
||||
const payload = {
|
||||
label,
|
||||
label_en: form.labelEn.trim() || null,
|
||||
label_pl: form.labelPl.trim() || null,
|
||||
time_range: `${form.timeFrom} - ${form.timeTo}`,
|
||||
translations: form.translations,
|
||||
};
|
||||
|
||||
const res = form.key
|
||||
@@ -160,30 +158,28 @@ export default function SectionManager() {
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div className="grid gap-3 sm:grid-cols-2">
|
||||
<div>
|
||||
<label className="label" htmlFor="section-label-en">
|
||||
{dict.sectionManager.nameEnLabel}
|
||||
</label>
|
||||
<input
|
||||
id="section-label-en"
|
||||
className="input"
|
||||
value={form.labelEn}
|
||||
onChange={(e) => setForm({ ...form, labelEn: e.target.value })}
|
||||
/>
|
||||
{languages.length > 0 && (
|
||||
<div className="grid gap-3 sm:grid-cols-2">
|
||||
{languages.map((lang) => (
|
||||
<div key={lang.code}>
|
||||
<label className="label" htmlFor={`section-label-${lang.code}`}>
|
||||
{lang.label}
|
||||
</label>
|
||||
<input
|
||||
id={`section-label-${lang.code}`}
|
||||
className="input"
|
||||
value={form.translations[lang.code] ?? ""}
|
||||
onChange={(e) =>
|
||||
setForm({
|
||||
...form,
|
||||
translations: { ...form.translations, [lang.code]: e.target.value },
|
||||
})
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<div>
|
||||
<label className="label" htmlFor="section-label-pl">
|
||||
{dict.sectionManager.namePlLabel}
|
||||
</label>
|
||||
<input
|
||||
id="section-label-pl"
|
||||
className="input"
|
||||
value={form.labelPl}
|
||||
onChange={(e) => setForm({ ...form, labelPl: e.target.value })}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
<div className="flex gap-3">
|
||||
<div className="max-w-32">
|
||||
<label className="label" htmlFor="section-time-from">
|
||||
@@ -267,8 +263,7 @@ export default function SectionManager() {
|
||||
setForm({
|
||||
key: section.key,
|
||||
label: section.label,
|
||||
labelEn: section.label_en ?? "",
|
||||
labelPl: section.label_pl ?? "",
|
||||
translations: { ...section.translations },
|
||||
timeFrom: from,
|
||||
timeTo: to,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user