Skip to main content

PaperLocale

tests release PyPI license

Verified, layout-preserving academic PDF translation with pluggable model providers and domain-specific terminology packs.

中文说明

PaperLocale verified workflow

The demo below is generated from PaperLocale's own one-page, double-column PDF fixture. It contains formula text, a vector table, and an embedded image; no copyrighted paper is redistributed.

PaperLocale source, translation, and all-page QA demo

Status

PaperLocale is under active development. The first release focuses on one strict pipeline:

  1. collect translatable segments from a PDF layout engine;
  2. translate them with one explicitly selected provider;
  3. reject translations that lose formulas, style tags, numbers, units, abbreviations, URLs, DOIs, or required terminology;
  4. rebuild the PDF without changing its page geometry;
  5. render every page and produce a reviewable QA report.

The project does not promise bitwise-identical typography. Chinese text naturally changes line breaks. Its promise is narrower and testable: preserve the page structure and protected scientific content, and fail before rendering when that contract is broken.

Implemented providers and gates

  • codex-local: local-only translation through an authenticated Codex CLI session;
  • openai-compatible: BYOK access to OpenAI and compatible endpoints;
  • an auditable manual ChatGPT Web bridge that exports hash-bound prompts and imports strict JSON responses without browser login, scraping, or automation;
  • qwen-mt: BYOK access to Qwen-MT's dedicated translation endpoint, with one-segment checkpoints and domain-pack terminology intervention;
  • an extensible atmospheric-science pack with terminology and evaluation cases;
  • a resumable collect -> translate -> validate -> render -> qa -> accept workflow;
  • page geometry, image-object, vector-drawing, blank-page, placeholder, and all-page visual checks.

PaperLocale never reads or copies Codex authentication files. ChatGPT-managed Codex access is for trusted local use only and is not exposed as a public translation API.

Domain packs

The first built-in pack is atmospheric-science. A pack contains a manifest, glossary, prompt rules, and evaluation cases. New disciplines can be added without changing the translation pipeline.

python -m paperlocale domain-check atmospheric-science
python -m paperlocale validate-segments \
  --segments segments.jsonl \
  --translations translations.jsonl \
  --domain atmospheric-science

Evaluate a real Provider on every public domain case and save candidates next to their references:

paperlocale provider-eval \
  --provider codex-local \
  --model gpt-5.6-sol \
  --reasoning-effort high \
  --domain atmospheric-science \
  --output provider-eval.json

The report automatically evaluates only the hard content contract and exact reference matches. It never treats string similarity as semantic accuracy; every candidate remains marked for manual domain review.

Install

Python 3.10–3.13 and Poppler's pdftoppm are required for the complete workflow. PaperLocale 0.4.0 is published on PyPI through attested Trusted Publishing. The audited maintainer procedure and release evidence are documented in docs/PYPI_PUBLISHING.zh-CN.md. The v0.4.0 manual ChatGPT Web bridge is documented in docs/CHATGPT_WEB_MANUAL.zh-CN.md for its copy/paste workflow and usage-limit boundary.

python -m venv .venv
source .venv/bin/activate
python -m pip install "paperlocale[layout]==0.4.0"
paperlocale --version
paperlocale domain-check atmospheric-science

Quick start

Use the same resumable command to initialize the run, collect layout segments, translate, validate, rebuild, and generate all-page QA:

# Uses the authenticated Codex CLI session on this trusted local machine.
paperlocale run paper.pdf --run-dir runs/paper \
  --provider codex-local \
  --model gpt-5.6-sol \
  --reasoning-effort high \
  --domain atmospheric-science

# The first invocation stops after collection for reference review.
paperlocale confirm-references --run-dir runs/paper \
  --segment-id manually-confirmed-reference-segment-id \
  --confirmed-by "Your name"

# Rerun the original paperlocale run command after confirmation.
paperlocale run paper.pdf --run-dir runs/paper \
  --provider codex-local \
  --model gpt-5.6-sol \
  --reasoning-effort high \
  --domain atmospheric-science

# Inspect every image under runs/paper/qa/comparisons/ before acceptance.
paperlocale accept --run-dir runs/paper --reviewed-by "Your name"

