feat: add bilingual article translation system#119
Open
GoToBoy wants to merge 9 commits into
Open
Conversation
Add entry translation feature using Google Translate (deep-translator). Translates articles in bilingual interleave mode - each paragraph gets its translated counterpart inserted below with distinct styling. Backend: - EntryTranslation model, TranslationService, and API endpoints - Worker task with HTML-aware bilingual translation (BeautifulSoup) - Auto-detect target language (Chinese ↔ English) - Batch translation with chunk splitting for long content Frontend: - useEntryTranslation hook with polling for async results - Bilingual display in ArticleReader with amber-styled translations - i18n strings for en and zh-CN Tests: - 14 translation service unit tests - 18 worker task unit tests (bilingual HTML, chunking, skip ancestors) - 11 API integration tests Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace worker-based whole-article translation with frontend-driven viewport translation. Only visible content (+ 500px buffer) is translated via IntersectionObserver, with sentence-by-sentence bilingual display beneath each paragraph. - Add sync POST /entries/translate-texts API endpoint using Google Translate with batched ||| separator technique - Add useViewportTranslation hook with IntersectionObserver, in-memory cache, and debounced batch translation - Add sentence splitter (English/Chinese punctuation) and language detector utilities - Update ArticleReader to use new viewport translation hook - Add CSS for .glean-translation-line with fade-in animation - Fix NotValidLength bug in worker translation batch fallback - Add entry_translations migration Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…lingual display Persist sentence-level translations in a new paragraph_translations JSONB column so repeated viewport scrolls hit DB cache instead of Google Translate. Switch frontend from appending translation divs to in-place bilingual replacement (Immersive Translate style) with restore-on-deactivate support. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…e/DeepL/OpenAI) Allow users to choose their translation provider and API key in Settings. Introduces a provider abstraction layer with Google Free (default), DeepL, and OpenAI backends. No key = Google free fallback. Settings are stored in the existing User.settings JSONB field and flow through both the sync viewport translation endpoint and the async worker task. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The Select component's onValueChange passes `string | null`, but setModel expects `string`. Guard against null to fix TS2322 build error. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Remove unused _deactivateTranslation variable (ESLint) - Add strict=True to zip() call (Ruff B905) - Replace for loop with any() in _has_skip_ancestor (Ruff SIM110) - Rewrite worker tests to use mock provider instead of GoogleTranslator - Fix enqueue_job assertion to include user_id parameter - Use @pytest_asyncio.fixture for async test fixtures Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Changes
Backend
EntryTranslationdatabase model with Alembic migrationTranslationServicewith provider abstraction (Google/DeepL/OpenAI)Frontend
TranslationTabcomponent in Settings for provider configurationuseViewportTranslationhook for viewport-based sentence-level translationuseEntryTranslationhook for full entry translationTest plan
🤖 Generated with Claude Code