Skip to content

Add language switch feature to support Chinese - #19

Merged
huangyiirene merged 5 commits into
mainfrom
copilot/add-language-toggle-feature
Jan 19, 2026
Merged

Add language switch feature to support Chinese#19
huangyiirene merged 5 commits into
mainfrom
copilot/add-language-toggle-feature

Conversation

CopilotAI commented Jan 19, 2026

Copy link
Copy Markdown
Contributor

Add Language Switcher to Documentation Site

Problem

  • Chinese translations exist (/cn/docs) but no UI to switch between languages
  • Users cannot discover or access the Chinese version from the English site
  • Homepage was missing the language switcher

Solution

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

  1. Added i18n configuration to RootProvider (apps/docs/app/[lang]/layout.tsx)

    • Configured locale and locales list with English and Chinese labels
    • Language names: "English" and "中文"
    • Created LANGUAGE_NAMES mapping object for easy maintenance when adding more languages
  2. Enabled i18n in DocsLayout (apps/docs/app/[lang]/docs/layout.tsx)

    • Added i18n prop to enable language switcher in the documentation layout
  3. Enabled i18n in HomeLayout (apps/docs/app/[lang]/page.tsx)

    • Added i18n prop to enable language switcher on the homepage

Automatic Language Detection

The middleware (apps/docs/middleware.ts) already handles automatic language detection:

  • Detects user's preferred language from browser settings or cookies
  • Redirects users to the appropriate localized version automatically
  • Stores language preference as a cookie for future visits

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/docs or /cn with Chinese content
✅ Clicking English switches to /docs or / 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.

@vercel

vercelBot commented Jan 19, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

ProjectDeploymentReviewUpdated (UTC)
specReadyReadyPreview, CommentJan 19, 2026 2:19pm

Request Review

Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
@huangyiirene

Copy link
Copy Markdown
Collaborator

@copilot 继续

@hotlong

Copy link
Copy Markdown
Contributor

@copilot 继续

Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>

CopilotAI commented Jan 19, 2026

Copy link
Copy Markdown
ContributorAuthor

@copilot 继续

语言切换功能已完成实现 (Language switcher feature implemented)! ✅

Changes in commit 243250e:

  • Added language switcher button to the documentation site
  • Configured i18n provider with English ("English") and Chinese ("中文") options
  • Language switching now works seamlessly between /docs (English) and /cn/docs (Chinese)

Screenshots showing the feature:

Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
@huangyiirene
huangyiirene requested review from Copilot and removed request for hotlong and huangyiireneJanuary 19, 2026 13:58
@github-actionsgithub-actionsBot added documentation Improvements or additions to documentation size/s labels Jan 19, 2026
CopilotAI changed the title [WIP] Add language switch feature to support ChineseAdd language switch feature to support ChineseJan 19, 2026
CopilotAI requested a review from hotlongJanuary 19, 2026 13:59

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_NAMES mapping for maintainable language label configuration

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

FileDescription
apps/docs/app/[lang]/layout.tsxAdded LANGUAGE_NAMES constant and configured RootProvider with i18n settings to map language codes to display names
apps/docs/app/[lang]/docs/layout.tsxEnabled i18n prop in DocsLayout to activate the language switcher component

@huangyiirene

Copy link
Copy Markdown
Collaborator

@copilot 网站首页还缺少切换语言的入口,而且应该根据当前用户的语言自动跳转到对应的语言

@hotlong

Copy link
Copy Markdown
Contributor

@copilot 继续

Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>

CopilotAI commented Jan 19, 2026

Copy link
Copy Markdown
ContributorAuthor

@copilot 继续

已完成两个功能的实现 (Both features implemented)! ✅

1. 首页语言切换入口 (Homepage language switcher) - Commit 494855a:

  • 在首页导航栏添加了语言切换按钮
  • 与文档页面一样,支持英文和中文切换

2. 自动语言检测 (Automatic language detection):

  • 已通过 middleware 实现自动语言检测
  • 根据浏览器语言设置自动跳转到相应语言版本
  • 语言偏好会保存在 cookie 中

Homepage with language switcher:
Homepage

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentationImprovements or additions to documentationsize/s

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@huangyiirene@hotlong