2020-11-13 08:34:52 +00:00
|
|
|
#!/usr/bin/env sh
|
|
|
|
#
|
|
|
|
# Translate the page, or if `--text` argument is given the current selection, with google translate.
|
|
|
|
#
|
|
|
|
# Adapted code from https://github.com/AckslD/Qute-Translate, with much gratitude.
|
2023-08-08 15:12:53 +00:00
|
|
|
PAGE="https://lingva.garudalinux.org/SOURCELANGUAGE/TARGETLANGUAGE/TRANSLATETEXT"
|
2020-11-13 08:34:52 +00:00
|
|
|
|
|
|
|
while [ $# -gt 0 ]; do
|
2021-04-04 18:52:52 +00:00
|
|
|
case $1 in
|
|
|
|
-s | --source)
|
|
|
|
QUTE_TRANS_SOURCE=$2
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-t | --target)
|
|
|
|
QUTE_TRANS_TARGET=$2
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--url)
|
|
|
|
QUTE_TRANS_URL="true"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--text)
|
|
|
|
QUTE_TRANS_URL="false"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
esac
|
2020-11-13 08:34:52 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
if [ -z "$QUTE_TRANS_SOURCE" ]; then
|
2021-04-04 18:52:52 +00:00
|
|
|
# Default use automatic language for source
|
|
|
|
QUTE_TRANS_SOURCE="auto"
|
2020-11-13 08:34:52 +00:00
|
|
|
fi
|
|
|
|
if [ -z "$QUTE_TRANS_TARGET" ]; then
|
2021-04-04 18:52:52 +00:00
|
|
|
# Default use English for target
|
|
|
|
QUTE_TRANS_TARGET="en"
|
2020-11-13 08:34:52 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$QUTE_TRANS_URL" = "false" ]; then
|
2021-04-04 18:52:52 +00:00
|
|
|
# Translate selected text
|
2023-08-08 15:12:53 +00:00
|
|
|
PAGE=$(echo "$PAGE" | sed -e "s/SOURCELANGUAGE/$QUTE_TRANS_SOURCE/" -e "s/TARGETLANGUAGE/$QUTE_TRANS_TARGET/" -e "s/TRANSLATETEXT/$QUTE_SELECTED_TEXT/")
|
|
|
|
echo "open -t ${PAGE}" >>"$QUTE_FIFO"
|
2020-11-13 08:34:52 +00:00
|
|
|
else
|
2021-04-04 18:52:52 +00:00
|
|
|
# Default translate URL
|
|
|
|
PAGE="https://translate.google.com/translate?"
|
|
|
|
CONT_KEY="u"
|
2023-08-08 15:12:53 +00:00
|
|
|
CONTENT="$QUTE_URL"
|
|
|
|
echo "open -t ${PAGE}sl=${QUTE_TRANS_SOURCE}&tl=${QUTE_TRANS_TARGET}&${CONT_KEY}=\"${CONTENT}\"" >>"$QUTE_FIFO"
|
2020-11-13 08:34:52 +00:00
|
|
|
fi
|
|
|
|
|