'多语言'

This commit is contained in:
eric
2026-03-08 04:30:57 -05:00
parent 51eeea3be3
commit def36bf3aa
30 changed files with 6058 additions and 323 deletions

28
proxy.ts Normal file
View File

@@ -0,0 +1,28 @@
import { NextRequest, NextResponse } from "next/server";
const LOCALES = ["zh", "en"] as const;
const DEFAULT_LOCALE = "zh";
function proxy(request: NextRequest) {
const pathname = request.nextUrl.pathname;
// 检查路径是否已有 locale 前缀
const hasLocale = LOCALES.some(
(loc) => pathname === `/${loc}` || pathname.startsWith(`/${loc}/`)
);
if (hasLocale) {
return NextResponse.next();
}
// 根路径或无效路径,重定向到默认 locale
const url = request.nextUrl.clone();
url.pathname = `/${DEFAULT_LOCALE}${pathname === "/" ? "" : pathname}`;
return NextResponse.redirect(url);
}
export { proxy };
export const config = {
matcher: ["/((?!api|trpc|_next|_vercel|.*\\..*).*)"],
};