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:17
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 2 of 7 [100 Posts]   Goto page: Previous 1, 2, 3, 4, 5, 6, 7 Next
Author Message
stemsee

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

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

fredx181 wrote:
Trans script in Python ? Just bash AFAIK.
Fred
Which proves I really do know nothing about bash too .... Laughing
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, 12:29    Post subject:  

stemsee wrote:
Quote:
fredx181 wrote:
Trans script in Python ? Just bash AFAIK.
Fred
Which proves I really do know nothing about bash too .... Laughing

Well... for me too the trans script doesn't look like understandable bash code... Rolling Eyes

Tried the audio option of trans (works for me only with mpv), it seems to me there's a limit of characters (or words) that can be used, this example works for me (Dutch+French+Spanish):
Code:
echo "Better to reinforce that baffle with, for example, the 2x2 bars that you have, instead of what I said earlier, otherwise I think it will be very wobbly and vulnerable don't you think?" | trans -e google -b -tl nl+fr+es -p -player mpv

But when adding more words to the text it fails for me. (around 190 chars limit maybe ? pity !)

P.S. The voice is nice IMHO ! (same btw as playing audio from google translate in browser)

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: Sun 25 Aug 2019, 13:04    Post subject:  

Hi All, new trans_tray2 with some improvements, changes.

- The position and size of the "Trans" window will now be remembered when changed (request from 666philb, thanks for suggestion, it's a nice feature !)
Used the code for that from here: http://murga-linux.com/puppy/viewtopic.php?p=989285#989285
Thanks to MochiMoppel and stemsee !
This needed a change for the info "Translating to ...." , moved now from header text to top of the text-info, otherwise the header text could become too long which makes the window not properly resizable, see issue here: http://murga-linux.com/puppy/viewtopic.php?p=1035321#1035321

- All (edit: most) dialogs will show now in the bottom right corner, which is more convenient IMO.

EDIT 2019-08-26: Made a mistake by testing with yad v0.41, which allows using --geometry --width and --height together, earlier versions don't allow that.
Fixed now and re-attached new trans_tray2 that should work well with e.g. yad v0.38

Fred
trans_tray2.gz
Description  Updated 2019-08-26 Remove fake .gz and make executable
gz

 Download 
Filename  trans_tray2.gz 
Filesize  111.72 KB 
Downloaded  24 Time(s) 
2019-08-25-185336_1183x635_scrot_783x420.jpg
 Description   Enlarged 'Trans' window, size and position will be remembered
 Filesize   100.4 KB
 Viewed   464 Time(s)

2019-08-25-185336_1183x635_scrot_783x420.jpg


_________________
Dog Linux website
Tinylinux blog by wiak

Last edited by fredx181 on Mon 26 Aug 2019, 04:14; edited 2 times in total
Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1897
Location: Japan

PostPosted: Sun 25 Aug 2019, 22:03    Post subject:  

The trans script.does't work in Slacko 5.6.
Plenty of syntax errors from gawk
Code:
gawk: /dev/fd/63:2024: LocaleAlias[Locale[i]["iso"]] = i
gawk: /dev/fd/63:2024:                      ^ syntax error
gawk: /dev/fd/63:2024: fatal: invalid subscript expression
Using gawk 3.1.8
Back to top
View user's profile Send private message 
fredx181


Joined: 11 Dec 2013
Posts: 4088
Location: holland

PostPosted: Mon 26 Aug 2019, 02:58    Post subject:  

MochiMoppel wrote:
Using gawk 3.1.8

Required is 4.0 or later https://github.com/soimort/translate-shell#dependencies

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: Mon 26 Aug 2019, 04:16    Post subject:  

Made a mistake with last trans_tray2, see EDIT and new attachment:
http://murga-linux.com/puppy/viewtopic.php?p=1035338#1035338

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: Mon 26 Aug 2019, 13:53    Post subject:  

Experimented a bit by adding some more menu entries:
- Type or paste text to be translated, could be handy.
- Translate webpage
(see pics)

EDIT: 'default_web-browser' or 'defaultbrowser' or 'xdg-open' probably in most cases should work also when setting the browser in the "Translate webpage" dialog.

EDIT: Mmmm... few hours later... found that translating from menu "Type or paste text to be translated" didn't show any translation, sorry, should be fixed now, re-attached script below.

Fred
trans_tray2.gz
Description  Updated with fix, see EDIT, remove fake .gz and make executable
gz

 Download 
Filename  trans_tray2.gz 
Filesize  115.56 KB 
Downloaded  28 Time(s) 
2019-08-26-193601_636x484_scrot.png
 Description   Type or paste text to be translated
 Filesize   93.21 KB
 Viewed   296 Time(s)

2019-08-26-193601_636x484_scrot.png

2019-08-26-193827_840x404_scrot_740x356.png
 Description   Translate webpage
 Filesize   169.93 KB
 Viewed   294 Time(s)

2019-08-26-193827_840x404_scrot_740x356.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: Mon 26 Aug 2019, 15:48    Post subject:  

Again to quick with sharing, needed a fix, see EDIT:... and new attachment above.

Fred

_________________
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: Tue 27 Aug 2019, 01:32    Post subject:  

Hi Fred

I've been experiencing some drama at work.... So not been around. But I couldn't get my own geometry recording function to work after much effort. I can't wait to see how you did it (I'm on android phone right now! ) I guessed I might need unset WINDOWTITLE before each occurrence.

