forked from dsmid/kindle-pw2-l10n-cs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
translate_js
executable file
·36 lines (32 loc) · 1.17 KB
/
translate_js
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
#!/bin/bash
. config
VER="$VERSION"
cd root_$VERSION
while read engb
do
item=${engb#*/mesquite/*/}
item=${item#*/webkit-1.0/*/}
itemroot=${engb%$item}
echo Processing "$itemroot - $item"
[ -d "../install/${itemroot}$item" ] && find "../install/${itemroot}$item" \( -name '*.js' -or -name '*.js.native' \) -delete
while read jsfile
do
basen=$(basename "$jsfile")
dest="../install/${jsfile}"
destdir=$(dirname "$dest")
[ -d "$destdir" ] || mkdir -p "$destdir"
cp -f "$jsfile" "$destdir/"
trjsfile="$destdir/$basen"
native2ascii -reverse "$trjsfile" "$trjsfile.native"
OLDIFS=$IFS
printf -v IFS "\t"
while read src tran
do
tran=$(sed 's|&|\\&|g' <<<"$tran")
[ -n "$tran" ] && sed -i "s|'$src'|'$tran'|g; s|"'"'"$src"'"'"|"'"'"$tran"'"'"|g;" "$trjsfile.native"
done < <(sqlite3 -separator " " ../kindle_loc.sqlite "select src,tran from trans where file='""$jsfile""' and ver='""$VER""' ;")
IFS=$OLDIFS
native2ascii "$trjsfile.native" "$trjsfile"
rm -f "$trjsfile.native"
done < <(find $engb -name '*.js')
done < <(find . -type d \( -path '*/mesquite/*/locales/en-GB' -or -path '*/webkit-1.0/*/locales/en-GB' \) )