Nextra supports Next.js Internationalized Routing out of the box, allowing you to serve documentation in multiple languages from the same codebase. You define your locales inDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/shuding/nextra/llms.txt
Use this file to discover all available pages before exploring further.
next.config.mjs, organize content into per-locale directories, and configure the language switcher dropdown in your theme layout.
Setup
import nextra from 'nextra'
const withNextra = nextra({})
export default withNextra({
i18n: {
locales: ['en', 'zh', 'de'],
defaultLocale: 'en'
}
})
You can use any valid
UTS Locale Identifier
for your locale codes, including region variants like
en-US or zh-TW.Pass the
i18n prop to the <Layout> component in your root layout.tsx to wire up the language-switcher dropdown that appears in the navbar:import { Layout } from 'nextra-theme-docs'
export default function RootLayout({ children, params }) {
return (
<Layout
i18n={[
{ locale: 'en', name: 'English' },
{ locale: 'zh', name: '中文' },
{ locale: 'de', name: 'Deutsch' },
{ locale: 'ar', name: 'العربية', direction: 'rtl' }
]}
{/* ...other props */}
>
{children}
</Layout>
)
}
content/
├── en/
│ ├── _meta.js
│ ├── index.mdx
│ └── getting-started.mdx
├── zh/
│ ├── _meta.js
│ ├── index.mdx
│ └── getting-started.mdx
└── de/
├── _meta.js
├── index.mdx
└── getting-started.mdx
Each locale directory can have its own
_meta.js file to control sidebar ordering and titles in that language.To redirect users to their preferred language automatically, create a
proxy.ts (or proxy.js) file at the root of your project and re-export Nextra’s middleware:export { middleware } from 'nextra/locales'
export const config = {
matcher: ['/((?!_next|_static|_vercel|[\\w-]+\\.\\w+).*)']
}
Automatic locale detection via middleware does not work for sites
statically exported with
output: 'export' in nextConfig.For i18n sites using a shared theme layout, you can add a locale-aware custom
not-found page. See the SWR i18n example for a reference implementation.Locale-Aware Links
Theunstable_shouldAddLocaleToLinks option in your Nextra config controls whether locale prefixes are automatically added to links in the page map. This is useful when you are not using Nextra’s built-in middleware for locale detection:
Per-Locale _meta.js Files
Each locale directory can contain a _meta.js file to customize the sidebar navigation for that language. This lets you set translated titles and control page order independently per locale:
Configuration Reference
| Option | Type | Default | Description |
|---|---|---|---|
i18n.locales | string[] | — | List of supported locale codes. |
i18n.defaultLocale | string | — | The locale used when no locale prefix is present in the URL. |
unstable_shouldAddLocaleToLinks | boolean | false | Prefix locale to all links in the page map — useful when not using Nextra’s middleware function. |