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,6 +1,7 @@
import { NextResponse } from 'next/server';
import { PrismaClient } from '@prisma/client';
import { requireAdminAuth } from '@/lib/auth';
import { getLocalizedValue } from '@/lib/i18n';
const prisma = new PrismaClient();
@@ -10,6 +11,7 @@ export async function GET(request: Request) {
const { searchParams } = new URL(request.url);
const limit = parseInt(searchParams.get('limit') || '10');
const featuredOnly = searchParams.get('featured') === 'true';
const locale = searchParams.get('locale');
const where = featuredOnly ? { featured: true } : {};
@@ -27,6 +29,19 @@ export async function GET(request: Request) {
}
});
if (locale) {
const localizedNews = news.map(item => ({
...item,
title: getLocalizedValue(item.title, locale),
content: getLocalizedValue(item.content, locale),
special: item.special ? {
...item.special,
name: getLocalizedValue(item.special.name, locale)
} : null
}));
return NextResponse.json(localizedNews);
}
return NextResponse.json(news);
} catch (error) {
console.error('Error fetching news:', error);
@@ -52,10 +67,14 @@ export async function POST(request: Request) {
);
}
// Ensure title and content are stored as JSON
const titleData = typeof title === 'string' ? { de: title, en: title } : title;
const contentData = typeof content === 'string' ? { de: content, en: content } : content;
const news = await prisma.news.create({
data: {
title,
content,
title: titleData,
content: contentData,
author: author || null,
featured: featured || false,
specialId: specialId || null
@@ -93,8 +112,8 @@ export async function PUT(request: Request) {
}
const updateData: any = {};
if (title !== undefined) updateData.title = title;
if (content !== undefined) updateData.content = content;
if (title !== undefined) updateData.title = typeof title === 'string' ? { de: title, en: title } : title;
if (content !== undefined) updateData.content = typeof content === 'string' ? { de: content, en: content } : content;
if (author !== undefined) updateData.author = author || null;
if (featured !== undefined) updateData.featured = featured;
if (specialId !== undefined) updateData.specialId = specialId || null;