Environment API Matrix
Pack:
next-intlParent skill: Next Intl Server Runtime Source:next-intl/next-intl-server-runtime/references/environment-api-matrix.md
Read this when
Section titled “Read this when”- deciding between hooks and awaitable APIs
- wiring
i18n/request.ts - debugging missing locale, missing provider, or wrong-environment usage
Request config baseline
Section titled “Request config baseline”Keep i18n/request.ts as the server runtime source of truth.
import {getRequestConfig} from 'next-intl/server';import {hasLocale} from 'next-intl';import {routing} from '@/i18n/routing';
export default getRequestConfig(async ({requestLocale}) => { const requested = await requestLocale; const locale = hasLocale(routing.locales, requested) ? requested : routing.defaultLocale;
return { locale, messages: (await import(`../../messages/${locale}.json`)).default };});requestLocale semantics
Section titled “requestLocale semantics”requestLocaleusually corresponds to the[locale]segment matched by the middleware.- It can be invalid when the dynamic segment catches an unknown path like
/unknown.txt. - It can be
undefinedwhen code renders outside the[locale]segment. - It is bypassed when you pass an explicit
localeto awaitables likegetTranslations({locale: 'en'}).
Which API belongs where
Section titled “Which API belongs where”- non-async shared or Server Components:
useTranslationsuseFormatteruseLocaleuseNowuseTimeZoneuseMessages
- async Server Components:
getTranslationsgetFormattergetLocalegetMessagesgetNowgetTimeZone
- Server Actions, Metadata API, Route Handlers:
- use
next-intl/serverawaitables
- use
- Client Components:
- rely on
NextIntlClientProvider
- rely on
Shared component rule
Section titled “Shared component rule”- A non-async component using
useTranslationscan render as a Server Component by default. - The same component can also run on the client if imported by a Client Component.
- Keep assumptions compatible with both environments.
Provider inheritance
Section titled “Provider inheritance”NextIntlClientProviderbridgeslocale,messages,formats,timeZone, andnowinto client code.- Nested providers inherit these props from ancestors, but props are atomic and do not deep-merge automatically.
- Use
messages={null}when client components should not receive message catalogs. onErrorandgetMessageFallbackare not inherited because they are not serializable. Add them in a client wrapper provider.
High-signal footguns
Section titled “High-signal footguns”- Do not call hook APIs in
asynccomponents. - Do not trust
requestLocaleblindly. - Do not forget that explicit
localearguments overriderequestLocale. - Do not scatter config across layouts and helpers when
getRequestConfig(...)can own it centrally. - Do not leave
nowandtimeZoneimplicit when deterministic formatting matters.
Source map
Section titled “Source map”https://next-intl.dev/docs/usage/configurationhttps://next-intl.dev/docs/environments/server-client-componentshttps://next-intl.dev/docs/getting-started/app-routerhttps://next-intl.dev/blog/next-intl-3-22https://next-intl.dev/blog/date-formatting-nextjs