-
Notifications
You must be signed in to change notification settings - Fork 0
/
preview
executable file
·55 lines (47 loc) · 1.17 KB
/
preview
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/bash
# get command name from arguments
if [ "x$1" = "x" ]; then
echo "Invalid argument."
exit 1
fi
CMD=$1
# check if po4a is installed
which po4a-translate > /dev/null 2>&1
if [ ! "x$?" = "x0" ]; then
echo "Sorry, you need to install po4a first."
exit 1
fi
# find the command number
NUM=0
find_num(){
for i in `seq 9`
do
# we assume if the po file exists, the man page exists
po="po/"$CMD"."$i".zh_CN.po"
if [ -e $po ];then
eval "$1=$i"
break
fi
done
}
find_num NUM
if [ $NUM = "0" ]; then
echo $CMD" does not exist in this repo!"
exit
fi
po="po/"$CMD"."$NUM".zh_CN.po"
master="raw/man"$NUM"/"$CMD"."$NUM
target="/tmp/"$CMD"."$NUM
echo "This is the original man page: "$master
# regard fuzzy translations as translated
sed -e "s/fuzzy//g" $po > /tmp/tmp.po
# generated the translated man page
po4a-translate -f man -m $master -p /tmp/tmp.po -l /tmp/tmp.1
if [ ! -e /tmp/tmp.1 ]; then
echo "Ooops, cannot generate the translated $target"
exit
fi
# show this command in man browser
echo ". mso zh.tmac" > /tmp/ChineseSupport
cat /tmp/ChineseSupport /tmp/tmp.1 > $target
man $target