Improvements to the clipboard translator.

This commit is contained in:
Storm Dragon 2022-10-04 20:48:30 -04:00
parent 52fa738f86
commit 3332cb8d39

View File

@ -20,9 +20,14 @@ while : ; do
if [[ "${#newText}" -lt 1 ]]; then
continue
fi
if [[ "${newText}" =~ ^[0-9A-Za-z[:space:][:punct:]]+$ ]]; then
spd-say "$newText"
echo "" | xclip -d "${DISPLAY:-:0}" -selection clipboard 2> /dev/null
continue
fi
export newText
translatedText="$(awk -v originalText="${newText}" 'BEGIN { exitCode = 1; FS = "\\)==:\\[" }
$1~originalText { print $2; exitCode = 0; exit}
translatedText="$(awk -v originalText="${newText})==:" 'BEGIN { exitCode = 1; FS = "\\)==:\\[" }
$0~originalText { print $2; exitCode = 0; exit}
END { exit exitCode }' "$dictionaryFile")"
if [[ "${#translatedText}" -ge 1 ]]; then
spd-say "$translatedText"
@ -30,7 +35,7 @@ while : ; do
continue
fi
translatedText="$(trans -b -- "$newText")"
if [[ "${newText}" != "${translatedText}" ]]; then
if ! [[ "${newText}" =~ ^[0-9[:punct:]]+$ ]]; then
echo "${newText})==:[${translatedText}" >> "$dictionaryFile"
fi
spd-say "$translatedText"