Skip to main content

Next.js i18n routing

Next.js has built in internationalization routing.

React Bricks starters with Next.js are already configure to leverage the i18n routing.

You just need to add languages to the languages array in next.config.json:

module.exports = {
i18n: {
locales: ['en'], // Add your languages here
defaultLocale: 'en',
localeDetection: false,
},
}

To fetch localized content in Next.js you can use the context:

export const getStaticProps: GetStaticProps = async (context) => {
const { slug } = context.params
try {
const page = await fetchPage(slug.toString(), config.apiKey, context.locale)
return { props: { page } }
} catch {
return { props: { error: 'NOPAGE' } }
}
}