feat(i18n): Fix language loss in navigation and add language selector (#6467)

* feat(docs): enable i18n language selector

* docs(i18n): translate introduction page to English

* fix(i18n): fix language switching issue by always showing locale prefix

* fix(docs): use relative paths for internal links to preserve language

* refactor(i18n): add getLocalizedPath helper to simplify URL generation

* refactor(i18n): make getLocalizedPath respect hideLocale config

* feat(i18n): fallback to default language when translation missing, keep URL unchanged

* feat(i18n): fix language loss in navigation and add language selector

- Set hideLocale to 'never' to always show language prefix
- Add localized-navigation.ts with useLocalizedRouter hook
- Update all navigation points to preserve language:
  1. Tab navigation (already using getLocalizedPath)
  2. Sidebar navigation (handled by Fumadocs)
  3. Home/404 redirects (using getLocalizedPath)
  4. MDX Redirect component (using useLocalizedRouter)
  5. Old page redirects (updated not-found.tsx)
  6. Document links (custom LocalizedLink component)
- Configure language selector in layout.config.tsx
- Add LOCALIZED_NAVIGATION.md documentation

* fix(i18n): fix type errors and useEffect dependencies

* refactor(i18n): move redirects to middleware for SSR support

- Move old path redirects from client-side (not-found.tsx) to server-side (middleware.ts)
- Use 301 permanent redirects for better SEO
- Preserve language prefix in redirects
- Fix SSR issue caused by client-side redirects

* refactor(i18n): clean up not-found.tsx, remove duplicate redirect maps

- Remove duplicate exactMap and prefixMap (now in middleware)
- Keep dynamic meta.json lookup for unknown pages
- Simplify to only handle fallback cases
- Two-layer approach: middleware (SSR) + not-found (dynamic)

* refactor(i18n): simplify not-found to always redirect to introduction

- Remove dynamic meta.json lookup
- Always redirect to introduction page on 404
- Ensures no 404 pages are shown
- Keep language prefix in redirect

* fix(i18n): fix middleware type error with ts-expect-error

- Add @ts-expect-error for Fumadocs middleware signature mismatch
- Fix syntax error in config matcher (remove literal \n)

---------

Co-authored-by: archer <archer@archerdeMac-mini.local>
This commit is contained in:
Archer
2026-02-26 16:29:03 +08:00
committed by GitHub
parent 616ac03150
commit 2fd4b6030b
17 changed files with 417 additions and 94 deletions
+6 -5
View File
@@ -7,7 +7,7 @@
"document/content/docs/faq/index.mdx": "2025-08-02T19:38:37+08:00",
"document/content/docs/faq/other.mdx": "2025-08-04T22:07:52+08:00",
"document/content/docs/faq/points_consumption.mdx": "2025-08-02T19:38:37+08:00",
"document/content/docs/introduction/cloud.mdx": "2026-02-26T00:22:01+08:00",
"document/content/docs/introduction/cloud.mdx": "2026-02-26T00:26:52+08:00",
"document/content/docs/introduction/commercial.mdx": "2025-09-21T23:09:46+08:00",
"document/content/docs/introduction/development/configuration.mdx": "2025-08-05T23:20:39+08:00",
"document/content/docs/introduction/development/custom-models/bge-rerank.mdx": "2025-07-23T21:35:03+08:00",
@@ -87,7 +87,8 @@
"document/content/docs/introduction/guide/team_permissions/customDomain.mdx": "2025-12-10T20:07:05+08:00",
"document/content/docs/introduction/guide/team_permissions/invitation_link.mdx": "2025-07-23T21:35:03+08:00",
"document/content/docs/introduction/guide/team_permissions/team_roles_permissions.mdx": "2025-07-23T21:35:03+08:00",
"document/content/docs/introduction/index.mdx": "2025-09-29T11:34:11+08:00",
"document/content/docs/introduction/index.en.mdx": "2026-02-26T00:54:15+08:00",
"document/content/docs/introduction/index.mdx": "2026-02-26T00:26:52+08:00",
"document/content/docs/openapi/app.mdx": "2026-02-12T18:45:30+08:00",
"document/content/docs/openapi/chat.mdx": "2026-02-12T18:45:30+08:00",
"document/content/docs/openapi/dataset.mdx": "2026-02-12T18:45:30+08:00",
@@ -101,11 +102,11 @@
"document/content/docs/protocol/privacy.mdx": "2025-12-15T23:36:54+08:00",
"document/content/docs/protocol/terms.en.mdx": "2025-12-15T23:36:54+08:00",
"document/content/docs/protocol/terms.mdx": "2025-12-15T23:36:54+08:00",
"document/content/docs/toc.en.mdx": "2026-02-12T18:02:02+08:00",
"document/content/docs/toc.en.mdx": "2026-02-26T00:54:15+08:00",
"document/content/docs/toc.mdx": "2026-02-24T13:48:31+08:00",
"document/content/docs/upgrading/4-10/4100.mdx": "2025-08-02T19:38:37+08:00",
"document/content/docs/upgrading/4-10/4101.mdx": "2025-09-08T20:07:20+08:00",
"document/content/docs/upgrading/4-11/4110.mdx": "2025-08-05T23:20:39+08:00",
"document/content/docs/upgrading/4-11/4110.mdx": "2026-02-26T00:26:52+08:00",
"document/content/docs/upgrading/4-11/4111.mdx": "2025-08-07T22:49:09+08:00",
"document/content/docs/upgrading/4-12/4120.mdx": "2025-09-07T14:41:48+08:00",
"document/content/docs/upgrading/4-12/4121.mdx": "2025-09-07T14:41:48+08:00",
@@ -202,7 +203,7 @@
"document/content/docs/use-cases/app-cases/translate-subtitle-using-gpt.mdx": "2025-07-23T21:35:03+08:00",
"document/content/docs/use-cases/external-integration/dingtalk.mdx": "2025-07-23T21:35:03+08:00",
"document/content/docs/use-cases/external-integration/feishu.mdx": "2025-07-24T14:23:04+08:00",
"document/content/docs/use-cases/external-integration/official_account.mdx": "2026-02-12T18:45:30+08:00",
"document/content/docs/use-cases/external-integration/official_account.mdx": "2026-02-26T00:26:52+08:00",
"document/content/docs/use-cases/external-integration/openapi.mdx": "2026-02-12T18:45:30+08:00",
"document/content/docs/use-cases/external-integration/wecom.mdx": "2025-12-10T20:07:05+08:00",
"document/content/docs/use-cases/index.mdx": "2025-07-24T14:23:04+08:00"