diff options
Diffstat (limited to 'packages/docs/app/root.tsx')
| -rw-r--r-- | packages/docs/app/root.tsx | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/packages/docs/app/root.tsx b/packages/docs/app/root.tsx index a6c807e..9032c80 100644 --- a/packages/docs/app/root.tsx +++ b/packages/docs/app/root.tsx @@ -6,11 +6,25 @@ import { Outlet, Scripts, ScrollRestoration, + useParams, } from 'react-router'; import { RootProvider } from 'fumadocs-ui/provider/react-router'; import type { Route } from './+types/root'; import './app.css'; +import { defineI18nUI } from 'fumadocs-ui/i18n'; +import { i18n } from './lib/i18n'; +const { provider } = defineI18nUI(i18n, { + translations: { + en: { + displayName: 'English', + }, + zh: { + displayName: '中文', + search: '查找文档', + }, + }, +}); export const links: Route.LinksFunction = () => [ { rel: 'preconnect', href: 'https://fonts.googleapis.com' }, { @@ -25,8 +39,10 @@ export const links: Route.LinksFunction = () => [ ]; export function Layout({ children }: { children: React.ReactNode }) { + const { lang = i18n.defaultLanguage } = useParams(); + return ( - <html lang="en" suppressHydrationWarning> + <html lang={lang} suppressHydrationWarning> <head> <meta charSet="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> @@ -34,7 +50,7 @@ export function Layout({ children }: { children: React.ReactNode }) { <Links /> </head> <body className="flex flex-col min-h-screen"> - <RootProvider>{children}</RootProvider> + <RootProvider i18n={provider(lang)}>{children}</RootProvider> <ScrollRestoration /> <Scripts /> </body> |