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.
This commit is contained in:
parent
c81447e2ef
commit
c15980b32a
@ -24,7 +24,8 @@ import {
|
||||
|
||||
/**
|
||||
* Fumadocs documentation
|
||||
* 1. https://fumadocs.com/docs/configuration
|
||||
*
|
||||
* https://fumadocs.vercel.app/docs/headless/content-collections
|
||||
*/
|
||||
const docs = defineCollection({
|
||||
name: 'docs',
|
||||
|
@ -3,11 +3,15 @@ title: Hello World
|
||||
description: Your first document
|
||||
---
|
||||
|
||||
Welcome to the docs! You can start writing documents in `/content/docs`.
|
||||
Hey there!
|
||||
|
||||
## What is Next?
|
||||
## Heading
|
||||
|
||||
<Cards>
|
||||
<Card title="Learn more about Next.js" href="https://nextjs.org/docs" />
|
||||
<Card title="Learn more about Fumadocs" href="https://fumadocs.vercel.app" />
|
||||
</Cards>
|
||||
|
||||
### Heading
|
||||
|
||||
#### Heading
|
||||
|
8
content/docs/index.zh.mdx
Normal file
8
content/docs/index.zh.mdx
Normal file
@ -0,0 +1,8 @@
|
||||
---
|
||||
title: 中文
|
||||
description: 您的第一個文檔
|
||||
---
|
||||
|
||||
## Hi 中文
|
||||
|
||||
Fumadocs 對 i18n 有良好的支持
|
@ -1,17 +1,21 @@
|
||||
---
|
||||
title: Components
|
||||
description: Components
|
||||
title: Test Document
|
||||
description: Your first document
|
||||
---
|
||||
|
||||
## Code Block
|
||||
Hey there!
|
||||
|
||||
```js
|
||||
console.log('Hello World');
|
||||
```
|
||||
|
||||
## Cards
|
||||
## Heading
|
||||
|
||||
<Cards>
|
||||
<Card title="Learn more about Next.js" href="https://nextjs.org/docs" />
|
||||
<Card title="Learn more about Fumadocs" href="https://fumadocs.vercel.app" />
|
||||
</Cards>
|
||||
|
||||
### Heading
|
||||
|
||||
```js
|
||||
console.log('Hello World');
|
||||
```
|
||||
|
||||
#### Heading
|
||||
|
@ -9,12 +9,14 @@ import {
|
||||
} from 'fumadocs-ui/page';
|
||||
import type { Metadata } from 'next';
|
||||
import { notFound } from 'next/navigation';
|
||||
import { Locale } from 'next-intl';
|
||||
|
||||
export default async function Page(props: {
|
||||
params: Promise<{ slug?: string[] }>;
|
||||
export default async function Page({
|
||||
params,
|
||||
}: {
|
||||
params: { slug?: string[]; locale: Locale };
|
||||
}) {
|
||||
const params = await props.params;
|
||||
const page = source.getPage(params.slug);
|
||||
const page = source.getPage(params.slug, params.locale);
|
||||
if (!page) notFound();
|
||||
|
||||
return (
|
||||
@ -40,11 +42,12 @@ export function generateStaticParams() {
|
||||
return source.generateParams();
|
||||
}
|
||||
|
||||
export async function generateMetadata(props: {
|
||||
params: Promise<{ slug?: string[] }>;
|
||||
export async function generateMetadata({
|
||||
params,
|
||||
}: {
|
||||
params: { slug?: string[]; locale: Locale };
|
||||
}) {
|
||||
const params = await props.params;
|
||||
const page = source.getPage(params.slug);
|
||||
const page = source.getPage(params.slug, params.locale);
|
||||
if (!page) notFound();
|
||||
|
||||
return {
|
||||
|
@ -9,7 +9,7 @@ import { I18nProvider } from 'fumadocs-ui/i18n';
|
||||
|
||||
import '@/styles/docs.css';
|
||||
|
||||
const cn: Partial<Translations> = {
|
||||
const zhTranslations: Partial<Translations> = {
|
||||
toc: '目录',
|
||||
search: '搜索文档',
|
||||
lastUpdate: '最后更新于',
|
||||
@ -19,6 +19,22 @@ const cn: Partial<Translations> = {
|
||||
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 = [
|
||||
@ -28,7 +44,7 @@ const locales = [
|
||||
},
|
||||
{
|
||||
name: 'Chinese',
|
||||
locale: 'cn',
|
||||
locale: 'zh',
|
||||
},
|
||||
];
|
||||
|
||||
@ -42,7 +58,11 @@ export default async function DocsRootLayout({ children, params }: DocsLayoutPro
|
||||
|
||||
return (
|
||||
<DocsProviders>
|
||||
<I18nProvider locales={locales} locale={locale} translations={cn}>
|
||||
<I18nProvider
|
||||
locales={locales}
|
||||
locale={locale}
|
||||
translations={translations[locale] || enTranslations}
|
||||
>
|
||||
<DocsLayout tree={source.pageTree[locale]} {...baseOptions}>
|
||||
{children}
|
||||
</DocsLayout>
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { createMDXSource } from '@fumadocs/content-collections';
|
||||
import { allDocs, allMetas } from 'content-collections';
|
||||
import { loader } from 'fumadocs-core/source';
|
||||
import { createMDXSource } from '@fumadocs/content-collections';
|
||||
import { docsI18nConfig } from './i18n';
|
||||
|
||||
export const source = loader({
|
||||
|
Loading…
Reference in New Issue
Block a user