Dev.to Blog Translation Tool
A command-line tool that automatically translates your Dev.to draft articles from any language to English using Google's Gemini AI.
Features
- ๐ Automatically fetches all draft articles from your Dev.to account (supports pagination for 300+ articles)
- ๐ Translates article titles and content to English using Gemini 2.0 Flash Lite
- ๐ง Smart language detection - automatically skips articles with English titles
- ๐ Preserves markdown formatting, code blocks, and technical terms
- ๐งน Automatically removes Jekyll/Hugo frontmatter metadata before translation
- ๐ Automatically publishes translated articles to Dev.to
- ๐ Secure API key management using environment variables
- โก Fast and efficient translation processing with rate limiting
- ๐ Detailed progress reporting and statistics
Prerequisites
- Go 1.21 or higher
- Dev.to account with API access
- Google Gemini API key
Installation
- Clone the repository:
git clone https://github.com/al03034132/devto-blog-translation-tool.git
cd devto-blog-translation-tool- Install dependencies:
go mod download- Set up environment variables:
cp .env.example .env- Edit
.envand add your API keys:
DEVTO_API_KEY=your_devto_api_key_here
GEMINI_API_KEY=your_gemini_api_key_hereGetting API Keys
Dev.to API Key
- Go to Dev.to Settings > Extensions
- Generate a new API key
- Copy the key to your
.envfile
Google Gemini API Key
- Visit Google AI Studio
- Create a new API key
- Copy the key to your
.envfile
Usage
Run the translation tool:
go run cmd/translator/main.goThe tool will:
- Display a confirmation prompt explaining what will happen
- Load your API keys from the
.envfile - Fetch all draft articles from your Dev.to account (with pagination support)
- For each draft article:
- Display the article ID and original title
- Check if the title is already in English (skip if yes)
- Translate title and content to English using Gemini AI
- UPDATE the existing draft article with translated content
- Publish the updated article
- Display a summary with statistics:
- Number of articles translated and published
- Number of articles skipped (already in English)
- Number of failed translations
โ ๏ธ IMPORTANT NOTES
- Updates Existing Drafts: This tool UPDATES your existing draft articles, it does NOT create new articles
- Uses PUT Request: The tool uses
PUT /articles/:idto update the same article with translated content - Publishes Automatically: After translation, the article will be automatically published
- Confirmation Required: The tool will ask for confirmation before starting
- Shows Article IDs: Each processed article will display its ID so you can verify it's updating the correct article
- Frontmatter Removal: Automatically removes Jekyll/Hugo frontmatter (metadata between
---) before translation to avoid translating metadata
Example Output
โ ๏ธ WARNING โ ๏ธ
=====================================
This tool will:
1. Fetch ALL your draft articles from Dev.to
2. Translate non-English articles to English
3. UPDATE the existing draft articles with translations
4. PUBLISH the updated articles
Note: This will UPDATE your existing drafts,
NOT create new articles.
=====================================
Do you want to continue? (yes/no): yes
โ
Starting translation and publishing process...
๐ Fetching draft articles from Dev.to...
Fetched page 1 (30 articles, total: 30)
Fetched page 2 (30 articles, total: 60)
...
โ
Found 300 draft article(s)
[1/300] Article ID: 2457408
Original Title: ไฝฟ็จ Gemini 3.0 Pro Image API ๆ้ PDF ๆๅญๅชๅๅทฅๅ
ท
Translating title... โ
Translated Title: Building a PDF Text Optimization Tool with Gemini 3.0 Pro Image API
Translating content... (removing frontmatter) โ
Updating article ID 2457408 and publishing... โ
Published!
[2/300] Article ID: 2457409
Original Title: Introduction to Machine Learning
โญ๏ธ Skipping: Title is already in English
...
========================================
SUMMARY
========================================
โ
Translated & Published: 250
โญ๏ธ Skipped (English): 45
โ Failed: 5
๐ Total processed: 300
========================================
๐ Process completed!
Project Structure
devto-blog-translation-tool/
โโโ cmd/
โ โโโ translator/
โ โโโ main.go # Main application entry point
โโโ internal/
โ โโโ devto/
โ โ โโโ client.go # Dev.to API client (with pagination & publish)
โ โโโ gemini/
โ โ โโโ client.go # Gemini API client for translation
โ โโโ translator/
โ โ โโโ translator.go # Translation service logic
โ โโโ utils/
โ โโโ language.go # Language detection utilities
โ โโโ markdown.go # Markdown/frontmatter processing
โโโ .env # Your API keys (DO NOT COMMIT!)
โโโ .env.example # Template for environment variables
โโโ .gitignore # Git ignore file
โโโ go.mod # Go module file
โโโ test_security.sh # Security verification script
โโโ README.md # This file
Frontmatter Handling
The tool automatically detects and removes Jekyll/Hugo frontmatter before translation. This prevents metadata from being translated.
Example:
Original content with frontmatter:
---
title: [VS Code][Colab] Google Officially Releases Colab VS Code Plugin
published: false
date: 2025-11-14 00:00:00 UTC
tags:
canonical_url: https://www.evanlin.com/colab-vscode-plugin/
---
# Introduction
This is the actual article content...The tool will:
- Detect the frontmatter (content between
---) - Remove it before translation
- Only translate the actual article content:
# Introduction
This is the actual article content...Supported formats:
- Standard frontmatter:
--- ... --- - Code block style:
``` ... ```
Security
๐ IMPORTANT: This project uses environment variables to store sensitive API keys.
- NEVER commit your
.envfile to Git - The
.envfile is already listed in.gitignore - Use
.env.exampleas a template for other developers - API keys are never logged or displayed in the output
Building
To build a standalone executable:
go build -o translator cmd/translator/main.goThen run:
./translatorTroubleshooting
"DEVTO_API_KEY environment variable is not set"
Make sure you have created a .env file in the project root with your API keys.
"failed to fetch draft articles: API request failed with status 401"
Your Dev.to API key may be invalid or expired. Generate a new key from Dev.to settings.
"failed to generate translation"
Check that your Gemini API key is valid and you haven't exceeded the rate limits.
Dependencies
- godotenv - Environment variable management
- generative-ai-go - Google Gemini AI SDK
License
MIT License
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Author
Created for translating Dev.to blog posts efficiently.