Trans_tray translation program

Moderator: Forum moderators

User avatar
fredx181
Posts: 3089
Joined: Tue Dec 03, 2019 1:49 pm
Location: holland
Has thanked: 376 times
Been thanked: 1316 times
Contact:

Trans_tray translation program

Post by fredx181 »

UPDATE: New trans-tray v1.2, some changes, see info here: viewtopic.php?p=59111#p59111

trans-tray-1.2.0_noarch.pet
trans_tray pet v1.2
(68.02 KiB) Downloaded 96 times

--------------------------------------------------------------------------------------------------------
Hi All, attached "trans-tray_1.1.0_noarch.pet" (earlier shared Here) including the latest trans_tray version (v6) and 'trans' see https://github.com/soimort/translate-shell
Development thread: http://murga-linux.com/puppy/viewtopic.php?t=116794 (thanks to stemsee, vovchik, Argolance and others)

After install it appears in menu category 'Utility'

Requirements:
- gawk (version 4.0 or higher)
Check the gawk version with:

Code: Select all

gawk -V	

(most modern Puppies should have it)
- yad (version 0.37 or higher)
(if you have lower version of yad, .pet packages version 0.40 attached below)
- xclip (most puppies have it included)
As stated above the 'trans' script is included in the pet (/usr/local/bin/trans)

Usage: From right-click icon > Help:
----------------------------------------------------------------------------------
*** Trans-tray usage help ***
1
Make your preferred settings by right clicking on the icon and:
- Select translator, e.g. Google, Bing, Yandex (or All).
(note that Yandex may not work often)
- Select language(s) you wish to translate to (Select target language ...), a list will appear then, selecting multiple languages is supported.

- Select some text (no need to copy, just select it), e.g. in browser or text file.
Then by left-clicking the icon, a window will appear with the translated text.

- From menu (right-click) there are some other options, e.g:
- Preferences, to change some default settings, set text-editor
- Translate webpage
- Dialogue mode for translating to two languages of choice side by side
- Set keyboard layout (temporarily)

For installing or upgrading 'trans', select from Menu 'Install/Upgrade trans'.
Required also is to have 'xclip' installed.
----------------------------------------------------------------------------------

trans_tray menu
trans_tray menu
2019-09-22-121927_387x399_scrot.png (176.94 KiB) Viewed 2627 times

Fred

Attachments
trans-tray-1.1.0_noarch.pet
trans_tray pet
(67.44 KiB) Downloaded 92 times
yad-0.40-i686.pet
yad v0.40
(70.82 KiB) Downloaded 69 times
yad-0.40-amd64.pet
yad v0.40
(74.3 KiB) Downloaded 64 times
User avatar
stemsee
Posts: 779
Joined: Sun Jul 26, 2020 8:11 am
Location: lattitude 8
Has thanked: 185 times
Been thanked: 131 times

Re: Trans_tray translation program

Post by stemsee »

Hi Fred

Here is dialogue function with changes to accomodate espeak and xvkbdconf ... have a play!

Code: Select all

