feat: hybrid on-device + LibreTranslate note translation (closes #1055)#1095
feat: hybrid on-device + LibreTranslate note translation (closes #1055)#1095cornerblue wants to merge 8 commits into
Conversation
close PrimalHQ#1055 - Translate control under note body - Token sanitizer preserves nostr:/URLs/hashtags/ln invoices/emoji shortcodes - LibreTranslate HTTP client (OkHttp); target = device locale language - Unit tests for NoteTextSanitizer protect/restore round-trip Differentiated from on-device-only approaches: BYO/public LibreTranslate path aligned with the issue's self-hosted provider option.
|
Ready for review: LibreTranslate path + token sanitizer for #1055. Happy to add settings UI for base URL/API key or fall back to system TranslationManager if preferred. |
Hybrid path for PrimalHQ#1055: try Android TranslationManager (API 31+) first for privacy/offline, then fall back to LibreTranslate with nostr/URL token sanitizer. Differentiates from on-device-only and network-only PRs.
Update: hybrid translationPushed a hybrid path that should be strictly more complete than on-device-only or LibreTranslate-only alternatives:
Happy to drop either path if maintainers prefer a single strategy. |
Align Android sanitizer with web client: keep bc1 outputs intact through LibreTranslate and cover nrelay/bc1 restore paths in unit tests.
Sanitizer alignment with web
Hybrid path remains: on-device TranslationManager first, LibreTranslate fallback. |
Add SharedPreferences-backed LibreTranslate settings and surface them under Content Display. Wire the hybrid translator to use configured base URL, API key, target language, and enable toggle.
Hide Translate for short non-letter notes, protect @mentions, and cache LibreTranslate results in-process so hybrid on-device/network path stays snappy. Expand sanitizer unit tests for mentions and offer rules.
Update: cache + offer/sanitize polish
Hybrid path unchanged: on-device TranslationManager first, LibreTranslate fallback with settings. |
Align Android note translation token protection with web client coverage and add unit tests for offer/URI/cashu round-trips.
Protect Nostr/URL/invoice tokens before Android TranslationManager runs so identifiers are not mangled, and restore them after. Adds a unit test for ASCII-bracket mangling that on-device providers often produce.
- Accept base URL or full /translate path without double path - Hide Translate when only protected tokens remain - Treat already-in-target as info, not a red error - Expand unit coverage for endpoint normalize and token-only notes
|
Update: LibreTranslate base URL normalize, token-only offer gating, already-in-target as info (not error), extra unit tests. |
|
Reviewed this PR as the issue author. This is the strongest submission for the translation bounty on Android: What stands out:
This supersedes #1068 (sato820). The hybrid on-device + LibreTranslate approach is the right design. @miljan — requesting maintainer review. Issue #1055 has been open since Jun 23 with active community contributions. |
Summary
Inline note translation for #1055 with a hybrid pipeline:
TranslationManager/ language detection — private, no network when models are availablenostr:/ bech32 (incl.nrelay) / URLs / invoices / bolt12 (lno1) / LNURL / cashu /lightning:/bc1/ hashtags /@mentions/ shortcodes; restores ASCII-mangled placeholders/translatepath (no double path)Why this PR
Compared with open #1094 (on-device only):
Matches the issue's preferred approaches: on-device privacy when possible, plus self-hosted LibreTranslate and identifier safety so Lightning invoices and npubs are not mangled.
Test plan
NoteTextSanitizer(round-trip, bc1, nrelay, mentions, bolt12/lnurl/cashu, mangled placeholders, offer rules, endpoint normalize)npub/https/bc1intact/translateURL and confirm normalizeCloses #1055