Skip to content

Commit

Permalink
Docs: improve i18n section
Browse files Browse the repository at this point in the history
  • Loading branch information
fuma-nama committed Dec 24, 2024
1 parent 67124b1 commit a619297
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
2 changes: 1 addition & 1 deletion apps/docs/app/docs/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DocsLayout, type DocsLayoutProps } from 'fumadocs-ui/layouts/notebook';
import { DocsLayout, type DocsLayoutProps } from 'fumadocs-ui/layouts/docs';
import type { ReactNode } from 'react';
import { MessageCircle } from 'lucide-react';
import { baseOptions, linkItems } from '@/app/layout.config';
Expand Down
40 changes: 24 additions & 16 deletions apps/docs/content/docs/ui/internationalization.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ description: Support multiple languages in your documentation
icon: Globe
---

<Callout title='Before you get started'>

Fumadocs is not a full-powered i18n library, you can also use other libraries like [next-intl](https://github.com/amannn/next-intl).
I18n functionality of Fumadocs works without the built-in middleware.

</Callout>

You can setup i18n using Fumadocs CLI or update the configurations manually.

> Read the [Next.js Docs](https://nextjs.org/docs/app/building-your-application/routing/internationalization) to learn more about implementing I18n in Next.js.
Expand Down Expand Up @@ -42,7 +49,7 @@ export const source = loader({
});
```

Update the usages to your source:
Update the usages to your source to include a locale code:

```ts
import { source } from '@/lib/source';
Expand All @@ -57,7 +64,8 @@ source.getPage(params.slug, params.lang);
source.getPages(params.lang);
```

See [Source API](/docs/headless/source-api) for other usages.
Note that without providing a locale code, it uses your default locale instead.
You can see [Source API](/docs/headless/source-api) for other usages.

### Middleware

Expand Down Expand Up @@ -105,20 +113,6 @@ export default function RootLayout({
}
```

### Docs Page

Make sure to update references to `source` and configure Static Site Generation correctly.

```json doc-gen:file
{
"file": "../../examples/i18n/app/[lang]/docs/[[...slug]]/page.tsx",
"codeblock": {
"lang": "tsx",
"meta": "title=\"page.tsx\""
}
}
```

### Writing Documents

see [Page Conventions](/docs/ui/page-conventions#internationalization) to learn how to organize your documents.
Expand Down Expand Up @@ -171,3 +165,17 @@ export const baseOptions: BaseLayoutProps = {
i18n: true,
};
```

## Navigation

Fumadocs will only handle i18n navigation for its own layouts (e.g. sidebar components),
you have to re-create components like `<Link>` from `next/link` and `useParams` hook to auto attend the locale to `href`.

In addition, the [`fumadocs-core/dynamic-link`](/docs/headless/components/link#dynamic-hrefs) component supports linking to dynamic hrefs, including the locale prefix.
For Markdown/MDX content, you may use it instead of the default anchor (`a`) component:

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

<DynamicLink href="/[lang]/another-page">This is a link</DynamicLink>
```

0 comments on commit a619297

Please sign in to comment.