function trans_dialogue () {
[ -f  $HOME/.trans_tray/prefs ] && . $HOME/.trans_tray/prefs
[ "$ON_TOP" = "TRUE" ] && export ONTOP="--on-top"

export LANGUAGES='Afrikaans - af!Albanian - sq!Amharic - am!Arabic - ar!Armenian - hy!Azerbaijani - az!Basque - eu!Belarusian - be!Bengali - bn!Bosnian - bs!Bulgarian - bg!Cantonese - yue!Catalan - ca!Cebuano - ceb!Chichewa - ny!Chinese(Simple) - zh-CN!Chinese(Trad) - zh-TW!Corsican - co!Croatian - hr!Czech - cs!Danish - da!Dutch - nl!English - en!Esperanto - eo!Estonian - et!Fijian - fj!Filipino - tl!Finnish - fi!French - fr!Frisian - fy!Galician - gl!Georgian - ka!German - de!Greek - el!Gujarati - gu!Haitian-Creole - ht!Hausa - ha!Hawaiian - haw!Hebrew - he!Hindi - hi!Hmong - hmn!Hmong-Daw - mww!Hungarian - hu!Icelandic - is!Igbo - ig!Indonesian - id!Irish - ga!Italian - it!Japanese - ja!Javanese - jv!Kannada - kn!Kazakh - kk!Khmer - km!Klingon - tlh!Korean - ko!Kurdish - ku!Kyrgyz - ky!Lao - lo!Latin - la!Latvian - lv!Lithuanian - lt!Luxembourgish - lb!Macedonian - mk!Malagasy - mg!Malay - ms!Malayalam - ml!Maltese - mt!Maori - mi!Marathi - mr!Mongolian - mn!Myanmar - my!Nepali - ne!Norwegian - no!Pashto - ps!Persian - fa!Polish - pl!Portuguese - pt!Punjabi - pa!Queretaro-Otomi - otq!Roman - rm!Romanian - ro!Russian - ru!Samoan - sm!Scots-Gaelic - gd!Serbian(Cyr) - sr-Cyrl!Serbian(Latin) - sr-Latn!Sesotho - st!Shona - sn!Sindhi - sd!Sinhala - si!Slovak - sk!Slovenian - sl!Somali - so!Spanish - es!Sundanese - su!Swahili - sw!Swedish - sv!Tahitian - ty!Tajik - tg!Tamil - ta!Tatar - tt!Telugu - te!Thai - th!Tongan - to!Turkish - tr!Udmurt - udm!Ukrainian - uk!Urdu - ur!Uzbek - uz!Vietnamese - vi!Welsh - cy!Xhosa - xh!Yiddish - yi!Yoruba - yo!Yucatec-Maya - yua!Zulu - zu'

export run_acmd='@bash -c "run_dtrans1 %1 %2 %3 %4"'
export run_bcmd='@bash -c "run_dtrans2 %1 %2 %3 %4"'

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

trap "rm -f $fpipe $dpipe /tmp/trans_tray/run_trans1 /tmp/trans_tray/run_trans2" EXIT

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

function run_trans_save {
if [[ ! -f /tmp/trans_tray/run_trans1 && ! -f /tmp/trans_tray/run_trans2 ]]; then
exit
fi
DATE=$(date +"%Y%m%d_%H%M%S")
TRANS1="$(cat /tmp/trans_tray/run_trans1 2> /dev/null)"
TRANS2="$(cat /tmp/trans_tray/run_trans2 2> /dev/null)"
if [ -n "$TRANS1" ]; then 
echo -e "$TRANS1\n\n$TRANS2" > $HOME/.trans_tray/savedtexts/transD-$DATE
else
echo -e "$TRANS2" > $HOME/.trans_tray/savedtexts/transD-$DATE
fi
#cp -a /tmp/trans_tray/run_trans  $HOME/.trans_tray/savedtexts/transD-$DATE
yad --title="Translation saved"  --fontname="$FONT" --borders=6 --window-icon=$ICON --text="  <b>Saved to ~/.trans_tray/savedtexts/trans-$DATE </b>" --geometry=500x35-40-70 --undecorated --timeout 5 --no-buttons $ONTOP
bash -c refresh
}
export -f run_trans_save

function run_dtrans1
{
    echo "4:@disable@"
export TLANG1="$1"
export _TLANG1=$(echo "$1" | awk '{print $1}')
echo $TLANG1 > $HOME/.trans_tray/.trans_target_lang3
[ -z "$TLANG1" ] && export TLANG1="English - en"
[ -z "$_TLANG1" ] && export _TLANG1="English"
export ENGINE=$(cat $HOME/.trans_tray/_trans_engine_2 2> /dev/null)
[ -z "$ENGINE" ] && ENGINE=google

[ -n "$2" ] && export TTEXT="$2" || exit

# echo -e '\f' >> "$fpipe"
echo -e "$TLANG1!$LANGUAGES" >> $fpipe
echo -e ""  >> "$fpipe"

T_TEXT=$(for ex in $ENGINE
do
#echo "icon:/tmp/$ex.svg" >$PIPE
echo "----- $ex translate to $(echo $TLANG1 | awk '{print $1}') -----"
echo -e "$TTEXT" | trans -e $ex -b -tl $(echo $TLANG1 | awk '{print $NF}'); done)
echo -e "$T_TEXT" > /tmp/trans_tray/run_trans1
T_TEXT=$(while read -r line; do printf "%s" "$line\n"; done <<< "$T_TEXT")
printf "%s\n" "$T_TEXT" | sed s'/\\n$//' >> $fpipe
 
  echo "$run_acmd" >> $fpipe
    echo "4:$run_acmd"
}; export -f run_dtrans1

function run_dtrans2
{
    echo "4:@disabled@"
export TLANG2="$1"
export _TLANG2=$(echo "$1" | awk '{print $1}')
echo $TLANG2 > $HOME/.trans_tray/.trans_target_lang4
[ -z "$TLANG2" ] && export TLANG2="English - en"
[ -z "$_TLANG2" ] && export _TLANG2="English"
export ENGINE=$(cat $HOME/.trans_tray/_trans_engine_2 2> /dev/null)
[ -z "$ENGINE" ] && ENGINE=google

[ -n "$2" ] && export TTEXT="$2" || exit

#echo -e '\f' >> "$dpipe"
echo -e "$TLANG2!$LANGUAGES" >> $dpipe
echo -e ""  >> "$dpipe"

T_TEXT=$(for ex in $ENGINE
do
#echo "icon:/tmp/$ex.svg" >$PIPE
echo "----- $ex translate to $(echo $TLANG2 | awk '{print $1}') -----"
echo -e "$TTEXT" | trans -e $ex -b -tl $(echo $TLANG2 | awk '{print $NF}'); done)
echo -e "$T_TEXT" > /tmp/trans_tray/run_trans2
T_TEXT=$(while read -r line; do printf "%s" "$line\n"; done <<< "$T_TEXT")
printf "%s\n" "$T_TEXT" | sed s'/\\n$//' >> $dpipe
 
  echo "$run_bcmd" >> $dpipe
    echo "4:$run_bcmd"
}; export -f run_dtrans2

clear_all () {
echo -e '\f' > $fpipe
bash -c clearA &
bash -c ClearB
rm -f /tmp/trans_tray/run_trans1 /tmp/trans_tray/run_trans2
}; export -f clear_all

clearA (){
	echo -e '\f' > $fpipe
TLANG=$(cat $HOME/.trans_tray/.trans_target_lang3 2> /dev/null)
[ -z "$TLANG" ] && export TLANG="English - en"
echo -e "$TLANG!$LANGUAGES"  >> $fpipe
echo -e ""  >> $fpipe
echo -e ""  >> $fpipe
   echo "$run_acmd" >> $fpipe
rm -f /tmp/trans_tray/run_trans1
}; export -f clearA

ClearB (){
   echo -e "\f"  >> $dpipe
TLANG=$(cat $HOME/.trans_tray/.trans_target_lang4 2> /dev/null)
[ -z "$TLANG" ] && export TLANG="English - en"
echo -e "$TLANG!$LANGUAGES"  >> $dpipe
echo -e ""  >> $dpipe
echo -e ""  >> $dpipe
   echo "$run_bcmd" >> $dpipe
rm -f /tmp/trans_tray/run_trans2
}; export -f ClearB

export TLANG1=$(cat $HOME/.trans_tray/.trans_target_lang3 2> /dev/null)
export _TLANG1=$(cat $HOME/.trans_tray/.trans_target_lang3 2> /dev/null | awk '{print $1}')
[ -z "$TLANG1" ] && export TLANG1="English - en"
[ -z "$_TLANG1" ] && export _TLANG1="English"

export TLANG2=$(cat $HOME/.trans_tray/.trans_target_lang4 2> /dev/null)
export _TLANG2=$(cat $HOME/.trans_tray/.trans_target_lang4 2> /dev/null | awk '{print $1}')
[ -z "$TLANG2" ] && export TLANG2="English - en"
[ -z "$_TLANG2" ] && export _TLANG2="English"

exec 5<> $fpipe
exec 6<> $dpipe

echo -e '\f' >&5
echo -e "$TLANG1!$LANGUAGES" >> $fpipe
echo -e "" >&5
echo -e "" >&5
echo "$run_acmd" >&5

echo -e '\f' >&6
echo -e "$TLANG2!$LANGUAGES" >> $dpipe
echo -e "" >&6
echo -e "" >&6
echo "$run_bcmd" >&6

yad --plug="$fkey" --tabnum=1  --fontname="$FONT" --listen --form --enable-spell --cycle-read --field="Target language:CB" --field="<b>A:</b>  Input/paste:TXT"  --field="    Translation:TXT"  --field="Translate!gtk-refresh:fbtn" <&5 &
yad --plug="$fkey" --tabnum=2  --fontname="$FONT" --listen --form --enable-spell --cycle-read --field="Target language:CB" --field="<b>B:</b>  Input/paste:TXT"  --field="    Translation:TXT"  --field="Translate!gtk-refresh:fbtn" <&6 &
yad --key=$fkey --title="Dialogue mode" --fontname="$FONT"  --window-icon="$ICON" --splitter=350 --width=700 --height=600 --paned --tab=AB --tab=BA --orient=hori --buttons-layout=center --button="Kybrd":"bash -c xvkbdconf" --button="eSpeak+ipa":"bash -c trans_speak" --button="Clear A:bash -c clearA" --button="Clear B:bash -c ClearB" --button="SaveAll:bash -c run_trans_save" --button="ClearAll!gtk-clear:bash -c clear_all" --button="Close!gtk-close:1" $ONTOP
#rm -f /tmp/trans_tray/run_trans
}; export -f trans_dialogue
User avatar
stemsee
Posts: 779
Joined: Sun Jul 26, 2020 8:11 am
Location: lattitude 8
Has thanked: 185 times
Been thanked: 131 times

Re: Trans_tray translation program

Post by stemsee »

Here is a cutdown version of xvkbdconf, feel free to add its essentials as a function to trans_tray if you think its appropriate.

Code: Select all

export res=`xwininfo -root | grep 'geometry' | awk '{print $2}' | cut -f1 -d'+'`
export XX=`echo $res | cut -f1 -d'x'`
export YY=`echo $res | cut -f2 -d'x'`
export pos="$((XX / 4))+$(((YY / 2) + XX / 16))"

running=`ps -e | grep xvkbd | wc -l` 
if [[ "$running" -gt 2 ]]; then
	killall xvkbd #check if running, one instance only
else
	xvkbd -geometry $((XX / 2))x$((XX / 5))+"$pos" -no-keypad -always-on-top &
fi
User avatar
stemsee
Posts: 779
Joined: Sun Jul 26, 2020 8:11 am
Location: lattitude 8
Has thanked: 185 times
Been thanked: 131 times

Re: Trans_tray translation program

Post by stemsee »

I forgot to provide the trans_speak functions

Code: Select all

