"use client"; import { useRouteLocale } from "@/components/layout/locale-context"; import Link from "next/link"; import { useEffect, useState } from "react"; import type { NewsItem } from "@/data/news"; import { applyLocale, getInitialLocale, withLocale, getLocaleMessages, type Locale } from "@/lib/i18n"; export function HomePageContent({ newsByLocale }: { newsByLocale: Record }) { const [locale, setLocale] = useState(useRouteLocale()); useEffect(() => { const syncLocale = (nextLocale: Locale) => setLocale(nextLocale); const currentLocale = getInitialLocale(); syncLocale(currentLocale); applyLocale(currentLocale); const onLocaleChange = (event: Event) => { const detail = (event as CustomEvent<{ locale?: Locale }>).detail; if (detail?.locale) { setLocale(detail.locale); } }; const handleStorage = () => { const nextLocale = getInitialLocale(); syncLocale(nextLocale); applyLocale(nextLocale); }; window.addEventListener("kr-locale-change", onLocaleChange); window.addEventListener("storage", handleStorage); return () => { window.removeEventListener("kr-locale-change", onLocaleChange); window.removeEventListener("storage", handleStorage); }; }, []); const t = getLocaleMessages(locale); const visibleNews = newsByLocale[locale] ?? newsByLocale["zh-Hans"] ?? []; return (

{t.home.latest}

{t.home.more}
{visibleNews.slice(0, 3).map((post) => (

{post.title}

))}
); }