Added gtranslate through dmenu.

This commit is contained in:
dabruh 2022-06-04 15:06:12 +02:00
parent 231012f045
commit 4bc98a7df0
3 changed files with 185 additions and 0 deletions

View File

@ -10,3 +10,7 @@ bindsym $mod+Shift+Return exec "$calc_cmd"
# Start file manager
bindsym $mod+Ctrl+Return exec "$file_cmd"
# gtranslate through dmenu
bindsym $mod+Ctrl+Shift+t exec dmenugtranslate
for_window [class="Alacritty"][instance="translation"] floating enable

32
.local/bin/dmenugtranslate Executable file
View File

@ -0,0 +1,32 @@
#!/bin/sh
text=$(xclip -o -selection clipboard)
map=~/.local/share/dabruh/gtranslate-lang-map
# Get user selection via dmenu from language map file.
from=$(cut -d '=' -f1 "$map" | dmenu -i -l 30 -p "Translate from")
[ -z "$from" ] && exit 1
from_code="$(grep "^$from=" "$map" | cut -d '=' -f2)"
to=$(cut -d '=' -f1 "$map" | grep -v Automatic | dmenu -i -l 30 -p "Translate to")
[ -z "$to" ] && exit 1
to_code="$(grep "^$to=" "$map" | cut -d '=' -f2)"
translation="$(curl --silent --get \
--data-urlencode "from=$from_code" \
--data-urlencode "to=$to_code" \
--data-urlencode "text=$text" \
"http://localhost:5000/api")"
rc=$?
if [ $rc -ne 0 ]; then
e="Translation from $from_code to $to_code failed. Input: '$text'"
notify-send "$e" &
echo "ERROR: $e" 1>&2
exit 2
fi
echo "$translation"
printf '%s' "$translation" | xclip -selection clipboard
notify-send "Translation from $from_code to $to_code copied to clipboard." &
alacritty --class translation -e bash -c "echo '$translation' | less" &

View File

@ -0,0 +1,149 @@
Automatic=auto
Afrikaans=af
Akan=ak
Albanian=sq
Amharic=am
Arabic=ar
Armenian=hy
Azerbaijani=az
Basque=eu
Belarusian=be
Bemba=bem
Bengali=bn
Bihari=bh
Bosnian=bs
Breton=br
Bulgarian=bg
Cambodian=km
Catalan=ca
Cherokee=chr
Chichewa=ny
Chinese (Simplified)=zh-CN
Chinese (Traditional)=zh-TW
Corsican=co
Croatian=hr
Czech=cs
Danish=da
Dutch=nl
Elmer Fudd=xx-elmer
English=en
Esperanto=eo
Estonian=et
Ewe=ee
Faroese=fo
Filipino=tl
Finnish=fi
French=fr
Frisian=fy
Ga=gaa
Galician=gl
Georgian=ka
German=de
Greek=el
Guarani=gn
Gujarati=gu
Hacker=xx-hacker
Haitian Creole=ht
Hausa=ha
Hawaiian=haw
Hebrew=iw
Hindi=hi
Hungarian=hu
Icelandic=is
Igbo=ig
Indonesian=id
Interlingua=ia
Irish=ga
Italian=it
Japanese=ja
Javanese=jw
Kannada=kn
Kazakh=kk
Kinyarwanda=rw
Kirundi=rn
Klingon=xx-klingon
Kongo=kg
Korean=ko
Krio (Sierra Leone)=kri
Kurdish=ku
Kurdish (Soranî)=ckb
Kyrgyz=ky
Laothian=lo
Latin=la
Latvian=lv
Lingala=ln
Lithuanian=lt
Lozi=loz
Luganda=lg
Luo=ach
Macedonian=mk
Malagasy=mg
Malay=ms
Malayalam=ml
Maltese=mt
Maori=mi
Marathi=mr
Mauritian Creole=mfe
Moldavian=mo
Mongolian=mn
Montenegrin=sr-ME
Nepali=ne
Nigerian Pidgin=pcm
Northern Sotho=nso
Norwegian=no
Norwegian (Nynorsk)=nn
Occitan=oc
Oriya=or
Oromo=om
Pashto=ps
Persian=fa
Pirate=xx-pirate
Polish=pl
Portuguese (Brazil)=pt-BR
Portuguese (Portugal)=pt-PT
Punjabi=pa
Quechua=qu
Romanian=ro
Romansh=rm
Runyakitara=nyn
Russian=ru
Scots Gaelic=gd
Serbian=sr
Serbo-Croatian=sh
Sesotho=st
Setswana=tn
Seychellois Creole=crs
Shona=sn
Sindhi=sd
Sinhalese=si
Slovak=sk
Slovenian=sl
Somali=so
Spanish=es
Spanish (Latin American)=es-419
Sundanese=su
Swahili=sw
Swedish=sv
Tajik=tg
Tamil=ta
Tatar=tt
Telugu=te
Thai=th
Tigrinya=ti
Tonga=to
Tshiluba=lua
Tumbuka=tum
Turkish=tr
Turkmen=tk
Twi=tw
Uighur=ug
Ukrainian=uk
Urdu=ur
Uzbek=uz
Vietnamese=vi
Welsh=cy
Wolof=wo
Xhosa=xh
Yiddish=yi
Yoruba=yo
Zulu=zu