function trans_speak (){

function espeakfn1 (){
case $1 in
A) TLANG=`cat $HOME/.trans_tray/.trans_target_lang3 | cut -f1 -d' '`;;
B) TLANG=`cat $HOME/.trans_tray/.trans_target_lang4 | cut -f1 -d' '`;;
esac
case $TLANGA in
Afrikaans|afrikaans) lnga=af;;
Aragonese|aragonese) lnga=an;;
Bulgarian|bulgarian) lnga=bg;;
Bosnian|bosnian) lnga=bs;;
Catalan|catalan) lnga=ca;;
Czech|czech) lnga=cs;;
Welsh|welsh) lnga=cy;;
Danish|danish) lnga=da;;
German|german) lnga=de;;
Greek|greek) lnga=el;;
English|default) lnga=en;;
english) lnga=en-gb;;
Scottish|en-scottish) lnga=en-sc;;
Northern|english-north) lnga=en-uk-north;;
English-UK|english_rp) lnga=en-uk-rp;;
Midlands|english_wmids) lnga=en-uk-wmids;;
English-US|english-us) lnga=en-us;;
WestIndian|en-westindies) lnga=en-wi;;
Esperanto|esperanto) lnga=eo;;
Spanish|spanish) lnga=es;;
Spanish-la|spanish-latin-am) lnga=es-la;;
Estonian|estonian) lnga=et;;
Farsi|Persian|persian) lnga=fa;;
Pinglish|persian-pinglish) lnga=fa-pin;;
Finnish|finnish) lnga=fi;;
Frencg-blg|french-Belgium) lnga=fr-be;;
French|french) lnga=fr-fr;;
Irish|Gaelic|irish-gaeilge) lnga=ga;;
Greek-trad|greek-ancient) lnga=grc;;
Hindi|hindi) lnga=hi;;
Croatian|croatian) lnga=hr;;
Hungariann|hungarian) lnga=hu;;
Armenian|armenian) lnga=hy;;
Armenian-w|armenian-west) lnga=hy-west;;
Indonesian|indonesian) lnga=id;;
Icelandic|icelandic) lnga=is;;
Italian|italian) lnga=it;;
Lojban|lojban) lnga=jbo;;
Georgian|georgian) lnga=ka;;
Kannada|kannada) lnga=kn;;
Kurdish|kurdish) lnga=ku;;
Latin|latin) lnga=la;;
Lingua-Franca-Nova|lingua_franca_nova) lnga=lfn;;
Lithuanian|lithuanian) lnga=lt;;
Latvian|latvian) lnga=lv;;
Macedonian|macedonian) lnga=mk;;
Malayalam|malayalam) lnga=ml;;
Malay|malay) lnga=ms;;
Nepalese|nepali) lnga=ne;;
Dutch|dutch) lnga=nl;;
Norwegian|norwegian) lnga=no;;
Punjabi|punjabi) lnga=pa;;
Polish|polish) lnga=pl;;
Brazillian|brazil) lnga=pt-br;;
Portuguese|portugal) lnga=pt-pt;;
Romanian|romanian) lnga=ro;;
Russian|russian) lnga=ru;;
Slovakian|slovak) lnga=sk;;
Albanian|albanian) lnga=sq;;
Serbian|serbian) lnga=sr;;
Swedish|swedish) lnga=sv;;
Swahili|swahili-test) lnga=sw;;
Tamil|tamil) lnga=ta;;
Turkish|turkish) lnga=tr;;
Vietnamese|vietnam) lnga=vi;;
Vietnamese-hue|vietnam_hue) lnga=vi-hue;;
Vietnamese-sgn|vietnam_sgn) lnga=vi-sgn;;
Chinese*Simple*|Pudonghua|Mandarin|chinese|Chinese) lnga=zh;;
Chinese*Trad*|Cantonese|cantonese) lnga=zh-yue;;
esac
lnga
tail -fn0 /tmp/trans_tray/run_trans1 | while read line; do espeak -v $lnga "$line" --ipa --phonout=/tmp/trans_tray/yspk; done &
export tspk=$!
}; export -f espeakfn1

function espeakfn2 (){
lngb=`echo "$1" | cut -f3 -d' ' | cut -f1 -d'|'`
espeak -v $lngb "$(xclip -o)" --ipa --phonout=/tmp/trans_tray/yspk &
export spkt=$!
}; export -f espeakfn2

[ ! -d /tmp/trans_tray ] && mkdir -p /tmp/trans_tray
[ ! -e /tmp/trans_tray/yspk ] && mkfifo /tmp/trans_tray/yspk
exec 2<> /tmp/trans_tray/yspk

echo "afrikaans - af
aragonese - an
bulgarian - bg
bosnian - bs
catalan - ca
czech - cs
welsh - cy
danish - da
german - de
greek - el
default - en
english - en-gb
en-scottish - en-sc
english-north - en-uk-north
english_rp - en-uk-rp
english_wmids - en-uk-wmids
english-us - en-us
en-westindies - en-wi
esperanto - eo
spanish - es
spanish-latin-am - es-la
estonian - et
persian - fa
persian-pinglish - fa-pin
finnish - fi
french-Belgium - fr-be
french - fr-fr
irish-gaeilge - ga
greek-ancient - grc
hindi - hi
croatian - hr
hungarian - hu
armenian - hy
armenian-west - hy-west
indonesian - id
icelandic - is
italian - it
lojban - jbo
georgian - ka
kannada - kn
kurdish - ku
latin - la
lingua_franca_nova - lfn
lithuanian - lt
latvian - lv
macedonian - mk
malayalam - ml
malay - ms
nepali - ne
dutch - nl
norwegian - no
punjabi - pa
polish - pl
brazil - pt-br
portugal - pt-pt
romanian - ro
russian - ru
slovak - sk
albanian - sq
serbian - sr
swedish - sv
swahili-test - sw
tamil - ta
turkish - tr
vietnam - vi
vietnam_hue - vi-hue
vietnam_sgn - vi-sgn
Mandarin - zh
cantonese - zh-yue" >/tmp/trans_tray/yspk

yad --title="eSpeak Text-to-Speech" \
--text="Use with Trans_Tray dialogue-mode Or Standalone to read copied \
text\nSimply select from language list to change accent or read in text language \
\n\nPhonetics are appended in/to the language list view" \
--list --editable --column=SpokenLanguage  --fontname="$FONT" --select-action="bash -c 'espeakfn2 %s'" \
--center --width=400 --height=400 --button="Dialogue Speech Off":"bash -c 'kill $tspk'" \
--button="Dialogue A":"bash -c 'espeakfn1 A'"  --button="Dialogue B":"bash -c 'espeakfn1 B'" --listen <&2 &
}; export -f trans_speak
User avatar
stemsee
Posts: 779
Joined: Sun Jul 26, 2020 8:11 am
Location: lattitude 8
Has thanked: 185 times
Been thanked: 131 times

Re: Trans_tray translation program

Post by stemsee »

Fred

I have fixed a few things in trans_tray, or rather completed code I submitted.... i.e. saved trans texts pop up menu. Has 7 functioning entries.

Also I have modified the script to use a variable for the copy command (CLIP=`xclip -o -p`) in case xsel or clipit is installed and not xclip.

xsel and xclip seem interchangeable 'xsel -o -p' 'xclip -o -p', and adding 'clipit -p' would allow trans_tray to run on woofce pups with clipit.

Any thoughts?
stemsee

trans_tray.gz
(86 KiB) Downloaded 65 times
Attachments
trans-popup-menu.png
trans-popup-menu.png (18.47 KiB) Viewed 2465 times
User avatar
stemsee
Posts: 779
Joined: Sun Jul 26, 2020 8:11 am
Location: lattitude 8
Has thanked: 185 times
Been thanked: 131 times

Re: Trans_tray translation program

Post by stemsee »

This is a fixupdate should run on any dog or pup with xsel or xclip or clipit.

--splitter sometimes needs a negative value.
--fontname added to all yad calls.

Savedtexts double-click menu reorganised.

trans-tray-1.1.1_noarch.sfs
(64 KiB) Downloaded 73 times
User avatar
stemsee
Posts: 779
Joined: Sun Jul 26, 2020 8:11 am
Location: lattitude 8
Has thanked: 185 times
Been thanked: 131 times

Re: Trans_tray translation program

Post by stemsee »

I have re-worked the dialogue function so that it is possible to clear any text field A1 A2 B1 B2, and save 'A1 A2' and 'B1 B2' fields.

Code: Select all


