Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Markdown Translator

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.
A powerful command-line tool that uses Claude AI to translate markdown and MDX files from English to any specified language while preserving formatting and structure.

## Usage at StarRocks

Expand All @@ -20,7 +20,7 @@ This code and most of the README are from the team at [PlayCanvas](https://githu
-o, --output <file> Output file path (for single file translation)
-d, --output-dir <dir> Output directory (for batch translation or single
file)
-k, --key <apikey> Google Gemini API key (or set GEMINI_API_KEY env var)
-k, --key <apikey> Anthropic API key (or set ANTHROPIC_API_KEY env var)
--flat Use flat structure in output directory (default:
preserve structure)
--suffix <suffix> Custom suffix for output files (default: language
Expand All @@ -33,7 +33,7 @@ This code and most of the README are from the team at [PlayCanvas](https://githu

The translator now uses the AST pipeline by default.

When `--trace` is enabled, the tool logs one JSON trace record per ID and includes the full `sourceText` and `translatedText` values. The only masking applied is replacing any accidental `GEMINI_API_KEY` occurrences with `***`.
When `--trace` is enabled, the tool logs one JSON trace record per ID and includes the full `sourceText` and `translatedText` values. The only masking applied is replacing any accidental `ANTHROPIC_API_KEY` occurrences with `***`.

### Interpreting AST parse failures

Expand All @@ -53,10 +53,10 @@ How to read the outcome:
## Quick Start

1. cd into the root of this repo
2. Get a Gemini API Key
3. Export your Gemini API Key like so:
2. Get an Anthropic API Key
3. Export your Anthropic API Key like so:
```sh
export GEMINI_API_KEY="<your key here>"
export ANTHROPIC_API_KEY="<your key here>"
```
4. Install the prerequisites:
```sh
Expand All @@ -74,8 +74,8 @@ How to read the outcome:

## Example use on your workstation with the StarRocks repo
```sh
# Export your Gemini API key
export GEMINI_API_KEY="AIxxxxxxxxxxxxxxxx"
# Export your Anthropic API key
export ANTHROPIC_API_KEY="sk-ant-xxxxxxxxxxxxxxxx"

# in the markdown-translator repo directory install the translator globally on your system:
npm install
Expand Down Expand Up @@ -108,14 +108,14 @@ How to read the outcome:
- 🏗️ **Structure preservation** - Maintain directory structure or flatten output as needed
- 📊 **Progress tracking** - Real-time progress indication with spinners for single files and batches
- 🎨 **Beautiful CLI** - Colorful, user-friendly command-line interface
- ⚡ **Fast processing** - Optimized for speed with high-performance Gemini model
- ⚡ **Fast processing** - Optimized for speed with high-performance Claude model

## Installation

### Prerequisites

- Node.js 16.0.0 or higher
- Google Gemini API key ([Get one here](https://aistudio.google.com/app/apikey))
- Anthropic API key ([Get one here](https://console.anthropic.com/))

> **Note**: This tool uses ES modules (ESM) and requires Node.js 16+ for full compatibility.

Expand All @@ -139,9 +139,9 @@ node bin/cli.js

## Setup

### 1. Get Google Gemini API Key
### 1. Get Anthropic API Key

1. Visit [Google AI Studio](https://aistudio.google.com/app/apikey)
1. Visit [Anthropic Console](https://console.anthropic.com/)
2. Create a new API key
3. Copy the generated key

Expand All @@ -150,7 +150,7 @@ node bin/cli.js
**Option A: Environment Variable (Recommended)**

```bash
export GEMINI_API_KEY="your-api-key-here"
export ANTHROPIC_API_KEY="your-api-key-here"
```

**Option B: Command Line Argument**
Expand Down Expand Up @@ -208,7 +208,7 @@ Options:
-l, --language <lang> Target language (required)
-o, --output <file> Output file path (for single file translation)
-d, --output-dir <dir> Output directory (for batch translation or single file)
-k, --key <apikey> Google Gemini API key (optional)
-k, --key <apikey> Anthropic API key (optional)
--flat Use flat structure in output directory (default: preserve structure)
--suffix <suffix> Custom suffix for output files (default: language name)
--log-chunk-metadata Log API metadata for each chunk
Expand Down Expand Up @@ -377,7 +377,7 @@ The tool provides detailed progress feedback for both single file and batch proc
```
╔═══════════════════════════════════════╗
║ Markdown Translator ║
║ Powered by Google Gemini AI
Powered by Claude AI
╚═══════════════════════════════════════╝

📋 Translation Details:
Expand All @@ -400,7 +400,7 @@ The tool provides detailed progress feedback for both single file and batch proc
```
╔═══════════════════════════════════════╗
║ Markdown Translator ║
║ Powered by Google Gemini AI
Powered by Claude AI
╚═══════════════════════════════════════╝

📋 Batch Translation Details:
Expand Down Expand Up @@ -454,7 +454,7 @@ This project uses **ES modules (ESM)** for modern JavaScript development:

### Key Dependencies

- `@google/generative-ai` - Google Gemini AI SDK
- `@anthropic-ai/sdk` - Anthropic Claude AI SDK
- `commander` - Command-line interface framework
- `chalk` - Terminal styling
- `ora` - Progress spinners
Expand All @@ -477,8 +477,8 @@ This project is licensed under the MIT License - see the LICENSE file for detail
### API Key Issues

- 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
- Check that you have sufficient quota in your Anthropic account
- Verify the API key is active in the Anthropic Console

### Large File Processing

Expand Down
28 changes: 13 additions & 15 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ const program = new Command();
const banner = `
╔═══════════════════════════════════════╗
║ Markdown Translator ║
║ Powered by Google Gemini AI
Powered by Claude AI
╚═══════════════════════════════════════╝
`;

program
.name('md-translate')
.description('Translate markdown files using Google Gemini AI')
.description('Translate markdown files using Claude AI')
.version('1.0.0');

program
Expand All @@ -33,7 +33,7 @@ program
.option('-s, --source <lang>', 'Source language (default: English)')
.option('-o, --output <file>', 'Output file path (for single file translation)')
.option('-d, --output-dir <dir>', 'Output directory (for batch translation or single file)')
.option('-k, --key <apikey>', 'Google Gemini API key (or set GEMINI_API_KEY env var)')
.option('-k, --key <apikey>', 'Anthropic API key (or set ANTHROPIC_API_KEY env var)')
.option('--flat', 'Use flat structure in output directory (default: preserve structure)')
.option('--suffix <suffix>', 'Custom suffix for output files (default: language name)')
.option('--log-chunk-metadata', 'Log API metadata for each chunk')
Expand All @@ -43,11 +43,10 @@ program

try {
// Get API key from options or environment
const apiKey = options.key || process.env.GEMINI_API_KEY;
const apiKey = options.key || process.env.ANTHROPIC_API_KEY;
if (!apiKey) {
console.error(chalk.red('❌ Error: Google Gemini API key is required.'));
console.log(chalk.yellow('Set GEMINI_API_KEY environment variable or use --key option'));
console.log(chalk.blue('Get your API key from: https://aistudio.google.com/app/apikey'));
console.error(chalk.red('❌ Error: Anthropic API key is required.'));
console.log(chalk.yellow('Set ANTHROPIC_API_KEY environment variable or use --key option'));
process.exit(1);
}

Expand Down Expand Up @@ -223,9 +222,8 @@ program

} catch (error) {
console.error(chalk.red(`\n❌ Error: ${error.message}`));
if (error.message.includes('API_KEY_INVALID')) {
console.log(chalk.yellow('Please check your Google Gemini API key'));
console.log(chalk.blue('Get your API key from: https://aistudio.google.com/app/apikey'));
if (error.message.includes('API_KEY_INVALID') || error.message.includes('authentication')) {
console.log(chalk.yellow('Please check your Anthropic API key'));
}
process.exit(1);
}
Expand Down Expand Up @@ -254,22 +252,22 @@ program
console.log(row);
}

console.log(chalk.yellow('\n💡 Tip: You can also use any other language name that Gemini supports'));
console.log(chalk.yellow('\n💡 Tip: You can also use any other language name that Claude supports'));
});

program
.command('setup')
.description('Setup guide for Google Gemini API key')
.description('Setup guide for Anthropic API key')
.action(() => {
console.log(chalk.cyan(banner));
console.log(chalk.blue('🔧 Setup Guide:'));
console.log('');
console.log(chalk.yellow('1. Get your Google Gemini API key:'));
console.log(chalk.gray(' Visit: https://aistudio.google.com/app/apikey'));
console.log(chalk.yellow('1. Get your Anthropic API key:'));
console.log(chalk.gray(' Visit: https://console.anthropic.com/'));
console.log('');
console.log(chalk.yellow('2. Set your API key (choose one):'));
console.log(chalk.gray(' Option A - Environment variable:'));
console.log(chalk.white(' export GEMINI_API_KEY="your-api-key-here"'));
console.log(chalk.white(' export ANTHROPIC_API_KEY="your-api-key-here"'));
console.log('');
console.log(chalk.gray(' Option B - Command line argument:'));
console.log(chalk.white(' md-translate translate -i file.md -l Spanish --key your-api-key-here'));
Expand Down
81 changes: 72 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "markdown-translator",
"version": "1.0.0",
"description": "A command line tool to translate markdown and MDX files using Google Gemini AI",
"description": "A command line tool to translate markdown and MDX files using Claude AI",
"type": "module",
"main": "index.js",
"bin": {
Expand All @@ -19,15 +19,16 @@
"markdown",
"docusaurus",
"translation",
"gemini",
"claude",
"anthropic",
"ai",
"cli"
],
"author": "Your Name",
"license": "MIT",
"dependencies": {
"@google/generative-ai": "^0.24.1",
"@playcanvas/eslint-config": "2.1.0",
"@anthropic-ai/sdk": "^0.95.2",
"@playcanvas/eslint-config": "2.1.0",
"chalk": "^5.4.1",
"commander": "^14.0.0",
"eslint": "^9.31.0",
Expand Down
Loading