Implementiere i18n für Frontend, Admin und Datenbank

This commit is contained in:
Hördle Bot
2025-11-28 15:36:06 +01:00
parent 9df9a808bf
commit 771d0d06f3
37 changed files with 3717 additions and 560 deletions

View File

@@ -1,18 +1,32 @@
import { PrismaClient, Special } from '@prisma/client';
import { NextResponse } from 'next/server';
import { requireAdminAuth } from '@/lib/auth';
import { getLocalizedValue } from '@/lib/i18n';
const prisma = new PrismaClient();
export async function GET() {
export async function GET(request: Request) {
const { searchParams } = new URL(request.url);
const locale = searchParams.get('locale');
const specials = await prisma.special.findMany({
orderBy: { name: 'asc' },
// orderBy: { name: 'asc' },
include: {
_count: {
select: { songs: true }
}
}
});
if (locale) {
const localizedSpecials = specials.map(s => ({
...s,
name: getLocalizedValue(s.name, locale),
subtitle: getLocalizedValue(s.subtitle, locale)
})).sort((a, b) => a.name.localeCompare(b.name));
return NextResponse.json(localizedSpecials);
}
return NextResponse.json(specials);
}
@@ -25,10 +39,15 @@ export async function POST(request: Request) {
if (!name) {
return NextResponse.json({ error: 'Name is required' }, { status: 400 });
}
// Ensure name is stored as JSON
const nameData = typeof name === 'string' ? { de: name, en: name } : name;
const subtitleData = subtitle ? (typeof subtitle === 'string' ? { de: subtitle, en: subtitle } : subtitle) : null;
const special = await prisma.special.create({
data: {
name,
subtitle: subtitle || null,
name: nameData,
subtitle: subtitleData,
maxAttempts: Number(maxAttempts),
unlockSteps,
launchDate: launchDate ? new Date(launchDate) : null,
@@ -61,17 +80,19 @@ export async function PUT(request: Request) {
if (!id) {
return NextResponse.json({ error: 'ID required' }, { status: 400 });
}
const updateData: any = {};
if (name) updateData.name = typeof name === 'string' ? { de: name, en: name } : name;
if (subtitle !== undefined) updateData.subtitle = subtitle ? (typeof subtitle === 'string' ? { de: subtitle, en: subtitle } : subtitle) : null;
if (maxAttempts) updateData.maxAttempts = Number(maxAttempts);
if (unlockSteps) updateData.unlockSteps = unlockSteps;
if (launchDate !== undefined) updateData.launchDate = launchDate ? new Date(launchDate) : null;
if (endDate !== undefined) updateData.endDate = endDate ? new Date(endDate) : null;
if (curator !== undefined) updateData.curator = curator || null;
const updated = await prisma.special.update({
where: { id: Number(id) },
data: {
...(name && { name }),
subtitle: subtitle || null, // Allow clearing or setting
...(maxAttempts && { maxAttempts: Number(maxAttempts) }),
...(unlockSteps && { unlockSteps }),
launchDate: launchDate ? new Date(launchDate) : null,
endDate: endDate ? new Date(endDate) : null,
curator: curator || null,
},
data: updateData,
});
return NextResponse.json(updated);
}