Implementiere i18n für Frontend, Admin und Datenbank
This commit is contained in:
@@ -2,33 +2,38 @@
|
||||
|
||||
import { useEffect, useState } from 'react';
|
||||
import ReactMarkdown from 'react-markdown';
|
||||
import Link from 'next/link';
|
||||
import { Link } from '@/lib/navigation';
|
||||
import { getLocalizedValue } from '@/lib/i18n';
|
||||
|
||||
interface NewsItem {
|
||||
id: number;
|
||||
title: string;
|
||||
content: string;
|
||||
title: any;
|
||||
content: any;
|
||||
author: string | null;
|
||||
publishedAt: string;
|
||||
featured: boolean;
|
||||
special: {
|
||||
id: number;
|
||||
name: string;
|
||||
name: any;
|
||||
} | null;
|
||||
}
|
||||
|
||||
export default function NewsSection() {
|
||||
interface NewsSectionProps {
|
||||
locale: string;
|
||||
}
|
||||
|
||||
export default function NewsSection({ locale }: NewsSectionProps) {
|
||||
const [news, setNews] = useState<NewsItem[]>([]);
|
||||
const [isExpanded, setIsExpanded] = useState(false);
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
fetchNews();
|
||||
}, []);
|
||||
}, [locale]);
|
||||
|
||||
const fetchNews = async () => {
|
||||
try {
|
||||
const res = await fetch('/api/news?limit=3');
|
||||
const res = await fetch(`/api/news?limit=3&locale=${locale}`);
|
||||
if (res.ok) {
|
||||
const data = await res.json();
|
||||
setNews(data);
|
||||
@@ -115,7 +120,7 @@ export default function NewsSection() {
|
||||
fontWeight: '600',
|
||||
color: '#111827'
|
||||
}}>
|
||||
{item.title}
|
||||
{getLocalizedValue(item.title, locale)}
|
||||
</h3>
|
||||
</div>
|
||||
|
||||
@@ -145,14 +150,14 @@ export default function NewsSection() {
|
||||
<>
|
||||
<span>•</span>
|
||||
<Link
|
||||
href={`/special/${item.special.name}`}
|
||||
href={`/special/${getLocalizedValue(item.special.name, locale)}`}
|
||||
style={{
|
||||
color: '#be185d',
|
||||
textDecoration: 'none',
|
||||
fontWeight: '500'
|
||||
}}
|
||||
>
|
||||
★ {item.special.name}
|
||||
★ {getLocalizedValue(item.special.name, locale)}
|
||||
</Link>
|
||||
</>
|
||||
)}
|
||||
@@ -187,7 +192,7 @@ export default function NewsSection() {
|
||||
li: ({ children }) => <li style={{ margin: '0.25rem 0' }}>{children}</li>
|
||||
}}
|
||||
>
|
||||
{item.content}
|
||||
{getLocalizedValue(item.content, locale)}
|
||||
</ReactMarkdown>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user