🚨 Problem with i18n in Next.js v14.2.5
Unanswered
Soft-Coated Wheaten Terrier posted this in #help-forum
Soft-Coated Wheaten TerrierOP
I'm using the app/ directory with internationalization (i18n) and set everything up in next.config.js, but Next.js can't find my [lang]/layout.tsx and [lang]/page.tsx files.
3 Replies
Soft-Coated Wheaten TerrierOP
my config.ts:
export const locales = ['bg', 'en'] as const;
i18n.ts:
import { getRequestConfig } from "next-intl/server";
import { notFound } from "next/navigation";
import { locales } from "./config";
import { error } from "node:console";
export default getRequestConfig(async ({ locale }) => {
if (!locales.includes(locale as any)) {
console.error(
Unsupported locale: ${locale});
alert(
Unsupported locale: ${locale});
notFound();
}
return {
locale: locale as string, // Ensure locale is always a string
messages: (await import(
./messages/${locale}.json)).default,
};
});
middleware.ts:
// middleware.ts
import createMiddleware from "next-intl/middleware";
import { locales } from "./config"; // ✅ you already have this
export default createMiddleware({
locales,
defaultLocale: "bg",
});
export const config = {
matcher: ["/((?!api|_next|favicon.ico|.*\\..*).*)"],
};