Your additional features and menu entries are great! You are 'FAST & FURIOUS'
Back to top
View user's profile Send private message MSN Messenger 
fredx181


Joined: 11 Dec 2013
Posts: 4088
Location: holland

PostPosted: Tue 27 Aug 2019, 03:58    Post subject:  

Hi stemsee,

For remembering geometry I just took over MochiMoppels's code http://murga-linux.com/puppy/viewtopic.php?p=989285#989285

Btw, I found that it can be simplified, this works too, (may give negative values for x or y, but yad can handle that):
Code:
function sayonara {
   XWININFO=$(xwininfo -id $YAD_XID)
   echo "$XWININFO" | grep "\-geometry " | awk '{print $2}' > /tmp/yad_trans_geometry
   kill -s SIGUSR1 $YAD_PID
}; export -f sayonara

One thing I'm not happy about is that after a reboot the geometry isn't remembered anymore, so may be better to write to > $HOME/yad_trans_geometry

See you around soon !

Fred

_________________
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: Tue 27 Aug 2019, 05:38    Post subject:  

Hi Fred

Great optimisation.

I suggest using /tmp/trans_tray/ & $HOME/. trans_tray/{geometry, savedtexts} / as a policy in general. And then removal will be easier. I'm sure geometry recording will become a trend in future scripts and apps.

Stemsee

I just had a thought of adding some code that would give this app gettext formatting for ease of gettexting.... No idea what that might be though!

EDIT: It's really good the type what you want translated, but I will try to get that so that we have two panes which allow you to type your text in the left pane, and view translation/s in the right text-info pane so you can also see exactly what you typed and not just remember it. (I think I already did this in refdnd or something similar).
Back to top
View user's profile Send private message MSN Messenger 
stemsee

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

PostPosted: Tue 27 Aug 2019, 08:58    Post subject:  

fredx181 wrote:
Hi stemsee,

For remembering geometry I just took over MochiMoppels's code http://murga-linux.com/puppy/viewtopic.php?p=989285#989285

Btw, I found that it can be simplified, this works too, (may give negative values for x or y, but yad can handle that):
Code:
function sayonara {
   XWININFO=$(xwininfo -id $YAD_XID)
   echo "$XWININFO" | grep "\-geometry " | awk '{print $2}' > /tmp/yad_trans_geometry
   kill -s SIGUSR1 $YAD_PID
}; export -f sayonara

One thing I'm not happy about is that after a reboot the geometry isn't remembered anymore, so may be better to write to > $HOME/yad_trans_geometry

See you around soon !

Fred


Where/how is YAD_XID defined? How is it the correct window id is captured, if you have several yad windows open?
Back to top
View user's profile Send private message MSN Messenger 
misko_2083


Joined: 08 Nov 2016
Posts: 81

PostPosted: Tue 27 Aug 2019, 10:22    Post subject:  

stemsee wrote:

Where/how is YAD_XID defined? How is it the correct window id is captured, if you have several yad windows open?

It's in the manual
Code:
man yad
       YAD_XID
              This variable sets to the value of current dialog's X Window  ID
              and  accessible in all dialog children. This variable is not set
              in print and notification dialogs, and in a dialogs  which  acts
              as a notebook or paned children.
Back to top
View user's profile Send private message 
fredx181


