Skip to content

[WIP] Add support for default language configuration - #18

Merged
hotlong merged 2 commits into
mainfrom
copilot/add-default-language-support
Jan 19, 2026
Merged

[WIP] Add support for default language configuration#18
hotlong merged 2 commits into
mainfrom
copilot/add-default-language-support

Conversation

CopilotAI commented Jan 19, 2026

Copy link
Copy Markdown
Contributor

✅ i18n Support for Documentation Site

This PR implements internationalization (i18n) support for the ObjectStack documentation site, enabling automatic language detection and multi-language content delivery.

🎯 Features Implemented

  1. Default Language Configuration - English (en) set as default
  2. Language Catalog - Support for English and Chinese (cn)
  3. Automatic Language Detection - Middleware detects user's browser language
  4. Clean URL Structure - Default language URLs hide locale prefix (e.g., /docs instead of /en/docs)
  5. Localized Content - Full support for existing Chinese (.cn.mdx) translations

🏗️ Architecture Changes

Configuration Files

  • apps/docs/lib/i18n.ts - i18n configuration with Fumadocs

    • Default language: en
    • Supported languages: ['en', 'cn']
    • Hide locale for default language: hideLocale: 'default-locale'
  • apps/docs/middleware.ts - Language detection and routing middleware

    • Detects browser language preferences
    • Handles automatic redirection
    • Stores language preference in cookies

Structural Changes

  • Restructured App Directory - Moved routes under [lang] dynamic segment

    • app/[lang]/page.tsx - Homepage with language parameter
    • app/[lang]/docs/layout.tsx - Docs layout with language-specific page tree
    • app/[lang]/docs/[[...slug]]/page.tsx - Documentation pages with language routing
  • Updated Source Loader - Integrated i18n configuration with Fumadocs loader

📸 Screenshots

English Documentation (Default - /docs)
English Docs

Chinese Documentation (/cn/docs)
Chinese Docs

🔄 URL Structure

LanguageURL PatternExample
English (default)/docs/.../docs/guides/getting-started
Chinese/cn/docs/.../cn/docs/guides/getting-started

✅ Testing

  • Build successful with i18n configuration
  • English docs accessible at /docs (no language prefix)
  • Chinese docs accessible at /cn/docs (with language prefix)
  • Navigation between languages works correctly
  • Page metadata properly localized
  • Sidebar navigation translated based on language
  • All existing Chinese (.cn.mdx) content renders correctly

📝 Checklist

  • Create i18n configuration file (apps/docs/lib/i18n.ts)
  • Update source configuration to use i18n (apps/docs/app/source.ts)
  • Create middleware for automatic language detection and redirection (apps/docs/middleware.ts)
  • Restructure app with [lang] dynamic route for language support
  • Update root layout for i18n
  • Update docs layout for language routing
  • Update docs pages to accept language parameter
  • Build successfully with i18n support
  • Test language detection and redirection
  • Verify existing Chinese content works with new i18n setup

🚀 Next Steps

The i18n infrastructure is now in place. Future enhancements could include:

  • Language switcher UI component
  • Additional language support
  • Automatic language detection from Accept-Language headers
  • RTL language support

Translation Note: 文档站点现已支持配置默认语言(English)和语言清单(English/Chinese),首页可根据用户的浏览器语言自动转向相应语言版本。

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 0:37am

Request Review

Co-authored-by: huangyiirene <7665279+huangyiirene@users.noreply.github.com>
@hotlong
hotlong marked this pull request as ready for review January 19, 2026 12:45
CopilotAI review requested due to automatic review settings January 19, 2026 12:45
@hotlong
hotlong merged commit aa96f92 into mainJan 19, 2026
7 checks passed
Copilot stopped work on behalf of huangyiirene due to an error January 19, 2026 12:46

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 implements internationalization (i18n) support for the ObjectStack documentation site using Fumadocs. It introduces automatic language detection, multi-language routing with a [lang] dynamic segment, and clean URL structures that hide the default language prefix.

Changes:

  • Added i18n configuration and middleware for automatic language detection and routing
  • Restructured the app directory to support language-based routing with [lang] dynamic segments
  • Updated the source loader to integrate i18n configuration
  • Modified workspace configuration to optimize build dependencies

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 8 comments.

Show a summary per file
FileDescription
pnpm-workspace.yamlAdded build optimization for esbuild and sharp dependencies (unrelated to i18n)
apps/docs/middleware.tsCreated middleware for automatic language detection and redirection
apps/docs/lib/i18n.tsCreated i18n configuration defining supported languages (en, cn) and default language
apps/docs/app/source.tsIntegrated i18n configuration with the Fumadocs source loader
apps/docs/app/page.tsxReplaced homepage with fallback redirect to default language
apps/docs/app/layout.tsxSimplified root layout to delegate to language-specific layouts
apps/docs/app/[lang]/page.tsxCreated language-aware homepage (moved from root)
apps/docs/app/[lang]/layout.tsxCreated language-specific layout with HTML structure and RootProvider
apps/docs/app/[lang]/docs/layout.tsxCreated language-aware docs layout using language-specific page tree
apps/docs/app/[lang]/docs/[[...slug]]/page.tsxUpdated to accept and use language parameter for page rendering
Comments suppressed due to low confidence (2)

