A powerful command-line tool that uses Google Gemini AI to translate markdown and MDX files from English to any specified language while preserving formatting and structure.
- 🌍 Multi-language support - Translate to 40+ languages
- 📝 Markdown-aware - Preserves all markdown formatting (headers, links, code blocks, tables, etc.)
- 🔄 Smart chunking - Handles large files by splitting content intelligently
- 🎯 Selective translation - Only translates text content, keeps code and URLs intact
- 📊 Progress tracking - Real-time progress indication with spinners
- 🎨 Beautiful CLI - Colorful, user-friendly command-line interface
- ⚡ Fast processing - Optimized for speed with high-performance Gemini model
- Node.js 16.0.0 or higher
- Google Gemini API key (Get one here)
Note: This tool uses ES modules (ESM) and requires Node.js 16+ for full compatibility.
npm install
npm link
Or run directly with Node:
node bin/cli.js
- Visit Google AI Studio
- Create a new API key
- Copy the generated key
Option A: Environment Variable (Recommended)
export GEMINI_API_KEY="your-api-key-here"
Option B: Command Line Argument
md-translate translate -i file.md -l Spanish --key your-api-key-here
# Translate README.md to Spanish
md-translate translate -i README.md -l Spanish
# Translate with custom output file
md-translate translate -i docs/guide.md -l French -o docs/guide_fr.md
# Translate using API key argument
md-translate translate -i file.md -l German --key your-api-key
md-translate translate [options]
Options:
-i, --input <file> Input markdown/MDX file path (required)
-l, --language <lang> Target language (required)
-o, --output <file> Output file path (optional)
-k, --key <apikey> Google Gemini API key (optional)
md-translate languages
md-translate setup
md-translate --help
The tool supports 40+ languages including:
- European: Spanish, French, German, Italian, Portuguese, Dutch, Russian, Polish, Swedish, Norwegian, Danish, Finnish, Greek, Ukrainian, Czech, Hungarian, Romanian, Bulgarian, Croatian, Serbian, Slovak, Slovenian, Estonian, Latvian, Lithuanian, Catalan, Basque, Welsh, Irish
- Asian: Chinese, Japanese, Korean, Hindi, Thai, Vietnamese, Indonesian, Malay
- Middle Eastern: Arabic, Hebrew, Turkish
md-translate translate -i README.md -l Spanish
Output: Creates README_spanish.md
with Spanish translation
md-translate translate -i docs/api.md -l French -o docs/fr/api.md
Output: Creates docs/fr/api.md
with French translation
md-translate translate -i guide.md -l German --key AIzaSyC...
The tool automatically handles large files by splitting them into chunks:
md-translate translate -i large-document.md -l Japanese
✅ Translated:
- Heading text
- Paragraph text
- List items
- Table content
- Link text
- Image alt text
- Quote text
❌ Preserved:
- Code blocks and inline code
- URLs and file paths
- Markdown syntax characters
- HTML tags
- Mathematical expressions
- Technical terms and proper nouns (when appropriate)
The tool provides detailed progress feedback:
╔═══════════════════════════════════════╗
║ Markdown Translator ║
║ Powered by Google Gemini AI ║
╚═══════════════════════════════════════╝
📋 Translation Details:
Input: /path/to/README.md
Output: /path/to/README_spanish.md
Language: Spanish
⠋ Translating chunk 2/3...
✅ Translation completed successfully!
📊 Summary:
Original length: 2,845 characters
Translated length: 3,120 characters
Language: Spanish
Output file: /path/to/README_spanish.md
The tool provides clear error messages for common issues:
- Missing or invalid API key
- File not found
- Invalid file format
- Network connectivity issues
- API rate limiting
markdown-translator/
├── bin/
│ └── cli.js # CLI entry point
├── src/
│ └── translator.js # Core translation logic
├── package.json # Dependencies and scripts
└── README.md # Documentation
This project uses ES modules (ESM) for modern JavaScript development:
- All files use
import
/export
syntax instead ofrequire
/module.exports
package.json
includes"type": "module"
for ESM support- Compatible with the latest versions of dependencies (chalk 5.x, ora 8.x)
- Requires Node.js 16+ for full ESM compatibility
@google/generative-ai
- Google Gemini AI SDKcommander
- Command-line interface frameworkchalk
- Terminal stylingora
- Progress spinnersfs-extra
- Enhanced file system operations
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Ensure your API key is valid and active
- Check that you have sufficient quota in your Google Cloud account
- Verify the API key has access to the Gemini API
- The tool automatically chunks large files
- Each chunk is processed with a small delay to avoid rate limiting
- Very large files may take several minutes to process
- Ensure you have a stable internet connection
- The tool will retry failed requests automatically
- Check firewall settings if you encounter connection issues
If you encounter any issues or have questions:
- Check the troubleshooting section above
- Run
md-translate setup
for configuration help - Create an issue on the project repository
Happy translating! 🌍✨