Docs
/Getting started
/Installation
Installation
npm install next-intl
- Add the provider in
_app.js
.
import {NextIntlProvider} from 'next-intl';
export default function App({Component, pageProps}) {
return (
<NextIntlProvider messages={pageProps.messages}>
<Component {...pageProps} />
</NextIntlProvider>
);
}
- Provide messages on a page-level.
// pages/index.js
export async function getStaticProps({locale}) {
return {
props: {
// You can get the messages from anywhere you like. The recommended
// pattern is to put them in JSON files separated by language and read
// the desired one based on the `locale` received from Next.js.
messages: (await import(`../../messages/${locale}.json`)).default
}
};
}
- Make sure you have internationalized routing set up or alternatively provide an explicit
locale
toNextIntlProvider
. - Use translations in your components!
💡
Next steps:
- Exploring
next-intl
? Check out the usage guide. - Decided you're sticking with
next-intl
? Consider the steps of the checklist for production. - Ran into an issue? Have a look at the minimal setup example to explore a working app.