Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I explain:
1) This is a script in ~/bin.
2) --font='STIX Bold Italic 16' # you can choose any font and any size of the text (but not the title) of the window
3) --window-icon=/home/pictures/someimage.jpg # image for window if you want
4) --width=600 --height=250 # window size
5) --title="TRANSLATE" # title of the window(how to change fonts and font size for it I could not find).
6) 2> >(grep -v 'GtkDialog'>&2) # suppress error message "Gtk-Message: GtkDialog mapped without a transient parent. This is discouraged".
7) this is only window with translation without source text
8) auto&tl=ru&dt # change "ru" for your language.
9) Place the file translate-icon.png in your folder "~/bin".
This script is not my credit. I have looked at a lot of posts on the internet on this topic. The task was to make the conclusion simple - no source text. In addition, in this script, the entire text is translated, and not up to the first point, as usual.
My merit - I found how to choose a font and its size for zenity. The regular font is very small and hard to read for me.
I could not find it anywhere on the Internet. Usually they suggest using the "span" function, which I did not understand. Only the Gnome website has information that the font can be changed for "--text-info" function of ZENITY(in fact, they write about the "dialog" command, and zenity is written in its base). The syntax for the fonts was chosen at random. It turned out that all font data is written with a space, no commas.
I didn't use the "yad" command. Perhaps "yad" is better. However, the translation articles talked about ZENITY, so I used it even though the project not developing since 2013.
Thanks for the tip “Web-Scraping”, I'll keep it in mind.
Last edited by Alexcostariha; 07-07-2021 at 01:14 PM.
That error is because what's intended as a single line is broken across three lines, and the first break is inside a string. (Hence the End Of Line inside string error.)
(Afaik, LQ doesn't split long lines inside code blocks, so it seems Alexcostariha manually broke it, and perhaps needs to increase their knowledge of Bash/Python syntax.)
Though I'm not sure why it's such a convoluted script in the first place. It can be simplified to:
Which also allows "xsel -o | ./translate2.sh" or "cat kartoffel.txt | ./translate.sh de en" or whatever.
In both cases, the firefox command could be replaced with a lightweight Python webview/whatever with a customised interface, (if there's actually a reason to do that).
Read this basic article about this theme, please. Maybe you must install "libnotify-bin" or "xclip". Then you must assign a keyboard shortcut to your script. I use this script on UBUNTU 14 and the latest LinuxMint 20.1 Cinnamon and it works great everywhere. My script is named "lingvatrans_zenity" (I have five translate scripts in total). Му shortcut for it is Alt+Shift+6. If you have LinuxMint or Ubuntu with Cinnamon - you can customize hot corners. Then you just touch for example the lower right corner with the mouse and receive your translate window.
To test the script, select some text you want to translate and then run the "./lingvatrans_zenity" command in the script folder(without using keyboard shortcut).
Last edited by Alexcostariha; 07-07-2021 at 03:20 PM.
python script.py
Input something: I+ruled+a+translator+with+zenity+and+this+is+what+I+ended+up+with
[['Я с энтузиазмом правил переводчиком и вот что у меня получилось', 'I ruled a translator with zenity and this is what I ended up with', None, None, 3, None, None, [[]], [[['cce7c67b3f2439089dd6b428e0b83b88', 'en_ru_2020q2.md']]]]]
That error is because what's intended as a single line is broken across three lines, and the first break is inside a string. (Hence the End Of Line inside string error.)
(Afaik, LQ doesn't split long lines inside code blocks, so it seems Alexcostariha manually broke it, and perhaps needs to increase their knowledge of Bash/Python syntax.)
oof, that was it.
Thanks, sorry, I should've seen that. I guess it was late.
TBF, I like these small yad scripts, and plan to assign something like it to a hotkey indeed.
The one I'm currently using is way too complex.
Quote:
Originally Posted by Alexcostariha
Read this basic article about this theme, please. Maybe you must install "libnotify-bin" or "xclip".
Sorry but this is nonsense.
Please read what boughtonp wrote.
I would like to say "good effort for your first script", but somehow this feels like you copy-pasted most of it without understanding what it does.
You are right! I made correction for my script, please test. There were two extra line feeds.
Thank You and boughtonp for comments.
Indeed, this is not my script. It is changed script from Andrey Chizhegov(as comment to basic article). You can compare it and mine:
Code:
#!/usr/bin/env bash
xsel -o | python3 -c "import sys,urllib.request,json; r = json.loads(urllib.request.urlopen(urllib.request.Request('http://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl=ru&dt=t&q=' + urllib.parse.quote(sys.stdin.read().replace('\n',' ')), None, { 'User-Agent' : 'Mozilla/5.0' })).read().decode('utf-8')); [print(t[0], end='') for t in r[0]]; print('\n--==<<>>==--'); [print(t[1], end='') for t in r[0]];" | zenity --text-info --width=500 --height=500 --title="Translation"
Last edited by Alexcostariha; 07-09-2021 at 08:52 AM.
What a translate one can receive from basic article's script(see image 01): translate only up to first point, little print, md5sum(what for?) and line breaks.
What a translate can one receive from "my" script(see image 2): full translate of selected text, large print, beautiful appearance and nothing more.
Last edited by Alexcostariha; 07-09-2021 at 08:54 AM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.