I found this utility, pytranslate, which translates a variety of languages into each other using Google's translation API. It works exactly as described.
However I've gotten sick of selecting a word I do not understand, then middle-clicking it into the command. The command format is as such:
pytranslate WORD
Is there a program/script that has the ability to detect when I select a word, or a series of words with my mouse, and then executes the above command with the selected text in the place of WORD in a terminal window?
Example:
Selected text:
Bonjour mondiale...
Resultant command/result:
pytranslate Bonjour mondiale
Detected source language: fr
Hello World
Now just put this in
~/bin
(make sure that's included in your PATH), and run it. (You may need to install the xsel package.) It will take the current contents of the primary selection buffer and pass it to pytranslate.If you want it as a button, create a launcher which runs this in a terminal, and use bash's read command to do "Press ENTER to continue".