Repository navigation
Translate notes to user's preferred language - #1118
Open
alkeke45-cpu wants to merge 1 commit into
Open
alkeke45-cpu wants to merge 1 commit into
alkeke45-cpu wants to merge 1 commit into
Conversation
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.
Closes #1055
What this adds
Inline translation of text notes into the user's preferred language, directly in the note footer — the X-style flow requested in #1055. This is the Android counterpart of the translation feature proposed for the web app in PrimalHQ/primal-web-app#133 (PR PrimalHQ/primal-web-app#241), porting the same service logic to Kotlin so the platforms behave identically.
Unlike the LibreTranslate-based approaches, this needs zero user setup: no API key, no endpoint configuration, no backend.
How it works
Locale.getDefault()), normalized for the translation endpoint (en-us → en,zh-CNkept,nb → no, …).gtxendpoint — no API key, no backend. 15s timeout (connect/read/write/call) with one retry on HTTP 429/5xx; failures degrade gracefully to a subtle "Translation failed. Try again." hint and never crash or block the feed.nostr:URIs, bech32 IDs (npub/note/nevent/naddr/nprofile), URLs, hashtags, Lightning invoices and Cashu tokens are replaced with placeholders and restored afterwards, so mentions, links and invoices are never mangled.note_translate_*,accessibility_translate_note).Files
app/src/main/kotlin/net/primal/android/notes/translation/NoteTranslationService.kt(new) — translation service: entity protection, chunking, bounded cache, language normalization, gtx client on OkHttp + kotlinx.serialization.app/src/main/kotlin/net/primal/android/notes/translation/NoteTranslation.kt(new) — result model.app/src/main/kotlin/net/primal/android/notes/feed/note/ui/NoteTranslationSection.kt(new) — Translate action + inline translated block with header and Show/Hide toggle.app/src/main/kotlin/net/primal/android/notes/feed/note/FeedNoteCard.kt— renders the section in the note footer between the content and the actions row, aligned with the content indent.app/src/main/kotlin/net/primal/android/core/compose/icons/primaliconpack/FeedTranslate.kt(new) — globe icon in the existing 16dp icon-pack format.app/src/main/res/values/strings.xml— newnote_translate_*strings.Verification
CommonJsonfromnet.primal.core.utils.serialization,AppTheme, icon-pack format) and structurally reviewed end-to-end: every import resolves to a real class in this repo, call-site signatures match, brace/paren balance and the 120-char line limit verified,strings.xmlre-parsed as valid XML.:app:compileDebugKotlincould not be executed there. The change is additive (6 files, +600/−0) and touches no existing signatures, so CI should give a clean signal.Submitted for the Lightning Bounties reward on this issue (50,000 sats).