function trans_dialogue () {
[ -f  "$camino"/prefs ] && . "$camino"/prefs
[ "$ON_TOP" = "TRUE" ] && export ONTOP="--on-top"

export LANGUAGES='Afrikaans - af!Albanian - sq!Amharic - am!Arabic - ar!Armenian - hy!Azerbaijani - az!Basque - eu!Belarusian - be!Bengali - bn!Bosnian - bs!Bulgarian - bg!Cantonese - yue!Catalan - ca!Cebuano - ceb!Chichewa - ny!Chinese(Simple) - zh-CN!Chinese(Trad) - zh-TW!Corsican - co!Croatian - hr!Czech - cs!Danish - da!Dutch - nl!English - en!Esperanto - eo!Estonian - et!Fijian - fj!Filipino - tl!Finnish - fi!French - fr!Frisian - fy!Galician - gl!Georgian - ka!German - de!Greek - el!Gujarati - gu!Haitian-Creole - ht!Hausa - ha!Hawaiian - haw!Hebrew - he!Hindi - hi!Hmong - hmn!Hmong-Daw - mww!Hungarian - hu!Icelandic - is!Igbo - ig!Indonesian - id!Irish - ga!Italian - it!Japanese - ja!Javanese - jv!Kannada - kn!Kazakh - kk!Khmer - km!Klingon - tlh!Korean - ko!Kurdish - ku!Kyrgyz - ky!Lao - lo!Latin - la!Latvian - lv!Lithuanian - lt!Luxembourgish - lb!Macedonian - mk!Malagasy - mg!Malay - ms!Malayalam - ml!Maltese - mt!Maori - mi!Marathi - mr!Mongolian - mn!Myanmar - my!Nepali - ne!Norwegian - no!Pashto - ps!Persian - fa!Polish - pl!Portuguese - pt!Punjabi - pa!Queretaro-Otomi - otq!Roman - rm!Romanian - ro!Russian - ru!Samoan - sm!Scots-Gaelic - gd!Serbian(Cyr) - sr-Cyrl!Serbian(Latin) - sr-Latn!Sesotho - st!Shona - sn!Sindhi - sd!Sinhala - si!Slovak - sk!Slovenian - sl!Somali - so!Spanish - es!Sundanese - su!Swahili - sw!Swedish - sv!Tahitian - ty!Tajik - tg!Tamil - ta!Tatar - tt!Telugu - te!Thai - th!Tongan - to!Turkish - tr!Udmurt - udm!Ukrainian - uk!Urdu - ur!Uzbek - uz!Vietnamese - vi!Welsh - cy!Xhosa - xh!Yiddish - yi!Yoruba - yo!Yucatec-Maya - yua!Zulu - zu'

export savecmndA='@bash -c "saveA %2 %3"'
export savecmndB='@bash -c "saveB %2 %3"'
export run_acmd='@bash -c "run_dtrans1 %1 %2 %3"'
export run_bcmd='@bash -c "run_dtrans2 %1 %2 %3"'

export fpipe="$track/run_trans.$RANDOM"
mkfifo "$fpipe"
export dpipe="$track/run_trans.$RANDOM"
mkfifo "$dpipe"

trap "rm -f $fpipe $dpipe "$track"/run_trans1 "$track"/run_trans2" EXIT

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

function saveA {
if [[ -z "$1" && -z "$2" ]]; then
	exit
fi
DATE=$(date +"%Y%m%d_%H%M%S")
echo -e "$1\n$2" > "$camino"/savedtexts/transD-$DATE
yad --title="Translation saved" --borders=6 --window-icon=$ICON --text="  <b>Saved to ~/.trans_tray/savedtexts/transD-$DATE </b>" --geometry=500x35-40-70 --undecorated --timeout 5 --no-buttons $ONTOP
bash -c refresh
}
export -f saveA

function saveB {
if [[ -z "$1" && -z "$2" ]]; then
	exit
fi
DATE=$(date +"%Y%m%d_%H%M%S")
echo -e "$1\n$2" > "$camino"/savedtexts/transD-$DATE
yad --title="Translation saved" --borders=6 --window-icon=$ICON --text="  <b>Saved to ~/.trans_tray/savedtexts/transD-$DATE </b>" --geometry=500x35-40-70 --undecorated --timeout 5 --no-buttons $ONTOP
bash -c refresh
}
export -f saveB

function run_dtrans1
{
echo "4:@disable@"
export TLANG1="$1"
export _TLANG1=$(echo "$1" | awk '{print $1}')
echo $TLANG1 > "$camino"/.trans_target_lang3
[ -z "$TLANG1" ] && export TLANG1="English - en"
[ -z "$_TLANG1" ] && export _TLANG1="English"
export ENGINE=$(cat "$camino"/_trans_engine_2 2> /dev/null)
[ -z "$ENGINE" ] && ENGINE=google

[ -n "$2" ] && export TTEXT="$2" || exit

echo -e "$TLANG1!$LANGUAGES" >> $fpipe
echo -e ""  >> "$fpipe"

T_TEXT=$(for ex in $ENGINE
do
echo "----- $ex translate to $(echo $TLANG1 | awk '{print $1}') -----"
echo -e "$TTEXT" | trans -e $ex -b -tl $(echo $TLANG1 | awk '{print $NF}'); done)
echo -e "$T_TEXT" > "$track"/run_trans1
T_TEXT=$(while read -r line; do printf "%s" "$line\n"; done <<< "$T_TEXT")
printf "%s\n" "$T_TEXT" | sed s'/\\n$//' >> $fpipe
 
  echo "$run_acmd" >> $fpipe
  echo "$savecmndA" >> $fpipe
  echo "4:$run_acmd"
}; export -f run_dtrans1

function run_dtrans2
{
echo "4:@disable@"
export TLANG2="$1"
export _TLANG2=$(echo "$1" | awk '{print $1}')
echo $TLANG2 > "$camino"/.trans_target_lang4
[ -z "$TLANG2" ] && export TLANG2="English - en"
[ -z "$_TLANG2" ] && export _TLANG2="English"
export ENGINE=$(cat "$camino"/_trans_engine_2 2> /dev/null)
[ -z "$ENGINE" ] && ENGINE=google

[ -n "$2" ] && export TTEXT="$2" || exit

echo -e "$TLANG2!$LANGUAGES" >> $dpipe
echo -e ""  >> "$dpipe"

T_TEXT=$(for ex in $ENGINE
do
#echo "icon:/tmp/$ex.svg" >$PIPE
echo "----- $ex translate to $(echo $TLANG2 | awk '{print $1}') -----"
echo -e "$TTEXT" | trans -e $ex -b -tl $(echo $TLANG2 | awk '{print $NF}'); done)
echo -e "$T_TEXT" > "$track"/run_trans2
T_TEXT=$(while read -r line; do printf "%s" "$line\n"; done <<< "$T_TEXT")
printf "%s\n" "$T_TEXT" | sed s'/\\n$//' >> $dpipe
 
  echo "$run_bcmd" >> $dpipe
  echo "$savecmndB" >> $dpipe
  echo "4:$run_bcmd"
}; export -f run_dtrans2
function clearfn
{
	case $1 in
A1) printf "%s\n%s\n%s\n%s\n%s\n" '' '\' '' '' '' > "$fpipe";; 
A2) printf "%s\n%s\n%s\n%s\n%s\n" '' '' '\' '' '' > "$fpipe";;
B1) printf "%s\n%s\n%s\n%s\n%s\n" '' '\' '' '' '' > "$dpipe";;
B2) printf "%s\n%s\n%s\n%s\n%s\n" '' '' '\' '' '' > "$dpipe";;
ALL) printf "%s\n%s\n%s\n%s\n%s\n" '' '\' '\' '' '' > "$fpipe"
printf "%s\n%s\n%s\n%s\n%s\n" '' '\' '\' '' '' > "$dpipe";; 

esac
}; export -f clearfn
export TLANG1=$(cat "$camino"/.trans_target_lang3 2> /dev/null)
export _TLANG1=$(cat "$camino"/.trans_target_lang3 2> /dev/null | awk '{print $1}')
[ -z "$TLANG1" ] && export TLANG1="English - en"
[ -z "$_TLANG1" ] && export _TLANG1="English"

export TLANG2=$(cat "$camino"/.trans_target_lang4 2> /dev/null)
export _TLANG2=$(cat "$camino"/.trans_target_lang4 2> /dev/null | awk '{print $1}')
[ -z "$TLANG2" ] && export TLANG2="English - en"
[ -z "$_TLANG2" ] && export _TLANG2="English"

