-
Notifications
You must be signed in to change notification settings - Fork 2
/
translation2sqlite
executable file
·43 lines (38 loc) · 1.58 KB
/
translation2sqlite
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
#!/bin/bash
. config
cp -f kindle_loc.sqlite kindle_loc.sqlite.old
#cp -f kindle_loc.sqlite.base kindle_loc.sqlite
cd translation_$VERSION
VER="$VERSION"
cd translation
echo "begin;" > ../../trans_$VERSION.sql
echo "delete from trans where ver = '$VER';" >> ../../trans_$VERSION.sql
find . \( -name '*.translation' -or -name '*.js' -or -name '*.xml' \) -exec sh -c "awk 'BEGIN {FS="'"'"\\t|\\r"'"'"} { print "'"'"{}\t"'"'" \$1 "'"'"\t"'"'" \$2}' < {}" \; | \
sed "s/'/''/g" | \
(
printf -v IFS "\t"
while read file src tran
do
echo "insert into trans values ('$src','$tran', '$file', '$VER');" >> ../../trans_$VERSION.sql
# echo "insert into trans values ('$src','$tran', '$file', '$VER');" | \
# sqlite3 ../../kindle_loc.sqlite || \
echo " === insert into trans values ('$src','$tran', '$file', '$VER');"
done
)
find . -name '*.properties' -exec sh -c "awk 'BEGIN {FS="'"'"([[:space:]]*=[[:space:]]*)|\\r"'"'"} { print "'"'"{}\t"'"'" \$1 "'"'"\t"'"'" \$2}' < {}" \; | \
sed "s/'/''/g" | \
(
printf -v IFS "\t"
while read file src tran
do
[ -z "$src" ] && continue
[ -z "$tran" ] && continue
echo "insert into trans values ('$src','$tran', '$file', '$VER');" >> ../../trans_$VERSION.sql
# echo "insert into trans values ('$src','$tran', '$file', '$VER');" | \
# sqlite3 ../../kindle_loc.sqlite || \
echo " === insert into trans values ('$src','$tran', '$file', '$VER');"
done
)
echo "commit;" >> ../../trans_$VERSION.sql
sqlite3 ../../kindle_loc.sqlite < ../../trans_$VERSION.sql
rm -f ../../trans_$VERSION.sql