Проверка языка результата перевода: совпадения числа абзацев недостаточно; недостающие зависимости стороннего репозитория

This commit is contained in:
Илья Поляков
2026-08-03 10:31:35 +03:00
parent 9c7658df5e
commit b92a0a39c0
4 changed files with 86 additions and 9 deletions
+19 -5
View File
@@ -111,10 +111,16 @@ is the bridge: it writes the repo's input format, shells out to
It reports block/chapter/character counts and the detected source language.
`--force` overrides the refusal.
2. **Set up the external repo once** (a plain clone; never edit it), and its
credentials — `DEEPSEEK_API_KEY` in the environment or a `.env` in the
working directory, or `USE_OLLAMA` for a local model. Its `requirements.txt`
omits `openai`, which `deepseek_translator.py` imports — install it too.
2. **Set up the external repo once** (a plain clone; never edit it) and its
credentials — a `.env` in the working directory with `USE_LOCAL_MODEL=false`
and `DEEPSEEK_API_KEY=…`, or `USE_LOCAL_MODEL=true` plus `OLLAMA_MODEL` for a
local model. **Its `requirements.txt` is incomplete** — `pip install openai
pyyaml python-dotenv` as well. Both `openai` and `pyyaml` are imported at
runtime and missing from that file; without `pyyaml` every single request
dies inside `_create_system_prompt` *before* reaching the API, and the tool
reports "API запросов: 0, ошибок: N" while writing `[UNTRANSLATED]` stubs.
Write the `.env` under `umask 077`, and never echo the key into logs or
command output.
3. **Translate:**
`python scripts/translate.py book.html book.ru.html --repo <clone> --workdir <dir> --workers 12`
@@ -126,7 +132,15 @@ is the bridge: it writes the repo's input format, shells out to
потеряна" counts paragraphs where the model mangled the inline-tag markers
and the italics were dropped rather than corrupted. Both are expected to be
near zero — a large number means the translator misbehaved, not that the
bridge is broken.
bridge is broken. The script then checks the output's actual language and
exits non-zero if the text is still the source language or contains
`[UNTRANSLATED]` stubs — **matching paragraph counts do not prove anything
was translated**, since the external tool substitutes the original on API
failure. Do not pack a file that failed this check.
**Re-running after a failure needs the state cleared:** the external repo's
`progress/` directory marks those chapters complete and will skip them.
Delete `<workdir>/progress`, `<workdir>/context`, and
`<workdir>/translations` before the retry.
5. Pack `book.ru.html` with `--language=ru` and translated `--title`/`--authors`.
How formatting survives a translator that only speaks plain text: inline `<i>`