If a stage fails, rerun the same paperlocale run command. The manifest resumes from the last completed stage and every accepted segment is reused, including valid rows from a batch that also produced rejected candidates. Those candidates and their contract errors are stored in rejected_translations.jsonl. The command deliberately stops at qa_generated; it never records human acceptance. Once translation is complete, a resume command does not need --provider or API credentials.

If a rejected segment is genuinely non-translatable, such as a pure formula or an author-name list, confirm it explicitly instead of adding artificial Chinese text or weakening the global CJK gate:

paperlocale confirm-passthrough --run-dir runs/paper \
  --segment-id confirmed-nontranslatable-segment-id \
  --reason "Pure formula with no translatable prose" \
  --confirmed-by "Your name"

The audited map binds the source PDF and segments.jsonl hashes. Confirmed segments must remain byte-for-byte equal to their source, never reach the Provider, and can safely resolve a rejected partial batch without repeating already accepted model calls.

Before any Provider call, PaperLocale also compares collected segments with the source PDF's exact visible page text. A segment that starts or ends inside the same ASCII word (for example Figu + re ... perio + d), or a short ASCII segment absent from visible page text, is written to segment_safety_review.jsonl and blocks translation. Inspect that local file, then confirm every listed ID with confirm-passthrough. v0.3.2 deliberately keeps these objects unchanged; full translation requires upstream adjacent- object context or merge support.

The default reference policy is preserve. PaperLocale writes every segment to reference_review.jsonl, automatically selects only long segments that match the source PDF's exact REFERENCES region, and requires explicit confirmation before any model call. Automatically matched IDs do not need to be repeated; omit --segment-id when no manual additions are needed. The confirmed map is bound to the source PDF and segments.jsonl hashes. Use --reference-policy translate-titles to translate work titles only; reference rows do not use body-domain glossary gates.

The current released BabelDOC may still re-typeset an unchanged reference paragraph. The object-level fix is proposed upstream in BabelDOC #610 and PR #611; PaperLocale does not carry a local PDF overlay workaround while that review is pending.

The schema 4 run manifest binds the domain-pack content hash, provider, model, reasoning effort, Codex CLI version, collect/render layout-engine versions, and any human-confirmed passthrough map. A Codex run therefore requires an explicit --model.

When vector objects disappear, QA records their page, bounding box, and area, and draws red boxes at the expected locations in both comparison panels. Import an independently repaired candidate through the audited path:

paperlocale apply-vector-repair --run-dir runs/paper \
  --repaired-pdf repaired-paper.pdf \
  --description "Restore page 1 link vector icons"

The command rejects candidates that alter text, page geometry, or image counts, backs up the previous PDF, appends repair_history, and requires QA and human acceptance to run again.

If visual review finds a broken caption that cannot be repaired at segment level, replace only an explicitly reviewed page rectangle:

paperlocale apply-text-repair --run-dir runs/paper \
  --page 27 \
  --rect 40 120 500 160 \
  --replacement "Figure 5 corrected caption" \
  --font-file /path/to/NotoSansCJKsc-Regular.otf \
  --font-size 9.5 \
  --description "Repair a split-token figure caption"

The command verifies that the font contains every replacement glyph, removes text only inside the rectangle while preserving page geometry, images, links, existing vectors, and outside text, and rejects overflow. It subsets the repair font before embedding it without rewriting existing PDF font programs, and records the font and subset hashes, byte reduction, before/after text, geometry, PDF hashes, and backup in repair_history. QA and human acceptance must then run again. Use a locally licensed font and do not commit it to the repository; a TTF/OTF usually produces cleaner extraction metadata than a font collection, but every result still goes through the same QA warnings and visual review.

For a reviewed fragment that must only be removed, pass an explicit empty replacement and omit the font options:

paperlocale apply-text-repair --run-dir runs/paper \
  --page 2 --rect 120 29 144 39 --replacement '' \
  --description "Remove a reviewed split-token fragment"

Removal mode embeds no font, records text-removal in repair_history, and still enforces the same rectangle, outside-text, page, image, link, vector, backup, QA, and human-acceptance gates. Whitespace-only replacements are rejected.

For a BYOK OpenAI-compatible endpoint:

export PAPERLOCALE_API_KEY="your-key"
paperlocale run paper.pdf --run-dir runs/paper \
  --provider openai-compatible \
  --base-url https://api.example.com/v1 \
  --model your-model \
  --domain atmospheric-science

Remote compatible endpoints must use HTTPS. Plain HTTP is accepted only for loopback services on localhost, 127.0.0.1, or ::1.

For Alibaba Cloud Bailian's dedicated Qwen-MT endpoint, keep the API key in an environment variable and select the explicit provider. The base URL is the API version prefix and must not include /chat/completions:

export PAPERLOCALE_API_KEY="your-DashScope-key"
paperlocale run paper.pdf --run-dir runs/paper \
  --provider qwen-mt \
  --base-url https://dashscope.aliyuncs.com/compatible-mode/v1 \
  --model qwen-mt-plus \
  --domain atmospheric-science

Qwen-MT receives only one source segment per request. PaperLocale derives its language codes, domain instruction, and glossary terms from the selected domain pack, validates every returned segment, and saves each accepted result before starting the next request. API keys are sent only in the Authorization header and are never written to the run manifest.

For explicit stage-by-stage control, the same production path remains available as init-run -> collect -> reference-review/confirm-references -> optional confirm-passthrough -> translate -> validate -> render -> qa -> accept.

See the detailed Chinese guide, ROADMAP, ARCHITECTURE, domain-pack guide, Codex for Open Source readiness, and PROVENANCE.

Citation and community

Research and teaching users can cite the software through CITATION.cff; GitHub exposes the same metadata through its “Cite this repository” control. Participation in issues, pull requests, and reviews follows the PaperLocale Code of Conduct.

Development

Unit tests do not call a model or require the layout engine:

python -m pip install -e ".[test]"
python -m unittest discover -s tests -v

After layout-engine upgrades, run the deterministic full-path smoke test:

python -m pip install -e ".[layout,test]"
python scripts/layout_smoke.py \
  --output tmp/layout-smoke-001 \
  --demo-gif tmp/layout-smoke-001.gif

The script intentionally stops before visual acceptance and prints the comparison image to inspect. The scheduled compatibility workflow repeats this real CLI check weekly against the newest pdf2zh-next release allowed by the declared dependency range.

Contributing

Start with the scoped good first issues, or read CONTRIBUTING.md. Current entry points cover an ecology domain pack, Ubuntu installation verification, and independent review of the atmospheric-science Provider evaluation.

License

GNU Affero General Public License v3.0 only. This choice is aligned with the AGPL-licensed PDF layout engines the project is designed to integrate.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

paperlocale-0.4.0.tar.gz (106.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

paperlocale-0.4.0-py3-none-any.whl (87.6 kB view details)

Uploaded Python 3

File details

Details for the file paperlocale-0.4.0.tar.gz.

File metadata

  • Download URL: paperlocale-0.4.0.tar.gz
  • Upload date:
  • Size: 106.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for paperlocale-0.4.0.tar.gz
Algorithm Hash digest
SHA256 ae31f42a6631fbdd1c37b02ab8f605adfd99fc6809f5a445e029f5e232b50021
MD5 13fb6e2e6b876253f21ee78cec503ed7
BLAKE2b-256 b674497a0325076cef73e3b3afefa17c82337891a1ec4d12423c66f4b1b1915a

See more details on using hashes here.

Provenance

The following attestation bundles were made for paperlocale-0.4.0.tar.gz:

Publisher: publish-pypi.yml on hazugi2004/paperlocale

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file paperlocale-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: paperlocale-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 87.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for paperlocale-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 17206e70844ec3e37c3d021923b3a075614af2ad2f1b4aa6d78fe62920f560d9
MD5 599d03b1d477ade1696d16be9e10e50b
BLAKE2b-256 3004304e7fe0525fea3bf7f86532cf584806b66bc15988fb6478a652e7d491f4

See more details on using hashes here.

Provenance

The following attestation bundles were made for paperlocale-0.4.0-py3-none-any.whl:

Publisher: publish-pypi.yml on hazugi2004/paperlocale

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.6.2

2 files

0.6.1

2 files

0.6.0

2 files

0.5.3

2 files

0.5.2

2 files

0.5.1

2 files

0.5.0

2 files

0.4.3

2 files

0.4.2

2 files

0.4.1

2 files

This release

0.4.0 This release

2 files

0.3.4

2 files

0.3.3

2 files

0.3.2

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page