apps/docs/app/[lang]/docs/[[...slug]]/page.tsx:23

  • The source.getPage call is missing an 'await' keyword. While this may work if the function is synchronous, it's inconsistent with the async/await pattern used elsewhere in this file (e.g., line 22 with await props.params). Verify whether source.getPage returns a Promise and add await if necessary for consistency.
    apps/docs/app/[lang]/docs/[[...slug]]/page.tsx:52
  • The source.getPage call in generateMetadata is missing an 'await' keyword. This should be consistent with the async/await pattern used for awaiting props.params on line 51. Verify whether source.getPage returns a Promise and add await if necessary.

export default function RootLayout({ children }: { children: ReactNode }) {
// Root layout is only used for redirects with middleware
// The actual layout is in [lang]/layout.tsx
return children;

CopilotAIJan 19, 2026

Copy link

Choose a reason for hiding this comment

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

The root layout is missing the HTML structure (html and body tags). While the comment indicates this is intentional for middleware redirects, Next.js requires a proper HTML structure in the root layout. The layout should return a complete HTML document structure even if it's only used briefly before redirection.

Suggested change
returnchildren;
return(
<htmllang="en">
<body>{children}</body>
</html>
);

Copilot uses AI. Check for mistakes.
import { redirect } from 'next/navigation';
import type { ReactNode } from 'react';
import type { Metadata } from 'next';
import { i18n } from '@/lib/i18n';

CopilotAIJan 19, 2026

Copy link

Choose a reason for hiding this comment

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

The unused import 'i18n' should be removed from this file. The i18n configuration is imported but never used in the root layout.

Suggested change
import { i18n } from '@/lib/i18n';

Copilot uses AI. Check for mistakes.
Comment threadpnpm-workspace.yaml
Comment on lines +5 to +8

onlyBuiltDependencies:
- esbuild
- sharp

CopilotAIJan 19, 2026

Copy link

Choose a reason for hiding this comment

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

The pnpm-workspace.yaml change adding onlyBuiltDependencies for esbuild and sharp appears unrelated to the i18n feature. This configuration change should be in a separate PR or clearly documented in the PR description as it affects build behavior across the entire monorepo, not just the documentation site's i18n feature.

Suggested change
onlyBuiltDependencies:
- esbuild
- sharp

Copilot uses AI. Check for mistakes.
Comment on lines +12 to +14
children: ReactNode;
}) {
const { lang } = await params;

CopilotAIJan 19, 2026

Copy link

Choose a reason for hiding this comment

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

The language parameter from the URL is used directly without validation against the supported languages defined in i18n configuration. Consider validating that the lang parameter is one of the supported languages (['en', 'cn']) and redirecting to the default language if an invalid language is provided.

Copilot uses AI. Check for mistakes.
params: Promise<{ lang: string }>;
children: ReactNode;
}) {
const { lang } = await params;

CopilotAIJan 19, 2026

Copy link

Choose a reason for hiding this comment

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

The language parameter from the URL is used directly without validation against the supported languages defined in i18n configuration. Consider validating that the lang parameter is one of the supported languages (['en', 'cn']) and redirecting to the default language if an invalid language is provided.

Copilot uses AI. Check for mistakes.
Comment threadapps/docs/lib/i18n.ts
*/
export const i18n = defineI18n({
defaultLanguage: 'en',
languages: ['en', 'cn'],

CopilotAIJan 19, 2026

Copy link

Choose a reason for hiding this comment

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

The i18n configuration lacks documentation explaining the language codes used. Consider adding JSDoc comments to document that 'cn' refers to Chinese (Simplified) to avoid confusion with the ISO 639-1 standard code 'zh' or regional variants like 'zh-CN'.

Copilot uses AI. Check for mistakes.
@@ -1,7 +1,8 @@
import './global.css';
import { RootProvider } from 'fumadocs-ui/provider/next';
import { redirect } from 'next/navigation';

CopilotAIJan 19, 2026

Copy link

Choose a reason for hiding this comment

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

The unused import 'redirect' should be removed from this file. The import is declared but never used since the root layout only returns children without performing any redirect logic.

Suggested change
import { redirect } from 'next/navigation';

Copilot uses AI. Check for mistakes.
Comment on lines +7 to +21
export default async function Layout({
params,
children,
}: {
params: Promise<{ lang: string }>;
children: ReactNode;
}) {
const { lang } = await params;

return (
<DocsLayout tree={source.pageTree[lang]} {...baseOptions}>
{children}
</DocsLayout>
);
}

CopilotAIJan 19, 2026

Copy link

Choose a reason for hiding this comment

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

The old docs layout included a generateMetadata function that is now missing in the new language-specific layout. This metadata (title template and description specific to the docs section) should be restored to maintain proper SEO and browser tab titles for documentation pages.

Copilot uses AI. Check for mistakes.
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@huangyiirene@hotlong