Next.js I18n
⚠️
This feature is only available in the docs theme.
Nextra supports Next.js Internationalized Routing (opens in a new tab) out of the box. These docs explain how to configure and use it.
Add I18n Config
To add multi-language pages to your Nextra application, you need to config
i18n
in next.config.mjs
first:
next.config.mjs
import nextra from 'nextra'
const withNextra = nextra({
theme: 'nextra-theme-docs',
themeConfig: './theme.config.tsx'
})
export default withNextra({
i18n: {
locales: ['en', 'zh', 'de'],
defaultLocale: 'en'
}
})
Add Locale to Filenames
Then, add the locale codes to your file extensions (required for the default locale too):
/pages
_meta.en.json
_meta.zh.json
_meta.de.json
index.en.md
index.zh.md
index.de.md
...
Configure the Docs Theme
Finally, add the i18n
option to your theme.config.jsx
to configure the
language dropdown:
theme.config.jsx
i18n: [
{ locale: 'en', name: 'English' },
{ locale: 'zh', name: '中文' },
{ locale: 'de', name: 'Deutsch' },
{ locale: 'ar', name: 'العربية', direction: 'rtl' }
]