From c623930ecbfae3ec58f2646fe24723439a4fa9e5 Mon Sep 17 00:00:00 2001 From: Sanskar Jethi <29942790+sansyrox@users.noreply.github.com> Date: Sun, 12 Jan 2025 20:57:35 +0000 Subject: [PATCH] docs: first version of chinese docs (#1102) * docs: first version of chinese docs * fix minor ui bug * fix folder structure * add more docs * add more translation * add more translation --- docs_src/next.config.mjs | 14 ++ .../documentation/LanguageSelector.jsx | 72 ++++++ .../components/documentation/Navigation.jsx | 220 ++++++++++++++---- .../api_reference/advanced_features.mdx | 0 .../{ => en}/api_reference/authentication.mdx | 0 .../{ => en}/api_reference/const_requests.mdx | 0 .../{ => en}/api_reference/cors.mdx | 0 .../api_reference/dependency_injection.mdx | 0 .../{ => en}/api_reference/exceptions.mdx | 0 .../{ => en}/api_reference/file-uploads.mdx | 0 .../{ => en}/api_reference/form_data.mdx | 0 .../{ => en}/api_reference/future-roadmap.mdx | 0 .../api_reference/getting_started.mdx | 0 .../api_reference/graphql-support.mdx | 0 .../{ => en}/api_reference/index.mdx | 0 .../{ => en}/api_reference/middlewares.mdx | 0 .../api_reference/multiprocess_execution.mdx | 0 .../{ => en}/api_reference/openapi.mdx | 0 .../{ => en}/api_reference/redirection.mdx | 0 .../{ => en}/api_reference/request_object.mdx | 0 .../{ => en}/api_reference/robyn_env.mdx | 0 .../{ => en}/api_reference/scaling.mdx | 0 .../{ => en}/api_reference/templating.mdx | 0 .../api_reference/using_rust_directly.mdx | 0 .../{ => en}/api_reference/websockets.mdx | 0 .../en/api_reference/zh/getting_started.mdx | 139 +++++++++++ .../documentation/{ => en}/architecture.mdx | 0 .../{ => en}/community-resources.mdx | 0 .../authentication-middlewares.mdx | 0 .../{ => en}/example_app/authentication.mdx | 0 .../{ => en}/example_app/deployment.mdx | 0 .../{ => en}/example_app/index.mdx | 0 .../{ => en}/example_app/modeling_routes.mdx | 0 .../example_app/monitoring_and_logging.mdx | 0 .../{ => en}/example_app/openapi.mdx | 0 .../example_app/real_time_notifications.mdx | 0 .../example_app/subrouters_and_views.mdx | 0 .../{ => en}/example_app/templates.mdx | 0 .../documentation/en/example_app/zh/index.mdx | 37 +++ .../en/example_app/zh/subrouters.mdx | 45 ++++ .../framework_performance_comparison.mdx | 0 .../pages/documentation/{ => en}/hosting.mdx | 0 .../pages/documentation/{ => en}/index.mdx | 0 .../pages/documentation/{ => en}/plugins.mdx | 0 docs_src/src/pages/documentation/zh/index.mdx | 33 +++ 45 files changed, 517 insertions(+), 43 deletions(-) create mode 100644 docs_src/src/components/documentation/LanguageSelector.jsx rename docs_src/src/pages/documentation/{ => en}/api_reference/advanced_features.mdx (100%) rename docs_src/src/pages/documentation/{ => en}/api_reference/authentication.mdx (100%) rename docs_src/src/pages/documentation/{ => en}/api_reference/const_requests.mdx (100%) rename docs_src/src/pages/documentation/{ => en}/api_reference/cors.mdx (100%) rename docs_src/src/pages/documentation/{ => en}/api_reference/dependency_injection.mdx (100%) rename docs_src/src/pages/documentation/{ => en}/api_reference/exceptions.mdx (100%) rename docs_src/src/pages/documentation/{ => en}/api_reference/file-uploads.mdx (100%) rename docs_src/src/pages/documentation/{ => en}/api_reference/form_data.mdx (100%) rename docs_src/src/pages/documentation/{ => en}/api_reference/future-roadmap.mdx (100%) rename docs_src/src/pages/documentation/{ => en}/api_reference/getting_started.mdx (100%) rename docs_src/src/pages/documentation/{ => en}/api_reference/graphql-support.mdx (100%) rename docs_src/src/pages/documentation/{ => en}/api_reference/index.mdx (100%) rename docs_src/src/pages/documentation/{ => en}/api_reference/middlewares.mdx (100%) rename docs_src/src/pages/documentation/{ => en}/api_reference/multiprocess_execution.mdx (100%) rename docs_src/src/pages/documentation/{ => en}/api_reference/openapi.mdx (100%) rename docs_src/src/pages/documentation/{ => en}/api_reference/redirection.mdx (100%) rename docs_src/src/pages/documentation/{ => en}/api_reference/request_object.mdx (100%) rename docs_src/src/pages/documentation/{ => en}/api_reference/robyn_env.mdx (100%) rename docs_src/src/pages/documentation/{ => en}/api_reference/scaling.mdx (100%) rename docs_src/src/pages/documentation/{ => en}/api_reference/templating.mdx (100%) rename docs_src/src/pages/documentation/{ => en}/api_reference/using_rust_directly.mdx (100%) rename docs_src/src/pages/documentation/{ => en}/api_reference/websockets.mdx (100%) create mode 100644 docs_src/src/pages/documentation/en/api_reference/zh/getting_started.mdx rename docs_src/src/pages/documentation/{ => en}/architecture.mdx (100%) rename docs_src/src/pages/documentation/{ => en}/community-resources.mdx (100%) rename docs_src/src/pages/documentation/{ => en}/example_app/authentication-middlewares.mdx (100%) rename docs_src/src/pages/documentation/{ => en}/example_app/authentication.mdx (100%) rename docs_src/src/pages/documentation/{ => en}/example_app/deployment.mdx (100%) rename docs_src/src/pages/documentation/{ => en}/example_app/index.mdx (100%) rename docs_src/src/pages/documentation/{ => en}/example_app/modeling_routes.mdx (100%) rename docs_src/src/pages/documentation/{ => en}/example_app/monitoring_and_logging.mdx (100%) rename docs_src/src/pages/documentation/{ => en}/example_app/openapi.mdx (100%) rename docs_src/src/pages/documentation/{ => en}/example_app/real_time_notifications.mdx (100%) rename docs_src/src/pages/documentation/{ => en}/example_app/subrouters_and_views.mdx (100%) rename docs_src/src/pages/documentation/{ => en}/example_app/templates.mdx (100%) create mode 100644 docs_src/src/pages/documentation/en/example_app/zh/index.mdx create mode 100644 docs_src/src/pages/documentation/en/example_app/zh/subrouters.mdx rename docs_src/src/pages/documentation/{ => en}/framework_performance_comparison.mdx (100%) rename docs_src/src/pages/documentation/{ => en}/hosting.mdx (100%) rename docs_src/src/pages/documentation/{ => en}/index.mdx (100%) rename docs_src/src/pages/documentation/{ => en}/plugins.mdx (100%) 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..5b59a0fd5 100644 --- a/docs_src/next.config.mjs +++ b/docs_src/next.config.mjs @@ -19,6 +19,20 @@ const nextConfig = { experimental: { scrollRestoration: true, }, + i18n: { + locales: ['en', 'zh'], + defaultLocale: 'en', + localeDetection: false, + }, + async redirects() { + return [ + { + source: '/documentation', + destination: '/documentation/en', + permanent: false, + }, + ] + }, } 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..7c0b46402 --- /dev/null +++ b/docs_src/src/components/documentation/LanguageSelector.jsx @@ -0,0 +1,72 @@ +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 = asPath.includes('/zh') ? 'zh' : 'en' + + const changeLanguage = (locale) => { + const currentPath = asPath.split('?')[0] + + if (currentPath === '/documentation' || currentPath === '/documentation/') { + router.push(`/documentation/${locale}`) + return + } + + const newPath = currentPath.replace( + /\/documentation\/(en|zh)/, + `/documentation/${locale}` + ) + + router.push(newPath) + } + + 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..51115fb8e 100644 --- a/docs_src/src/components/documentation/Navigation.jsx +++ b/docs_src/src/components/documentation/Navigation.jsx @@ -4,10 +4,10 @@ import { useRouter } from 'next/router' import clsx from 'clsx' import { AnimatePresence, motion, useIsPresent } from 'framer-motion' -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) { @@ -187,37 +187,37 @@ export const navigation = [ { title: 'Example Application', links: [ - { title: 'Getting Started', href: '/documentation/example_app' }, + { title: 'Getting Started', href: '/documentation/en/example_app' }, { title: 'Modeling Routes', - href: '/documentation/example_app/modeling_routes', + href: '/documentation/en/example_app/modeling_routes', }, { title: 'Authentication and Authorization', - href: '/documentation/example_app/authentication', + href: '/documentation/en/example_app/authentication', }, { title: 'Middlewares', - href: '/documentation/example_app/authentication-middlewares', + href: '/documentation/en/example_app/authentication-middlewares', }, { title: 'Real Time Notifications', - href: '/documentation/example_app/real_time_notifications', + href: '/documentation/en/example_app/real_time_notifications', }, { title: 'Monitoring and Logging', - href: '/documentation/example_app/monitoring_and_logging', + href: '/documentation/en/example_app/monitoring_and_logging', }, - { title: 'Deployment', href: '/documentation/example_app/deployment' }, + { title: 'Deployment', href: '/documentation/en/example_app/deployment' }, { title: 'OpenAPI Documentation', - href: '/documentation/example_app/openapi', + href: '/documentation/en/example_app/openapi', }, - { title: 'Templates', href: '/documentation/example_app/templates' }, + { title: 'Templates', href: '/documentation/en/example_app/templates' }, { title: 'SubRouters', - href: '/documentation/example_app/subrouters', + href: '/documentation/en/example_app/subrouters', }, ], }, @@ -225,87 +225,87 @@ export const navigation = [ title: 'API Reference', links: [ { - href: '/documentation/api_reference/', + href: '/documentation/en/api_reference/', title: 'Installation', }, { - href: '/documentation/api_reference/getting_started', + href: '/documentation/en/api_reference/getting_started', title: 'Getting Started', }, { - href: '/documentation/api_reference/request_object', + href: '/documentation/en/api_reference/request_object', title: 'The Request Object', }, { - href: '/documentation/api_reference/robyn_env', + href: '/documentation/en/api_reference/robyn_env', title: 'The Robyn Env file', }, { - href: '/documentation/api_reference/middlewares', + href: '/documentation/en/api_reference/middlewares', title: 'Middlewares, Events and Websockets', }, { - href: '/documentation/api_reference/authentication', + href: '/documentation/en/api_reference/authentication', title: 'Authentication', }, { - href: '/documentation/api_reference/const_requests', + href: '/documentation/en/api_reference/const_requests', title: 'Const Requests and Multi Core Scaling', }, { - href: '/documentation/api_reference/cors', + href: '/documentation/en/api_reference/cors', title: 'CORS', }, { - href: '/documentation/api_reference/templating', + href: '/documentation/en/api_reference/templating', title: 'Templating', }, { title: 'Redirection', - href: '/documentation/api_reference/redirection', + href: '/documentation/en/api_reference/redirection', }, { - href: '/documentation/api_reference/file-uploads', + href: '/documentation/en/api_reference/file-uploads', title: 'File Uploads', }, { - href: '/documentation/api_reference/form_data', + href: '/documentation/en/api_reference/form_data', title: 'Form Data', }, { - href: '/documentation/api_reference/websockets', + href: '/documentation/en/api_reference/websockets', title: 'Websockets', }, { - href: '/documentation/api_reference/exceptions', + href: '/documentation/en/api_reference/exceptions', title: 'Exceptions', }, { - href: '/documentation/api_reference/scaling', + href: '/documentation/en/api_reference/scaling', title: 'Scaling the Application', }, { - href: '/documentation/api_reference/advanced_features', + href: '/documentation/en/api_reference/advanced_features', title: 'Advanced Features', }, { - href: '/documentation/api_reference/multiprocess_execution', + href: '/documentation/en/api_reference/multiprocess_execution', title: 'Multiprocess Execution', }, { - href: '/documentation/api_reference/using_rust_directly', + href: '/documentation/en/api_reference/using_rust_directly', title: 'Direct Rust Usage', }, { - href: '/documentation/api_reference/graphql-support', + href: '/documentation/en/api_reference/graphql-support', title: 'GraphQL Support', }, { - href: '/documentation/api_reference/openapi', + href: '/documentation/en/api_reference/openapi', title: 'OpenAPI Documentation', }, { - href: '/documentation/api_reference/dependency_injection', + href: '/documentation/en/api_reference/dependency_injection', title: 'Dependency Injection', } ], @@ -314,11 +314,11 @@ export const navigation = [ title: 'Community Resources', links: [ { - href: '/documentation/community-resources#talks', + href: '/documentation/en/community-resources#talks', title: 'Talks', }, { - href: '/documentation/community-resources#blogs', + href: '/documentation/en/community-resources#blogs', title: 'Blogs', }, ], @@ -327,7 +327,7 @@ export const navigation = [ title: 'Architecture', links: [ { - href: '/documentation/architecture', + href: '/documentation/en/architecture', title: 'Architecture', }, ], @@ -336,7 +336,7 @@ export const navigation = [ title: 'Framework Comparison', links: [ { - href: '/documentation/framework_performance_comparison', + href: '/documentation/en/framework_performance_comparison', title: 'Performance Comparison', }, ], @@ -345,11 +345,11 @@ export const navigation = [ title: 'Hosting', links: [ { - href: '/documentation/hosting#railway', + href: '/documentation/en/hosting#railway', title: 'Railway', }, { - href: '/documentation/hosting#exposing-ports', + href: '/documentation/en/hosting#exposing-ports', title: 'Exposing Ports', }, ], @@ -358,7 +358,7 @@ export const navigation = [ title: 'Plugins', links: [ { - href: '/documentation/plugins', + href: '/documentation/en/plugins', title: 'Plugins', }, ], @@ -367,21 +367,155 @@ export const navigation = [ title: 'Future Roadmap', links: [ { - href: '/documentation/api_reference/future-roadmap', + href: '/documentation/en/api_reference/future-roadmap', title: 'Upcoming Features', }, ], }, ] +// Add translations for navigation titles +const navigationTitles = { + en: { + 'Documentation': 'Documentation', + 'Example Application': 'Example Application', + 'API Reference': 'API Reference', + 'Community Resources': 'Community Resources', + 'Architecture': 'Architecture', + 'Framework Comparison': 'Framework Comparison', + 'Hosting': 'Hosting', + 'Plugins': 'Plugins', + 'Future Roadmap': 'Future Roadmap' + }, + zh: { + 'Documentation': '文档', + 'Example Application': '示例应用', + 'API Reference': 'API 参考', + 'Community Resources': '社区资源', + 'Architecture': '架构', + 'Framework Comparison': '框架对比', + 'Hosting': '托管', + 'Plugins': '插件', + 'Future Roadmap': '未来路线图' + } +} + +// Add translations for navigation titles and link titles +const translations = { + en: { + titles: navigationTitles.en, + links: { + 'Getting Started': 'Getting Started', + 'Modeling Routes': 'Modeling Routes', + 'Authentication and Authorization': 'Authentication and Authorization', + 'Middlewares': 'Middlewares', + 'Real Time Notifications': 'Real Time Notifications', + 'Monitoring and Logging': 'Monitoring and Logging', + 'Deployment': 'Deployment', + 'OpenAPI Documentation': 'OpenAPI Documentation', + 'Templates': 'Templates', + 'SubRouters': 'SubRouters', + 'Installation': 'Installation', + 'The Request Object': 'The Request Object', + 'The Robyn Env file': 'The Robyn Env file', + 'Middlewares, Events and Websockets': 'Middlewares, Events and Websockets', + 'Authentication': 'Authentication', + 'Const Requests and Multi Core Scaling': 'Const Requests and Multi Core Scaling', + 'CORS': 'CORS', + 'Templating': 'Templating', + 'Redirection': 'Redirection', + 'File Uploads': 'File Uploads', + 'Form Data': 'Form Data', + 'Websockets': 'Websockets', + 'Exceptions': 'Exceptions', + 'Scaling the Application': 'Scaling the Application', + 'Advanced Features': 'Advanced Features', + 'Multiprocess Execution': 'Multiprocess Execution', + 'Direct Rust Usage': 'Direct Rust Usage', + 'GraphQL Support': 'GraphQL Support', + 'Dependency Injection': 'Dependency Injection', + 'Talks': 'Talks', + 'Blogs': 'Blogs', + 'Introduction': 'Introduction', + 'Upcoming Features': 'Upcoming Features', + 'Railway': 'Railway', + 'Exposing Ports': 'Exposing Ports' + } + }, + zh: { + titles: navigationTitles.zh, + links: { + 'Getting Started': '开始使用', + 'Modeling Routes': '路由建模', + 'Authentication and Authorization': '身份验证和授权', + 'Middlewares': '中间件', + 'Real Time Notifications': '实时通知', + 'Monitoring and Logging': '监控和日志', + 'Deployment': '部署', + 'OpenAPI Documentation': 'OpenAPI 文档', + 'Templates': '模板', + 'SubRouters': '子路由', + 'Installation': '安装', + 'The Request Object': '请求对象', + 'The Robyn Env file': 'Robyn 环境文件', + 'Middlewares, Events and Websockets': '中间件、事件和 WebSocket', + 'Authentication': '身份验证', + 'Const Requests and Multi Core Scaling': '常量请求和多核心扩展', + 'CORS': '跨域资源共享', + 'Templating': '模板系统', + 'Redirection': '重定向', + 'File Uploads': '文件上传', + 'Form Data': '表单数据', + 'Websockets': 'WebSocket', + 'Exceptions': '异常处理', + 'Scaling the Application': '应用程序扩展', + 'Advanced Features': '高级功能', + 'Multiprocess Execution': '多进程执行', + 'Direct Rust Usage': '直接使用 Rust', + 'GraphQL Support': 'GraphQL 支持', + 'Dependency Injection': '依赖注入', + 'Talks': '演讲', + 'Blogs': '博客', + 'Introduction': '介绍', + 'Upcoming Features': '即将推出的功能', + 'Railway': 'Railway', + 'Exposing Ports': '端口暴露' + } + } +} + export function Navigation(props) { + const router = useRouter() + const currentLanguage = router.asPath.includes('/zh') ? 'zh' : 'en' + + const getLocalizedHref = (href) => { + if (href === '/documentation') { + return `/documentation/${currentLanguage}` + } + return href.replace('/documentation/en/', `/documentation/${currentLanguage}/`) + } + + // Create localized navigation with translated titles and link titles + const localizedNavigation = navigation.map(group => ({ + ...group, + title: translations[currentLanguage].titles[group.title] || group.title, + links: group.links.map(link => ({ + ...link, + title: translations[currentLanguage].links[link.title] || link.title, + href: getLocalizedHref(link.href) + })) + })) + return (