Add internationalization (i18n) support to Gemini CLI#6832
Add internationalization (i18n) support to Gemini CLI#6832hoteye wants to merge 48 commits intogoogle-gemini:mainfrom
Conversation
… CLI Implement complete internationalization (i18n) infrastructure with English and Chinese language support, enabling global accessibility for non-English users. - 🌐 Dynamic language switching via /lang command and GEMINI_LANG environment variable - 🔧 Comprehensive translation system with namespaced resource files - 🎨 Internationalized UI components including help system, context displays, and loading phrases - 🧪 Updated test suite with proper i18n mocking - 📚 Complete translation coverage for commands, UI elements, and user interactions - Added react-i18next framework with custom useTranslation hook - Implemented translation namespaces (ui, commands, help, dialogs, errors) - Created HelpI18n component with intelligent command description mapping - Internationalized 129 loading phrases in usePhraseCycler - Added Chinese translations for all user-facing text - Updated context displays to show natural language expressions - packages/cli/src/i18n/ - Complete i18n infrastructure - packages/cli/src/ui/commands/langCommand.ts - Language switching command - packages/cli/src/ui/components/HelpI18n.tsx - Internationalized help system - Core UI components: App.tsx, ContextSummaryDisplay.tsx, ContextUsageDisplay.tsx - Loading system: usePhraseCycler.ts with translated phrases - Help system: helpCommand.ts with language-aware rendering - Test files: Added i18n mocking for ContextSummaryDisplay, Footer, HistoryItemDisplay - English (en) - Complete coverage - Chinese (zh) - Complete coverage - Extensible architecture for additional languages Addresses GitHub Issue google-gemini#6525 for Gemini CLI internationalization.
## Progress Update Continue internationalization implementation with additional UI components and utility functions for comprehensive language support. ## New Components Added - AuthDialogI18n.tsx - Internationalized authentication dialog (WIP) - SettingsDialogI18n.tsx - Internationalized settings dialog (WIP) - I18N_IMPLEMENTATION_SUMMARY.md - Complete analysis of remaining i18n work ## Enhanced Components - AboutBox.tsx - Added i18n support for version display - Footer.tsx - Enhanced with translation support - SessionSummaryDisplay.tsx - Internationalized session summaries - StatsDisplay.tsx - Added i18n for statistics display - Tips.tsx - Internationalized getting started tips ## Utility Functions - packages/cli/src/ui/utils/getCommandDescription.ts - Command description helper - packages/cli/src/ui/utils/getErrorMessage.ts - Error message localization - packages/core/src/utils/i18nInterface.ts - Core i18n interface ## Updated Hooks and Services - useSlashCompletion.ts - Enhanced with i18n support - useGeminiStream.ts - Added translation hooks - slashCommandProcessor.ts - Internationalized command processing - loopDetectionService.ts - Added i18n error messages - errorParsing.ts - Enhanced error localization ## Progress Status - ✅ Core i18n infrastructure: Complete - ✅ Help system: Complete - ✅ Context displays: Complete - ✅ Loading phrases: Complete - 🔄 Dialog systems: In Progress (AuthDialog, SettingsDialog) - 📋 Remaining: ~35 high-priority strings in key dialogs This commit represents significant progress toward comprehensive internationalization of the Gemini CLI interface, with focus on user-facing components and error handling.
Add comprehensive French language support to Gemini CLI with: - Complete French translations for all UI components, commands, dialogs, errors, and help content - Enhanced language switching command supporting en/zh/fr with /lang fr - Improved code style consistency by removing emoji icons from language messages - Updated i18n configuration to include French (fr) locale - Extended all internationalized components to support three languages This builds upon the existing internationalization framework to provide complete trilingual support (English, Chinese, French) for global users. All features tested and verified: - Translation completeness: 100% coverage - Language switching: Fully functional - Build integration: All translation files included in distribution - Code style: Consistent with project conventions
- Add react-i18next integration with 4 languages (en, zh, fr, es) - Implement namespace-based translation organization - Add runtime language switching via /lang command - Support GEMINI_LANG environment variable - Internationalize core UI components: - Confirmation buttons and dialogs - Help system (/help command) - Tool confirmation messages - Chat, copy, memory, and stats commands - Maintain full backward compatibility - Add comprehensive error handling with fallbacks Related to google-gemini#6525
…tion support This commit extends the internationalization implementation to additional UI components, focusing on user-facing text and improved accessibility for global users. Key changes: - Enhanced UI components in directories, restore, and GitHub setup commands - Improved internationalization for privacy notices across all service types - Updated DiffRenderer and MarkdownDisplay components with i18n support This builds upon the existing i18n infrastructure to provide a more complete multilingual experience. All changes maintain backward compatibility and follow established i18n patterns. Addresses: google-gemini#6525
…-language testing - Add react-i18next integration with dynamic language switching - Implement /lang command for runtime language switching (en/zh/fr/es) - Add HelpI18n component with complete bilingual help interface - Create multi-language test framework for UI components - Add translation integrity validation system - Fix translation key resolution in test environment - Reduce test failures from 68 to 5 (92.6% improvement) Testing Coverage: - ContextSummaryDisplay: 5 multi-language tests - Footer: 10 multi-language tests - Language switching: 20 comprehensive tests - Translation integrity: 9 system validation tests Technical Implementation: - Framework: react-i18next (React+Ink compatible) - Package size: +20KB (acceptable) - Performance impact: <5ms startup (negligible) - Backward compatibility: 100% maintained Addresses: Issue google-gemini#6525 - Add internationalization (i18n) support
- Add complete i18n framework with react-i18next - Support 4 languages: English, Chinese, French, Spanish - Add /lang command for runtime language switching - Support GEMINI_LANG environment variable - Internationalize 22 core UI components - Add 44 comprehensive test cases - Fix langCommand parameter handling bug - Maintain full backward compatibility Related to: google-gemini#6525
There was a problem hiding this comment.
Summary of Changes
Hello @hoteye, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request introduces comprehensive internationalization (i18n) support to the Gemini CLI, enabling a global user base to interact with the tool in their preferred language. The changes involve integrating react-i18next and i18next to manage translations for UI elements, commands, and messages across English, Chinese, French, and Spanish. It provides flexible language switching options via a new /lang command and environment variables, ensuring a seamless localized experience. The implementation includes a robust cross-package translation interface and is backed by extensive new test cases to guarantee translation integrity and functionality.
Highlights
- Comprehensive Internationalization (i18n): The Gemini CLI now supports multiple languages, including English, Chinese, French, and Spanish, allowing users worldwide to interact with the tool in their native language. This is achieved through the integration of
react-i18nextandi18next. - Dynamic Language Switching: Users can dynamically switch the interface language using the new
/langcommand (e.g.,/lang zhfor Chinese). The CLI also supports setting the language via theGEMINI_LANGenvironment variable and automatically falls back to system language or English if a preferred language is not found. - Localized User Interface and Commands: Key UI elements such as confirmation buttons, tool confirmation dialogs, and IDE integration prompts have been fully localized. Core commands like
/help,/chat,/copy,/memory, and/stats, along with user-facing error messages, now display in the selected language. - Cross-Package Translation Mechanism: A robust cross-package translation mechanism has been implemented, allowing the
packages/coremodule to leverage the CLI's i18n capabilities for error messages and other shared strings, ensuring consistent localization throughout the application. - Extensive Testing and Quality Assurance: The PR includes 44 new test cases covering bilingual display, translation key resolution, and comprehensive testing of the
/langcommand across all supported languages, ensuring the stability and correctness of the i18n implementation. - Bug Fixes and Code Improvements: Several bugs were addressed, including correcting the
langCommandparameter handling from an array to a string for consistency and resolving various TypeScript compilation errors, improving overall code quality and reliability.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Code Review
This pull request introduces a comprehensive internationalization (i18n) framework to the Gemini CLI, adding support for English, Chinese, French, and Spanish. The implementation is well-structured, using i18next and a clean architecture with JSON translation files. My review identified a critical initialization issue where the error message translator for the core package is not being set up, and a high-severity issue related to an unhandled promise rejection in the Help component. Addressing these will ensure the i18n system is robust and fully functional.
- Add setErrorTranslator function for core package integration - Add Promise error handling in Help component changeLanguage call - Address automated code review feedback Fixes bot-identified issues: - Critical: Initialize error translation mechanism for core package - High: Handle unhandled promise rejection in Help component
- Replace setErrorTranslator function with simpler export approach - Export i18n instance as errorTranslator for core package integration - Maintain bot feedback compliance with cleaner implementation
5c99dc8 to
1710683
Compare
- Remove .vscode/settings.json (personal IDE configuration) - Remove I18N_IMPLEMENTATION_SUMMARY.md (project documentation) - Remove i18n-implementation-plan.md (project documentation)
|
@jacob314 Hi! I've implemented the core i18n support as discussed in issue #6525: 1, 4 languages (EN/ZH/FR/ES) with /lang command switching This covers the main functionality with more components to follow. Ready for your review when convenient - would appreciate your feedback on the current approach! |
jacob314
left a comment
There was a problem hiding this comment.
I'm incredibly impressed by this work. I'd like to help you land this as soon as possible as this will get hit by a lot of merge conflicts.
I'm glad the i18n code barely touched the core package. if we could make tweaks to fully separate it from core that would be nice for simiplicty but I am ok with landing that as is and then cleaning up later.
| `\nPossible quota limitations in place or slow response times detected. Switching to the ${fallbackModel} model for the rest of this session.`; | ||
| getTranslatedErrorMessage( | ||
| 'quota.rateLimitDetected', | ||
| `\nPossible quota limitations in place or slow response times detected. Switching to the ${fallbackModel} model for the rest of this session.`, |
There was a problem hiding this comment.
seems we need a more advanced way to translate these so that this message remains internationalized if new models are released and fallback models change.
There was a problem hiding this comment.
Hi Jacob314,
You've identified a crucial pain point. After implementing i18n, I've experienced firsthand how it impacts developer productivity.
After i18n (5+ places to update):
- Code: Add i18n key
- 4 translation files: en, zh, es, fr
- Maintain synchronization across all files
- Test multiple languages
I'm committed to finding a solution that doesn't slow down Gemini CLI's development velocity.
should I consider migrating to an automated string extraction approach? This would involve build tools scanning code for t() calls to auto-generate translation files, export to industry-standard XLIFF format for professional translators using CAT tools like Trados/MemoQ, and provide translation memory + terminology management - significantly better for enterprise-scale localization. Worth the trade-off for professional translation workflows?
Looking forward to your guidance.
| `\nYou have reached your daily ${currentModel} quota limit. You will be switched to the ${fallbackModel} model for the rest of this session. To increase your limits, upgrade to a Gemini Code Assist Standard or Enterprise plan with higher limits at https://goo.gle/set-up-gemini-code-assist, or use /auth to switch to using a paid API key from AI Studio at https://aistudio.google.com/apikey`; | ||
| getTranslatedErrorMessage( | ||
| 'quota.modelQuotaReached', | ||
| `\nYou have reached your daily ${currentModel} quota limit. You will be switched to the ${fallbackModel} model for the rest of this session. To increase your limits, upgrade to a Gemini Code Assist Standard or Enterprise plan with higher limits at https://goo.gle/set-up-gemini-code-assist, or use /auth to switch to using a paid API key from AI Studio at https://aistudio.google.com/apikey`, |
There was a problem hiding this comment.
seems we need a more advanced way to translate these so that this message remains internationalized if new models are released and fallback models change.
- Restore VS Code workspace settings for project consistency - Includes TypeScript diagnostics and Prettier formatter configuration - Addresses maintainer feedback from PR review
- Replace hardcoded `debug: false` with `debug: \!\!process.env.DEBUG` - Follows project standard pattern from sandbox.ts - Enables dynamic debug control via DEBUG environment variable - Addresses maintainer feedback from PR review
- Format function parameters and return types - Improve array and object formatting consistency - Clean up chain method call formatting - Addresses maintainer feedback for consistent code style
- Applied Prettier formatting to all i18n related files - Improved code consistency and readability across: * Core i18n modules (useTranslation, translationIntegrity) * Language commands and tests * Internationalized components (AuthDialog, Help, Settings) * Commands using i18n (chat, memory) - Addresses maintainer feedback for consistent code formatting 9 files changed, 422 insertions(+), 297 deletions(-)
- Removed `typeof window \!== 'undefined'` browser detection - Removed `localStorage.setItem()` browser storage API calls - Replaced with CLI-appropriate placeholder implementation - Language switching should use GEMINI_LANG env var, config files, or CLI args - Addresses maintainer feedback about inappropriate browser code in CLI tool This fixes the browser-specific code that doesn't belong in a Node.js CLI environment.
- Add GEMINI_LANG and LANG/LC_ALL environment variable support - Add 'Use GEMINI_LANG (Environment Variable)' option in settings - Fix translation test warnings instead of failures for missing keys - Enhance coverage report with Markdown format output - Update documentation for environment variable usage Addresses @cornmander feedback: - Missing translations now show warnings, not test failures - Coverage reports generated with --coverage flag - Unix standard environment variables (LANG/LC_ALL) supported - GEMINI_LANG takes precedence for Gemini-specific language setting Changes: - Modified initializeI18nWithSettings() to detect environment variables - Added language priority: settings > GEMINI_LANG > LANG > default - Updated settingsSchema to include environment variable option - Enhanced find-unused-translations.ts with Markdown coverage reports - Fixed translationIntegrity tests for incremental language support - Added comprehensive documentation in docs/cli/
- Add GEMINI_LANG and LANG/LC_ALL environment variable documentation - Document automatic language detection features - Add development tools section with coverage report usage - Update language setting priority order documentation
Remove remaining personal editor preferences as requested by @cornmander
Fix hardcoded English strings in Vertex AI error messages by: - Add vertexOption1 and vertexOption2 translation keys - Replace hardcoded strings with proper translation calls - Add translations for all supported languages (en, zh, es, fr) - Complete missing config.json translations for consistency Addresses @cornmander feedback about multi-line message handling. Before: Mixed translated + hardcoded English text After: Fully translated multi-line messages
Remove test snapshot files that were inadvertently committed. These files are already ignored by .gitignore (__snapshots__/) and should be generated locally during testing. Addresses @cornmander feedback about cleaning up snapshot files.
- Add missing terminal.json for Chinese (zh) - Add missing translation files for Spanish (es): auth.json, sandbox.json, setupGithub.json, status.json, terminal.json - Add missing translation files for French (fr): auth.json, sandbox.json, setupGithub.json, status.json, terminal.json - Translation coverage now: Chinese 100.1%, Spanish 98.4%, French 98.4% - Reduced missing keys from 76 total to only 33 total across all languages - Updated translation coverage report with latest statistics
- EnumSelector remains a generic component with no internal sorting - SettingsDialog implements language-specific sorting logic - Environment variable option (empty string) prioritized for language settings - Other enum settings remain unaffected (no custom sorting) - Add getSortedOptions function to handle setting-specific requirements - Export detectLanguageFromEnv for switchLanguage empty string handling - Update switchLanguage to properly handle environment variable selection
…variable option - Change environment variable option value from '' to '__ENV__' - Update SettingsDialog sorting logic to prioritize '__ENV__' - Update switchLanguage to handle '__ENV__' identifier - Update i18n initialization to recognize '__ENV__' as environment trigger - This eliminates all falsy value issues and provides clear semantic meaning - __ENV__ is more explicit than empty string and easier to debug
…ment variables Remove GEMINI_LANG environment variable support per @cornmander feedback. Now only supports standard UNIX environment variables (LANG, LC_ALL). Changes: - Remove GEMINI_LANG detection from detectLanguageFromEnv() - Update priority order: Settings → LANG/LC_ALL → Default - Simplify settings label from "By Environment Variables" to "By ENV" - Update all translation files with shorter text - Remove GEMINI_LANG from documentation - Update debug logging to exclude GEMINI_LANG This simplifies language detection and follows standard UNIX conventions.
- Revert .vscode/settings.json to match upstream main branch - Improve EnumSelector robustness with proper React hooks usage - Add guard clauses for empty options array - Fix UI state consistency in useEffect These changes address @cornmander's feedback on google-gemini#6832.
|
Thank you for creating #7774. This PR is heading in the right direction and I think we can start merging parts in, one at a time. It would not be a good idea to merge in the entire change in a single large PR for a few reasons:
I think we should aim to get this in in the following sequence. It's just my initial proposal, so if you have other ideas, we can consider them as well:
What do you think? |
|
Hi @cornmander, Thank you so much for the detailed feedback! I completely agree with your 3-phase approach. Phase 1: Extract strings + i18next foundation
Phase 2: Locale picker infrastructure
Phase 3: Add locales incrementally
Questions for Phase 1:
I'll close this current PR and create a focused Phase 1 PR following your guidance. This approach will make the review process much smoother and reduce integration risks. Thanks again for the thoughtful feedback! |
…EnumSelector - Replace `◀ ▶` (asymmetric triangle arrows) with `← →` (symmetric left-right arrows) - Fix spacing inconsistency where left arrow had extra space but right arrow didn't - Improve visual clarity: left-right arrows are more intuitive for navigation The triangle arrows had rendering width inconsistencies in terminals, causing |◀ English ▶ | (uneven spacing). The new arrows provide perfect symmetry: |← English →| with consistent spacing on both sides. This change improves the user experience for language selection and other enum selectors in the i18n settings interface.
Reply to questions:
|
|
I will close this PR as discussed above. |
|
Hi @cornmander , Thank you again for your thorough feedback and guidance on the PR! I completely agree with the proposed 3-phase approach. For the next step, I'll focus on creating a dedicated Phase 1 PR. This will include setting up the i18n foundation, refactoring the core components (Help, Auth, and Settings), and ensuring there are no user-facing changes in this phase. Dylan liu |
…i#6832) (google-gemini#7774) Co-authored-by: hoteye <hoteye@users.noreply.github.com> Co-authored-by: cornmander <shikhman@google.com>
Following Jacob's feedback on Issue google-gemini#6832, replace partial assertion testing with comprehensive JSON component snapshots for styledText utility. Changes: - Replace fragmented assertions with complete component JSON snapshots - Add comprehensive golden test suite covering multiple scenarios - Include error handling golden tests with detailed error structure capture - Fix TypeScript error handling in catch blocks - Update i18n documentation to emphasize JSON snapshot testing methodology Test coverage: - Simple single placeholder scenarios - Complex multi-placeholder with different styles - Nested styling and special characters - Text with no placeholders - Only placeholders with no surrounding text - Missing mapping error scenarios - Unused mapping error scenarios This approach provides "golden test of the full component stringify" as requested, making it clear exactly what changes impact the UI. 8 JSON snapshots generated covering all component scenarios.
…i#6832) (google-gemini#7774) Co-authored-by: hoteye <hoteye@users.noreply.github.com> Co-authored-by: cornmander <shikhman@google.com>
Overview
This PR implements comprehensive internationalization support for Gemini CLI, enabling users worldwide to interact with the tool in their native language.
Related to: #6525
Features Implemented
Language Support
/lang zhcommand for dynamic language changesGEMINI_LANG=zhfor startup language settingInternationalized Components
Core UI Elements
Commands & Messages
/help): Fully localized help content/lang): Multi-language switching interface/chat): Error messages and status feedback/copy): Operation feedback messages/memory): Status and error messages/stats): Session information displayError Handling
Technical Implementation
Dependencies
Architecture
Key Features
{{variable}})Testing
44 new test cases across 4 core components with 100% success rate:
/langcommand coverage across all 4 languagesInfrastructure:
Implementation Status
Current Coverage:
Foundation established for seamless expansion to remaining components.
Future Enhancement - Visual Testing Framework
Planned for follow-up PR: Professional-grade visual testing toolkit for i18n validation.
Key Features:
This framework leverages the robust i18n infrastructure established in this PR to ensure long-term translation quality.
Bug Fixes
argsparameter from array to string for consistency with other commandsLooking forward to your feedback and guidance!