prmbr-image-mksaas/src/app/[locale]/docs/layout.tsx
javayhu c15980b32a feat: update documentation and enhance internationalization support
- Updated documentation links in content-collections.ts for accuracy.
- Modified index.mdx and test.mdx files to improve content structure and clarity.
- Added new Chinese documentation file (index.zh.mdx) to support localization.
- Enhanced layout.tsx to include translations for English and Chinese.
- Updated page.tsx to handle locale parameters for improved routing.
- Refactored source.ts to streamline imports and maintain consistency.
2025-03-29 12:32:25 +08:00

73 lines
1.8 KiB
TypeScript

import { baseOptions } from '@/app/[locale]/docs/layout.config';
import { source } from '@/lib/docs/source';
import { Translations } from 'fumadocs-ui/i18n';
import { DocsLayout } from 'fumadocs-ui/layouts/docs';
import { Locale } from 'next-intl';
import type { ReactNode } from 'react';
import { DocsProviders } from './providers-docs';
import { I18nProvider } from 'fumadocs-ui/i18n';
import '@/styles/docs.css';
const zhTranslations: Partial<Translations> = {
toc: '目录',
search: '搜索文档',
lastUpdate: '最后更新于',
searchNoResult: '没有结果',
previousPage: '上一页',
nextPage: '下一页',
chooseLanguage: '选择语言',
};
const enTranslations: Partial<Translations> = {
toc: 'Table of Contents',
search: 'Search docs',
lastUpdate: 'Last updated on',
searchNoResult: 'No results',
previousPage: 'Previous',
nextPage: 'Next',
chooseLanguage: 'Select language',
};
// Map of locale to translations
const translations: Record<string, Partial<Translations>> = {
zh: zhTranslations,
en: enTranslations,
};
// 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: 'zh',
},
];
interface DocsLayoutProps {
children: ReactNode;
params: Promise<{ locale: Locale }>;
}
export default async function DocsRootLayout({ children, params }: DocsLayoutProps) {
const { locale } = await params;
return (
<DocsProviders>
<I18nProvider
locales={locales}
locale={locale}
translations={translations[locale] || enTranslations}
>
<DocsLayout tree={source.pageTree[locale]} {...baseOptions}>
{children}
</DocsLayout>
</I18nProvider>
</DocsProviders>
);
}