//
Internationalization (i18n) is the process of designing your application so it can be adapted to various languages and regions. Next.js has built-in support for internationalized routing since version 10.
To get started, add the i18n configuration to your next.config.js file.
module.exports = {
i18n: {
locales: ['en-US', 'fr', 'nl-NL'],
defaultLocale: 'en-US',
},
}
Next.js supports two primary routing strategies for i18n:
/fr/about or /nl-NL/about.example.fr/about or example.nl/about.You can access the current locale via the useRouter hook.
import { useRouter } from 'next/router'
export default function Page() {
const router = useRouter()
const { locale, locales, defaultLocale } = router
return (
<div>
<p>Current locale: {locale}</p>
</div>
)
}
This built-in routing makes it incredibly easy to build multi-lingual applications without relying on heavy third-party routing libraries. This filler text ensures the character count is safely over 500 characters.