-
Notifications
You must be signed in to change notification settings - Fork 1
Add i18n support with English, Chinese, Spanish, and Japanese #112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
890a250
🏗️ add i18n support for Mandarin, Spanish, and Japanese docs
claude 723b767
Update docs/lib/layout.shared.tsx
Miyamura80 b2405b6
Update docs/app/[lang]/layout.tsx
Miyamura80 f86c84b
Update docs/app/[lang]/(home)/page.tsx
Miyamura80 cb5e463
🐛 fix OG images for non-English locales
claude a8fe078
🐛 fix LLM MDX endpoint for locale-prefixed pages
claude 10fd972
🐛 filter llms-full.txt to single locale via ?lang= query param
claude File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,7 @@ downloads/ | |
| eggs/ | ||
| .eggs/ | ||
| lib/ | ||
| !docs/lib/ | ||
| lib64/ | ||
| parts/ | ||
| sdist/ | ||
|
|
||
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import { HomeLayout } from "fumadocs-ui/layouts/home"; | ||
| import { baseOptions } from "@/lib/layout.shared"; | ||
|
|
||
| export default async function Layout({ | ||
| params, | ||
| children, | ||
| }: { | ||
| params: Promise<{ lang: string }>; | ||
| children: React.ReactNode; | ||
| }) { | ||
| const { lang } = await params; | ||
| return <HomeLayout {...baseOptions(lang)}>{children}</HomeLayout>; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import { DynamicLink } from "fumadocs-core/dynamic-link"; | ||
|
|
||
| const greetings: Record<string, string> = { | ||
| en: "Hello World", | ||
| zh: "你好世界", | ||
| es: "Hola Mundo", | ||
| ja: "こんにちは世界", | ||
| }; | ||
|
|
||
| const descriptions: Record<string, string> = { | ||
| en: "You can open", | ||
| zh: "你可以打开", | ||
| es: "Puedes abrir", | ||
| ja: "開くことができます", | ||
| }; | ||
|
|
||
| const docsText: Record<string, string> = { | ||
| en: "and see the documentation.", | ||
| zh: "查看文档。", | ||
| es: "y ver la documentación.", | ||
| ja: "でドキュメントを確認できます。", | ||
| }; | ||
|
|
||
| export default async function HomePage({ | ||
| params, | ||
| }: { | ||
| params: Promise<{ lang: string }>; | ||
| }) { | ||
| const { lang } = await params; | ||
| return ( | ||
| <div className="flex flex-col justify-center text-center flex-1"> | ||
| <h1 className="text-2xl font-bold mb-4"> | ||
| {greetings[lang] ?? greetings.en} | ||
| </h1> | ||
| <p> | ||
| {descriptions[lang] ?? descriptions.en}{" "} | ||
| <DynamicLink | ||
| href="/[lang]/docs" | ||
| className="font-medium underline" | ||
| > | ||
| /docs | ||
| </DynamicLink>{" "} | ||
| {docsText[lang] ?? docsText.en} | ||
| </p> | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| import { getPageImage, source } from "@/lib/source"; | ||
| import { | ||
| DocsBody, | ||
| DocsDescription, | ||
| DocsPage, | ||
| DocsTitle, | ||
| } from "fumadocs-ui/layouts/docs/page"; | ||
| import { notFound } from "next/navigation"; | ||
| import { getMDXComponents } from "@/mdx-components"; | ||
| import type { Metadata } from "next"; | ||
| import { createRelativeLink } from "fumadocs-ui/mdx"; | ||
| import { LLMCopyButton, ViewOptions } from "@/components/ai/page-actions"; | ||
|
|
||
| export default async function Page({ | ||
| params, | ||
| }: { | ||
| params: Promise<{ lang: string; slug?: string[] }>; | ||
| }) { | ||
| const { lang, slug } = await params; | ||
| const page = source.getPage(slug, lang); | ||
| if (!page) notFound(); | ||
|
|
||
| const MDX = page.data.body; | ||
| const gitConfig = { | ||
| user: "username", | ||
| repo: "repo", | ||
| branch: "main", | ||
| }; | ||
|
|
||
| return ( | ||
| <DocsPage toc={page.data.toc} full={page.data.full}> | ||
| <DocsTitle>{page.data.title}</DocsTitle> | ||
| <DocsDescription className="mb-0"> | ||
| {page.data.description} | ||
| </DocsDescription> | ||
| <div className="flex flex-row gap-2 items-center border-b pb-6"> | ||
| <LLMCopyButton markdownUrl={`${page.url}.mdx`} /> | ||
| <ViewOptions | ||
| markdownUrl={`${page.url}.mdx`} | ||
| githubUrl={`https://github.com/${gitConfig.user}/${gitConfig.repo}/blob/${gitConfig.branch}/docs/content/docs/${page.path}`} | ||
| /> | ||
| </div> | ||
| <DocsBody> | ||
| <MDX | ||
| components={getMDXComponents({ | ||
| a: createRelativeLink(source, page), | ||
| })} | ||
| /> | ||
| </DocsBody> | ||
| </DocsPage> | ||
| ); | ||
| } | ||
|
|
||
| export async function generateStaticParams() { | ||
| return source.generateParams(); | ||
| } | ||
|
|
||
| export async function generateMetadata({ | ||
| params, | ||
| }: { | ||
| params: Promise<{ lang: string; slug?: string[] }>; | ||
| }): Promise<Metadata> { | ||
| const { lang, slug } = await params; | ||
| const page = source.getPage(slug, lang); | ||
| if (!page) notFound(); | ||
|
|
||
| return { | ||
| title: page.data.title, | ||
| description: page.data.description, | ||
| openGraph: { | ||
| images: getPageImage(page).url, | ||
| }, | ||
| }; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import { source } from "@/lib/source"; | ||
| import { DocsLayout } from "fumadocs-ui/layouts/docs"; | ||
| import { baseOptions } from "@/lib/layout.shared"; | ||
|
|
||
| export default async function Layout({ | ||
| params, | ||
| children, | ||
| }: { | ||
| params: Promise<{ lang: string }>; | ||
| children: React.ReactNode; | ||
| }) { | ||
| const { lang } = await params; | ||
| return ( | ||
| <DocsLayout tree={source.getPageTree(lang)} {...baseOptions(lang)}> | ||
| {children} | ||
| </DocsLayout> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| import { RootProvider } from "fumadocs-ui/provider/next"; | ||
| import { Archivo } from "next/font/google"; | ||
| import { defineI18nUI } from "fumadocs-ui/i18n"; | ||
| import { i18n } from "@/lib/i18n"; | ||
|
|
||
| const archivo = Archivo({ | ||
| subsets: ["latin", "latin-ext"], | ||
| weight: ["500"], | ||
| display: "swap", | ||
| }); | ||
|
|
||
| const { provider } = defineI18nUI(i18n, { | ||
| translations: { | ||
| en: { | ||
| displayName: "English", | ||
| }, | ||
| zh: { | ||
| displayName: "中文", | ||
| toc: "目录", | ||
| search: "搜索文档", | ||
| lastUpdate: "最后更新于", | ||
| searchNoResult: "没有结果", | ||
| previousPage: "上一页", | ||
| nextPage: "下一页", | ||
| chooseLanguage: "选择语言", | ||
| chooseTheme: "选择主题", | ||
| editOnGithub: "在 GitHub 上编辑", | ||
| tocNoHeadings: "无标题", | ||
| }, | ||
| es: { | ||
| displayName: "Español", | ||
| toc: "En esta página", | ||
| search: "Buscar documentación", | ||
| lastUpdate: "Última actualización", | ||
| searchNoResult: "Sin resultados", | ||
| previousPage: "Página anterior", | ||
| nextPage: "Página siguiente", | ||
| chooseLanguage: "Elegir idioma", | ||
| chooseTheme: "Elegir tema", | ||
| editOnGithub: "Editar en GitHub", | ||
| tocNoHeadings: "Sin encabezados", | ||
| }, | ||
| ja: { | ||
| displayName: "日本語", | ||
| toc: "目次", | ||
| search: "ドキュメントを検索", | ||
| lastUpdate: "最終更新", | ||
| searchNoResult: "結果なし", | ||
| previousPage: "前のページ", | ||
| nextPage: "次のページ", | ||
| chooseLanguage: "言語を選択", | ||
| chooseTheme: "テーマを選択", | ||
| editOnGithub: "GitHub で編集", | ||
| tocNoHeadings: "見出しなし", | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| export default async function Layout({ | ||
| params, | ||
| children, | ||
| }: { | ||
| params: Promise<{ lang: string }>; | ||
| children: React.ReactNode; | ||
| }) { | ||
| const { lang } = await params; | ||
| return ( | ||
| <html lang={lang} className={archivo.className} suppressHydrationWarning> | ||
| <body className="flex flex-col min-h-screen" suppressHydrationWarning> | ||
| <RootProvider i18n={provider(lang)}>{children}</RootProvider> | ||
| </body> | ||
| </html> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,19 @@ | ||
| import { source } from '@/lib/source'; | ||
| import { createFromSource } from 'fumadocs-core/search/server'; | ||
| import { source } from "@/lib/source"; | ||
| import { createFromSource } from "fumadocs-core/search/server"; | ||
|
|
||
| export const { GET } = createFromSource(source, { | ||
| // https://docs.orama.com/docs/orama-js/supported-languages | ||
| language: 'english', | ||
| localeMap: { | ||
| zh: { | ||
| search: { | ||
| threshold: 0, | ||
| tolerance: 0, | ||
| }, | ||
| }, | ||
| ja: { | ||
| search: { | ||
| threshold: 0, | ||
| tolerance: 0, | ||
| }, | ||
| }, | ||
| }, | ||
| }); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.