Add language switch feature to support Chinese#19
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
|
@copilot 继续 |
|
@copilot 继续 |
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
语言切换功能已完成实现 (Language switcher feature implemented)! ✅ Changes in commit
Screenshots showing the feature:
|
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR adds a language switcher UI component to enable users to toggle between English and Chinese versions of the documentation site. Previously, Chinese translations existed at /cn/docs but were only accessible via direct URL.
Changes:
- Added i18n configuration to RootProvider with language display names ("English" and "中文")
- Enabled the i18n prop in DocsLayout to display the language switcher
- Introduced
LANGUAGE_NAMESmapping for maintainable language label configuration
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| apps/docs/app/[lang]/layout.tsx | Added LANGUAGE_NAMES constant and configured RootProvider with i18n settings to map language codes to display names |
| apps/docs/app/[lang]/docs/layout.tsx | Enabled i18n prop in DocsLayout to activate the language switcher component |
|
@copilot 网站首页还缺少切换语言的入口,而且应该根据当前用户的语言自动跳转到对应的语言 |
|
@copilot 继续 |
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
已完成两个功能的实现 (Both features implemented)! ✅ 1. 首页语言切换入口 (Homepage language switcher) - Commit
2. 自动语言检测 (Automatic language detection):
|

Add Language Switcher to Documentation Site
Problem
/cn/docs) but no UI to switch between languagesSolution
Added a language switcher component to both the documentation pages and homepage, enabling users to toggle between English and Chinese versions throughout the entire site.
Changes Made
Added i18n configuration to RootProvider (
apps/docs/app/[lang]/layout.tsx)LANGUAGE_NAMESmapping object for easy maintenance when adding more languagesEnabled i18n in DocsLayout (
apps/docs/app/[lang]/docs/layout.tsx)i18nprop to enable language switcher in the documentation layoutEnabled i18n in HomeLayout (
apps/docs/app/[lang]/page.tsx)i18nprop to enable language switcher on the homepageAutomatic Language Detection
The middleware (
apps/docs/middleware.ts) already handles automatic language detection:Screenshots
Before (English): https://github.com/user-attachments/assets/dccc193a-25ae-4a03-947c-0712543a70ee
Before (Chinese - accessible only via direct URL): https://github.com/user-attachments/assets/f15e83be-d18e-4010-8c6f-9342726b9a06
After (English docs with Language Switcher): https://github.com/user-attachments/assets/4e2b49ba-9c18-4bae-986c-27dde98aa644
After (Chinese docs with Language Switcher): https://github.com/user-attachments/assets/5fce241a-016f-4ba2-a768-7e427248bcbd
After (Homepage with Language Switcher): https://github.com/user-attachments/assets/98a0a0fa-e35d-4471-b5a4-1d26dd3a6af8
Language Switcher Dropdown: https://github.com/user-attachments/assets/bb329f19-750a-419c-9829-1782c1174578
Testing
✅ Language switcher appears in both English and Chinese versions
✅ Language switcher appears on homepage and all documentation pages
✅ Dropdown shows both language options (English and 中文)
✅ Clicking Chinese switches to
/cn/docsor/cnwith Chinese content✅ Clicking English switches to
/docsor/with English content✅ Active language is highlighted in the dropdown
✅ Code is maintainable and ready for adding more languages
✅ Automatic language detection from browser settings works via middleware
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.