# Fumadocs (Framework Mode, Waku): Internationalization
URL: /docs/waku/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 Waku 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'],
});
```

Waku has no optional route segments, so every URL has a locale prefix, like `/en/docs`.

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 into a `[lang]` segment:

<Files>
<Folder name="src/pages" defaultOpen>
<File name="_layout.tsx" />

<File name="_api/api/search.ts" />

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

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

### 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="src/components/provider.tsx"
'use client';
import type { ReactNode } from 'react';
import { useRouter } from 'waku/router/client';
import { RootProvider } from 'fumadocs-ui/provider/waku';
import { i18nProvider } from 'fumadocs-ui/i18n';
import { i18n } from '@/lib/i18n';
import { translations } from '@/lib/layout.shared';

export function Provider({ children }: { children: ReactNode }) {
  // the first segment of the path
  const lang = useRouter().path.split('/')[1] || i18n.defaultLanguage;

  return <RootProvider i18n={i18nProvider(translations, lang)}>{children}</RootProvider>;
}
```

### 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 to your pages. Waku layouts don't receive it, so render `<HomeLayout />` and `<DocsLayout />` in the pages:

```tsx tab="Home Page" title="src/pages/[lang]/index.tsx"
export default function Home({ lang }: PageProps<'/[lang]'>) {
  return <HomeLayout {...baseOptions(lang)}>{/* ... */}</HomeLayout>;
}

export async function getConfig() {
  return {
    render: 'static',
    staticPaths: i18n.languages,
  } as const;
}
```

```tsx tab="Docs Page" title="src/pages/[lang]/docs/[...slugs].tsx"
export default function Page({ lang, slugs }: PageProps<'/[lang]/docs/[...slugs]'>) {
  const page = source.getPage(slugs, lang);
  if (!page) unstable_notFound();

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

export async function getConfig() {
  return {
    render: 'static',
    staticPaths: source.generateParams().map((item) => [item.lang, ...item.slug]),
  } as const;
}
```

## 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/waku/page-conventions#i18n-routing).

## Links [#links]

Fumadocs layouts add the locale to their links.

In your own components, read the locale from the path:

```tsx
'use client';
import { Link, useRouter } from 'waku/router/client';

export function AboutLink() {
  const lang = useRouter().path.split('/')[1];

  return <Link to={`/${lang}/about`}>About</Link>;
}
```

## 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.