Joined: 11 Dec 2013
Posts: 4088
Location: holland

PostPosted: Tue 27 Aug 2019, 13:11    Post subject:  

stemsee wrote:
I suggest using /tmp/trans_tray/ & $HOME/. trans_tray/{geometry, savedtexts} / as a policy in general. And then removal will be easier. I'm sure geometry recording will become a trend in future scripts and apps.


Yes, that would be much better.

Quote:
EDIT: It's really good the type what you want translated, but I will try to get that so that we have two panes which allow you to type your text in the left pane, and view translation/s in the right text-info pane so you can also see exactly what you typed and not just remember it. (I think I already did this in refdnd or something similar).


Would be nice !

fredx181 wrote:
Btw, I found that it can be simplified, this works too, (may give negative values for x or y, but yad can handle that):
Code:
function sayonara {
XWININFO=$(xwininfo -id $YAD_XID)
echo "$XWININFO" | grep "\-geometry " | awk '{print $2}' > /tmp/yad_trans_geometry
kill -s SIGUSR1 $YAD_PID
}; export -f sayonara

Correction: found that the latest yad versions (0.41 and 0.42) won't handle negative values for x/y properly (version 0.38.2 does that well though) so better keep Mochi's code for remembering geometry .

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: Wed 28 Aug 2019, 12:31    Post subject:  

stemsee wrote:
EDIT: It's really good the type what you want translated, but I will try to get that so that we have two panes which allow you to type your text in the left pane, and view translation/s in the right text-info pane so you can also see exactly what you typed and not just remember it. (I think I already did this in refdnd or something similar).


This works, with save option, only thing I cannot get done is that if you edit the translation that it will be saved too.
Code:
#! /bin/bash

mkdir /tmp/trans_tray 2> /dev/null

export run_cmd='@bash -c "run_trans %1 %2"'

export fpipe="/tmp/run_trans.$RANDOM"
mkfifo "$fpipe"

trap "rm -f $fpipe" EXIT

fkey=$(($RANDOM * $$))

function run_trans_save {
[ ! -f /tmp/trans_tray/run_trans ] && exit
DATE=$(date +"%Y%m%d_%H%M%S")
cp -a /tmp/trans_tray/run_trans  $HOME/trans-$DATE
yad --title="Translation saved" --borders=6 --window-icon=$ICON --text="  <b>Saved to $HOME/trans-$DATE </b>" --geometry=350x35-40-70 --undecorated --timeout 5 --no-buttons
}
export -f run_trans_save

function run_trans
{
    echo "2:@disable@"
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 -e '\f' >> "$fpipe"
[ -n "$1" ] && export TTEXT="$1" || exit
#echo "Using $ENGINE for translating"

for ex in $ENGINE
do
#echo "icon:/tmp/$ex.svg" >$PIPE
while read i; do
echo "----- $ex translate to $(echo $i | awk '{print $1}') -----"
echo -e "$TTEXT" | trans -e $ex -b -tl $(echo $i | awk '{print $NF}')
#echo ""
done <<< "$TLANG"; done | tee /tmp/trans_tray/run_trans >> "$fpipe"

    echo "2:$run_cmd"
}
export -f run_trans

exec 3<> $fpipe

yad --plug="$fkey" --tabnum=1 --form --field="Type some text to translate :TXT" "" --field="Translate!gtk-refresh:fbtn" "$run_cmd" &

yad --plug="$fkey" --tabnum=2 --text-info --editable --wrap --fore="black" --back="#FFF7EE" --margins=5 <&3 &

yad --paned --key="$fkey" --text="        <b>Translate to $_TLANG</b>" --button="Close!gtk-close:1" --button="Save!gtk-save:bash -c run_trans_save" --width=800 --height=600 \
    --title="Translate" --window-icon="gtk-refresh" --splitter=350 --orient=hor
rm -f /tmp/trans_tray/run_trans
#exec 3>&-


EDIT: few hours later, edited the code a little.

Fred
2019-08-28-182611_802x629_scrot_702x551.png
 Description   
 Filesize   46.63 KB
 Viewed   95 Time(s)

2019-08-28-182611_802x629_scrot_702x551.png


_________________
Dog Linux website
Tinylinux blog by wiak
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 2 of 7 [100 Posts]   Goto page: Previous 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.0666s ][ Queries: 12 (0.0075s) ][ GZIP on ]