Skip to content

Fumadocsの統合

Next.js App RouterでFumadocs 4のドキュメントサイトには、init -t ui-fumadocsdocsOutput.style: "fumadocs"を使用します。このプリセットは、空のdoc-systemとBCP-47または短いロケールコードが保持されたlocaleSubpathのエイリアスです(localePathLowercaseはデフォルトでfalse)。

Documentsと実行可能なexamples/fumadocs-docsデモ(ドットパーサー、ポート3080)も参照してください。

クイックスタート

bash
ai-i18n-tools init -t ui-fumadocs [-P <provider>]
# edit ai-i18n-tools.config.json (targetLocales, providers, contentPaths)
pnpm run i18n:sync   # or: ai-i18n-tools sync
pnpm run build       # Next.js build (project-specific script)

ページコンテンツ、meta.jsonサイドバーラベル、およびFumadocs UIのオーバーライドを1回のsync実行で翻訳する場合は、features.translateDocsを有効にします。

ページレイアウト

Fumadocsは、docsOutput.fumadocsParserを介して2つのi18nコンテンツレイアウトをサポートしています。ドットパーサーがデフォルトです(Fumadocsに組み込まれており、SWRなどの本番サイトで使用されています)。

ドットパーサー (デフォルト)

英語のMDXはコレクションのルートにあります。翻訳されたコピーは、同じディレクトリにロケールサフィックスを使用します。

text
content/docs/index.mdx                    →  content/docs/index.pt.mdx
content/docs/guide/getting-started.mdx    →  content/docs/guide/getting-started.zh.mdx
json
{
  "contentPaths": ["content/docs"],
  "outputDir": "content/docs",
  "docsOutput": {
    "style": "fumadocs",
    "docsRoot": "content/docs",
    "fumadocsParser": "dot",
    "rewriteFumadocsLinks": true
  }
}

lib/i18n.tstargetLocalesdefineI18n().languagesと正確に合わせます(例では短いコードptzhを使用しています)。

Dirパーサー(Nextraスタイル)

ロケールフォルダ(content/docs/en/content/docs/pt-BR/)に慣れているチームの場合、fumadocsParser"dir"に設定します。

text
content/docs/en/index.mdx           →  content/docs/pt-BR/index.mdx
content/docs/en/guide/foo.mdx       →  content/docs/zh-Hans/guide/foo.mdx
json
{
  "contentPaths": ["content/docs/en"],
  "outputDir": "content/docs",
  "docsOutput": {
    "style": "fumadocs",
    "docsRoot": "content/docs/en",
    "fumadocsParser": "dir",
    "rewriteFumadocsLinks": true
  }
}

コピー&ペースト可能なディレクトリ設定については、examples/fumadocs-docsai-i18n-tools.config.dir.example.json を参照してください。メンタルモデルは Nextra integration と一致します。

サイドバー (meta.json)

Fumadocsは、サイドバーの構造とタイトルにJSON meta.jsonファイルを使用します。docsOutput.style"fumadocs"の場合、translate-docsdocsRoot(またはdocs[].fumadocsMetaGlob)の下のmeta.jsonを収集し、docs[].fumadocsMetaTranslatableKeysにリストされているキー(デフォルト:titledescription)の文字列値を翻訳して、ロケール出力を書き込みます。

パーサー英語ソース出力
dotcontent/docs/**/meta.jsoncontent/docs/**/meta.{locale}.json
dircontent/docs/en/**/meta.jsoncontent/docs/{locale}/**/meta.json

翻訳しないでくださいpagesスラッグ配列、rooticondefaultOpen、またはその他の構造キー — 人間が読めるラベルのみを翻訳します。

UIカタログ

Fumadocsのレイアウトクローム(検索プレースホルダー、ロケール表示名、およびlib/layout.shared.ts内のその他のdefineTranslations / i18n.translations()オーバーライド)は、マークダウンから抽出されません。docsOutput.fumadocsUiCatalog を構成して、translate-docssourcePathから英語カタログをブートストラップし、ロケールごとのJSONを翻訳するようにします。

