Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Legacy Tools

Tools that informed the current translate CLI design. Both have been removed from the tree but are preserved in git history. This document captures the approaches tried, what worked, and what didn’t — so we don’t reinvent things we’ve already explored.

Evolution:

tool-alignment (v1 — purely deterministic)
    ↓  replaced: too complex, hard to calibrate thresholds
tool-onboarding (v2 — hybrid deterministic + Claude)
    ↓  replaced: block-level divergence mapping broke on structural changes
translate CLI backward/forward/status/init (current)
    → section-based analysis, whole-section re-translate

How the current CLI differs

The key insight that emerged from both tools: work at higher granularity, not block-by-block. Instead of trying to match individual code blocks or paragraphs across languages (which breaks when structure changes), the current CLI mostly works at the whole-file level — and where it does use sections (## headings), they’re matched by position, not content.

tool-alignment (v1)tool-onboarding (v2)translate CLI (current)
Analysis unitBlocks (code, math, prose)Blocks with look-aheadWhole-file (forward, backward, init) or sections (Action sync)
Matching strategyCount-based scoringSequential walk with divergence mappingPosition-based (section 1 ↔ section 1)
LLM usageOptional (bolt-on quality scoring)Hybrid (prose only)Core (all translation + analysis)
Translation approachN/A (diagnostic only)N/A (diagnostic only)Whole-file re-translate (forward, init); section-level update (Action sync of existing files)
Failure modeFalse positives from threshold miscalibrationCascading misalignment when blocks added/deletedOver-translates if section boundaries shift (rare)
ScopeOne-time diagnosticOne-time onboarding assessmentOngoing sync (forward, backward, init)

Translation granularity by mode:


tool-alignment (v1 — Deterministic Structural Analysis)

Period: Early development
Size: ~2,000 lines across 10 modules, 14 test fixtures
Approach: Purely deterministic — no LLM calls for core analysis (optional Claude quality scoring as a separate mode)

What It Did

Three analysis modes:

  1. Diagnose — Structure report comparing section/subsection/code/math block counts between source and target. Scored files on a weighted scale (sections 40%, subsections 30%, code 15%, math 15%).

  2. Triage — File-level action recommendations based on structure + code scores. Prioritized files as critical/high/medium/low/ok. Produced per-file reports with specific actions.

  3. Quality Assessment — Per-section Claude scoring with weighted rubric: accuracy (40%), fluency (25%), terminology (20%), completeness (15%). Supported glossary lookup and cost estimation per model tier.

Key Algorithms

Code Normalization Pipeline — The standout idea. To compare code blocks between source and target, it stripped content that’s expected to differ in translations:

1. Replace strings → "<<STRING>>" (handles f-strings, triple quotes)
2. Replace MyST captions → "<<CAPTION>>"
3. Replace comments → "# <<COMMENT>>" (language-aware: Python, JS, Julia, R)
4. Collapse whitespace

After normalization, blocks that matched were “normalized-match” (translation-only differences). Blocks that still differed had real code changes.

i18n-Only Pattern Detection — Recognized font family references (SimHei, SimSun, PingFang), matplotlib config (plt.rcParams['font.), Unicode handling (axes.unicode_minus), and locale setup. If all differences matched these patterns, the block was classified as “i18n-only” — acceptable translation-related changes, not real code divergence.

LCS-Based Diff — Used Longest Common Subsequence for line-by-line comparison after normalization. Showed only changed lines with 2-line context, truncated to 50 lines max.

Structure Scoring — Weighted component matching:

Score = (section match × 40) + (subsection match × 30) + (code blocks × 15) + (math blocks × 15)
→ 100 = aligned, 85-99 = likely-aligned, 55-84 = needs-review, <55 = diverged

Triage Decision Matrix — Combined structure score + code integrity score to recommend actions:

What Worked

Why It Was Replaced


tool-onboarding (v2 — Hybrid Code + Claude Analysis)

Period: After tool-alignment
Size: ~2,300 lines across 10 modules, 84 tests
Approach: Deterministic code analysis + Claude AI for prose — each doing what it’s best at

What It Did

One-time alignment assessment to determine if an existing translation repository was ready for action-translation automated sync.

Pipeline: File Discovery → Content Extraction → Hybrid Analysis → Decision Engine → Report Generation

For each paired source/target file:

Output: Per-file markdown reports with action checkboxes for human review.

Key Algorithms

Block-Level Divergence Mapping — The main innovation. A sequential algorithm that walked through source and target code blocks simultaneously (O(n) best case, O(n²) worst case due to look-ahead scanning):

while (srcIdx < source.length || tgtIdx < target.length):
  if exact or normalized match → ALIGNED
  if only source left → MISSING
  if only target left → INSERTED
  else:
    look ahead in target to find source block (shifted)
    look ahead in source to find target block
    if found ahead → mark intermediate as INSERTED/MISSING
    if not found → mark as MODIFIED

This handled code block reordering and renames well. But when blocks were added or deleted in either repo, the look-ahead couldn’t reliably recover alignment — subsequent blocks would cascade into false INSERTED/MISSING/MODIFIED classifications.

Hybrid Human-AI Workflow — Tool generated analysis + recommendations with checkboxes. Humans made final decisions. The tool never auto-synced anything.

Date-Aware Decision Logic — Used git commit timestamps to determine direction:

Document-Order Organization — Early versions grouped all code findings first, then all prose (confusing). Fixed by tracking startLine for every decision item and sorting by document position. Lesson learned: always present findings in document reading order.

What Worked

Why It Was Replaced

The fundamental issue: Block-level divergence mapping assumes relatively stable structure between source and target. When code blocks are added or deleted in either repo, the look-ahead algorithm can’t recover alignment — it marks too many subsequent blocks as modified/inserted, producing cascading false positives.

Real-world failure: lecture-python-intro had blocks added to source after initial translation. The tool couldn’t match them, producing massive false positives across many files (tracked as issue #677).

The solution: The current CLI uses section-based analysis instead of block-level matching. Whole sections are re-translated in one LLM call, which naturally handles added/removed/reordered blocks within a section. This was a fundamental shift from fine-grained block matching to coarse-grained section matching.


Ideas for Future Work

Curated list of approaches from both tools that could enhance the current CLI:

High Value — Consider for future CLI enhancements

IdeaSourceHow It Could Be Used
Code normalization pipelinetool-alignmentEnhance status command to show code-level detail (not just section counts). Strip strings/comments, then compare to distinguish real code changes from translation-only differences.
i18n-only pattern detectionBothFilter false positives in backward analysis. If differences are all font config / locale setup, flag as i18n-only rather than suggesting backport.
Quality scoring rubrictool-alignmentFormalize review mode scoring with weighted dimensions (accuracy, fluency, terminology, completeness) rather than single pass/fail.
Triage priority bucketstool-alignmentEnhance status --json output with criticality levels (critical/high/medium/low) to help users prioritize large backlogs.

Already Adopted

IdeaSourceWhere It Landed
Position-based section matchingBothCore to heading-map design and section pairing
Hybrid human-AI workflowtool-onboardingreview command (tool suggests, human decides)
Cost estimationBothReplaced by --dry-run pattern (lists what would be done without API calls)
Date-aware direction logictool-onboardingstatus command (OUTDATED based on commit dates)
Document-order presentationtool-onboardingAll report output sorted by position

Low Priority — Reference Only

IdeaSourceNotes
LCS-based diff algorithmtool-alignmentCurrent section-level approach makes line-level diffs unnecessary, but could be useful if we ever need finer-grained comparison within a section.
Block divergence mappingtool-onboardingProven to break on structural changes. Only worth revisiting if constrained to within a single section (where structure is more stable).
Multi-language comment strippingtool-alignmentHandled Python, JavaScript, Julia, R comments. Would be useful if code normalization is adopted.