A GitHub Action that automatically synchronizes translations across repositories using Claude Sonnet 4.5.
Version: v0.5.1 | Status: Testing & Development โ
This action monitors a source repository for merged pull requests and automatically translates changed MyST Markdown files to a target repository, creating pull requests for review.
Key Features:
- ๐ Language-Extensible: Easy configuration for multiple target languages
- ๐บ๏ธ Heading-Map System: Robust cross-language section matching
- ๐ Intelligent Diff Translation: Only translates changed sections
- โ๏ธ MyST Markdown Support: Preserves code blocks, math equations, and directives
- ๐ Glossary Support: Built-in glossaries for consistent terminology
- โ GPT5 Validated: 100% pass rate on 21 comprehensive test scenarios
- ๐ Language Configuration (v0.5.1): Extensible system for language-specific rules (punctuation, typography)
- ๐บ๏ธ Heading-Map System: Robust cross-language section matching that survives reordering
- ๐ Intelligent Diff Translation: Only translates changed sections, preserving existing translations
- ๐ Full File Translation: Handles new files with complete translation
- โ๏ธ MyST Markdown Support: Preserves code blocks, math equations, and MyST directives
- ๐ Glossary Support: Built-in glossaries for consistent technical terminology (355 terms for zh-cn)
- ๐ Automatic TOC Updates: Updates
_toc.ymlwhen new files are added - ๐ PR-Based Workflow: All translations go through pull request review
- โป๏ธ Recursive Subsections: Full support for nested headings at any depth (##-######)
- โ Extensively Tested: 147 unit tests passing, 24 GitHub integration test scenarios
Add this workflow to your source repository (e.g., .github/workflows/sync-translations.yml):
name: Sync Translations
on:
pull_request:
types: [closed]
paths:
- 'lectures/**/*.md'
jobs:
sync-to-chinese:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
steps:
- uses: quantecon/action-translation-sync@v1
with:
target-repo: 'quantecon/lecture-python.zh-cn'
target-language: 'zh-cn'
docs-folder: 'lectures/'
source-language: 'en'
glossary-path: '.github/translation-glossary.json'
anthropic-api-key: ${{ secrets.ANTHROPIC_API_KEY }}
github-token: ${{ secrets.GITHUB_TOKEN }}
# Optional: Request reviewers for translation PRs
pr-reviewers: 'username1,username2'
pr-team-reviewers: 'translation-team'
pr-labels: 'translation,automated,needs-review'| Input | Required | Default | Description |
|---|---|---|---|
target-repo |
Yes | - | Target repository (format: owner/repo) |
target-language |
Yes | - | Target language code (e.g., zh-cn, ja, es) |
docs-folder |
No | lectures/ |
Documentation folder to monitor |
source-language |
No | en |
Source language code |
glossary-path |
No | - | Path to custom glossary (built-in glossary used by default) |
toc-file |
No | _toc.yml |
Table of contents file name |
anthropic-api-key |
Yes | - | Anthropic API key for Claude |
claude-model |
No | claude-sonnet-4-5-20250929 |
Claude model to use for translation |
github-token |
Yes | - | GitHub token for API access |
pr-labels |
No | translation-sync,automated |
Comma-separated PR labels |
pr-reviewers |
No | - | Comma-separated GitHub usernames (e.g., user1,user2) |
pr-team-reviewers |
No | - | Comma-separated GitHub team slugs (e.g., team1,team2) |
| Output | Description |
|---|---|
pr-url |
URL of the created pull request |
files-synced |
Number of files synchronized |
The action includes built-in glossaries for consistent translation across all QuantEcon lectures.
Location: glossary/{language}.json
Current glossaries:
glossary/zh-cn.json- Simplified Chinese (355 terms) โglossary/ja.json- Japanese (planned)glossary/es.json- Spanish (planned)
The built-in glossary is automatically used - no configuration needed!
See glossary/README.md for details on the glossary structure and how to contribute.
If you need to add project-specific terms, you can provide a custom glossary:
with:
glossary-path: '.github/custom-glossary.json'Glossary format:
{
"version": "1.0",
"terms": [
{
"en": "household",
"zh-cn": "ๅฎถๅบญ",
"context": "economics"
},
{
"en": "equilibrium",
"zh-cn": "ๅ่กก"
}
],
"style_guide": {
"preserve_code_blocks": true,
"preserve_math": true,
"preserve_citations": true,
"preserve_myst_directives": true
}
}- Trigger: Activates when a PR is merged in the source repository
- Detection: Identifies changed MyST Markdown files
- Analysis: For each file:
- If file exists in target: Detects specific changes (diff mode)
- If file is new: Translates entire file (full mode)
- Section Matching: Uses heading-map system for robust cross-language matching
- Translation: Uses Claude Sonnet 4.5 with glossary support
- Heading-Map Update: Automatically maintains EnglishโTranslation mappings
- Validation: Verifies MyST syntax of translated content
- PR Creation: Opens a pull request in the target repository
- Review: Team reviews and merges the translation
The action uses a heading-map system to reliably match sections across language versions:
---
title: Dynamic Programming
heading-map:
Introduction: ็ฎไป
Economic Model: ็ปๆตๆจกๅ
Python Setup: Python ่ฎพ็ฝฎ
---Benefits:
- ๐ฏ Robust matching: Finds sections even if reordered or restructured
- ๐ Self-maintaining: Automatically populated and updated
- ๐๏ธ Transparent: Visible in document frontmatter
- ๐ Human-readable: Easy to inspect and manually correct if needed
See docs/HEADING-MAPS.md for detailed guide.
For comprehensive documentation, see the docs/ directory:
- Getting Started - Quick setup and development guide
- Heading Maps Guide - Robust section matching system
- Project Design - Architecture and design decisions
- Architecture - System diagrams and data flow
- Implementation - What's been built and how it works
- Status Report - Current project status and metrics
- TODO - Development roadmap and tasks
- Documentation Index - Complete documentation navigation
This project includes two standalone tools for different stages of the translation workflow:
Purpose: One-time bulk translation for initial repository setup
๐ฆ tool-bulk-translator/ - Standalone CLI tool
Features:
- Translates entire lecture series in one operation
- One-lecture-at-a-time approach for optimal quality and context
- Preserves complete Jupyter Book structure
- Auto-generates heading-maps for all sections
- Dry-run mode to preview before translating (no API costs)
Use case: Creating a new lecture-python.zh-cn from existing lecture-python
After bulk translation, use the main action for incremental updates.
Purpose: Testing and validation of the translation sync action
๐งช tool-test-action-on-github/ - Automated testing framework
Features:
- 24 comprehensive test scenarios
- Real GitHub PR workflow testing
- Dry-run mode for validation without API costs
- GPT5 evaluation reports
Test coverage:
- Basic changes (intro, title, content, reordering)
- Structural changes (add/delete sections, subsections)
- Scientific content (code cells, math equations)
- Document lifecycle (create, delete, rename, multi-file)
- Edge cases (preamble-only, deep nesting, special chars, empty sections)
Use case: Validating changes to the action before deployment
- Node.js 20+
- npm or yarn
# Install dependencies
npm install
# Build the action
npm run build
# Run tests
npm test
# Lint code
npm run lint
# Format code
npm run format.
โโโ src/ # Main action source code
โ โโโ index.ts # GitHub Actions entry point
โ โโโ parser.ts # MyST Markdown parser (section-based)
โ โโโ diff-detector.ts # Change detection (ADD/MODIFY/DELETE)
โ โโโ translator.ts # Claude API integration
โ โโโ file-processor.ts # Translation orchestration
โ โโโ heading-map.ts # Heading-map system
โ โโโ language-config.ts # Language-specific rules (v0.5.1)
โ โโโ types.ts # TypeScript type definitions
โ โโโ inputs.ts # GitHub Actions input handling
โโโ docs/ # Comprehensive documentation
โโโ glossary/ # Built-in translation glossaries
โ โโโ zh-cn.json # Simplified Chinese (355 terms)
โ โโโ README.md # Glossary format and contribution guide
โโโ tool-bulk-translator/ # Standalone CLI for bulk translation
โ โโโ src/bulk-translate.ts # Main CLI implementation
โ โโโ examples/ # Usage examples
โ โโโ README.md # Tool documentation
โโโ tool-test-action-on-github/ # GitHub integration testing
โ โโโ test-action-on-github.sh # Test script (24 scenarios)
โ โโโ test-action-on-github-data/ # Test fixtures
โ โโโ reports/ # GPT5 evaluation reports
โโโ examples/ # Example workflow configurations
โโโ action.yml # GitHub Action metadata
โโโ package.json # Dependencies and scripts
MIT
Contributions are welcome! Please open an issue or submit a pull request.
For development guidelines, see:
- Copilot Instructions - Project conventions and guidelines
- Documentation Index - Complete documentation navigation
- Quick Start Guide - Developer setup
We would like to thank the following contributors for their valuable reviews and contributions to this project: