oleg-kukharenkoHow I built a Linux desktop translator and email assistant that keeps client text on my own machines: Opus-MT in CTranslate2 from Rust, masking, a local Gemma 4 E4B, and an allow-list anonymizer with a preview card before any external LLM.
I write to English-speaking clients, mostly about embedded systems,
telemetry and backend code, and my working language is Russian. For this
kind of text, the requirements for a translator are narrow but strict:
The hardware was two ordinary laptops with no GPU: a Ryzen 7 PRO 3700U and a
Core i7-10510U, 16 GB each.
The result is xlate, now open source under Apache-2.0:
https://github.com/oleg-kukharenko/xlate. It is a personal tool, published as
is, without support. This article describes the decisions behind it, the
numbers I measured, and what did not work.
xlate is a Linux desktop tool with two windows.
A Rust daemon (xlated) does the work and exposes a D-Bus API. The GNOME
Shell extension and the GJS/GTK 4 windows are thin clients with no logic.
Translation runs on the work laptop. The local LLM (Gemma 4 E4B in a
llama.cpp server) and a small knowledge base (multilingual-e5-small
embeddings, SQLite with sqlite-vec) run on the second laptop, behind a
firewall, connected by a direct cable. The split exists so that the LLM does
not take CPU away from translation.
The obvious choice today would be to translate with an LLM. I measured it on
the target laptops: Qwen2.5-3B as a translator was 14 times slower than the
dedicated model EN→RU and 5.5 times slower RU→EN. It also had a worse
failure mode: it sometimes executed the text instead of translating it, for
example answering a question it was given to translate. A half-second
translation while typing is not possible with a CPU LLM.
NLLB was the other candidate. On these laptops it was 3–4 times slower than
Opus-MT tc-big. It was less accurate EN→RU on my set (chrF++ 62.2 against
66.2) and slightly more accurate RU→EN (69.6 against 68.0); speed decided.
So the translation models are Opus-MT tc-big, one per direction, quantized
to int8 with CTranslate2 and run on the CPU. A changed sentence of up to 12
words is translated in 0.47 s EN→RU and 0.56 s RU→EN (median) in the
Translator window; 13–25 words take 0.86 s and 1.00 s.
Before writing the daemon in Rust, I ran a parity spike: the same models
through the ct2rs binding and through the Python reference. The output was
identical, and the Rust process used 555 MB against 870–948 MB in Python,
about 40% less. The daemon translates the first sentence in 0.50 s, with a
peak RSS of about 580 MB.
The models were fine-tuned on a custom corpus on free Kaggle GPUs, in
several rounds. The corpus mixes domain pairs, 25–40% general language
against forgetting, human parallel texts, business mail, everyday text, and
later term pairs produced by a teacher LLM. On the development set, domain
terms translated correctly went from 80.7% / 80.1% with the base models to
90.0% in both directions. The local LLM is still used where it helps:
summaries, drafts and an "Improve" editor that proposes a polished version
of a translation, which I accept or reject.
Masking is the main source of quality in the pipeline. Code, URLs, formulas,
dates, sums, ranges and numbers with units are replaced by placeholders
before translation and restored afterwards, verbatim or in the target
language's notation. On a set of 18 phrases with units, ranges and ± / −
signs, all 18 were distorted before the masking rules and none after.
The same idea handles names. A glossary and a per-contact dictionary keep
names, company names and agreed terms of a conversation as they are.
Without it, "Rotterdam DC" (a distribution centre) became "District of
Columbia".
In technical correspondence the difference between "must" and "should" is a
difference in what you have promised. For RU→EN, a modality guard compares
the obligation in the Russian source with the English output and flags one
that was softened. A "≠ meaning" mark appears when the back-translation
differs from the source. Both only warn; neither changes the text.
Sometimes I need a stronger model than the one on my laptop. Two external
models are wired in: DeepSeek (ds>) and Claude (cl>). From a closed
(client) conversation, the path has four steps:
[NAME_1]. A separate check looks for secrets
(keys, passwords, tokens) and data dumps.From a closed conversation to the preview card takes about 30 s, mostly the
local LLM. From an open conversation (public technical topics), the question
goes out with fragments from the local knowledge base, and the answer cites
them.
On the anonymizer test sets: 0 leaks on 62 development cases, 15 held-out
cases and 4,590 bypass-matrix checks. The red-team set has 2 known misses of
68 (a name made only of common words at the start of a sentence, and a name
form with a fleeting vowel); the per-contact dictionary covers both.
Around the anonymizer there are more layers:
open, closed, forbidden): whether text may go to an
external model is decided by the zone of its source, not by the calling
code, and a new contact is closed by default;Thirty DeepSeek questions cost about 0.01 USD.
The sealed test set for EN→RU is 189 phrases, mostly from articles collected
after the training corpus was frozen, with a limit of 12 evaluations in
total, so it stays a final check and not a tuning target. On it, chrF++ went
from 53.7 with the base model to 56.2, +2.5 with a 95% bootstrap interval of
[+1.4; +3.6]. The first fine-tuned round alone gave +2.1. RU→EN moved from
66.8 to 67.9, which is not significant.
But chrF++ did not separate the later training rounds from each other,
although their term accuracy was clearly different. A blind A/B on 10–13
pairs could not separate even the first fine-tuned round from the base
model.
What did work was a terminology key of 1,384 terms. I checked a random
sample of 50 entries by hand: 45 were correct and 5 were fixed (90%); after
the fixes, the EN→RU term scores moved by 0.2–0.3 percentage points and no
earlier conclusion changed. On term evaluation pairs built around key terms,
targeted fine-tuning moved EN→RU term accuracy from 45.9% to 82.1% and RU→EN
from 56.2% to 78.9%. Model decisions now rest on the key, not on chrF++.
The anonymizer was too careful. In the first live runs with fictional
emails it labelled too much: about 10 of 30 external answers began with "not
enough information". Adding technical vocabulary to the allow-list cut the
labels on the same runs from 51 to 26, with no new leaks on the development
and red-team sets.
A leak through a cache. A cache audit found that the daemon kept
translations in an on-disk SQLite cache, which meant client text outside the
vault. The cache is now in memory only, and a canary test guards the fix.
An audit of outgoing requests reconstructed what was sent, where and
when, without reading the content. It found one request that included a file
from a secrets directory, because the path filter checked only the file
name. The file held no secrets, but the filter now checks every path
component.
A systemd sandbox that did not sandbox. The first network-less sandbox
used systemd-run --user -p PrivateNetwork=yes. Tested on Ubuntu 24.04, it
did not remove network access. It was replaced with bubblewrap.
Things I tried and dropped:
Measured on the two laptops, CPU only, with the fine-tuned models. How each
number was measured is in docs/evaluation.md.
| What | Result |
|---|---|
| Changed sentence ≤ 12 words, median | 0.47 s EN→RU, 0.56 s RU→EN |
| Domain terms correct (key of 1,384 terms) | 90% both directions (base about 80%) |
| Targeted fine-tuning, term pairs | EN→RU 46% → 82%, RU→EN 56% → 79% |
| Sealed set EN→RU, chrF++ | 53.7 → 56.2, +2.5 [+1.4; +3.6] |
| Phrases with numbers and units distorted | 18 → 0 |
| Anonymizer | 0 leaks on 62 + 15 cases and 4,590 bypass checks; 2 known misses of 68 in the red team |
| Assistant evals on the assembled system | 0 critical failures, 0 leaks, real local model |
| Email summary / reply draft, local LLM on CPU | 25–64 s / 32–105 s |
| Gemma 4 E4B on the second laptop | about 6.3 tokens/s |
| Knowledge-base search | Recall@3 0.84, about 140 ms |
| External model cost | about 0.01 USD for 30 DeepSeek questions |
| Automated checks | 482 test functions (233 Rust, 249 Python), 101 headless window checks, local CI of about 40 steps |
Configuration is data: every setting, prompt and interface string lives in
YAML under config/, with JSON Schemas generated from the Rust types and the
same loader in Rust and Python, checked for parity in CI. A CI guard rejects
hard-coded addresses, paths, model names and keys in the code.
The quick start builds the daemon with the public base Opus-MT models and
translates from the command line. It needs no GNOME and no LLM, but it does
need Linux x86-64, Python 3.12, cmake, a C++ compiler, rustup, about 15 GB of
free disk and 4 GB of free RAM.
git clone https://github.com/oleg-kukharenko/xlate && cd xlate
make demo
scripts/xlate translate "The gateway must buffer telemetry for at least 60 minutes."
On a clean Ubuntu 24.04 container with two build jobs, the whole demo took
about an hour, almost all of it compiling CTranslate2 and oneDNN.
With the base models, term accuracy is that of the base model (about 80% on
my key), not of the fine-tuned one. Masking, the modality guard and the
back-translation work the same.
Repository: https://github.com/oleg-kukharenko/xlate (Apache-2.0).
I take on paid embedded, backend and applied ML projects: Upwork, info@starflow.team.