exec 5<> $fpipe
exec 6<> $dpipe

echo -e '\f' >&5
echo -e "$TLANG1!$LANGUAGES" >> $fpipe
echo -e "" >&5
echo -e "" >&5
echo "$run_acmd" >&5
echo "$savecmndA" >&5

echo -e '\f' >&6
echo -e "$TLANG2!$LANGUAGES" >> $dpipe
echo -e "" >&6
echo -e "" >&6
echo "$run_bcmd" >&6
echo "$savecmndB" >&6

yad --plug="$fkey" --tabnum=1 --listen --fontname="$FONT" --form --cycle-read --field="Target language:CB" --field="<b>A1:</b>  Input/paste:TXT"  --field="<b>A2:</b>    Translation:TXT"  --field="Translate!gtk-refresh:fbtn" --field="Save!gtk-save:fbtn" <&5 &
yad --plug="$fkey" --tabnum=2 --listen --fontname="$FONT" --form --cycle-read --field="Target language:CB" --field="<b>B1:</b>  Input/paste:TXT"  --field="<b>B2:</b>    Translation:TXT"  --field="Translate!gtk-refresh:fbtn" --field="Save!gtk-save:fbtn" <&6 &
yad --key=$fkey --title="Dialogue mode" --window-icon="$ICON" --width=700 --height=600 --paned --tab=AB --tab=BA --orient=hori --buttons-layout=center --button="Clear A1:bash -c 'clearfn A1'" --button="Clear A2:bash -c 'clearfn A2'" --button="Clear B1:bash -c 'clearfn B1'" --button="Clear B2:bash -c 'clearfn B2'" --button="ClearAll!gtk-clear:bash -c 'clearfn ALL'" --button="Close!gtk-close:1" $ONTOP
}; export -f trans_dialogue
Attachments
TTD.png
TTD.png (30.86 KiB) Viewed 2304 times
Last edited by stemsee on Fri Jun 03, 2022 5:46 pm, edited 1 time in total.
User avatar
mikeslr
Posts: 2968
Joined: Mon Jul 13, 2020 11:08 pm
Has thanked: 179 times
Been thanked: 924 times

Re: It's not broken > Read the instructions

Post by mikeslr »

fredx181 and stemsee has done a phenomenal job. But I thought mine wasn't working. :( To try to figure out why I decided to read this thread from the beginning. You know what they say: "When in doubt, read the manual." :lol:
Most of how to use it is spelled out in the OP. Others in stemsee's couple of posts above :idea: READ THEM. Some things are not intuitive.

User avatar
stemsee
Posts: 779
Joined: Sun Jul 26, 2020 8:11 am
Location: lattitude 8
Has thanked: 185 times
Been thanked: 131 times

Re: Trans_tray translation program

Post by stemsee »

After using the transdialogue function for a few days I made further improvements and additions.
1) The translate button now appears between text fields.
2) clear all button removed and replaced by an Exec button that executes selected command and prints result to B2
3) Added espeak button which reads aloud selected text using language code from group B (right side) language selector selector and prints phonetic output to B2
4) Reduced 'Target Language' to 'TL' in gui allows a smaller footprint.
5) fixed a missing backslash in clearfn
6) the 'trans' script which does all the google api stuff has many features not yet explored by Trans_Tray. But dictionary lookup is now avalable. Add '#' as the first character followed by one two or three words, these will be looked up and dictionary entries will be shown for each word in turn.

Code: Select all

