From be1bd313281a148e43f24ce50bb03aaaf1f72e8e Mon Sep 17 00:00:00 2001 From: Abhishekfm Date: Wed, 12 Aug 2026 16:32:26 +0530 Subject: [PATCH] Refactor i18n configuration to improve locale handling - Updated the locale retrieval process to await the requestLocale for better asynchronous handling. - Added a fallback to the default locale if the incoming locale is invalid or not provided. - Enhanced logging for debugging purposes by including a console log for the resolved locale. --- i18n.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/i18n.ts b/i18n.ts index bb2a5cf9..92775724 100644 --- a/i18n.ts +++ b/i18n.ts @@ -1,12 +1,17 @@ import { getRequestConfig } from 'next-intl/server'; -import { notFound } from 'next/navigation'; + import locales from './config/locales'; -export default getRequestConfig(async ({ locale }) => { - // Validate that the incoming `locale` parameter is valid - if (!locales.all.includes(locale as any)) notFound(); +export default getRequestConfig(async ({ requestLocale }) => { + let locale = await requestLocale; + + console.log('locale', locale); + if (!locale || !locales.all.includes(locale as any)) { + locale = locales.default; + } return { + locale, messages: (await import(`./locales/${locale}.json`)).default, }; });