A lightweight, intelligent clipboard translation tool that automatically detects the source language and selects the appropriate target language based on your preferences.
- Automatic Language Detection: Uses the lingua library to detect the source language of clipboard text
- Smart Language Selection: Intelligently chooses the target language based on your primary and secondary language preferences
- Configurable: Easily customize your language preferences and translation service settings
- One-Click Copy & Close: Translate and copy with minimal interruption to your workflow
- OpenAI/OpenRouter Integration: High-quality translations powered by AI language models
The application uses a smart algorithm to determine the target language:
// Variables:
// PRIMARY_LANGUAGE — user's primary language
// SECONDARY_LANGUAGE — second language (most common translation from PRIMARY_LANGUAGE)
// LAST_LANGUAGE — last selected target language (or null)
// SRC — language of the source text
function chooseTargetLanguage(SRC, PRIMARY_LANGUAGE, SECONDARY_LANGUAGE, LAST_LANGUAGE):
// 1. If the source isn't the primary language, translate into the primary language
if SRC ≠ PRIMARY_LANGUAGE:
return PRIMARY_LANGUAGE
// 2. If the source is the primary language and there's a meaningful last choice, use it
if LAST_LANGUAGE ≠ null AND LAST_LANGUAGE ≠ PRIMARY_LANGUAGE:
return LAST_LANGUAGE
// 3. Otherwise, fall back to the secondary language
return SECONDARY_LANGUAGE
- Rust and Cargo
- GTK3 development libraries
- OpenRouter API key (or OpenAI API key)
-
Clone the repository:
git clone https://github.com/triklozoid/translator.git cd translator
-
Build the application:
cargo build --release
-
Set up your API key:
export OPENROUTER_API_KEY=your_api_key_here
The application creates a configuration file at ~/.config/translator/config.toml
with the following settings:
api_url = "https://openrouter.ai/api/v1"
model_version = "openai/gpt-4o"
primary_language = "EN"
secondary_language = "FR"
all_target_languages = ["EN", "FR", "IT", "PL"]
primary_language
: Your main language (default: English)secondary_language
: Your second most used language (default: French)all_target_languages
: List of languages available in the UIapi_url
: API endpoint for translationsmodel_version
: AI model to use for translations
- Copy text in any language to your clipboard
- Run the application:
./run
- The application will automatically detect the source language and translate to the appropriate target language
- Click on any language button to translate to that specific language
- Click "Copy & Close" to copy the translation to your clipboard and close the application
Contributions are welcome! Please feel free to submit a Pull Request.