-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Make i18n languages fully configurable via docs.site.json #44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
- 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]>
🚀 Preview DeploymentThis pull request will be automatically deployed to Vercel. Preview Links
Build StatusCheck the CI workflow for build status and any errors. Automated preview information for PR #44 |
There was a problem hiding this 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.jsonin 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: { |
Copilot
AI
Jan 18, 2026
There was a problem hiding this comment.
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.
| cn: { | |
| zh-CN: { |
| function loadSiteConfig() { | ||
| const configPath = path.resolve(process.cwd(), 'content/docs.site.json'); |
Copilot
AI
Jan 18, 2026
There was a problem hiding this comment.
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.
| 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; |
| 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]; |
Copilot
AI
Jan 18, 2026
There was a problem hiding this comment.
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.
| 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]; |
The system had hardcoded language references (
en,cn) scattered across CLI and UI layers despite having ani18n.languagesconfig indocs.site.json.Changes
CLI Translation Utility (
packages/cli/src/utils/translate.mjs)docs.site.jsonat runtime.{lang}.mdx) from configured languagesUI Translations (
packages/site/lib/translations.ts- new)getTranslations()filters to configured languages onlyLayout Components
getTranslations()callConfiguration
{ "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
languagesarray indocs.site.jsonpackages/site/lib/translations.ts(optional, falls back to language code)Backward compatible - existing
["en", "cn"]config unchanged.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.