Instruction: Explain the steps to set up internationalized (i18n) routing in a Next.js application.
Context: This question tests the candidate's experience with building multi-language Next.js applications.
Official answer available
Preview the opening of the answer, then unlock the full walkthrough.
Firstly, it's essential to define the locales (languages) that the application will support. In Next.js, this is done within the next.config.js file. Here, you specify the default locale, which is the language your application defaults to if no other locale is detected, and an array of the other locales you intend to support. For example, if you're building an application that supports English, French, and Spanish, with English as the default language, your configuration would look something like this:
module.exports = { i18n: { locales: ['en', 'fr', 'es'], defaultLocale: 'en', }, }...