Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Thu 19 Sep 2019, 09:30
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
Development of 'trans_tray' (translation program)
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 7 [100 Posts]   Goto page: 1, 2, 3, 4, 5, 6, 7 Next
Author Message
fredx181


Joined: 11 Dec 2013
Posts: 4088
Location: holland

PostPosted: Fri 23 Aug 2019, 13:05    Post subject:  Development of 'trans_tray' (translation program)
Subject description: Continuation from "Yad -Tips" topic
 

Development continuation of "trans_tray", which started in the "Yad - Tips" thread, initially here:
http://murga-linux.com/puppy/viewtopic.php?p=1034587#1034587
Until here (at this time): http://murga-linux.com/puppy/viewtopic.php?p=1035129#1035129

Started by Argolance who gave a hint about a script using 'xclip' and "trans" piped to yad, followed by contributions from vovchik (nice start concept), josejp2424 , stemsee and myself.

Further contributions and feedback are very welcome !

Fred

_________________
Dog Linux website
Tinylinux blog by wiak

Last edited by fredx181 on Fri 23 Aug 2019, 15:23; edited 1 time in total
Back to top
View user's profile Send private message 
fredx181


Joined: 11 Dec 2013
Posts: 4088
Location: holland

PostPosted: Fri 23 Aug 2019, 13:06    Post subject:  

Version progress:

trans_tray2
http://murga-linux.com/puppy/viewtopic.php?p=1035399#1035399

trans_tray3
http://murga-linux.com/puppy/viewtopic.php?p=1035783#1035783

trans_tray4
http://murga-linux.com/puppy/viewtopic.php?p=1036222#1036222

trans_tray5
http://murga-linux.com/puppy/viewtopic.php?p=1036875#1036875

trans_tray6
http://murga-linux.com/puppy/viewtopic.php?p=1037014#1037014

_________________
Dog Linux website
Tinylinux blog by wiak

Last edited by fredx181 on Sat 14 Sep 2019, 14:36; edited 5 times in total
Back to top
View user's profile Send private message 
stemsee

Joined: 27 Jun 2013
Posts: 2459
Location: In The Way

PostPosted: Fri 23 Aug 2019, 14:19    Post subject:  

I added this to save all translation window texts in root
Code:
for ex in $ENGINE
do
echo "icon:/usr/share/pixmaps/$ex.png" >$PIPE
for i in $TLANG
do
echo ---------------$ex $i-------------------
xclip -o | trans -e $ex -b -tl $i
done; done | yad \
--window-icon="$ICON" \
--text-align=center \
--title="$MYTITLE" \
--geometry=600x600+$SWIDTH+100 \
--fore="black" --back="#fef1e0" \
--margins=5 \
--button="$BUT" \
--text="$HELP" \
--fontname="$FONT" \
--text-info --wrap --tail --editable >$HOME/Trans-Text-$RANDOM

but this creates a file at function start and dumps data on exit, even if it's empty. It would be better to implement a save button. But I couldn't get it to work.
Back to top
View user's profile Send private message MSN Messenger 
musher0

Joined: 04 Jan 2009
Posts: 14307
Location: Gatineau (Qc), Canada

PostPosted: Fri 23 Aug 2019, 15:43    Post subject:  

Remember to use DeepL for most Western /
Latin languages, plus Polish and Russian, rather than Google Translate.

