From 50d71b1ed6b6848f9123a80e5aea113161c6407d Mon Sep 17 00:00:00 2001 From: Ivan Mercedes Date: Thu, 2 Jul 2026 08:42:37 -0400 Subject: [PATCH] feat: add fallback logic for missing locale dictionaries and update NextIntlClientProvider configuration --- .env.local.example | 2 +- src/app/layout.tsx | 2 +- src/i18n/request.ts | 10 +++++++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.env.local.example b/.env.local.example index f173197..a83e3ea 100644 --- a/.env.local.example +++ b/.env.local.example @@ -42,7 +42,7 @@ META_APP_SECRET=your-meta-app-secret # or a background worker that has no incoming request. NEXT_PUBLIC_SITE_URL=https://crm.example.com -# Default language locale (e.g. en, es) +# Default language locale (e.g. en) NEXT_PUBLIC_APP_LOCALE=en # ============================================================ diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 2565f16..4a8c05a 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -108,7 +108,7 @@ export default async function RootLayout({ /> - + {children} diff --git a/src/i18n/request.ts b/src/i18n/request.ts index 63a3015..20a9318 100644 --- a/src/i18n/request.ts +++ b/src/i18n/request.ts @@ -4,8 +4,16 @@ export default getRequestConfig(async () => { // Read the locale from the environment, defaulting to 'en' const locale = process.env.NEXT_PUBLIC_APP_LOCALE || 'en'; + let messages; + try { + messages = (await import(`../../messages/${locale}.json`)).default; + } catch (error) { + // Fallback to English if the dictionary for the requested locale doesn't exist yet + messages = (await import(`../../messages/en.json`)).default; + } + return { locale, - messages: (await import(`../../messages/${locale}.json`)).default + messages }; });