From 5b07f579d5c9f3129d9ad95159fd4c50ee9c4835 Mon Sep 17 00:00:00 2001 From: abdout Date: Sat, 25 Apr 2026 11:34:25 +0300 Subject: [PATCH] fix(404): locale-aware not-found page Reads NEXT_LOCALE from cookies (set by proxy.ts on every visit) and falls back to the default locale. Replaces hardcoded /en link and getDictionary('en') so Arabic users see the Arabic 404 with a button that returns them to /ar instead of /en. Closes #7 Co-Authored-By: Claude Opus 4.7 (1M context) --- src/app/[lang]/not-found.tsx | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/app/[lang]/not-found.tsx b/src/app/[lang]/not-found.tsx index deffbb2..8021649 100644 --- a/src/app/[lang]/not-found.tsx +++ b/src/app/[lang]/not-found.tsx @@ -1,12 +1,20 @@ import Link from 'next/link'; +import { cookies } from 'next/headers'; import { Button } from '@/components/ui/button'; import { getDictionary } from '@/components/internationalization/dictionaries'; -import type { Locale } from '@/components/internationalization/config'; +import { i18n, type Locale } from '@/components/internationalization/config'; + +async function resolveLocale(): Promise { + const store = await cookies(); + const cookieLocale = store.get('NEXT_LOCALE')?.value; + return (i18n.locales as readonly string[]).includes(cookieLocale ?? '') + ? (cookieLocale as Locale) + : i18n.defaultLocale; +} export default async function NotFound() { - // For not-found pages, we can't reliably get locale from params - // so we'll default to English and handle this gracefully - const dict = await getDictionary('en'); + const locale = await resolveLocale(); + const dict = await getDictionary(locale); return (
@@ -16,11 +24,11 @@ export default async function NotFound() {

{dict.errors.notFound}

); -} \ No newline at end of file +}