function trans_dialogue
{
[ -f  "$camino"/prefs ] && . "$camino"/prefs
[ "$ON_TOP" = "TRUE" ] && export ONTOP="--on-top"

export LANGUAGES='Afrikaans - af!Albanian - sq!Amharic - am!Arabic - ar!Armenian - hy!Azerbaijani - az!Basque - eu!Belarusian - be!Bengali - bn!Bosnian - bs!Bulgarian - bg!Cantonese - yue!Catalan - ca!Cebuano - ceb!Chichewa - ny!Chinese(Simple) - zh-CN!Chinese(Trad) - zh-TW!Corsican - co!Croatian - hr!Czech - cs!Danish - da!Dutch - nl!English - en!Esperanto - eo!Estonian - et!Fijian - fj!Filipino - tl!Finnish - fi!French - fr!Frisian - fy!Galician - gl!Georgian - ka!German - de!Greek - el!Gujarati - gu!Haitian-Creole - ht!Hausa - ha!Hawaiian - haw!Hebrew - he!Hindi - hi!Hmong - hmn!Hmong-Daw - mww!Hungarian - hu!Icelandic - is!Igbo - ig!Indonesian - id!Irish - ga!Italian - it!Japanese - ja!Javanese - jv!Kannada - kn!Kazakh - kk!Khmer - km!Klingon - tlh!Korean - ko!Kurdish - ku!Kyrgyz - ky!Lao - lo!Latin - la!Latvian - lv!Lithuanian - lt!Luxembourgish - lb!Macedonian - mk!Malagasy - mg!Malay - ms!Malayalam - ml!Maltese - mt!Maori - mi!Marathi - mr!Mongolian - mn!Myanmar - my!Nepali - ne!Norwegian - no!Pashto - ps!Persian - fa!Polish - pl!Portuguese - pt!Punjabi - pa!Queretaro-Otomi - otq!Roman - rm!Romanian - ro!Russian - ru!Samoan - sm!Scots-Gaelic - gd!Serbian(Cyr) - sr-Cyrl!Serbian(Latin) - sr-Latn!Sesotho - st!Shona - sn!Sindhi - sd!Sinhala - si!Slovak - sk!Slovenian - sl!Somali - so!Spanish - es!Sundanese - su!Swahili - sw!Swedish - sv!Tahitian - ty!Tajik - tg!Tamil - ta!Tatar - tt!Telugu - te!Thai - th!Tongan - to!Turkish - tr!Udmurt - udm!Ukrainian - uk!Urdu - ur!Uzbek - uz!Vietnamese - vi!Welsh - cy!Xhosa - xh!Yiddish - yi!Yoruba - yo!Yucatec-Maya - yua!Zulu - zu'

export savecmndA='@bash -c "saveA %2 %4"'
export savecmndB='@bash -c "saveB %2 %4"'
export run_acmd='@bash -c "run_dtrans1 %1 %2"'
export run_bcmd='@bash -c "run_dtrans2 %1 %2"'

export fpipe="$track/run_trans.$RANDOM"
mkfifo "$fpipe"
export dpipe="$track/run_trans.$RANDOM"
mkfifo "$dpipe"

trap "rm -f $fpipe $dpipe "$track"/run_trans1 "$track"/run_trans2" EXIT

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

function saveA {
if [[ -z "$1" && -z "$2" ]]; then
	exit
fi
DATE=$(date +"%Y%m%d_%H%M%S")
echo -e "$1\n$2" > "$camino"/savedtexts/transD-$DATE
yad --title="Translation saved" --borders=6 --window-icon=$ICON --text="  <b>Saved to ~/.trans_tray/savedtexts/transD-$DATE </b>" --geometry=500x35-40-70 --undecorated --timeout 1 --no-buttons $ONTOP
bash -c refresh
}
export -f saveA

function saveB {
if [[ -z "$1" && -z "$2" ]]; then
	exit
fi
DATE=$(date +"%Y%m%d_%H%M%S")
echo -e "$1\n$2" > "$camino"/savedtexts/transD-$DATE
yad --title="Translation saved" --borders=6 --window-icon=$ICON --text="  <b>Saved to ~/.trans_tray/savedtexts/transD-$DATE </b>" --geometry=500x35-40-70 --undecorated --timeout 1 --no-buttons $ONTOP
bash -c refresh
}
export -f saveB

function run_dtrans1
{
#echo "4:@disable@"
export TLANG1="$1"
export _TLANG1=$(echo "$1" | awk '{print $1}')
echo $TLANG1 > "$camino"/.trans_target_lang3
[ -z "$TLANG1" ] && export TLANG1="English - en"
[ -z "$_TLANG1" ] && export _TLANG1="English"
export ENGINE=$(cat "$camino"/_trans_engine_2 2> /dev/null)
[ -z "$ENGINE" ] && ENGINE=google

[ -n "$2" ] && export TTEXT="$2" || exit

echo -e "" >> $fpipe
echo -e ""  >> "$fpipe"
echo "" >> $fpipe

if [[ $(echo -e "$TTEXT" | cut -c1) != '#' ]]; then
T_TEXT=$(for ex in $ENGINE
do
echo "----- $ex translate to $(echo $TLANG1 | awk '{print $1}') -----"
echo -e "$TTEXT" | trans -e $ex -b -tl $(echo $TLANG1 | awk '{print $NF}'); done)
else
TTEXT=$(echo $TTEXT | cut -c2-$$)
T_TEXT=$(for ex in $TTEXT
do
trans -show-languages=y -show-original-phonetics=y -show-original-dictionary=y "$ex" -e "google" -tl "$(echo $TLANG1 | awk '{print $NF}')" | sed -r "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g"; done)
fi
echo -e "$T_TEXT" > "$track"/run_trans1
T_TEXT=$(while read -r line; do printf "%s" "$line\n"; done <<< "$T_TEXT")
printf "%s\n" "$T_TEXT" | sed s'/\\n$//' >> $fpipe

  echo "" >> $fpipe
  #echo "4:$run_acmd"
}; export -f run_dtrans1

function run_dtrans2
{
#echo "4:@disable@"
export TLANG2="$1"
export _TLANG2=$(echo "$1" | awk '{print $1}')
echo $TLANG2 > "$camino"/.trans_target_lang4
[ -z "$TLANG2" ] && export TLANG2="English - en"
[ -z "$_TLANG2" ] && export _TLANG2="English"
export ENGINE=$(cat "$camino"/_trans_engine_2 2> /dev/null)
[ -z "$ENGINE" ] && ENGINE=google

[ -n "$2" ] && export TTEXT="$2" || exit

echo -e "" >> $dpipe
echo -e ""  >> "$dpipe"
echo "" >> $dpipe

if [[ $(echo -e "$TTEXT" | cut -c1) != '#' ]]; then
T_TEXT=$(for ex in $ENGINE
do
echo "----- $ex translate to $(echo $TLANG2 | awk '{print $1}') -----"
echo -e "$TTEXT" | trans -e $ex -b -tl $(echo $TLANG1 | awk '{print $NF}'); done)
else
TTEXT=$(echo $TTEXT | cut -c2-$$)
T_TEXT=$(for ex in $TTEXT
do
trans -show-languages=y -show-original-phonetics=y -show-original-dictionary=y "$ex" -e "google" -tl "$(echo $TLANG2 | awk '{print $NF}')" | sed -r "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g"; done)
fi
echo -e "$T_TEXT" > "$track"/run_trans2
T_TEXT=$(while read -r line; do printf "%s" "$line\n"; done <<< "$T_TEXT")
printf "%s\n" "$T_TEXT" | sed s'/\\n$//' >> $dpipe
 
  echo "" >> $dpipe
  #echo "4:$run_bcmd"
}; export -f run_dtrans2
function execmndfn
{
	A_TEXT=`eval "$($CLIP)" | while read -r line; do  printf "%s" "$line\n" | sed 's/\\n|$//'; done`
	printf "%s\n%s\n%s\n%s\n%s\n" '' '' '' "$A_TEXT" '' > "$dpipe"
}; export -f execmndfn
function espeakfn
{
	killall espeak
	espeak -a 50 -s 160 -p 50 -v "$(echo $TLANG2 | awk '{print $3}' | cut -c1,2)" "$($CLIP)" &
	[ ! -z $(busybox which espeak) ] && espeak -q -s 160 -p 50 -v "$(echo $TLANG2 | awk '{print $3}' | cut -c1,2)" "$($CLIP)" --ipa  --phonout="$track"/espeak &
	[ -f "$track"/espeak ] && T_TEXT=$(cat "$track"/espeak)
	A_TEXT=$(while read -r line; do printf "%s" "$line\n"; done <<< "$T_TEXT")
	printf "%s\n%s\n%s\n%s\n%s\n" '' '' '' "$A_TEXT" '' > "$dpipe"

}; export -f espeakfn
function clearfn
{
	case $1 in
A1) printf "%s\n%s\n%s\n%s\n%s\n" '' '\' '' '' '' > "$fpipe";; 
A2) printf "%s\n%s\n%s\n%s\n%s\n" '' '' '' '\' '' > "$fpipe";;
B1) printf "%s\n%s\n%s\n%s\n%s\n" '' '\' '' '' '' > "$dpipe";;
B2) printf "%s\n%s\n%s\n%s\n%s\n" '' '' '' '\' '' > "$dpipe";;
ALL) printf "%s\n%s\n%s\n%s\n%s\n" '' '\' '' '\' '' > "$fpipe"
printf "%s\n%s\n%s\n%s\n%s\n" '' '\' '' '\' '' > "$dpipe";; 
	    esac
}; export -f clearfn
export TLANG1=$(cat "$camino"/.trans_target_lang3 2> /dev/null)
export _TLANG1=$(cat "$camino"/.trans_target_lang3 2> /dev/null | awk '{print $1}')
[ -z "$TLANG1" ] && export TLANG1="English - en"
[ -z "$_TLANG1" ] && export _TLANG1="English"

export TLANG2=$(cat "$camino"/.trans_target_lang4 2> /dev/null)
export _TLANG2=$(cat "$camino"/.trans_target_lang4 2> /dev/null | awk '{print $1}')
[ -z "$TLANG2" ] && export TLANG2="English - en"
[ -z "$_TLANG2" ] && export _TLANG2="English"

exec 5<> $fpipe
exec 6<> $dpipe

echo -e '\f' >&5
echo -e "$TLANG1!$LANGUAGES" >> $fpipe
echo -e "" >&5
echo "$run_acmd" >&5
echo -e "" >&5
echo "$savecmndA" >&5

echo -e '\f' >&6
echo -e "$TLANG2!$LANGUAGES" >> $dpipe
echo -e "" >&6
echo "$run_bcmd" >&6
echo -e "" >&6
echo "$savecmndB" >&6

yad --plug="$fkey" --tabnum=1 --listen --fontname="$FONT" --form --cycle-read --field="TL:CB" --field="<b>A1:</b>  Input/paste:TXT" --field="Translate / Dictionary!gtk-refresh!Add # at start for dictioinary:fbtn" --field="<b>A2:</b>    Translation:TXT" --field="Save!gtk-save:fbtn" <&5 &
yad --plug="$fkey" --tabnum=2 --listen --fontname="$FONT" --form --cycle-read --field="TL:CB" --field="<b>B1:</b>  Input/paste:TXT" --field="Translate / Dictionary!gtk-refresh!Add # at start for dictionary:fbtn"  --field="<b>B2:</b>    Translation:TXT"  --field="Save!gtk-save:fbtn" <&6 &
yad --key=$fkey --title="Dialogue mode" --window-icon="$ICON" --width=700 --height=600 --paned --tab=AB --tab=BA --orient=hori --buttons-layout=center --button="Clear A1:bash -c 'clearfn A1'" --button="Clear A2:bash -c 'clearfn A2'" --button="Clear B1:bash -c 'clearfn B1'" --button="Clear B2:bash -c 'clearfn B2'" --button="Exec:bash -c execmndfn" --button="eSpeak:bash -c espeakfn" $ONTOP
}; export -f trans_dialogue
TD.png
TD.png (65.25 KiB) Viewed 2230 times
TDD.png
TDD.png (77.07 KiB) Viewed 2209 times
Last edited by stemsee on Mon Jun 06, 2022 11:41 am, edited 6 times in total.
User avatar
amethyst
Posts: 2420
Joined: Tue Dec 22, 2020 6:35 am
Has thanked: 57 times
Been thanked: 506 times

Re: Trans_tray translation program

Post by amethyst »

