Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 17, 2026

The system had hardcoded language references (en, cn) scattered across CLI and UI layers despite having an i18n.languages config in docs.site.json.

Changes

CLI Translation Utility (packages/cli/src/utils/translate.mjs)

  • Load language configuration from docs.site.json at runtime
  • Generate file suffixes dynamically (.{lang}.mdx) from configured languages
  • Auto-detect target language as first non-default language

UI Translations (packages/site/lib/translations.ts - new)

  • Centralized translation registry for 6 languages: en, cn, ja, fr, de, es
  • getTranslations() filters to configured languages only
  • Fallback to minimal translation for unconfigured languages

Layout Components

  • Replaced hardcoded translation objects with getTranslations() call
  • Removed 27 lines of hardcoded language mappings

Configuration

{
  "i18n": {
    "enabled": true,
    "defaultLanguage": "en",
    "languages": ["en", "cn", "ja", "fr"]
  }
}

System now derives all language behavior from this config: file suffixes, UI translations, translation targets.

Adding New Languages

  1. Add language code to languages array in docs.site.json
  2. Add UI translations to packages/site/lib/translations.ts (optional, falls back to language code)
  3. Create content files with language suffix

Backward compatible - existing ["en", "cn"] config unchanged.

Original prompt

系统支持的语言应可以在docs.site.json中配置


💡 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
Copy link

vercel bot commented Jan 17, 2026

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

Project Deployment Review Updated (UTC)
docs Ready Ready Preview, Comment Jan 18, 2026 0:08am

Request Review

- Load site configuration dynamically from content/docs.site.json
- Generate language suffixes from configured languages array
- Auto-detect target language as first non-default language
- Export getSiteConfig() for use in translate command
- Add console output showing configured languages

Co-authored-by: huangyiirene <[email protected]>
- Create translations.ts with language translation mappings
- Support en, cn, ja, fr, de, es with full UI translations
- Update layout.tsx files to use getTranslations()
- Automatically filter translations based on docs.site.json config
- Add fallback for unconfigured languages

Co-authored-by: huangyiirene <[email protected]>
- Document i18n configuration in docs.site.json
- List all supported languages with translations
- Explain how to add new languages
- Update multi-language support features section

Co-authored-by: huangyiirene <[email protected]>
- Add comment explaining fallback config matches site-config.ts defaults
- Only show missing translation warnings in development mode
- Improve code quality and production readiness

Co-authored-by: huangyiirene <[email protected]>
Copilot AI changed the title [WIP] Add configurable supported languages in docs.site.json feat: Make i18n languages fully configurable via docs.site.json Jan 18, 2026
Copilot AI requested a review from huangyiirene January 18, 2026 00:11
@huangyiirene huangyiirene requested review from Copilot and removed request for huangyiirene January 18, 2026 00:27
@github-actions
Copy link

🚀 Preview Deployment

This pull request will be automatically deployed to Vercel.

Preview Links

  • 📝 Documentation: Will be available once Vercel deployment completes
  • 🌍 Languages: English (/en/docs) and Chinese (/cn/docs)

Build Status

Check the CI workflow for build status and any errors.


Automated preview information for PR #44

@github-actions github-actions bot added the documentation Improvements or additions to documentation label Jan 18, 2026
Copy link

Copilot AI left a comment

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 removes hardcoded language references throughout the codebase and makes all language behavior configurable via docs.site.json. The system now derives language suffixes, UI translations, and translation targets from the centralized i18n configuration.

Changes:

  • Centralized language configuration loading from docs.site.json in both CLI and UI layers
  • Replaced hardcoded translation objects with dynamic translation loading that filters to configured languages
  • Extended translation support from 2 languages (en, cn) to 6 languages with extensible architecture

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/site/lib/translations.ts New centralized translation registry with configurable language filtering
packages/site/app/layout.tsx Replaced hardcoded translations with dynamic getTranslations() call
packages/site/app/[lang]/layout.tsx Replaced hardcoded translations with dynamic getTranslations() call
packages/cli/src/utils/translate.mjs Made language suffixes and translation targets configurable via docs.site.json
packages/cli/src/commands/translate.mjs Added language configuration logging at translation start
README.md Updated documentation to reflect configurable i18n system

en: {
displayName: 'English',
},
cn: {
Copy link

Copilot AI Jan 18, 2026

Choose a reason for hiding this comment

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

The language code 'cn' is inconsistent with ISO 639-1 standard. The correct code for Chinese (Simplified) is 'zh-CN' or 'zh-Hans'. Consider using 'zh' or documenting this deviation from standard language codes.

Suggested change
cn: {
zh-CN: {

Copilot uses AI. Check for mistakes.
Comment on lines +9 to +10
function loadSiteConfig() {
const configPath = path.resolve(process.cwd(), 'content/docs.site.json');
Copy link

Copilot AI Jan 18, 2026

Choose a reason for hiding this comment

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

The config path is hardcoded to 'content/docs.site.json'. Consider making this configurable or using a constant to allow flexibility for different project structures.

Suggested change
function loadSiteConfig() {
const configPath = path.resolve(process.cwd(), 'content/docs.site.json');
const DEFAULT_SITE_CONFIG_PATH = path.resolve(
process.cwd(),
process.env.DOCS_SITE_CONFIG_PATH || 'content/docs.site.json'
);
function loadSiteConfig() {
const configPath = DEFAULT_SITE_CONFIG_PATH;

Copilot uses AI. Check for mistakes.
const LANGUAGE_SUFFIXES = languages.map(lang => `.${lang}.mdx`);

// Target language is the first non-default language
const targetLanguage = languages.find(lang => lang !== defaultLanguage) || languages[0];
Copy link

Copilot AI Jan 18, 2026

Choose a reason for hiding this comment

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

The fallback to languages[0] when all languages equal defaultLanguage could result in translating to the same language. This edge case should either throw an error or be explicitly documented as acceptable behavior.

Suggested change
const targetLanguage = languages.find(lang => lang !== defaultLanguage) || languages[0];
const nonDefaultLanguages = languages.filter(lang => lang !== defaultLanguage);
if (nonDefaultLanguages.length === 0) {
throw new Error(
`Invalid i18n configuration: languages (${JSON.stringify(
languages
)}) must include at least one language different from defaultLanguage ("${defaultLanguage}").`
);
}
const targetLanguage = nonDefaultLanguages[0];

Copilot uses AI. Check for mistakes.
@huangyiirene huangyiirene marked this pull request as ready for review January 18, 2026 00:29
@huangyiirene huangyiirene merged commit 3985cd9 into main Jan 18, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants