next-i18n-middleware
v0.0.7
Published
Simple i18n middleware for Next.js
Downloads
6
Maintainers
Readme
next-i18n-middleware
This is a package created to handle i18n in Next.js projects.
Install
# NPM
npm install --save next-i18n-middleware
Example
// 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>
);
}
File Structure
├── middleware.ts
└── app
└── [locale]
├── layout.tsx
└── page.tsx