Didn't read through all this but just saw in a previous post that it seems to use the online translator engines? So you need to be online to use it? If so, I don't really see the purpose of the application....., may as well just open the google translate page to copy and translate :roll:

User avatar
fredx181
Posts: 3089
Joined: Tue Dec 03, 2019 1:49 pm
Location: holland
Has thanked: 376 times
Been thanked: 1316 times
Contact:

Re: Trans_tray translation program

Post by fredx181 »

amethyst wrote: Sat Jun 04, 2022 4:28 pm

Didn't read through all this but just saw in a previous post that it seems to use the online translator engines? So you need to be online to use it? If so, I don't really see the purpose of the application....., may as well just open the google translate page to copy and translate :roll:

The advantage of it is that you don't need to run a browser page to translate, it's very convenient IMO.

User avatar
stemsee
Posts: 779
Joined: Sun Jul 26, 2020 8:11 am
Location: lattitude 8
Has thanked: 185 times
Been thanked: 131 times

Re: Trans_tray translation program

Post by stemsee »

amethyst wrote: Sat Jun 04, 2022 4:28 pm

Didn't read through all this but just saw in a previous post that it seems to use the online translator engines? So you need to be online to use it? If so, I don't really see the purpose of the application....., may as well just open the google translate page to copy and translate :roll:

You could!

That raises a challenge to make this work also offline ... why not?

However as it stands the over head of running another four web pages and the clumsy switching between them is better provided for with trans_tray! In addition to the convenience of saving and editing previous translations. So it would be difficult to align with your somewhat abrupt dismissal of an example of a rather good app with exemplary coding!

cheers!
stemsee

User avatar
fredx181
Posts: 3089
Joined: Tue Dec 03, 2019 1:49 pm
Location: holland
Has thanked: 376 times
Been thanked: 1316 times
Contact:

Re: Trans_tray translation program

Post by fredx181 »

Translating set to "Afrikaans", just highlight the text and click on the systray icon, done!

2022-06-04_20-56-24.gif
2022-06-04_20-56-24.gif (140.15 KiB) Viewed 1659 times
User avatar
amethyst
Posts: 2420
Joined: Tue Dec 22, 2020 6:35 am
Has thanked: 57 times
Been thanked: 506 times

Re: Trans_tray translation program

Post by amethyst »

stemsee wrote: Sat Jun 04, 2022 5:46 pm
amethyst wrote: Sat Jun 04, 2022 4:28 pm

Didn't read through all this but just saw in a previous post that it seems to use the online translator engines? So you need to be online to use it? If so, I don't really see the purpose of the application....., may as well just open the google translate page to copy and translate :roll:

You could!

That raises a challenge to make this work also offline ... why not?

However as it stands the over head of running another four web pages and the clumsy switching between them is better provided for with trans_tray! In addition to the convenience of saving and editing previous translations. So it would be difficult to align with your somewhat abrupt dismissal of an example of a rather good app with exemplary coding!

cheers!
stemsee

I'm not dismissing anything just don't find it very useful in this format (for me at least). I just open the google translate page. The other thing is that google translate has an automatic language detection feature which is very useful. Not sure if this application has that feature. Needs some more "excemplary coding" to include that me thinks to make it more useful. Now, if you really are smart you should also try to incorporate the google "huge" document translation feature (if it's not already included) and a feature to save the translation to a file (say a docx document). This should be a small challenge for you given your "exemplary" coding skills....

User avatar
fredx181
Posts: 3089
Joined: Tue Dec 03, 2019 1:49 pm
Location: holland
Has thanked: 376 times
Been thanked: 1316 times
Contact:

Re: Trans_tray translation program

Post by fredx181 »

Let's keep this conversation friendly please !

The other thing is that google translate has an automatic language detection feature which is very useful. Not sure if this application has that feature.

It has.
EDIT: btw, you wouldn't like it I guess if someone judges one of your applications without even trying it, don't you ?

User avatar
amethyst
Posts: 2420
Joined: Tue Dec 22, 2020 6:35 am
Has thanked: 57 times
Been thanked: 506 times

Re: Trans_tray translation program

Post by amethyst »

fredx181 wrote: Sat Jun 04, 2022 7:15 pm

Let's stay friendly please !

\

I am and trying to give good input (from my point of view). So this is how and why I personally use google translate most of the time - I read the comments on youtube which are in all sorts of languages so google's automatic detection feature is abolutely vital to me (obviously because I don't know what language needs to be translated). Then I use google translate to translate ebooks (big files) which can be uploaded and are then translated after which you can download a translated document.

User avatar
amethyst
Posts: 2420
Joined: Tue Dec 22, 2020 6:35 am
Has thanked: 57 times
Been thanked: 506 times

Re: Trans_tray translation program

Post by amethyst »

fredx181 wrote: Sat Jun 04, 2022 7:15 pm

Let's keep this conversation friendly please !

The other thing is that google translate has an automatic language detection feature which is very useful. Not sure if this application has that feature.

It has.
EDIT: btw, you wouldn't like it I guess if someone judges one of your applications without even trying it, don't you ?

Ha, ha, Stemsee has form in this regard (criticising my work). Not that that bothers me because I don't care if someone uses it. Getting a bit "touchy" now. I'm out of here, got better things to do.

User avatar
fredx181
Posts: 3089
Joined: Tue Dec 03, 2019 1:49 pm
Location: holland
Has thanked: 376 times
Been thanked: 1316 times
Contact:

Re: Trans_tray translation program

Post by fredx181 »

amethyst wrote:

Ha, ha, Stemsee has form in this regard (criticising my work). Not that that bothers me because I don't care if someone uses it. I'm out of here, got better things to do.

Criticising IS ok IMO, I just said "criticising without trying" is not OK.

User avatar
amethyst
Posts: 2420
Joined: Tue Dec 22, 2020 6:35 am
Has thanked: 57 times
Been thanked: 506 times

Re: Trans_tray translation program

Post by amethyst »

fredx181 wrote: Sat Jun 04, 2022 7:33 pm
amethyst wrote:

Ha, ha, Stemsee has form in this regard (criticising my work). Not that that bothers me because I don't care if someone uses it. I'm out of here, got better things to do.

Criticising IS ok IMO, I just said "criticising without trying" is not OK.

I like to gather information before downloading otherwise you download stuff and find out it's inadequate for your needs which for me is then a waste of time. Stemsee does not like any criticism whether positive or negative. We have some "history" :lol: Let's just leave it. I gather it can't translate big files and then output the translated file to another file for saving, eh (you haven't commented on this)? All in all more information required like how much text can be translated at a time (google translate has these two features, one for a restricted amount of words at a time and then a document function for large files). Also - I think it uses two different translation engines, one for the copy and paste translation box and one for the document translation method (where you upload a big file for conversion). The document feature gives better results so that's why I think different translations engines are used. BTW - I see your application has been coming along for a few years.... I thought it was something completely new that's why I commented on it in the first place. I also thought it was stemsee's brainchild and his creation. My reply was based on his comment about exemplary coding which I thought was bragging about or related to his own coding... :oops:

Feek
Posts: 398
Joined: Sun Oct 18, 2020 8:48 am
Location: cze
Has thanked: 54 times
Been thanked: 90 times

Re: Trans_tray translation program

Post by Feek »

Didn't read through all this but just saw in a previous post that it seems to use the online translator engines? So you need to be online to use it? If so, I don't really see the purpose of the application....., may as well just open the google translate page to copy and translate :roll:

The advantage of it is that you don't need to run a browser page to translate, it's very convenient IMO.

I absolutely agree. It is very very comfortable.

The moment I learned to use this app, I realized how great it is.

I use it basically every day and it works in all my installed dogs/puppies.

User avatar
amethyst
Posts: 2420
Joined: Tue Dec 22, 2020 6:35 am
Has thanked: 57 times
Been thanked: 506 times

Re: Trans_tray translation program

Post by amethyst »

Feek wrote: Sun Jun 05, 2022 8:47 am

