feat: add fallback logic for missing locale dictionaries and update NextIntlClientProvider configuration

This commit is contained in:
Ivan Mercedes 2026-07-02 08:42:37 -04:00
parent 1ce9581117
commit 50d71b1ed6
3 changed files with 11 additions and 3 deletions

View File

@ -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
# ============================================================

View File

@ -108,7 +108,7 @@ export default async function RootLayout({
/>
</head>
<body className="min-h-full bg-background text-foreground font-sans">
<NextIntlClientProvider messages={messages}>
<NextIntlClientProvider messages={messages} locale={locale}>
<ThemeProvider>
{children}
<ThemedToaster />

View File

@ -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
};
});