Content SDK applications that use the Next.js Pages Router template use next-localization to provide Sitecore dictionary phrases to application components. next-localization can be replaced with next-intl in a Content SDK Next.js Pages Router application to use a maintained translation library.
This article describes how to replace next-localization with next-intl in a Content SDK Next.js Pages Router application. The migration updates the translation provider and hooks while continuing to use the dictionary data supplied through page properties.
This topic describes how to:
npm uninstall next-localization
npm install next-intl
The NextIntlClientProvider component makes the current locale and dictionary phrases available to components through next-intl.
To update src/pages/_app.tsx:
import { I18nProvider } from 'next-localization';
import { NextIntlClientProvider } from 'next-intl';
<NextIntlClientProvider
locale={pageProps.page?.locale || scConfig.defaultLanguage}
messages={dictionary || {}}
>
<Component {...rest} />
</NextIntlClientProvider>
import { JSX } from 'react';
import type { AppProps } from 'next/app';
import { NextIntlClientProvider } from 'next-intl';
import Bootstrap from 'src/Bootstrap';
import { SitecorePageProps } from '@sitecore-content-sdk/nextjs';
import scConfig from 'sitecore.config';
function App({ Component, pageProps }: AppProps<SitecorePageProps>): JSX.Element {
const { dictionary, ...rest } = pageProps;
return (
<>
<Bootstrap {...pageProps} />
<NextIntlClientProvider
locale={pageProps.page?.locale || scConfig.defaultLanguage}
messages={dictionary || {}}
>
<Component {...rest} />
</NextIntlClientProvider>
</>
);
}
export default App;
If dictionary keys are converted to nested objects, pass the converted dictionary to messages instead.
Note: For more details and examples, see the next-intl documentation .