3.8 KiB
3.8 KiB
RikkaHub I18n Translation Manager
AI-powered translation manager for Android string resources with interactive TUI.
Features
- 🌐 Support for multiple target languages (Chinese, Japanese, Traditional Chinese)
- 🤖 AI-powered translations using Vercel AI SDK (Google Gemini, OpenAI)
- 📊 Translation progress tracking with completion percentages
- 🔍 Search and filter capabilities
- ✏️ Interactive editing of translations
- 📁 Multi-module Android project support
- 💾 Automatic XML file generation and updates
Setup
-
Install dependencies:
npm install # or bun install -
Configure environment variables: Copy
.env.exampleto.envand add your API keys:cp .env.example .envEdit
.envwith your API key:# For Google Gemini (default) GOOGLE_GENERATIVE_AI_API_KEY=your_gemini_api_key_here # For OpenAI OPENAI_API_KEY=your_openai_api_key_here -
Configure targets: Edit
config.ymlto set your target languages and modules:targets: - zh # Simplified Chinese - ja # Japanese - zh-rTW # Traditional Chinese modules: - app # Main app module - search # Search module # Add other modules as needed provider: type: google # or "openai" model: gemini-2.5-flash
Usage
Run the translation manager:
npm run dev
Navigation
Module Selection:
- ↑↓: Navigate between modules
- Enter: Select module
- Shows completion progress for each module
Language Selection:
- ↑↓: Navigate between target languages
- Enter: Select language
- Shows translation statistics
Translation Table:
- ↑↓: Navigate between translation entries
e: Edit selected translationt: Translate all missing entries with AIf: Toggle filter to show only missing translationsq: Go back to language selection- Ctrl+C: Exit application
Edit Mode:
- Type to edit translation
- Enter: Save changes
- Esc: Cancel edit
Translation Status Icons
- ✅ Translated
- ❌ Missing translation
- 🚫 Not translatable (marked with translatable="false")
File Structure
i18n/
├── src/
│ ├── config.ts # Configuration loader
│ ├── xml-parser.ts # Android XML string parser
│ ├── translator.ts # AI translation service
│ ├── module-loader.ts # Module data loader
│ └── tui/ # Terminal UI components
│ ├── App.tsx # Main app component
│ ├── ModuleSelector.tsx # Module selection screen
│ └── TranslationTable.tsx # Translation management screen
├── config.yml # Configuration file
├── .env.example # Environment variables template
└── package.json # Dependencies and scripts
Supported AI Providers
- Google Gemini (recommended):
gemini-2.5-flash,gemini-1.5-pro - OpenAI:
gpt-4,gpt-3.5-turbo,gpt-4-turbo
Translation Process
- The tool scans all configured modules for
strings.xmlfiles - Compares default strings with existing translations
- Uses AI to translate missing entries with context awareness
- Preserves Android formatting (e.g.,
%1$d,%1$s,\\n,\\') - Saves translations to appropriate
values-{locale}/strings.xmlfiles
Troubleshooting
API Rate Limits: The tool includes automatic delays between translations to avoid rate limits.
Missing Translations: Use the f key to filter and show only missing translations.
File Permissions: Ensure write permissions for the Android module directories.
API Key Issues: Verify your API key is correctly set in the .env file and has sufficient quota.