json
{
  "features": {
    "translateDocs": true
  },
  "docs": [
    {
      "contentPaths": ["content/docs"],
      "outputDir": "content/docs",
      "docsOutput": {
        "style": "fumadocs",
        "docsRoot": "content/docs",
        "fumadocsParser": "dot",
        "fumadocsUiCatalog": {
          "sourcePath": "lib/layout.shared.ts",
          "catalogPath": "lib/i18n/ui.en.json"
        }
      }
    }
  ]
}
  • catalogPath — 生成された英語のフラットJSON(ブートストラップ出力)。layout.shared.tsの英語のオーバーライドが変更された場合は、syncを再実行します。
  • outputPathTemplate(オプション) — ロケールごとの出力。デフォルト:catalogPathの隣のui.{locale}.json

layout.shared.tsloadUiCatalog(locale)を介してロケールごとのJSONをロードし、ルートレイアウトでi18nProvider(translations, lang)とマージします。examples/fumadocs-docs/lib/layout.shared.tsを参照してください。

標準ロケールは、LLM のコストなしで @fumadocs/language/* プリセットでカバーできます。カタログは、英語ブロックの プロジェクトのオーバーライドのみを翻訳します。

Fumadocs UI 文字列には json[]使用しないでください。このパイプラインは、関連性のないアプリのロケールバンドル用です。

リンクの表記規則

Fumadocsは、Next.jsミドルウェア(/docs/getting-started/pt/docs/getting-started)を介してロケールプレフィックス付きルートを提供します。ページ内リンクはロケールニュートラルであるべきです/docs/getting-started)。そうすることで、アクティブなロケールプレフィックスが自動的に適用されます。

組み込みのノーマライザーを有効にすると、translate-docsがすべての翻訳ファイルのリンクを自動的に修正します:

json
"docsOutput": {
  "style": "fumadocs",
  "docsRoot": "content/docs",
  "rewriteFumadocsLinks": true
}

rewriteFumadocsLinksは、style"fumadocs"の場合にデフォルトで有効になります。

英語ソースの作成者正規化後
[Guide](content/docs/guide/getting-started.mdx)[Guide](/docs/guide/getting-started)
[Home](content/docs/index.mdx)[Home](/docs)
[Guide](/ja/guide/getting-started.mdx)[Guide](/docs/guide/getting-started)
[Demo](https://github.com/org/repo)変更なし (完全な URL)

執筆ルール

  • ページ間のドキュメントリンク: 英語のMDXではロケールニュートラルなサイトルート/docs/…)を使用するか、content/docs/… / 相対.mdxパスを使用して、sync中に正規化ツールで書き換えさせます。
  • コンテンツツリー外のリポジトリファイル: 完全なURLを使用します。
  • ロケールサフィックス付きコピー(*.pt.mdx)やcontent/{locale}/ツリー内のリンクを手動で編集しないでくださいsync / translate-docsで再生成してください。

こちらも参照してください: Documents — link rewriting および Configuration — docsOutput

ロケールコード

Fumadocs アプリの ai-i18n-tools.config.jsontargetLocales を、defineI18n().languages完全に一致させてください。ドットの例では短いコード (ptzh) を使用していますが、ディレクトリ設定では BCP-47 フォルダー (pt-BRzh-Hans) を使用できます。強制的な正規化はありません。コードが一致しないと、誤った出力パスやページが見つからない原因となります。

複数のコレクション

Fumadocs プロジェクトでは、source.config.ts に複数の defineDocs ブロック (docs、blog、examples) を定義できます。翻訳するコレクションごとに 1 つの docs[] ブロックを追加し、それぞれに独自の contentPathsoutputDir、および docsRoot を設定します。

サンプルプロジェクト

examples/fumadocs-docscontent/docs/ の英語 MDX、コミットされた ptzh のドットサフィックスページ、meta.json、および lib/i18n/ui.{locale}.json。ポート 3080pnpm run dev を実行します。

相互参照

MITライセンスの下で公開されています。