Didn't read through all this but just saw in a previous post that it seems to use the online translator engines? So you need to be online to use it? If so, I don't really see the purpose of the application....., may as well just open the google translate page to copy and translate :roll:

The advantage of it is that you don't need to run a browser page to translate, it's very convenient IMO.

I absolutely agree. It is very very comfortable.

The moment I learned to use this app, I realized how great it is.

I use it basically every day and it works in all my installed dogs/puppies.

But the google translate page is so quick and user-friendly to access and has ALL the features. Now, this application could be very useful if you could do translations offline (the actual translation engines will have to be downloaded) but since you need to go online and probably want to translate something you find on a webpage (so you are already running a browser anyway), just opening another tab for the google translate page seems much easier and more convenient to me...but each to his own I suppose.

Feek
Posts: 398
Joined: Sun Oct 18, 2020 8:48 am
Location: cze
Has thanked: 54 times
Been thanked: 90 times

Re: Trans_tray translation program

Post by Feek »

amethyst wrote: Sun Jun 05, 2022 9:05 am
Feek wrote: Sun Jun 05, 2022 8:47 am

The advantage of it is that you don't need to run a browser page to translate, it's very convenient IMO.

I absolutely agree. It is very very comfortable.

The moment I learned to use this app, I realized how great it is.

I use it basically every day and it works in all my installed dogs/puppies.

But the google translate page is so quick and user-friendly to access and has ALL the features. Now, this application could be very useful if you could do translations offline (the actual translation engines will have to be downloaded) but since you need to go online and probably want to translate something you find on a webpage (so you are already running a browser anyway), just opening another tab for the google translate page seems much easier and more convenient to me...but each to his own I suppose.

In my opinion, translating text with Trans-Tray may be faster than Google Translator on the next browser tab.

I use this in this way:
1. I mark the text (anywhere) with the left mouse button
2. I click on the Trans-Tray icon in the system bar
3. The Trans-Tray Window pops up with the translation (if Trans-tray is already running, I switch between windows using Alt+Tab keys)

But as you say: each to his own of course ;)

User avatar
amethyst
Posts: 2420
Joined: Tue Dec 22, 2020 6:35 am
Has thanked: 57 times
Been thanked: 506 times

Re: Trans_tray translation program

Post by amethyst »

Okay guys, I downloaded it to give it a try. Had to upgrade yad. Then went online, opened a 800kb text file with leafpad and copied the text. It seems to be pasted correctly into the application window and it looked as if something was happening (could see data exchange). After 10 minutes I gave up. Nothing was translated couldn't see anything translated in the application window but still data was exchanged. Closed the application and STILL data was exchanged. I had to go offline to stop whatever was still happening. It did work with a much smaller amount of text (a paragraph). Doesn't seem to work with larger text. Tried again with a 280kb file. Again copied correctly to the window but this time nothing at all happened when I clicked translate. Uninstalled the application. :thumbdown:

User avatar
stemsee
Posts: 779
Joined: Sun Jul 26, 2020 8:11 am
Location: lattitude 8
Has thanked: 185 times
Been thanked: 131 times

Re: Trans_tray translation program

Post by stemsee »

Dear Nic

Thanks for testing. When you select text for translating in general it works better if the selected text and the target language are not the same. Because then the app actually has something to do.

Right click tray menu and then select target language or languages. Also select translation engine or engines, thus one can compare the quality and style of the translations, and receive translations into several other languages, and save them....all in two clicks.

Also find the most comprehensive keyboard layout selection in existence.

For offline translation would need dictionaries for each language, translation engine and probably a local server running. Heavy payload. Still researching it.

Lastly trans_tray is also provided as an sfs which can be loaded and unloaded without installation.

Kind regards and God bless.
stemsee

User avatar
amethyst
Posts: 2420
Joined: Tue Dec 22, 2020 6:35 am
Has thanked: 57 times
Been thanked: 506 times

Re: Trans_tray translation program

Post by amethyst »

@stemsee
Your sfs does not load neither does it extract when I use UExtract (reports unknown compression). Re-Compress it with xz or gzip so that I can try it.

User avatar
stemsee
Posts: 779
Joined: Sun Jul 26, 2020 8:11 am
Location: lattitude 8
Has thanked: 185 times
Been thanked: 131 times

Re: Trans_tray translation program

Post by stemsee »

This is gzip compressed. Previous upload may have been zstd compressed.

This is noarch, Pups'n'Dogs, optional dependency is espeak for text to speech

trans-tray-noarch (2).sfs
(72 KiB) Downloaded 55 times
User avatar
amethyst
Posts: 2420
Joined: Tue Dec 22, 2020 6:35 am
Has thanked: 57 times
Been thanked: 506 times

Re: Trans_tray translation program

Post by amethyst »

My observations, tried with Afrikaans and Dutch to English:
1. Only Google worked , yandex and bing didn't translate anything (languages not supported?).
2. Only limited sized text allowed, probably the same as the text limit of 5000 characters for the google text mode.
3. If you load large text (probably over the limit), one of two things happens: lots of interaction on the net but nothing happens (no translation), either this or nothing at all happens. Had to kill the processes because just exiting the application doesn't stop the data exchange. Also after this, using the application again, strange behaviour. The same box shows the input and output results (don't know what's going on there).

To do's: It would be useful if the documents function of google translate could be implemented (look on the website how it works). This will basically lift the size restriction of the translation.
I've recently used DeepL Translate which seems excellent (even better than Google). It works the same as google translate, maybe try to implement that too. Personally, I think I'll just stick with the google translate website, works fine for me and privides all I'm looking for.

User avatar
fredx181
Posts: 3089
Joined: Tue Dec 03, 2019 1:49 pm
Location: holland
Has thanked: 376 times
Been thanked: 1316 times
Contact:

Re: Trans_tray translation program

Post by fredx181 »

amethyst wrote:

1. Only Google worked , yandex and bing didn't translate anything (languages not supported?).

Yes, pity, the others used to work sometime ago, it depends perhaps on a new "trans" (translate_shell issue: https://github.com/soimort/translate-sh ... -870626543) update to make these work again.
EDIT: Just see now that it looks like trans is not really developed anymore, latest update is 2 years ago.

2. Only limited sized text allowed, probably the same as the text limit of 5000 characters for the google text mode.

Limited, probably yes, however I just tested with over 10000 chars, took a long time, but worked in the end.
Admittedly, it's not very suitable for large text chunks.

It would be useful if the documents function of google translate could be implemented (look on the website how it works).

I don't think that's possible to implement with this program ("trans" has no such option AFAIK).

I've recently used DeepL Translate which seems excellent (even better than Google). It works the same as google translate, maybe try to implement that too.

DeepL is nice, but unfortunately not supported by "trans".

User avatar
amethyst
Posts: 2420
Joined: Tue Dec 22, 2020 6:35 am
Has thanked: 57 times
Been thanked: 506 times

Re: Trans_tray translation program

Post by amethyst »

Okay, I thought you guys actually developed the whole thing but the translate shell script has been around for a while and there seems to be quite a few GUI's, etc. available. Anyway, seems to be a half-baked thing these days now that half the intended original features do not work anymore.

User avatar
fredx181
Posts: 3089
Joined: Tue Dec 03, 2019 1:49 pm
Location: holland
Has thanked: 376 times
Been thanked: 1316 times
Contact:

Re: Trans_tray translation program

Post by fredx181 »

*** New trans-tray package v1.2 *** with a few changes:
- Only Google engine is used for translation, so no choice for Bing and/or Yandex (didn't work anymore), this might take away some confusion and annoyance.
- Set as default now is to NOT show original text in the main window (previously default was to show it) can be changed in the Preferences.
(may need to delete '/root/.trans_tray/prefs' after installing v1.2 and restart trans_tray, to apply)
Attached at first post

2022-06-07_12-59-40.png
2022-06-07_12-59-40.png (48.92 KiB) Viewed 1722 times

@stemsee I didn't implement your latest changes (e.g. for dialogue mode), perhaps if you want, you can share your own package with these included :?:

Post Reply

Return to “Utilities”