You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/pages/blog/nextjs-root-params.mdx
+18-7
Original file line number
Diff line number
Diff line change
@@ -194,7 +194,7 @@ This needs to be removed now as otherwise this will qualify as a root layout ins
194
194
195
195
### Avoid reading the `[locale]` segment
196
196
197
-
Since `next-intl` provides the current locale via [`useLocale` and `getLocale`](/docs/usage/configuration#locale), you can seamlessly read the locale from these APIs instead of `params`:
197
+
Since `next-intl` provides the current locale via [`useLocale` and `getLocale`](/docs/usage/configuration#locale), you can seamlessly read the locale from these APIs instead of `params` now:
198
198
199
199
```diff filename="src/app/[locale]/layout.tsx"
200
200
+ import {getLocale} from 'next-intl/server';
@@ -223,7 +223,7 @@ Behind the scenes, if you call `useLocale` or `getLocale` in a Server Component,
If you're using async APIs like `getTranslations`, you might have previously passed the locale manually, e.g. to enable static rendering in the Metadata API.
226
+
If you're using async APIs like `getTranslations`, you might have previously passed the locale manually, typically to enable static rendering in the Metadata API.
227
227
228
228
Now, you can remove this and rely on the locale that is returned from `i18n/request.ts`:
229
229
@@ -243,7 +243,17 @@ export async function generateMetadata(
243
243
}
244
244
```
245
245
246
-
The only case where you might still want to pass a locale to `getTranslations` is if your UI renders multiple locales in parallel. If this is the case in your app, you should make sure to accept an override in your `i18n/request.ts` config:
246
+
The only rare case where you might still want to pass a locale to `getTranslations` is if your UI renders messages from multiple locales in parallel:
247
+
248
+
```tsx
249
+
// Use messages from the current locale
250
+
const t =getTranslations();
251
+
252
+
// Use messages from 'en', regardless of what the current user locale is
253
+
const t =getTranslations({locale: 'en'});
254
+
```
255
+
256
+
In this case, you should make sure to accept an override in your `i18n/request.ts` config:
While this article mentions an upcoming `hasLocale` API from `[email protected]` that simplifies working with `rootParams`, you can already try out the API today in the `3.0` range.
335
+
While this article mentions an upcoming `hasLocale` API from `[email protected]` that simplifies working with `rootParams`, you can already try out the API today even in the `3.0` range.
325
336
326
337
The one rare case where a change from `[email protected]` is required, is if you need to [manually pass a locale](#locale-override) to async APIs like `getTranslations` in case your UI renders multiple locales in parallel.
0 commit comments