refactor: make locale handling truly centralized and robust
- Added getPathWithoutLocale() and buildLocalePath() helpers to locales.ts - Updated Header to use centralized helpers instead of hardcoded regex - Updated middleware to use SUPPORTED_LOCALES in matcher config - Updated LocaleProvider to use isValidLocale() instead of hardcoded array To add a new language now, only update: 1. SUPPORTED_LOCALES in locales.ts 2. LOCALE_CONFIG entry with label, flag, saleorLocale 3. Add translation keys to all message files All routing now uses centralized constants - no more hardcoded locale lists.
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
import { NextIntlClientProvider } from "next-intl";
|
||||
import { getMessages } from "next-intl/server";
|
||||
import { notFound } from "next/navigation";
|
||||
import { SUPPORTED_LOCALES, isValidLocale } from "@/lib/i18n/locales";
|
||||
|
||||
export default async function LocaleProvider({
|
||||
children,
|
||||
@@ -11,8 +12,7 @@ export default async function LocaleProvider({
|
||||
children: React.ReactNode;
|
||||
locale: string;
|
||||
}) {
|
||||
const locales = ["en", "sr"];
|
||||
if (!locales.includes(locale)) notFound();
|
||||
if (!isValidLocale(locale)) notFound();
|
||||
|
||||
const messages = await getMessages();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user