Logo智流GEO
核心优势技术产品解决方案价格方案服务中心
国际化
2025/03/15

国际化

在您的文档中支持多种语言

Before you get started

Fumadocs is not a full-powered i18n library, it manages only its own components and utilities.

You can use other libraries like next-intl for the rest of your app. Read the Next.js Docs to learn more about implementing I18n in Next.js.

Manual Setup

Define the i18n configurations in a file, we will import it with @/ilb/i18n in this guide.

Pass it to the source loader.

lib/source.ts
import { i18n } from '@/lib/i18n';
import { loader } from 'fumadocs-core/source';

export const source = loader({
  i18n, 
  // other options
});

And update Fumadocs UI layout options.

app/layout.config.tsx
import { i18n } from '@/lib/i18n';
import type { BaseLayoutProps } from 'fumadocs-ui/layouts/shared';

export function baseOptions(locale: string): BaseLayoutProps {
  return {
    i18n,
    // different props based on `locale`
  };
}

Middleware

Create a middleware that redirects users to appropriate locale.

{
  "file": "../../examples/i18n/middleware.ts",
  "codeblock": {
    "lang": "ts",
    "meta": "title=\"middleware.ts\""
  }
}

See Middleware for customisable options.

Note that this is optional, you can also use your own middleware or the one provided by i18n libraries.

Routing

Create a /app/[lang] folder, and move all files (e.g. page.tsx, layout.tsx) from /app to the folder.

Wrap the root provider inside I18nProvider, and provide available languages & translations to it. Note that only English translations are provided by default.

app/[lang]/layout.tsx
import { RootProvider } from 'fumadocs-ui/provider';
import { I18nProvider, type Translations } from 'fumadocs-ui/i18n';

const cn: Partial<Translations> = {
  search: 'Translated Content',
  // other translations
};

// available languages that will be displayed on UI
// make sure `locale` is consistent with your i18n config
const locales = [
  {
    name: 'English',
    locale: 'en',
  },
  {
    name: 'Chinese',
    locale: 'cn',
  },
];

export default async function RootLayout({
  params,
  children,
}: {
  params: Promise<{ lang: string }>;
  children: React.ReactNode;
}) {
  const lang = (await params).lang;

  return (
    <html lang={lang}>
      <body>
        <I18nProvider
          locale={lang}
          locales={locales}
          translations={{ cn }[lang]}
        >
          <RootProvider>{children}</RootProvider>
        </I18nProvider>
      </body>
    </html>
  );
}

Pass Locale

Pass the locale to Fumadocs in your pages and layouts.

Search

Configure i18n on your search solution.

  • Built-in Search (Orama): For Supported Languages, no further changes are needed.

    Otherwise, additional config is required (e.g. Chinese & Japanese). See Special Languages.

  • Cloud Solutions (e.g. Algolia): They usually have official support for multilingual.

Writing Documents

Navigation

Fumadocs only handles navigation for its own layouts (e.g. sidebar). For other places, you can use the useParams hook to get the locale from url, and attend it to href.

import Link from 'next/link';
import { useParams } from 'next/navigation';

const { lang } = useParams();

return <Link href={`/${lang}/another-page`}>This is a link</Link>;

In addition, the fumadocs-core/dynamic-link component supports dynamic hrefs, you can use it to attend the locale prefix. It is useful for Markdown/MDX content.

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

<DynamicLink href="/[lang]/another-page">This is a link</DynamicLink>
全部文章

分类

  • 公司
  • 产品
Manual SetupMiddlewareRoutingPass LocaleSearchWriting DocumentsNavigation

更多文章

搜索
公司新闻

搜索

在您的文档中实现文档搜索

2025/02/15
测试专用付费文章
会员
产品

测试专用付费文章

这是一篇测试专用付费文章。

avatar for Fox
Fox
2025/08/30
什么是 Fumadocs
公司产品

什么是 Fumadocs

介绍 Fumadocs,一个可以打破常规的文档框架

avatar for Fox
Fox
2025/04/01

订阅通讯

加入社区

订阅我们的通讯,获取最新资讯与更新

为什么选择智流AI

智流GEO是专注于人工智能搜索生态优化服务解决方案,我们作为AI搜索时代的先试者,致力于为合作伙伴提供专业高效的GEO数据分析监测及策略服务。

智流GEO希望通过全域数据洞察,帮助合作伙伴明晰品牌当前AI可见度现状,驱动正确营销策略,实现AI营销决策升级。

二维码待甲方提供
小红书
二维码待甲方提供
微信
关于我们
  • 公司介绍
  • 加入我们
  • 帮助中心
  • 合作加盟
产品服务
  • 核心优势
  • 解决方案
  • 价格体系
  • 数据分析
新闻资讯
  • 暂无新闻
© 2026 智流GEO. All Rights Reserved. 沪ICP备2026003151号  网ICP备2026003XXX号
隐私政策服务条款友情链接智流GEO v1.0.0