A
A
Alexander Stepanov2019-10-16 00:38:27
ubuntu
Alexander Stepanov, 2019-10-16 00:38:27

How to change a script running in Kubuntu to work in Ubuntu 18.04?

I found an excellent utility for translating selected text in the window of any program - translate-shell and an excellent article ( poke ) on its use, but .. The script given in the article only works for KDE - displays the result in kdialog.
Ubuntu uses notify-send for popups, as I found out from another article ( poke ), which uses a similar method, but without translate-shell.
I would like to use translate-shell to the fullest and see the message in the popup (highlighted text + translation) and convert the script for Ubuntu and notify-send.
Script for KDE:

# #!/usr/bin/env bash
a=`xsel -o | trans :ru -no-ansi -b -l`
echo -e "$a" > /tmp/kdetrans
kdialog --title 'Перевод' --passivepopup "`cat /tmp/kdetrans`"

After a little trickery, I managed to call the notify-send popup, but only with the result of the translation, but I would still like to see the text selected for translation, otherwise the selection would suddenly shift or something like that ...
It’s also interesting how to call notify-send in the popup and the sound of the selected pronunciation - when using translate-shell in the console, everything sounds wonderful, but when calling the script with a popup, there is no sound.
It would be great to know how to tame it all.
Z.Y.
Maybe my question will be useful to someone without an answer. quick translation is convenient not only in Android, but also on the desktop.
Especially if you want to learn a language.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Stepanov, 2019-10-16
@Exebeche

Dancing with a tambourine COULD!!!
Won this case.
There was no voice acting. stupidly copied and pasted and did not pay attention to the keys - the key

-sp
(source, play) voices the original language.
Now, at your leisure, I would like to figure out where the pop-up styles are stored, but that will be another story.
After some simple experiments, it was obtained:
#!/usr/bin/env bash
text="$(xsel -o)" # Переводимый текст
translate="$(xsel -o | trans :ru -no-ansi -sp -b)" # Результат с произношением оригинала (ключь -sp)
# echo "$translate" | xclip -selection clipboard 
notify-send --icon=info "$text" "$translate" # Вызов popup с нужными данными

Now I have a quick translation from Google Translate both on my phone and on my laptop.
I hope it will be useful to someone else.
Z.Y.
Who will come in handy - do not be too lazy to click "Like" and improve karma

A
Adamos, 2019-10-16
@Adamos

Actually, Ubuntu has a GoldenDict out of the box that allows you to specify a query string as a dictionary and works on double Ctrl-C in any program by default.
In general, without tambourines and a hammock ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question