feat(docs): update 14-internationalization.mdx (#62484)

### Improving Documentation

follow the
[example](https://github.com/vercel/next.js/blob/canary/examples/app-dir-i18n-routing/middleware.ts#L53),
it is better to use NextResponse instead of Response.
This commit is contained in:
bestlyg 2024-02-24 23:11:19 +08:00 committed by GitHub
parent 7d4821de6f
commit e98978033f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -33,6 +33,7 @@ match(languages, locales, defaultLocale) // -> 'en-US'
Routing can be internationalized by either the sub-path (`/fr/products`) or domain (`my-site.fr/products`). With this information, you can now redirect the user based on the locale inside [Middleware](/docs/app/building-your-application/routing/middleware). Routing can be internationalized by either the sub-path (`/fr/products`) or domain (`my-site.fr/products`). With this information, you can now redirect the user based on the locale inside [Middleware](/docs/app/building-your-application/routing/middleware).
```js filename="middleware.js" ```js filename="middleware.js"
import { NextResponse } from "next/server";
let locales = ['en-US', 'nl-NL', 'nl'] let locales = ['en-US', 'nl-NL', 'nl']
@ -53,7 +54,7 @@ export function middleware(request) {
request.nextUrl.pathname = `/${locale}${pathname}` request.nextUrl.pathname = `/${locale}${pathname}`
// e.g. incoming request is /products // e.g. incoming request is /products
// The new URL is now /en-US/products // The new URL is now /en-US/products
return Response.redirect(request.nextUrl) return NextResponse.redirect(request.nextUrl)
} }
export const config = { export const config = {