forked from dsmid/kindle-pw2-l10n-cs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
translate_acx
executable file
·81 lines (76 loc) · 2.61 KB
/
translate_acx
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/bash
. config
VER="$VERSION"
rm -rf build/acx
cd root_$VERSION
root=$PWD
orig=./opt/amazon/acw
dest=$root/../install/$orig
[ -d $dest ] & rm -rf $dest
mkdir -p $dest
while read acx
do
echo ACX: $acx
[ -d "$root/../build/acx/$acx" ] || mkdir -p "$root/../build/acx/$acx"
cp -f $acx $root/../build/acx/$acx/
cd $root/../build/acx/$acx/
unzip $(basename "$acx")
rm -f $(basename "$acx")
rm -f author-signature.xml
cd $root
done < <(find $orig -name '*.acx')
cd $root/../translation_$VERSION/acx_tweaks
while read tweak
do
echo "Copying tweak $tweak"
tdir=$(dirname "$tweak")
[ -d "$root/../build/acx/$tdir" ] || mkdir -p "$root/../build/acx/$tdir"
cp -f "$tweak" $root/../build/acx/"$tweak"
done < <(find . -type f )
cd $root/../build/acx
while read jsfile
do
echo "Translating $jsfile"
native2ascii -reverse "$jsfile" "$jsfile.native"
OLDIFS=$IFS
printf -v IFS "\t"
while read src tran
do
tran=$(sed 's|&|\\&|g' <<<"$tran")
[ -n "$tran" ] && sed -i "s|:[[:space:]]*'$src'|: '$tran'|g; s|:[[:space:]]*"'"'"$src"'"'"|: "'"'"$tran"'"'"|g;" "$jsfile.native"
done < <(sqlite3 -separator " " $root/../kindle_loc.sqlite "select src,tran from trans where file='""$jsfile""' and ver='""$VER""' ;")
IFS=$OLDIFS
native2ascii "$jsfile.native" "$jsfile"
rm -f "$jsfile.native"
done < <(find $orig \( -path '*/locales/en-gb/*.js' -or -path '*/endactions.acx/Strings.js' \) -exec bash -c 'js={}; mv -f {} {}.ee; js-beautify -o {} {}.ee; rm -f {}.ee' \; -print)
cd $root/../build/acx
while read xml
do
echo "Translating $xml"
OLDIFS=$IFS
printf -v IFS "\t"
while read src tran
do
tran=$(sed 's|&|&|g' <<<"$tran")
if [ "$VER" == "5.3.7" ]
then
[ -n "$tran" ] && sed -i "s|>$src</name>|>$tran</name>|g;s|<description>$src</description>|<description>$tran</description>|g;" "$xml"
else
[ -n "$tran" ] && sed -i "s|\"en-gb\">$src</name>|\"en-gb\">$tran</name>|g;" "$xml"
fi
done < <(sqlite3 -separator " " $root/../kindle_loc.sqlite "select src,tran from trans where file='""$xml""' and ver='""$VER""' ;")
IFS=$OLDIFS
done < <(find $orig -path '*/config.xml' -print)
cd $root/../build/acx
while read acx
do
echo "Packing ACX: $acx"
cd "$acx"
baseacx=$(basename "$acx")
zip -r "$baseacx" *
echo "Signing ACX: $acx"
java -jar $root/../signing/widgetsigner.jar -w "$baseacx" -s 0 -k $root/../signing/author.p12 -a 'HomebrewActiveContentExtensions' -p ''
mv -f "$baseacx" $dest/
cd $root/../build/acx
done < <(find $orig -type d -name '*.acx')
cd $root