I need to work with some text files (source code) that have comments in a language that is foreign to me, and I am wondering if there is a text editor available that has some built-in support to make translation easier.
I can copy and paste to google translate running in a browser in another window and then copy and paste back again, but it would be much easier if I could highlight, right click and choose "translate...", or something like that!
I'm not looking for automatic translation of the whole file, just the bits I highlight.
Kubuntu 18.01, and Kate is my usual editor of choice but I'd be happy to use another editor for this job if it had some helpful features.
Here's one way using
translate-shell
which is in the Bionic multiverse repository. The homepage is here.You may need to have
gawk
,curl
, andxsel
on your system.There are a lot of details on the homepage and probably a more efficient way to do things, but this is what I got:
In Kubuntu 18.04, I called this script
trans.sh
, saved it to~/bin
, made it executable, and bound it to Meta+U using theShortcuts
>Custom Shortcuts
inSystem Settings
.On a page such as https://pl.lipsum.com/, I highlight some text, move to the location in the destination text editor (including Kate), press Meta+U, wait a couple of seconds, and then press Ctrl+V. The translated text is pasted in at the cursor position.
Source:
Note: in the example script, I've used
"
but you may prefer using'
unless'
occurs internally as mentioned in the home page: