Quick text translations to desktop notifications

I recently discovered instructions for a bash script which will take highlighted text, translate it via google translate (using automatic language detection), and display the resulting translation with a desktop popup notification. On Arch Linux, this required installing the xsel package, as everything else was already installed. The contents of the script are as follows:

#!/usr/bin/env bash
notify-send --icon=info "$(xsel -o)" "$(wget -U "Mozilla/5.0" -qO - "<a class="linkification-ext" title="Linkification: http://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&" href="http://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&">http://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&</a><b>tl=en</b>&dt=t&q=$(xsel -o | sed "s/[\"'<>]//g")" | sed "s/,,,0]],,.*//g" | awk -F'"' '{print $2, $6}')"

All that’s left to do, once this is put in a script file and set to executable, is to create some kind of keyboard shortcut pointing to it. When activated, any highlighted text on the desktop will be translated to English (by default). Please note, this will only work for Xorg, and not Wayland.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s