Skip to content

Fix translate feature and add a source/target language picker - #1

Open
giangnam0201 wants to merge 4 commits into
FelixNgH:mainfrom
giangnam0201:fix/translate-language-picker
Open

Fix translate feature and add a source/target language picker#1
giangnam0201 wants to merge 4 commits into
FelixNgH:mainfrom
giangnam0201:fix/translate-language-picker

Conversation

@giangnam0201

Copy link
Copy Markdown

The problem

Translation never ran. Three independent causes, each enough on its own:

1. The selection gesture could never arm (PdfGpuView). The Ctrl/Alt marquee branch sat below the ViewTool::SelectText branch, link activation, Pan, and every annotation tool — all of which return unconditionally. With the Select tool active, a headline 2.4 feature, mousePressEvent returned long before reaching it. The branch now runs first in the handler, guarded by m_hasImage.

2. The two backends disagreed on the modifier. ContinuousView used Ctrl, PdfGpuView used Alt — and Alt+LeftDrag is frequently swallowed by the Windows window manager. Both now accept Ctrl or Alt.

3. The request had no timeout. A stalled connection emitted neither finished() nor failed(), so the UI sat on "Translating…" forever with nothing to show — the "it just does nothing" symptom. Both the Google and Gemini requests now use setTransferTimeout(15s), and both reply connects got a this receiver context.

Making failures legible

The old path could fail in total silence, which is what made this hard to diagnose:

  • Google is retried as a GET when the POST returns an empty 200 — some proxies drop the request body and the old code read that as "no translation".
  • A missing Qt TLS backend is now reported as such, instead of surfacing as an opaque reply error.
  • Every attempt logs http=, the Qt error enum and string, and the byte count.
  • Failures appear in the translation popup with the reason, rather than a 4-second status-bar flash.

The language picker

Translator::translate() is now parameterised over a 21-language table, and makeCacheKey() hashes both languages — previously en→vi and fr→vi collided in the cache and returned each other's results.

LanguagePickerPopup opens at the cursor after a selection and asks from X into Y, defaulting to English → Vietnamese, with a swap button and an "always use this pair" opt-out. Choices persist via QSettings (translate/srcLang, translate/dstLang, translate/rememberLangs). The result popup shows the pair it used. UI copy that hardcoded "to Vietnamese" or "Alt+Drag" was updated to match what the code now does.

CI

The last three commits add a Windows build workflow (Qt 6.8.1/MSVC 2022, vcpkg for OpenSSL/QPDF/ZLIB/Tesseract, vendored PDFium) producing a portable zip artifact. It also fails the build if CMake silently falls back to the OCR stub, and verifies the package contains the exe, Qt network/TLS, PDFium, the CRT, the tesseract runtime and all 10 bundled tessdata languages before uploading.

These are separate commits and easy to drop if the workflow isn't something you want to maintain — the fix itself is the first commit alone.

Testing

Built via the workflow above and tested on Windows 10 x64 against the produced portable package. The CI build matches the shipped portable in scope, including OCR and the same 10 tessdata languages.

🤖 Generated with Claude Code

https://claude.ai/code/session_01GBDMRRnXFtfN8AG3fQCWSY

giangnam0201 added 4 commits August 29, 2026 22:47
The translate gesture could never arm in PdfGpuView: its Ctrl/Alt marquee
branch sat below the SelectText, link-activation, Pan and every annotation
tool branch, all of which return unconditionally. With the Select tool
active -- a headline 2.4 feature -- the selection was simply never started.
The branch now runs first in mousePressEvent.

The two view backends also disagreed on the modifier (ContinuousView used
Ctrl, PdfGpuView used Alt, and Alt+drag is frequently swallowed by the
Windows window manager). Both now accept Ctrl or Alt.

On the network side the Google request had no transfer timeout, so a
stalled connection emitted neither finished() nor failed() and the UI sat
on "Translating..." forever. Both requests now time out at 15s, Google is
retried as a GET when the POST comes back empty (some proxies drop the
body and return an empty 200), a missing Qt TLS backend is reported
explicitly instead of as an opaque reply error, and every attempt logs its
HTTP status, Qt error and byte count. Failures surface in the translation
popup rather than a 4-second status flash.

Translator::translate is now language-parameterised over a 21-language
table, and the cache key hashes both languages so en->vi and fr->vi no
longer collide. LanguagePickerPopup asks "from X into Y" at the cursor
after each selection, defaulting to English -> Vietnamese, with a swap
button and an "always use this pair" opt-out persisted via QSettings.

Adds a Windows CI workflow so the portable build can be produced without a
local Qt/MSVC toolchain.
windeployqt leaves msvcp140/vcruntime140 out by default, so the zip only
ran on machines with the VC++ redistributable already installed. The
shipped portable build carries them locally; match that.
windeployqt --compiler-runtime silently copied nothing on the runner, so
the package still depended on the VC++ redistributable being installed.
Adds tesseract to the vcpkg set so FELIXPDF_ENABLE_OCR turns on, fails the
configure step if CMake falls back to the OCR stub, and checks the packaged
folder for the exe, Qt network/TLS, PDFium, the CRT, the tesseract runtime
and the bundled tessdata languages before uploading.
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