sábado, 9 de abril de 2016

Script for automated text translation in Linux*

* I'm working with GNU/Linux Debian, but it should work ;)

Motivation

Some times you are reading stuff on books, documents, or simply the web. I know it sucks to keep opening new tabs on your browser in order to get translations for some words you don't understand. A Friend of mine told me about some script that can be bound to a keystroke combination, popping out the meaning of the highlighted text.

There are several of such scripts on the web, so making one by myself wouldn't be smart righ? Wrong!. I've tried some of them and all of them lack of features like checking that the clipboard is not empty or setting some limit for the size of the text to be translated or something like checking the languages involved in the translation(It could be useful every now and then). Besides it proved to be a good bash excercise for me.


How it works?

The operation steps are:

  • Check the contents of the primary clipboard. This clipboard always stores the text selected with thw mouse pointer at X sessions.
  • Queries a translation of the contents to google translator api
  • Formats result and makes a call to notify-send to deal with notifications daemon who shows the translation

Take a look at the script here

Making things work

Download the script and place it somewhere like /usr/local/bin give it execution permissions and bind the executable to some key combination that you will press each time you need to translate a selection of text :D

No hay comentarios.:

Publicar un comentario