An intelligent Python tool that automatically resolves merge conflicts between English and French versions of documentation by using OpenAI's GPT-4 for translation analysis and generation.
- 🔍 Automatic Conflict Detection: Scans your entire codebase for merge conflicts
- 🤖 AI-Powered Translation: Uses OpenAI GPT-4 to compare and translate content
- 🇫🇷 French-First Approach: Keeps existing French translations when they're close enough
- ✅ Smart Resolution: Only translates when necessary, preserving code and technical terms
- 🚨 Safety First: Flags problematic translations for manual review instead of making mistakes
- 📝 Comprehensive Logging: Shows detailed progress and results for every conflict
- Detection: Scans for merge conflict markers (
<<<<<<<,=======,>>>>>>>) - Analysis: For each conflict:
- Compares the English (incoming) and French (current) versions
- Asks GPT-4 if the French version is an acceptable translation
- If close enough → keeps the French version
- If different → translates the English to French
- Validation: Ensures translations are in French and don't contain obvious errors
- Resolution: Replaces conflict blocks with the appropriate French text
- Safety: Leaves conflicts unresolved if translation fails or seems incorrect
# Navigate to the project directory
cd translation-manager
# Create a virtual environment
python3 -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# Install dependencies
pip install -r requirements.txtThe script looks for an .env.local file with your OpenAI API key. By default, it searches in ../fr.react.dev/.env.local, but you can specify a custom path.
Your .env.local should contain:
OPENAI_API_KEY='your-api-key-here'# Activate virtual environment
source .venv/bin/activate
# Run the script (will scan ../fr.react.dev by default)
python3 src/main.py# Dry run (analyze but don't modify files)
python3 src/main.py --dry-run
# Specify a custom codebase path
python3 src/main.py --codebase-path /path/to/your/repo
# Specify a custom .env.local location
python3 src/main.py --env-file /path/to/.env.local
# Process only the first N files (useful for testing)
python3 src/main.py --max-files 5
# Combine options
python3 src/main.py --dry-run --max-files 10Scanning codebase: /Users/you/fr.react.dev
Found 115 file(s) with merge conflicts.
Analyzing conflicts with OpenAI...
============================================================
[1/115] src/content/learn/keeping-components-pure.md
Conflict 1/3: ✓ Keeping French (close enough)
Conflict 2/3: 🔄 Translating... ✓ Done
Conflict 3/3: ⚠️ Failed - keeping for manual review
============================================================
SUMMARY
============================================================
Total files processed: 115
Total conflicts found: 234
✓ Resolved automatically: 198
⚠️ Need manual review: 36
Files modified: 98
The script is designed to be conservative and safe:
- Never outputs English: If translation fails, it keeps the conflict for manual review
- Never translates code: Only natural language text is translated; code stays in English
- Preserves formatting: Markdown, code blocks, and structure are maintained
- Validates output: Checks that translations appear to be in French
- Dry-run mode: Test without modifying any files
translation-manager/
├── src/
│ ├── main.py # Entry point and orchestration
│ ├── conflict_detector.py # Finds merge conflicts in files
│ ├── translation_checker.py # Wraps OpenAI translation checks
│ ├── openai_client.py # OpenAI API integration
│ ├── file_processor.py # Resolves conflicts in files
│ └── utils/
│ ├── file_utils.py # File operations
│ └── diff_utils.py # Diff utilities
├── config/
│ └── rules.py # Configuration and rules
├── tests/
│ ├── test_conflict_detector.py
│ ├── test_translation_checker.py
│ └── test_openai_client.py
├── requirements.txt # Python dependencies
└── README.md # This file
- Python 3.8+
- OpenAI API key with GPT-4 access
- Dependencies:
- openai==0.28.1
- python-dotenv==0.17.1
- requests==2.25.1
Make sure you have a .env.local file with your API key, or specify the path with --env-file.
The script detected that GPT-4 didn't properly translate to French. The conflict will be left for manual review.
If you hit rate limits, use --max-files to process fewer files at once.
This script uses OpenAI's GPT-4 API:
- Each conflict requires 2 API calls (comparison + translation if needed)
- With 115 files and ~200 conflicts, expect ~400 API calls
- Estimated cost: $2-5 per full run
Use --dry-run and --max-files to control costs while testing.
MIT License