This is a package created to handle i18n in Next.js projects.
# NPM
npm install --save next-i18n-middleware
// middleware.ts at the root of the project
import { createMiddleware } from "next-i18n-middleware";
export default createMiddleware({
// A list of all locales that are supported
locales: ["en", "de"],
defaultLocale: "en",
});
export const config = {
// Skip all paths that should not be internationalized
matcher: ["/((?!api|_next|.*\\..*).*)"],
};
// app/[locale]/layout.tsx
export default function RootLayout({ children, params: { locale } }) {
// pass locale to your i18n lib
return (
<html lang="en">
<body>{children}</body>
</html>
);
}
├── middleware.ts
└── app
└── [locale]
├── layout.tsx
└── page.tsx