Q28: How does Internationalized (i18n) Routing work in the Pages Router?
Next.js provides built-in internationalized routing configured in next.config.js. Supports two strategies: Sub-path Routing (/en/blog, /fr/blog) and Domain Routing (example.com/blog, example.fr/blog).
i18n Configuration
// next.config.js
module.exports = {
i18n: {
locales: ['en', 'fr', 'es'],
defaultLocale: 'en',
},
};💡 Automatically handles sub-path localization routing across all pages.
Key Takeaways
- Configure
i18nobject innext.config.jswithlocalesanddefaultLocale. - Access active locale via
useRouter().localeorcontext.locale.
Knowledge Check
How do you access the active locale string inside getStaticProps?