Skip to content

Enable local Codex translation without API keys#1124

Open
XiaKaiYang wants to merge 1 commit into
PDFMathTranslate:mainfrom
XiaKaiYang:local-cli-translation-stability
Open

Enable local Codex translation without API keys#1124
XiaKaiYang wants to merge 1 commit into
PDFMathTranslate:mainfrom
XiaKaiYang:local-cli-translation-stability

Conversation

@XiaKaiYang
Copy link
Copy Markdown

@XiaKaiYang XiaKaiYang commented Apr 22, 2026

What changed

This PR adds a local Codex-based translation path for PDFMathTranslate, so users can translate PDFs through the local Codex CLI without wiring up any external translation API key.

Key changes:

  • add a built-in codex translator that uses the local Codex CLI
  • keep the existing CLI and GUI service entry points intact
  • add capability probing plus fast/compat command selection for the local CLI path
  • add bounded batch translation, long-text splitting, retry, and fallback behavior so full PDFs can complete reliably
  • force effective concurrency to 1 for the local CLI path instead of following the generic thread fanout
  • add whitespace normalization for Chinese output so unnecessary spaces between Chinese words and punctuation are removed

Why this changed

The main goal is to make Codex usable as a local translation backend out of the box.

Before this change, users who wanted a Codex-style workflow still had to rely on external translation APIs or on a fragile short-text-only prototype. This PR makes the local CLI path practical for end-to-end PDF translation while keeping the integration surface simple.

User impact

Users can now translate with:

  • local Codex CLI
  • existing Codex login state
  • no user-provided translation API key

Notable behavior:

  • pdf2zh file.pdf -s codex is supported
  • GUI keeps exposing Codex
  • the local CLI translator batches text internally for better full-PDF throughput
  • effective concurrency is fixed to 1 for this translator path
  • Chinese output spacing is cleaned up before the translated PDF is written

Validation

Automated:

  • PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 /opt/anaconda3/bin/python3.12 -m pytest test/test_translator.py test/test_converter.py test/test_kernel.py -q
  • /opt/anaconda3/bin/python3.12 -m compileall pdf2zh test

Live checks:

  • single-string smoke translation
  • multi-item batch smoke translation
  • long-text batch smoke translation
  • full target PDF smoke run producing mono and dual outputs for MPC 跟踪控制.pdf

@XiaKaiYang XiaKaiYang marked this pull request as ready for review April 22, 2026 17:42
@XiaKaiYang XiaKaiYang changed the title Improve local CLI translation stability and spacing handling Enable local Codex translation without API keys Apr 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant