Skip to content

Commit 243250e

Browse files
Copilothotlong
andcommitted
Add language switcher with i18n support for English and Chinese
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 1656b11 commit 243250e

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

apps/docs/app/[lang]/docs/layout.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import type { Metadata } from 'next';
33
import { DocsLayout } from 'fumadocs-ui/layouts/docs';
44
import type { ReactNode } from 'react';
55
import { baseOptions } from '@/app/layout.config';
6-
import { i18n } from '@/lib/i18n';
76

87
export default async function Layout({
98
params,
@@ -18,7 +17,7 @@ export default async function Layout({
1817
<DocsLayout
1918
tree={source.pageTree[lang]}
2019
{...baseOptions}
21-
i18n={i18n}
20+
i18n
2221
>
2322
{children}
2423
</DocsLayout>

apps/docs/app/[lang]/layout.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,17 @@ export default async function LanguageLayout({
1414
return (
1515
<html lang={lang} suppressHydrationWarning>
1616
<body>
17-
<RootProvider>{children}</RootProvider>
17+
<RootProvider
18+
i18n={{
19+
locale: lang,
20+
locales: i18n.languages.map((l) => ({
21+
name: l === 'en' ? 'English' : '中文',
22+
locale: l,
23+
})),
24+
}}
25+
>
26+
{children}
27+
</RootProvider>
1828
</body>
1929
</html>
2030
);

0 commit comments

Comments
 (0)