feat: add translations for DocsPage in English and Chinese
- Introduced new translation entries for the DocsPage, including Table of Contents, search functionality, last update information, and pagination controls in both English and Chinese. - Refactored layout.tsx to utilize dynamic translations from the message files, enhancing internationalization support and maintainability.
This commit is contained in:
parent
5c96b83455
commit
de37908d05
@ -152,6 +152,15 @@
|
||||
"noPostsFound": "No posts found",
|
||||
"allPosts": "All Posts"
|
||||
},
|
||||
"DocsPage": {
|
||||
"toc": "Table of Contents",
|
||||
"search": "Search docs",
|
||||
"lastUpdate": "Last updated on",
|
||||
"searchNoResult": "No results",
|
||||
"previousPage": "Previous",
|
||||
"nextPage": "Next",
|
||||
"chooseLanguage": "Select language"
|
||||
},
|
||||
"Marketing": {
|
||||
"navbar": {
|
||||
"features": {
|
||||
|
@ -147,6 +147,15 @@
|
||||
"noPostsFound": "没有找到文章",
|
||||
"allPosts": "全部文章"
|
||||
},
|
||||
"DocsPage": {
|
||||
"toc": "目录",
|
||||
"search": "搜索文档",
|
||||
"lastUpdate": "最后更新于",
|
||||
"searchNoResult": "没有结果",
|
||||
"previousPage": "上一页",
|
||||
"nextPage": "下一页",
|
||||
"chooseLanguage": "选择语言"
|
||||
},
|
||||
"Marketing": {
|
||||
"navbar": {
|
||||
"features": {
|
||||
|
@ -7,35 +7,10 @@ import type { ReactNode } from 'react';
|
||||
import { DocsProviders } from './providers-docs';
|
||||
import { I18nProvider } from 'fumadocs-ui/i18n';
|
||||
import { LOCALE_LIST } from '@/i18n/routing';
|
||||
import { getTranslations } from 'next-intl/server';
|
||||
|
||||
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 = Object.entries(LOCALE_LIST).map(([locale, data]) => ({
|
||||
@ -50,13 +25,25 @@ interface DocsLayoutProps {
|
||||
|
||||
export default async function DocsRootLayout({ children, params }: DocsLayoutProps) {
|
||||
const { locale } = await params;
|
||||
const t = await getTranslations({ locale, namespace: 'DocsPage' });
|
||||
|
||||
// Create translations object for fumadocs-ui from our message files
|
||||
const translations: Partial<Translations> = {
|
||||
toc: t('toc'),
|
||||
search: t('search'),
|
||||
lastUpdate: t('lastUpdate'),
|
||||
searchNoResult: t('searchNoResult'),
|
||||
previousPage: t('previousPage'),
|
||||
nextPage: t('nextPage'),
|
||||
chooseLanguage: t('chooseLanguage'),
|
||||
};
|
||||
|
||||
return (
|
||||
<DocsProviders>
|
||||
<I18nProvider
|
||||
locales={locales}
|
||||
locale={locale}
|
||||
translations={translations[locale] || enTranslations}
|
||||
translations={translations}
|
||||
>
|
||||
<DocsLayout tree={source.pageTree[locale]} {...baseOptions}>
|
||||
{children}
|
||||
|
Loading…
Reference in New Issue
Block a user