-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbrave_translate.sh
More file actions
37 lines (31 loc) · 1.09 KB
/
brave_translate.sh
File metadata and controls
37 lines (31 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/sh
chromium_based_browser="brave"
en_to_ar="https://translate.google.com.eg/?hl=ar&tab=rT1&sl=en&tl=ar&op=translate"
ar_to_en="https://translate.google.com.eg/?hl=ar&tab=rT1&sl=ar&tl=en&op=translate"
text=$(
rofi -dmenu \
-p "Translate : " \
-theme "${XDG_CONFIG_HOME:-~/.config}"/rofi/oneliner.rasi
)
[ -z "$text" ] && exit 1
arabic_count=$(echo "$text" | grep -o -P "\p{Arabic}" | wc -l)
english_count=$(echo "$text" | grep -o -P "[A-Za-z]" | wc -l)
if [ "$arabic_count" -gt "$english_count" ]; then
urlencode() {
_str="$1"
_str_len=${#_str}
_pos=0
while [ "$_pos" -lt "$_str_len" ]; do
_c=$(printf '%s' "$_str" | cut -c "$((_pos + 1))")
case "$_c" in
[a-zA-Z0-9.~_-]) printf '%s' "$_c" ;;
*) printf '%%%02X' "'$_c" ;;
esac
_pos=$((_pos + 1))
done
}
encoded_text=$(urlencode "$text")
nohup $chromium_based_browser "--app=$ar_to_en&text=$encoded_text" --test-type --password-store=basic >/dev/null 2>&1 &
else
nohup $chromium_based_browser "--app=$en_to_ar&text=$text" --test-type --password-store=basic >/dev/null 2>&1 &
fi