Closed amannn closed 1 month ago
The latest updates on your projects. Learn more about Vercel for Git ↗︎
Name | Status | Preview | Comments | Updated (UTC) |
---|---|---|---|---|
next-intl-docs | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | Oct 2, 2024 3:56pm |
next-intl-example-app-router | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | Oct 2, 2024 3:56pm |
next-intl-example-app-router-without-i18n-routing | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | Oct 2, 2024 3:56pm |
Since Next.js is switching
headers()
to beasync
, thelocale
that is passed togetRequestConfig
needs to be replaced by an awaitable alternative. Note that this is only relevant for your app in case you're using i18n routing.tldr;
Switch to the new API and call it a day:
If your app worked well before, then this is a 1:1 switch and will get your app in shape for Next.js 15.
Details
The new
requestLocale
parameter also offered a chance to get in some enhancements for edge cases that were previously harder to support. Therefore, the following migration is generally recommended:Before:
After:
The differences are:
requestLocale
is a promise that needs to be awaitedundefined
—therefore a default should be supplied. The default assignment allows handling cases where an error would be thrown previously, e.g. when using APIs likeuseTranslations
on a global language selection page atapp/page.tsx
.locale
should be returned (since you can now adjust it in the function body).notFound()
in response to an invalid[locale]
param inapp/[locale]/layout.tsx
instead of ini18n/request.ts
. This unlocks another use case, where APIs likeuseTranslations
can now be used on a globalapp/not-found.tsx
page.See also the updated getting started docs.
Note that this change is non-breaking, but the synchronously available
locale
is now considered deprecated and will be removed in a future major version.Contributes to https://github.com/amannn/next-intl/issues/1375 Addresses https://github.com/amannn/next-intl/discussions/1355