electronim icon indicating copy to clipboard operation
electronim copied to clipboard

[translation] Built-in Translation Service

Open manusa opened this issue 2 months ago • 0 comments

Description

Add a built-in translation feature that allows users to translate selected text within any service tab without leaving ElectronIM. This feature will leverage free/libre translation libraries to maintain the project's FOSS philosophy and avoid external API dependencies or registration requirements.

Resources to look into:

  • https://github.com/argosopentech/argos-translate
  • https://opennmt.net/

Motivation

Users frequently communicate across language barriers in instant messaging applications. Currently, they must switch to external translation services, copy text, translate, and switch back. An integrated translation feature streamlines this workflow while maintaining ElectronIM's commitment to privacy and free software.

User Story

As an ElectronIM user, I want to translate selected text directly within my messaging tabs, so that I can quickly understand messages in foreign languages without leaving the application or using external services.

Proposed Solution

Global Settings

  • Add a "Translation" section in Settings
  • Enable/disable translation feature (default: disabled)
  • Select default target language from supported languages list

Context Menu Integration

  • When text is selected in any service tab, show translation options in the context menu:
    • "Translate to [Default Language]" - Translates to user's configured default
    • "Translate to..." submenu - Shows list of all supported target languages
    • Auto-detect source language

Translation Display

  • Show translation in a non-intrusive overlay/tooltip near the selected text
  • Include source language detection result
  • Provide option to copy translated text
  • Allow closing the translation overlay with ESC key or clicking outside

Acceptance Criteria

Settings Implementation

  • [ ] Translation settings section appears in the Settings UI
  • [ ] Toggle to enable/disable translation feature persists across sessions
  • [ ] Dropdown to select default target language from all supported languages
  • [ ] Language selection persists in application configuration
  • [ ] Settings UI shows loading state while fetching available languages
  • [ ] Error handling for translation service initialization failures

Context Menu

  • [ ] Context menu shows translation options only when text is selected
  • [ ] "Translate to [Default]" option appears first
  • [ ] "Translate to..." submenu contains all supported languages except default
  • [ ] Languages in submenu are sorted alphabetically
  • [ ] Translation options are not visible when translation feature is turned off
  • [ ] Context menu maintains existing functionality (copy, paste, etc.)

Translation Functionality

  • [ ] Selected text is correctly extracted and passed to translation service
  • [ ] Source language is automatically detected
  • [ ] Translation completes within reasonable time (<3 seconds for typical text)
  • [ ] Long text selections (>1000 characters) are handled appropriately
  • [ ] Special characters, emojis, and formatting are preserved where possible
  • [ ] Translation works across all service tabs (WhatsApp, Telegram, Slack, etc.)

Translation Display

  • [ ] Translation result appears in a styled overlay near selected text
  • [ ] Overlay shows: source language, target language, and translated text
  • [ ] Copy button copies translated text to clipboard
  • [ ] Overlay can be dismissed with ESC key
  • [ ] Overlay can be dismissed by clicking outside
  • [ ] Overlay positioning doesn't obscure important UI elements
  • [ ] Multiple simultaneous translations are handled gracefully

Error Handling

  • [ ] Network errors show user-friendly error message
  • [ ] Unsupported language pairs show appropriate warning
  • [ ] Translation timeout (>10 seconds) shows timeout message
  • [ ] Service unavailable errors provide troubleshooting guidance
  • [ ] Errors don't break the application or context menu

Performance

  • [ ] Translation service initializes without blocking UI
  • [ ] Context menu appears instantly (<100ms) after text selection
  • [ ] Translation requests don't freeze the application
  • [ ] Multiple rapid translation requests are queued appropriately
  • [ ] Memory usage remains reasonable with repeated translations

Testing Checklist

  • [ ] Unit tests for TranslationService methods
  • [ ] Integration tests for IPC communication
  • [ ] E2E tests for context menu workflow
  • [ ] Performance testing with long texts
  • [ ] Error scenario testing (network failures, timeouts)
  • [ ] Settings persistence testing

Documentation Requirements

  • [ ] Update README.md with translation feature description
  • [ ] Add translation section to Setup Guide
  • [ ] Document supported languages
  • [ ] Provide troubleshooting guide for translation errors
  • [ ] Add screenshots of translation UI to documentation
  • [ ] Document how to self-host LibreTranslate for privacy

Future Enhancements (Not in Scope)

  • Translation history
  • Custom translation glossaries
  • Automatic page translation
  • Translation keyboard shortcuts
  • Multiple translation engine selection per session

manusa avatar Oct 22 '25 05:10 manusa