i18n-json-translator
v1.0.1
Published
JSON internationalization translator using Google Gemini API
Maintainers
Readme
I18n JSON Translator
Overview
A powerful Node.js application for translating JSON files across multiple languages using the Google Gemini API. This tool is designed to simplify internationalization (i18n) workflows by automatically translating nested JSON structures.
Features
- 🌐 Supports complex, nested JSON translations
- 🚀 Chunk-based translation to handle large files
- 🛡️ Robust error handling
- 📦 Preserves original JSON structure
- 🔧 Configurable translation parameters
Prerequisites
- Node.js (v16+ recommended)
- Google Gemini API Key
Installation
- Clone the repository:
git clone https://github.com/esamani77/i18n-json-translator.git
cd i18n-json-translator- Install dependencies:
npm install- Create a
.envfile in the project root:
GEMINI_API_KEY=your_google_gemini_api_key_hereConfiguration
Edit src/index.ts to customize translation settings:
await translationManager.translateLargeJson({
inputJsonPath: "./input.json", // Path to input JSON
outputDir: "./translations", // Output directory
sourceLanguage: "en", // Source language code
targetLanguage: "es", // Target language code
chunkSize: 5, // Translation chunk size
delayBetweenRequests: 1500, // Delay between API calls
});Usage
Running the Translator
npm startTranslation Parameters
inputJsonPath: Path to the JSON file you want to translateoutputDir: Directory where translated files will be savedsourceLanguage: Original language of the JSON (e.g., 'en')targetLanguage: Target language for translation (e.g., 'es', 'fr')chunkSize: Number of items to translate in each API requestdelayBetweenRequests: Milliseconds between chunk translations
Example Input JSON
{
"page": {
"langs": {
"en-uk": "English (UK)",
"en-us": "English (US)"
},
"navigation": {
"home": "Home",
"about": "About"
}
}
}Supported Languages
The translator supports most languages recognized by the Google Gemini API, including:
- English
- Spanish
- French
- German
- Arabic
- Chinese
- Russian
- And many more!
Troubleshooting
- Ensure your Gemini API key is valid
- Check internet connectivity
- Verify input JSON structure
- Monitor console for detailed error messages
Rate Limiting
To prevent API rate limits:
- Adjust
chunkSizeanddelayBetweenRequests - Use smaller chunk sizes for large files
- Implement exponential backoff if needed
Contributing
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
License
[MIT License]
Disclaimer
This tool uses the Google Gemini API. Ensure compliance with Google's terms of service and API usage guidelines.
Support
For issues or questions, please open a GitHub issue or contact the maintainer.