DeepL does a better job: its translations sound more natural in the target language.
(And it's not just me saying so.)

_________________
musher0
~~~~~~~~~~
Je suis né pour aimer et non pas pour haïr. (Sophocle) /
I was born to love and not to hate. (Sophocles)
Back to top
View user's profile Send private message 
josejp2424


Joined: 01 Aug 2010
Posts: 492

PostPosted: Fri 23 Aug 2019, 19:32    Post subject: button exit  

you should remove the middle mouse button click on the system tray icon.
since we have exit button in the menu.

_________________
Shiba Inu | Pupjibaro jessie | My Blog
Back to top
View user's profile Send private message Visit poster's website 
Argolance


Joined: 06 Jan 2008
Posts: 3667
Location: PORT-BRILLET (Mayenne - France)

PostPosted: Sat 24 Aug 2019, 03:23    Post subject:  

Bonjour,

@musher0
musher0 wrote:
Remember to use DeepL for most Western/Latin languages, plus Polish and Russian, rather than Google Translate.

As I pointed out on my Arrow 2Pot (2P Online Translator) thread, for me, DeepL has not worked at all for a long time. I think I probably overused the engine while I was working on my scripts and I'm now probably on a blacklist, which can happen to any user. Google, Bing, Yandex do the same thing but only temporarily and not permanently like DeepL, which strategy is unfortunate: pettiness has only a time (it seems that Google has improved significantly since the creation of DeepL).

@josejp2424
Wink

Cordialement.

_________________

A second life for your PCs...
Back to top
View user's profile Send private message Visit poster's website 
fredx181


Joined: 11 Dec 2013
Posts: 4088
Location: holland

PostPosted: Sat 24 Aug 2019, 03:30    Post subject:  

stemsee wrote:
I added this to save all translation window texts in root
Code:
for ex in $ENGINE
do
echo "icon:/usr/share/pixmaps/$ex.png" >$PIPE
for i in $TLANG
do
echo ---------------$ex $i-------------------
xclip -o | trans -e $ex -b -tl $i
done; done | yad \
--window-icon="$ICON" \
--text-align=center \
--title="$MYTITLE" \
--geometry=600x600+$SWIDTH+100 \
--fore="black" --back="#fef1e0" \
--margins=5 \
--button="$BUT" \
--text="$HELP" \
--fontname="$FONT" \
--text-info --wrap --tail --editable >$HOME/Trans-Text-$RANDOM

but this creates a file at function start and dumps data on exit, even if it's empty. It would be better to implement a save button. But I couldn't get it to work.


Works for me this way with Save button, trans_paste function:
Code:
trans_paste () {
#set -x
export TLANG=$(cat $HOME/.trans_target_lang2 2> /dev/null)
export _TLANG=$(cat $HOME/.trans_target_lang2 2> /dev/null | awk '{print $1}' | tr '\n' '+' | sed 's/.$//')
[ -z "$TLANG" ] && export TLANG="English - en"
export ENGINE=$(cat /tmp/_trans_engine_2 2> /dev/null)
[ -z "$ENGINE" ] && ENGINE=google
echo "Using $ENGINE for translating"
ICON="/tmp/trans-paste.svg"
if [ ! -e "$ICON" ]; then
   SVG="<""svg height='100' width='100'>
     <path style='fill:red;stroke:darkred;stroke-width:3;'
     d='M 93,62 C 83,82 65,96 48,96 32,96 19,89 15,79 L 5,90 5,53
     40,53 29,63 c 0,0 5,14 26,14 16,0 38,-15 38,-15 z'/>
     <path style='fill:red;stroke:darkred;stroke-width:3;'
     d='M 5,38 C 11,18 32,4 49,4 65,4 78,11 85,21 L 95,10 95,47
     57,47 68,37 C 68,37 63,23 42,23 26,23 5,38 5,38 z'/>
   </svg>"
   echo "$SVG" > /tmp/trans-paste.svg
fi
HELP=" Translating to $_TLANG... \n Press <b>ESC</b> key or click <b>Exit</b> to dismiss, or click <b>Save</b> (if desired, edit text first)"
MYTITLE="Trans"
BUT="<span color='darkblue'><b>Exit</b></span>"
BUTSAVE="<span color='darkgreen'><b>Save</b></span>"
FONT="Mono 12"
TWIDTH=$(xdpyinfo  | grep 'dimensions:' | cut -d' ' -f7 | cut -d'x' -f1)
SWIDTH=$(( $TWIDTH - 600 ))
#echo $SWIDTH
GUI=$(for ex in $ENGINE
do
echo "icon:/tmp/$ex.svg" >$PIPE
while read i; do
echo " ----- $ex translate to $(echo $i | awk '{print $1}') -----"
xclip -o | trans -e $ex -b -tl $(echo $i | awk '{print $NF}')
echo
done <<< "$TLANG"; done | yad \
--window-icon="$ICON" \
--text-align=center \
--title="$MYTITLE" \
--geometry=600x600+$SWIDTH+100 \
--fore="black" --back="#fef1e0" \
--margins=5 \
--button="$BUTSAVE:0" \
--button="$BUT:1" \
--text="$HELP" \
--fontname="$FONT" \
--text-info  --wrap --tail --editable)
if [ $? -eq 0 ]; then
DATE=$(date +"%Y%m%d_%H%M%S")
echo "$GUI" >  $HOME/trans-$DATE
yad --title="Translation saved" --borders=6 --window-icon=$ICON --text="  <b>Saved to $HOME/trans-$DATE </b>" --geometry=350x40-40-70 --undecorated --timeout 5 --no-buttons
fi
[ "$ENGINE" = "google bing" ] && echo "icon:/tmp/all.svg" >$PIPE
}
export -f trans_paste


@josejp2424
Quote:
you should remove the middle mouse button click on the system tray icon.
since we have exit button in the menu.

Yes, better, will do that.

Fred

_________________
Dog Linux website
Tinylinux blog by wiak
Back to top
View user's profile Send private message 
fredx181


Joined: 11 Dec 2013
Posts: 4088
Location: holland

PostPosted: Sat 24 Aug 2019, 03:44    Post subject:  

Hi everyone. Attached new trans_tray2.

- Added 'Save' button to the window with translated text (possible to edit first)
- Disabled middle click to Exit the tray-icon (since there's Exit in the Menu, as josejp24 and Argolance already stated)

Fred
trans_tray2.gz
Description  Remove fake .gz and make executable
gz

 Download 
Filename  trans_tray2.gz 
Filesize  110.09 KB 
Downloaded  17 Time(s) 
2019-08-24-094204_470x196_scrot.png
 Description   
 Filesize   106.55 KB
 Viewed   267 Time(s)

2019-08-24-094204_470x196_scrot.png

2019-08-24-093810_600x629_scrot_500x524.png
 Description   Added Save button
 Filesize   131.08 KB
 Viewed   267 Time(s)

2019-08-24-093810_600x629_scrot_500x524.png


_________________
Dog Linux website
Tinylinux blog by wiak
Back to top
View user's profile Send private message 
fredx181


Joined: 11 Dec 2013
Posts: 4088
Location: holland

PostPosted: Sat 24 Aug 2019, 05:08    Post subject:  

Hi All, just discovered this brilliant code from stemsee (many thanks, also to misko for the help)
http://murga-linux.com/puppy/viewtopic.php?p=1035150#1035150
modified a bit and added it to the right-click menu options (View saved translations).
Hope you don't mind Stemsee ? (you can always change how you prefer of course)

Fred
trans_tray2.gz
Description  New trans_tray2, remove fake .gz and make executable
gz

 Download 
Filename  trans_tray2.gz 
Filesize  110.82 KB 
Downloaded  19 Time(s) 
2019-08-24-110305_728x704_scrot_528x511.jpg
 Description   View saved translations
 Filesize   82.7 KB
 Viewed   246 Time(s)

2019-08-24-110305_728x704_scrot_528x511.jpg


_________________
Dog Linux website
Tinylinux blog by wiak
Back to top
View user's profile Send private message 
stemsee

Joined: 27 Jun 2013
Posts: 2459
Location: In The Way

PostPosted: Sat 24 Aug 2019, 09:26    Post subject:  

Very Happy

Fred, your enthusiasm is contagious! You usually take the initiative and remain a step ahead of the pack!(a lot of the time anyway! Confused )

Is a progress indicator during translation 'easily' implemented....from your googledrive and other apps; you have far more successful experience withit (taking in to account Mochi's observations and hints about progress indicators cutting out before reaching the end.)

EDIT:
Also just to clarify why I prefer the locale code $i (en es de) etc .... it is educational....lazyish learners will learn the international country codes.

Also if only Bing and Google re to be used then 'All' is inappropriate, change 'All' to 'Both' .... I'm keeping yandex so 'All' is ok. But later when you gettext could make a difference.

Also when previewing saved texts --editable for tabnum=2 might be useful, requiring additional save button, and also a refresh button to update list of texts, without closing and opening the viewer again. Or just a button to open selected in geany/leafpad etc.

As for adding DeepL, I'm all for it, but the 'trans' script is in python which I know nothing about, and that's where it needs to be added, unless someone learns DeepL API and implements basic functions in trans_tray2...(maybe you can musher).

stemsee

Last edited by stemsee on Sat 24 Aug 2019, 10:44; edited 3 times in total
Back to top
View user's profile Send private message MSN Messenger 
fredx181


Joined: 11 Dec 2013
Posts: 4088
Location: holland

PostPosted: Sat 24 Aug 2019, 10:07    Post subject:  

stemsee wrote:
Fred, your enthusiasm is contagious! You usually take the initiative and remain a step ahead of the pack!(a lot of the time anyway! Confused )


Yeah yeah, I will try to calm down now Laughing Laughing

Quote:
Is a progress indicator during translation 'easily' implemented...

Not saying it's impossible, but to be honest I have no idea even where to start making progress bar for this... Rolling Eyes

Fred

_________________
Dog Linux website
Tinylinux blog by wiak
Back to top
View user's profile Send private message 
666philb


Joined: 07 Feb 2010
Posts: 3476
Location: wales

PostPosted: Sat 24 Aug 2019, 10:42    Post subject:  

i'm liking this! thanks fredx181

some feature requests...

a button to clear the contents

it would also be good to remember window position and size, or at least always open at the bottom directly above the tray icon. remembering the position & size would be better though.

cheers

phil

_________________
Bionicpup64 built with bionic beaver packages http://murga-linux.com/puppy/viewtopic.php?t=114311
Xenialpup64, built with xenial xerus packages http://murga-linux.com/puppy/viewtopic.php?t=107331
Back to top
View user's profile Send private message 
stemsee

Joined: 27 Jun 2013
Posts: 2459
Location: In The Way

PostPosted: Sat 24 Aug 2019, 10:53    Post subject:  

Hi 666philb

Are you talking about all opening windows or one specific one?

Anyway, in savedtranstext function notice the WINDOWTITLE variable, with the title in spacedless text, that makes it suitable for geometry recorder which has geometry recording code from Mochimoppel, in a function by myself.

Code:
function sayonara {     #MochiMoppel/stemsee geometry recorder
export track=/tmp/trans_tray2
export camino=$HOME/.trans_tray2
[[ ! -f "$track"/geom ]] && exit
   yad --text="$WINDOWTITLE: WT Geometry-Recorder" --window-icon="$pics/wireless.png" \
   --geometry=200x10+100-100 --no-focus --no-buttons --undecorated \
   --on-top --form --skip-taskbar --field="MoreTime:FBTN" "bash -c sayonara" \
   --timeout-indicator=top --timeout=6
   nought=`xwininfo -stats -name "$WINDOWTITLE" | grep "$WINDOWTITLE"`
   XWININFO=`xwininfo -stats -name "$WINDOWTITLE"`
   if [[ ! -z "$nought" ]]; then
      ARRAY=(${XWININFO#* X: })
      AX=${ARRAY[0]}
      AY=${ARRAY[4]}
      RX=${ARRAY[8]}
      RY=${ARRAY[12]}
      W=${ARRAY[14]}
      H=${ARRAY[16]}
      X=$((AX-RX))
      Y=$((AY-RY))
      echo "$W"x"$H"+"$X"+"$Y" > $camino/geometry/$WINDOWTITLE
   else
      exit
   fi
}; export -f sayonara

function switchgr (){ #toggle geometry recorder on or off
[[ -f "$track"/geom ]] && rm -f "$track"/geom || touch "$track"/geom
}; export -f switchgr

#code misko_2083
function savedtranstexts (){
   rm -f /tmp/TP
   stxtp=/tmp/TP
   mkfifo -m 755 $stxtp
   exec 4<> $stxtp
yad --plug=$$ --tabnum=1 --list --item-separator=" " --column="Saved Trans" \
    $(for f in $HOME/trans-*_*; do [[ -f "${f}" ]] && echo "${f##*/}"; done) \
    --select-action="bash -c \"echo -e '\f' >/tmp/TP ; cd "$HOME" ; cat  "%s" >/tmp/TP ; echo -e '\n' >/tmp/TP \""  &
yad --plug=$$ --tabnum=2 --editable --text-info --wrap --listen <&4 &

export WINDOWTITLE="Saved-Texts"
yad --window-icon=gtk-save --geometry=$camino/geometry/$WINDOWTITLE --no-buttons --on-top --paned --splitter=180 --key=$$ --title="$WINDOWTITLE" --tab="Selector" --tab="Preview" --orient=horizontal
   4<&-
   5<&-
   kill -9 $MON_PID
}; export -f savedtranstexts

from my wifi app, edit accordingly...

Last edited by stemsee on Sat 24 Aug 2019, 11:21; edited 2 times in total
Back to top
View user's profile Send private message MSN Messenger 
666philb


Joined: 07 Feb 2010
Posts: 3476
Location: wales

PostPosted: Sat 24 Aug 2019, 11:12    Post subject:  

hi stemsee,

i just meant the main 'trans' window. i have a 4k screen and it's opening right up in the top right of the screen. i've edited the script now for me personally so that it opens bottom right.

thanks for posting the code snippet, although it's way above my pay grade Smile .. hopefully it will make sense to fredx181

cheers

_________________
Bionicpup64 built with bionic beaver packages http://murga-linux.com/puppy/viewtopic.php?t=114311
Xenialpup64, built with xenial xerus packages http://murga-linux.com/puppy/viewtopic.php?t=107331
Back to top
View user's profile Send private message 
fredx181


Joined: 11 Dec 2013
Posts: 4088
Location: holland

PostPosted: Sat 24 Aug 2019, 11:27    Post subject:  

666philb wrote:
i'm liking this! thanks fredx181
....
....


Thanks phil,

Quote:
a button to clear the contents

I assume you mean the contents of translated text window, what is it good for to clear the contents ?

Quote:
it would also be good to remember window position and size, or at least always open at the bottom directly above the tray icon. remembering the position & size would be better though.

Yes, that would be good, I think stemsee can make that work properly.

@stemsee
Quote:
EDIT:
Also just to clarify why I prefer the locale code $i (en es de) etc .... it is educational....lazyish learners will learn the international country codes.

I disagree !! (if you don't mind Wink ) this program is not for educational purpose.

Quote:
Also if only Bing and Google re to be used then 'All' is inappropriate, change 'All' to 'Both' .... I'm keeping yandex so 'All' is ok. But later when you gettext could make a difference.

Also when previewing saved texts --editable for tabnum=2 might be useful, requiring additional save button, and also a refresh button to update list of texts, without closing and opening the viewer again. Or just a button to open selected in geany/leafpad etc.

As for adding DeepL, I'm all for it, but the 'trans' script is in python which I know nothing about, and that's where it needs to be added, unless someone learns DeepL API and implements basic functions in trans_tray2...(maybe you can musher).


Yes, 'Both" will be better then, and yes additional Save button might be nice for saved-text, DeepL unfortunately isn't supported by trans anymore, I've read good reviews about it. Trans script in Python ? Just bash AFAIK.

Fred

_________________
Dog Linux website
Tinylinux blog by wiak
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 7 [100 Posts]   Goto page: 1, 2, 3, 4, 5, 6, 7 Next
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0883s ][ Queries: 12 (0.0213s) ][ GZIP on ]