tslate (664B) - View raw
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16#!/usr/bin/env bash tquery=${1:-$(xclip -o -selection primary 2>/dev/null || wl-paste 2>/dev/null)} encoded_query=$(echo "$tquery" | jq -sRr @uri) query=$(curl -s --connect-timeout 5 --max-time 10 -X 'GET' \ "https://mozhi.canine.tools/api/translate?engine=google&from=auto&to=ru&text=$encoded_query" \ -H 'accept: application/json') # Check for connection error (curl exit status stored in $?) [ $? -ne 0 ] && notify-send -h string:bgcolor:#bf616a -t 3000 "Connection error." && exit 1 translated_text=$(echo "$query" | jq -r '.["translated-text"]') lang=$(echo "$query" | jq -r '.["detected"]') notify-send -t 60000 "$translated_text" "$tquery ($lang)"