From 751017f790f2170f6b5628896c3c0df70798a22f Mon Sep 17 00:00:00 2001 From: Sanskar Jethi Date: Sat, 4 Jan 2025 23:19:28 +0000 Subject: [PATCH 1/6] docs: first version of chinese docs --- docs_src/next.config.mjs | 5 + .../documentation/LanguageSelector.jsx | 60 ++++++++ .../components/documentation/Navigation.jsx | 4 + .../api_reference/zh/getting_started.mdx | 139 ++++++++++++++++++ .../documentation/example_app/zh/index.mdx | 37 +++++ .../example_app/zh/subrouters.mdx | 45 ++++++ docs_src/src/pages/documentation/zh/index.mdx | 33 +++++ 7 files changed, 323 insertions(+) create mode 100644 docs_src/src/components/documentation/LanguageSelector.jsx create mode 100644 docs_src/src/pages/documentation/api_reference/zh/getting_started.mdx create mode 100644 docs_src/src/pages/documentation/example_app/zh/index.mdx create mode 100644 docs_src/src/pages/documentation/example_app/zh/subrouters.mdx create mode 100644 docs_src/src/pages/documentation/zh/index.mdx diff --git a/docs_src/next.config.mjs b/docs_src/next.config.mjs index bdb1d5973..fea282ed0 100644 --- a/docs_src/next.config.mjs +++ b/docs_src/next.config.mjs @@ -19,6 +19,11 @@ const nextConfig = { experimental: { scrollRestoration: true, }, + i18n: { + locales: ['en', 'zh'], + defaultLocale: 'en', + localeDetection: true, + }, } export default withMDX(nextConfig) diff --git a/docs_src/src/components/documentation/LanguageSelector.jsx b/docs_src/src/components/documentation/LanguageSelector.jsx new file mode 100644 index 000000000..4b99f8553 --- /dev/null +++ b/docs_src/src/components/documentation/LanguageSelector.jsx @@ -0,0 +1,60 @@ +import { useRouter } from 'next/router' +import { Menu } from '@headlessui/react' +import { motion } from 'framer-motion' + +const languages = [ + { code: 'en', name: 'English' }, + { code: 'zh', name: '中文' }, +] + +function LanguageSelector() { + const router = useRouter() + const { pathname, asPath, query } = router + const currentLanguage = router.locale || 'en' + + const changeLanguage = (locale) => { + router.push({ pathname, query }, asPath, { locale }) + } + + return ( + + + {languages.find(l => l.code === currentLanguage)?.name} + + + + + + {languages.map((language) => ( + + {({ active }) => ( + + )} + + ))} + + + ) +} + +export default LanguageSelector \ No newline at end of file diff --git a/docs_src/src/components/documentation/Navigation.jsx b/docs_src/src/components/documentation/Navigation.jsx index 2169baeee..8d0d82ad0 100644 --- a/docs_src/src/components/documentation/Navigation.jsx +++ b/docs_src/src/components/documentation/Navigation.jsx @@ -8,6 +8,7 @@ import { Button } from '@/components/documentation/Button' import { useIsInsideMobileNavigation } from '@/components/documentation/MobileNavigation' import { useSectionStore } from '@/components/documentation/SectionProvider' import { Tag } from '@/components/documentation/Tag' +import LanguageSelector from '@/components/documentation/LanguageSelector' import { remToPx } from '@/lib/remToPx' function useInitialValue(value, condition = true) { @@ -377,6 +378,9 @@ export const navigation = [ export function Navigation(props) { return (