# Fumadocs (Framework Mode, Next.js): Internationalization
URL: /docs/next/internationalization
Source: https://raw.githubusercontent.com/fuma-nama/fumadocs/refs/heads/main/apps/docs/content/docs/(framework)/[framework]/internationalization.mdx

Support multiple languages in your Next.js docs.

Fumadocs serves your docs and its UI in multiple languages. The rest of your app can use any i18n library.

To set up Fumadocs with i18n on an app, run:

```package-install
npx @fumadocs/cli init --i18n
```

To add i18n to an existing Fumadocs setup, follow the steps below.

## Setup [#setup]

### Define Languages [step] [#define-languages]

```ts title="lib/i18n.ts"
import { defineI18n } from 'fumadocs-core/i18n';

export const i18n = defineI18n({
  defaultLanguage: 'en',
  languages: ['en', 'cn'],
  // serve the default language without a prefix, like `/docs` instead of `/en/docs`
  hideLocale: 'default-locale',
});
```

See [Configuration](/docs/headless/internationalization/config) for other options, like the fallback language.

### Add a Locale Segment [step] [#add-a-locale-segment]

Move your pages and layouts into `app/[lang]`. Route handlers stay outside:

<Files>
<Folder name="app" defaultOpen>
<File name="api/search/route.ts" />

<Folder name="[lang]" defaultOpen>
<File name="layout.tsx" />

<File name="(home)/page.tsx" />

<File name="docs/[[...slug]]/page.tsx" />
</Folder>
</Folder>
</Files>

Update the relative imports of the moved files, like the import of `global.css`.

#### Proxy [#middleware]

Add a proxy to redirect or rewrite requests without a locale, following `hideLocale`:

```ts title="proxy.ts"
import { createI18nMiddleware } from 'fumadocs-core/i18n/middleware';
import { i18n } from '@/lib/i18n';

export default createI18nMiddleware(i18n);

export const config = {
  // skip `/api` and Next.js internals, add the files of `public` here too
  matcher: ['/((?!api|_next/static|_next/image|favicon.ico).*)'],
};
```

You can use another proxy, like one from an i18n library, if it handles `hideLocale` the same way. With `output: 'export'`, the proxy doesn't run, so remove `hideLocale` to keep the locale in every URL.

### Translate the UI [step] [#translations]

Define the UI translations next to your layout options, and take the locale in `baseOptions()`:

```tsx title="lib/layout.shared.tsx"
import { i18n } from '@/lib/i18n';
import { uiTranslations } from 'fumadocs-ui/i18n';
import type { BaseLayoutProps } from 'fumadocs-ui/layouts/shared';

export const translations = i18n
  .translations()
  .extend(uiTranslations())
  .add({
    cn: {
      // the name in the language switch
      displayName: '中文',
      'Search(search trigger)': '搜尋文檔',
    },
  });

export function baseOptions(locale: string): BaseLayoutProps {
  return {
    nav: {
      title: 'My App',
      url: `/${locale}`,
    },
  };
}
```

A [language pack](/docs/ui/translations#language-packs) translates the whole UI at once.

Pass the translations to `<RootProvider />`:

```tsx title="app/[lang]/layout.tsx"
import { RootProvider } from 'fumadocs-ui/provider/next';
import { i18nProvider } from 'fumadocs-ui/i18n';
import { translations } from '@/lib/layout.shared';

export default async function Layout({ params, children }: LayoutProps<'/[lang]'>) {
  const { lang } = await params;

  return (
    <html lang={lang} suppressHydrationWarning>
      <body className="flex flex-col min-h-screen">
        <RootProvider i18n={i18nProvider(translations, lang)}>{children}</RootProvider>
      </body>
    </html>
  );
}
```

### Pass the Locale [step] [#pass-the-locale]

Add your i18n config to `loader()`:

```ts title="lib/source.ts"
import { i18n } from '@/lib/i18n';

export const source = loader({
  i18n, // [!code ++]
  // ...
});
```

Then pass the locale of the route to your layouts and pages:

```tsx tab="Home Layout" title="app/[lang]/(home)/layout.tsx"
export default async function Layout({ params, children }: LayoutProps<'/[lang]'>) {
  const { lang } = await params;

  return <HomeLayout {...baseOptions(lang)}>{children}</HomeLayout>;
}
```

```tsx tab="Docs Layout" title="app/[lang]/docs/layout.tsx"
export default async function Layout({ params, children }: LayoutProps<'/[lang]/docs'>) {
  const { lang } = await params;

  return (
    <DocsLayout {...baseOptions(lang)} tree={source.getPageTree(lang)}>
      {children}
    </DocsLayout>
  );
}
```

```tsx tab="Docs Page" title="app/[lang]/docs/[[...slug]]/page.tsx"
export default async function Page(props: PageProps<'/[lang]/docs/[[...slug]]'>) {
  const params = await props.params;
  // also in `generateMetadata()`
  const page = source.getPage(params.slug, params.lang);
  if (!page) notFound();

  // ...
}

export function generateStaticParams() {
  // for a segment other than `[lang]`, pass its name: `generateParams('slug', 'locale')`
  return source.generateParams();
}
```

## Translated Pages [#translated-pages]

Add the locale to the file name of a page or meta file to translate it:

<Files>
<Folder name="content/docs" defaultOpen>
<File name="meta.json" />

<File name="meta.cn.json" />

<File name="get-started.mdx" />

<File name="get-started.cn.mdx" />
</Folder>
</Files>

A page without a translation falls back to the default language. To group files in a folder per language instead, see [i18n routing](/docs/next/page-conventions#i18n-routing).

## Links [#links]

Fumadocs layouts add the locale to their links.

In your own components and MDX content, `DynamicLink` fills `[lang]` with the locale of the current route:

```tsx
import { DynamicLink } from 'fumadocs-core/dynamic-link';

// `/cn/docs` on a Chinese page
<DynamicLink href="/[lang]/docs">Docs</DynamicLink>;
```

To use it in MDX, add it to your MDX components:

```tsx title="components/mdx.tsx"
import { DynamicLink } from 'fumadocs-core/dynamic-link';

export function getMDXComponents(components?: MDXComponents) {
  return {
    ...defaultMdxComponents,
    DynamicLink, // [!code ++]
    ...components,
  } satisfies MDXComponents;
}
```

## Search [#search]

The [built-in search](/docs/headless/search/orama#internationalization) indexes every language with no extra config, and the default search dialog searches the current locale.