-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgettext
More file actions
40 lines (36 loc) · 1.84 KB
/
gettext
File metadata and controls
40 lines (36 loc) · 1.84 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
38
39
40
#!/bin/ash
# Copyright (C) 2023 Marcos Contant (stemsee)
# with input and debugging by gyro
# transtext
# depends on trans script (a google api implementation)and google online translation services
# gpl 3 license for personal use. <http://www.opensource.org/licenses/GPL-3.0/>
# A Unique Arbitrary License applies for occupational usage from Copyright Holder.
function transtext {
[ ! "$lng" ] && lng=$(locale | grep LANG= | cut -f -d'_') || lng="$lng"
[[ ! -d /usr/share/locale/transtext/"$lng" ]] && mkdir -p /usr/share/locale/transtext/"$lng"
unset WORK
HANDLE=$(echo "$1" | md5sum | awk '{print $1}')
if [[ -f /usr/share/locale/transtext/"$lng"/"$HANDLE".transtext ]]; then
WORK=$(cat /usr/share/locale/transtext/"$lng"/"$HANDLE".transtext)
echo "$WORK"
elif [[ $(type -p trans) != "" ]]; then
WORK=$(echo -e "$1" | trans -e google -no-auto -b -tl "$lng" -download-audio-as /usr/share/locale/transtext/$lng/$HANDLE.mp3 &)
[ "$WORK" ] && echo "$WORK" || echo "$1"
[[ ! -f /usr/share/locale/transtext/"$lng"/"$HANDLE".transtext ]] && echo -e "$WORK" > /usr/share/locale/transtext/"$lng"/"$HANDLE".transtext
else
echo "$1"
fi
}; export -f transtext
[[ ! "$lng" ]] && lng=$(echo $LANG | cut -f1 -d'_')
[ ! -d /usr/share/locale/transtext/"$lng" ] && mkdir -p /usr/share/locale/transtext/"$lng"
unset WORK
HANDLE=$(echo "$1" | md5sum | awk '{print $1}')
if [[ -f /usr/share/locale/transtext/"$lng"/"$HANDLE".transtext ]]; then
WORK=$(cat /usr/share/locale/transtext/"$lng"/"$HANDLE".transtext)
echo "$WORK"
exit
elif [[ ! -f /usr/share/locale/transtext/"$lng"/"$HANDLE".transtext ]]; then
export WORK=$(echo -e "$1" | trans -e google -no-auto -no-warn -b -tl "$lng" -download-audio-as /usr/share/locale/transtext/$lng/$HANDLE.mp3)
echo -e "$WORK" > /usr/share/locale/transtext/"$lng"/"$HANDLE".transtext
echo "$WORK"
fi