mirror of
https://github.com/lukevella/rallly.git
synced 2025-05-28 08:16:22 +02:00
Add locale support (#228)
This commit is contained in:
parent
800af20132
commit
416a17c5b7
47 changed files with 967 additions and 467 deletions
22
src/middleware.ts
Normal file
22
src/middleware.ts
Normal file
|
@ -0,0 +1,22 @@
|
|||
import { NextRequest, NextResponse } from "next/server";
|
||||
|
||||
export function middleware({ headers, cookies, nextUrl }: NextRequest) {
|
||||
const locale =
|
||||
cookies.get("NEXT_LOCALE") ??
|
||||
(headers
|
||||
.get("accept-language")
|
||||
?.split(",")?.[0]
|
||||
.split("-")?.[0]
|
||||
.toLowerCase() ||
|
||||
"en");
|
||||
|
||||
const newUrl = nextUrl.clone();
|
||||
newUrl.pathname = `/${locale}${newUrl.pathname}`;
|
||||
|
||||
return NextResponse.rewrite(newUrl);
|
||||
}
|
||||
|
||||
export const config = {
|
||||
// these are paths we should rewrite to prev
|
||||
matcher: ["/admin/:id", "/demo", "/p/:id", "/profile", "/new"],
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue