aien-translate (translation server for translate.js, backed by your own model)
aien-translateis a Rust HTTP server that answers the translate.js translation protocol (/translate.jsonand friends) by sending text to an OpenAI-style chat model server, normally AIEN's own inference runtime. Every translation is checked by a guard before a visitor sees it and saved in a SQLite cache. Thescripts/folder holds Python tools that use a running server to translate a README, a built static website, or a LaTeX paper. Shared rules: read https://www.aienos.com/agents/RULES.md first. This file adds what is specific to this repository; where the two differ, this file wins here.
Scope
- Applies to the whole repository.
src/: the server.main.rsparses flags;lib.rsholds the routes and request handling;engine.rstalks to the model server;guard.rschecks translations;cache.rsis the SQLite cache;langs.rsis the language list.tests/protocol.rs: end-to-end tests against a fake model server.tests/fixtures/holds recorded bad model replies.scripts/translate_readme.py,scripts/translate_site.py,scripts/translate_latex.py: clients of a running server.demo/: a test page that loads the real translate.js, plusdemo/check.py.demo/translate.jsis downloaded, not committed (it is in.gitignore).docs/i18n/README.*.mdare machine translations generated byscripts/translate_readme.py.README.md(English) is the original. Do not hand-edit the translations; regenerate them.- translate.js itself is not in this repository. AIEN keeps a preserved copy at https://github.com/aien-dev/translate; upstream is https://github.com/xnx3/translate.
Installation
git clone https://github.com/aien-dev/aien-translate.git
cd aien-translate
cargo build --release
Needs a stable Rust toolchain. SQLite is bundled through rusqlite, so no system library is needed. The binary is target/release/aien-translate.
Running the server for real needs a model server that offers GET /v1/models and POST /v1/chat/completions (AIEN's aien-serve-http or any OpenAI-style chat server). The tests do not need one.
Configuration
All configuration is by flag; there is no config file and no environment variable besides HOME (used for the default cache path).
--listen loopback address only
--engine base URL of the model server
--cache SQLite file for saved translations
--keep-file names never translated, one per line (default: built-in list)
--auth-token-file local proxy bearer secret (required for public-site proxying)
./target/release/aien-translate --help prints the defaults. The listener refuses non-loopback addresses. Public browser traffic must use a same-origin authenticated and per-visitor-rate-limited reverse proxy; the browser never receives the backend token. See README.md for the deployment contract.
Usage
# Unit tests and end-to-end tests against a fake model (no GPU, no network)
cargo test
# Flag summary and defaults
./target/release/aien-translate --help
# Run the server (needs a reachable model server)
./target/release/aien-translate --listen <addr:port> --engine <model-server-url>
# Check a running server
curl http://<addr:port>/health
curl -X POST http://<addr:port>/translate.json \
-d 'from=english&to=japanese&text=%5B%22Hello%20world%22%5D'
Scripts (all need a running aien-translate; pass its address with --server URL):
python3 scripts/translate_readme.py [--server URL] [lang ...] # writes docs/i18n/README.<code>.md
python3 scripts/translate_site.py DIST OUT --langs zh-CN,ja [--server URL] [--base-url URL] # needs beautifulsoup4
python3 scripts/translate_latex.py paper.tex OUT_DIR --langs zh-CN,ja [--server URL] [--doi DOI] [--dry-run]
python3 demo/check.py URL # needs Playwright and a served demo/ folder with translate.js
translate_latex.py --dry-run prints the pieces the model would see and translates nothing. translate_readme.py has no --help; unknown arguments are read as language codes.
Conventions
- The guard is the product. A translation that loses a link, an email address, a backticked code span, a placeholder such as
{name}or%s, a keep-list name, or an inline tag marker, or that is empty or far longer than the source, is rejected and the original text is served. Never loosen a guard rule to make output appear; add a test insrc/guard.rsortests/protocol.rsfor every rule change. - When a batch reply cannot be matched to its inputs, the server splits the batch and retries down to single items. Keep that fallback; the fixtures in
tests/fixtures/are real failure shapes. - Model requests go one at a time because the GPU may be shared. Do not add parallel requests to the engine.
- The language list lives in
src/langs.rs; the scripts carry their ownLANGStables. Update both together. - Tests live beside the code in
#[cfg(test)]modules and intests/protocol.rs.cargo testmust stay runnable without a GPU or a model server.
Safety and approvals
- Do not point
--engineat a shared or production model server without the owner's approval; translation batches compete with its other users. - Real translation runs need a GPU-backed model server. Do not start one from this repository.
- The cache file holds visitors' page text. Never commit it or attach it to an issue or pull request.
- Machine-translated output (
docs/i18n/, translated sites or papers) is published as machine translation, never presented as reviewed. - Translation admission is bounded in
src/lib.rs(per-peer IP quota, one active request without queueing, request/body limits). Keep tests for unauthorized, saturated, and positive admission paths. The proxy sees real clients; the backend sees the proxy IP, so native quotas do not replace proxy quotas. - Work on a branch and merge through a pull request with the
cargo testresult in its body.
Further reading
README.md: the three-step setup, endpoint list, guard description and limits.src/guard.rs: the exact checks applied to every translation.- https://github.com/xnx3/translate: translate.js and its request protocol.