A standalone TypeScript project for automatically translating missing i18n keys using Google Cloud Translate API.
-
Install dependencies:
npm install
-
Set up Google Cloud credentials:
create .env file and add google translate API key:
GOOGLE_TRANSLATE_KEY=AIxxxxxxxxxxxxxxxxxx-xxxx0 GOOGLE_TRANSLATE_PROJECT_ID="google-translate" -
Copy your i18n.ts file: Copy your
i18n.tsfile from your main project to thesrc/directory.
npm test
# or
npm run translate:testnpm run startnpm run build- ✅ Automatic Detection: Finds missing translation keys compared to English
- ✅ Google Translate Integration: Uses Google Cloud Translate API
- ✅ Rate Limiting: Built-in delays to avoid API limits
- ✅ Retry Logic: Automatic retries for failed translations
- ✅ Backup Creation: Creates backup before modifying files
- ✅ TypeScript Support: Full TypeScript implementation
- ✅ Configurable: Easy configuration via
translate-config.ts
Edit src/translate-config.ts to customize:
apiDelay: Delay between API calls (default: 100ms)maxRetries: Maximum retry attempts (default: 3)verbose: Enable detailed logging (default: true)targetLanguages: Languages to translate to
- Spanish (es)
- French (fr)
- German (de)
- Italian (it)
- Portuguese (pt)
- Japanese (ja)
Add more language as per the requirement
google-translate/
├── src/
│ ├── i18n.ts # Your i18n file (copy from main project)
│ ├── translate-missing-keys.ts # Main translation script
│ ├── translate-config.ts # Configuration
│ ├── test-translate.ts # Test script
│ └── index.ts # Entry point
├── dist/ # Compiled JavaScript (after build)
├── package.json
├── tsconfig.json
└── README.md
- Copy your latest
i18n.tsfrom your main project tosrc/ - Run
npm testto see what keys are missing - Run
npm run translate:missingto auto-translate - Review the translations in the updated
i18n.ts - Copy the updated file back to your main project
- Review Required: Machine translations may need manual review
- API Costs: Google Translate API calls may incur charges
- Backup: Always creates a backup before modifying files
- Context: Some translations may need adjustment for UI context