From 9ed08004affee1e2a5de2e20911b3d5b794e4439 Mon Sep 17 00:00:00 2001 From: Marc Mintel Date: Wed, 11 Feb 2026 12:07:08 +0100 Subject: [PATCH] fix(i18n): harden locale validation and fix missing translation tags --- i18n/request.ts | 17 ++++++++++++----- messages/de.json | 4 ++-- messages/en.json | 4 ++-- sentry.edge.config.ts | 8 ++++++-- sentry.server.config.ts | 8 ++++++-- 5 files changed, 28 insertions(+), 13 deletions(-) diff --git a/i18n/request.ts b/i18n/request.ts index 3b1795b8..5cf50a78 100644 --- a/i18n/request.ts +++ b/i18n/request.ts @@ -2,11 +2,18 @@ import { getRequestConfig } from 'next-intl/server'; import * as Sentry from '@sentry/nextjs'; export default getRequestConfig(async ({ requestLocale }) => { - let locale = await requestLocale; + // Hardened locale validation: only allow 'en' or 'de' + // Use a temporary variable to validate before assigning to locale + const rawLocale = await requestLocale; + const supportedLocales = ['en', 'de']; + const locale = + typeof rawLocale === 'string' && supportedLocales.includes(rawLocale) ? rawLocale : 'en'; - // Ensure that a valid locale is used - if (!locale || !['en', 'de'].includes(locale)) { - locale = 'en'; + // Log to Sentry if we had to fallback, as it might indicate a routing issue + if (!rawLocale || !supportedLocales.includes(rawLocale as string)) { + console.warn( + `[i18n] Invalid or missing requestLocale received: "${rawLocale}". Falling back to "en".`, + ); } return { @@ -26,6 +33,6 @@ export default getRequestConfig(async ({ requestLocale }) => { return path; } return 'fallback'; - } + }, } as any; }); diff --git a/messages/de.json b/messages/de.json index f5e974e0..c9a8dd11 100644 --- a/messages/de.json +++ b/messages/de.json @@ -206,7 +206,7 @@ "title": "Produktportfolio | Hochwertige Kabel für jede Anwendung", "description": "Entdecken Sie unser umfassendes Sortiment an zertifizierten Kabeln: von Niederspannung über Mittel- und Hochspannung bis hin zu spezialisierten Solarkabeln." }, - "title": "Unsere Produkte", + "title": "Unsere Produkte", "subtitle": "Entdecken Sie unser umfassendes Sortiment an hochwertigen Kabeln für jede Anwendung.", "heroSubtitle": "Produktportfolio", "categoryLabel": "Kategorie", @@ -393,4 +393,4 @@ "cta": "Zurück zur Sicherheit" } } -} \ No newline at end of file +} diff --git a/messages/en.json b/messages/en.json index 3abc721d..c7b7764e 100644 --- a/messages/en.json +++ b/messages/en.json @@ -206,7 +206,7 @@ "title": "Product Portfolio | High-Quality Cables for Every Application", "description": "Explore our comprehensive range of certified cables: from low voltage to medium and high voltage, as well as specialized solar cables." }, - "title": "Our Products", + "title": "Our Products", "subtitle": "Explore our comprehensive range of high-quality cables designed for every application.", "heroSubtitle": "Product Portfolio", "categoryLabel": "Category", @@ -393,4 +393,4 @@ "cta": "Back to Safety" } } -} \ No newline at end of file +} diff --git a/sentry.edge.config.ts b/sentry.edge.config.ts index 4beaf25f..471d7cd6 100644 --- a/sentry.edge.config.ts +++ b/sentry.edge.config.ts @@ -5,6 +5,10 @@ const dsn = process.env.SENTRY_DSN; Sentry.init({ dsn, enabled: Boolean(dsn), - tracesSampleRate: 0, -}); + // Adjust this value in production, or use tracesSampler for greater control + tracesSampleRate: 1, + + // Setting this option to true will print useful information to the console while you're setting up Sentry. + debug: false, +}); diff --git a/sentry.server.config.ts b/sentry.server.config.ts index 4beaf25f..471d7cd6 100644 --- a/sentry.server.config.ts +++ b/sentry.server.config.ts @@ -5,6 +5,10 @@ const dsn = process.env.SENTRY_DSN; Sentry.init({ dsn, enabled: Boolean(dsn), - tracesSampleRate: 0, -}); + // Adjust this value in production, or use tracesSampler for greater control + tracesSampleRate: 1, + + // Setting this option to true will print useful information to the console while you're setting up Sentry. + debug: false, +});