fix(i18n): internalize locale logic in LandingPage to resolve content mismatch

This commit is contained in:
dyzulk
2026-01-09 10:55:34 +07:00
parent 3b51264fef
commit 10fd0c3a43
11 changed files with 8 additions and 36 deletions

View File

@@ -1,8 +1,9 @@
import { ArrowRight, Shield, Globe, Lock, Server, Zap, ChevronRight } from "lucide-react"; import { ArrowRight, Shield, Globe, Lock, Server, Zap, ChevronRight } from "lucide-react";
import Link from 'next/link'; import Link from 'next/link';
import { useRouter } from 'next/router';
interface LandingPageProps { interface LandingPageProps {
locale?: 'en' | 'id'; locale?: string;
} }
const translations = { const translations = {
@@ -46,9 +47,12 @@ const translations = {
} }
}; };
export function LandingPage({ locale = 'en' }: LandingPageProps) { export function LandingPage({ locale: propLocale }: LandingPageProps) {
console.log('LandingPage Locale:', locale); const { locale: routerLocale, defaultLocale } = useRouter();
const t = translations[locale] || translations.en; const currentLocale = (propLocale || routerLocale || defaultLocale || 'en') as 'en' | 'id';
console.log('LandingPage Final Locale:', currentLocale);
const t = translations[currentLocale] || translations.en;
return ( return (
<div className="flex flex-col gap-16 py-8"> <div className="flex flex-col gap-16 py-8">

View File

@@ -1,21 +0,0 @@
import { NextRequest, NextResponse } from 'next/server'
const PUBLIC_FILE = /\.(.*)$/
export function middleware(req: NextRequest) {
if (
req.nextUrl.pathname.startsWith('/_next') ||
req.nextUrl.pathname.includes('/api/') ||
PUBLIC_FILE.test(req.nextUrl.pathname)
) {
return
}
if (req.nextUrl.locale === 'default') {
const locale = req.cookies.get('NEXT_LOCALE')?.value || 'en'
return NextResponse.redirect(
new URL(`/${locale}${req.nextUrl.pathname}${req.nextUrl.search}`, req.url)
)
}
}

View File

@@ -1,11 +0,0 @@
import { useRouter } from 'next/router'
import { LandingPage } from '../components/LandingPage'
export const Index = () => {
const { locale } = useRouter()
return <LandingPage locale={locale} />
}
<Index />
# DEBUG_ID_FILE_RENDERED