Internationalization using next-intl
A Content SDK app created from the Next.js App Router template ships with built-in integration for internationalization using next-intl. The integration handles the following:
-
Locale-aware routing (including multisite support).
-
Server and client component translation access patterns.
-
Dictionary phrase retrieval from Sitecore per site (namespaced by
siteName).
You declare supported locales, configure the default locale, and control prefix behavior in src/i18n/routing.ts. You provide server-only resolution of locale plus dictionary phrases in src/i18n/request.ts.
Before you begin, configure languages in SitecoreAI before wiring up application-level i18n.
Configuration files
Your application directory's i18n folder contains two integration files provided by the next-intl package to support internationalization.
-
src/i18n/routing.ts- You must use this file to configure the following:-
All supported locales
-
Default language
-
Locale prefix setting
See the following example of the
routing.tsfile: -
-
src/i18n/request.ts- This file exposes thedefineRequestConfigfunction fromnext-intland resolves, per request, the current locale and associated dictionary phrases from Sitecore. This is then used by server components that can't use hooks.
Localized routing in multisite and SSG solutions
The Content SDK Next.js App Router template contains the following to support localized routing in multisite scenarios and static site generation (SSG):
-
Two leading segments as shown below in the catch-all route to match the current site and locale.
-
localeMiddlewareruns first insrc/middleware.ts, resolving the current locale from the configured list, then handing it to subsequent middlewares. -
generateStaticParamsin the catch-all route enumerates all site + locale combinations, producing static parameters for SSG builds.
Component internationalization
Because of Next.js App Router semantics, translation access differs between async server components, regular server components, and client components. All translation retrieval in this setup is ultimately backed by phrases fetched from Sitecore using the dictionary service in request.ts, namespaced by page.siteName (or equivalent context), ensuring isolation across sites. For more information, see Internationalization of Server and Client Components.
-
Async server components - primarily fetch data and cannot use hooks. To support this
next-intlprovides awaitable versions of the functions that you usually call as hooks from within the components. You can use them as shown: -
Non-async server components - can use the
useTranslationshook as shown below: -
Client components - receive locale and messages through
NextIntlClientProvider, which the template adds by default to the catch-all route,Page.tsx. Client components use the same functions as the non-async server components:
To retrieve the current locale, you can the appropriate API based on the component type as shown:
To learn more about client components and to optimize their performance, see the official next-intl documentation.