-
Notifications
You must be signed in to change notification settings - Fork 102
/
xml2po.sh
74 lines (67 loc) · 1.79 KB
/
xml2po.sh
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
#!/bin/bash
# XXX override this:
PACKAGE=$(basename $PWD)
TRAN=translations
RES=res/values
POT=$TRAN/$PACKAGE.pot
PODIR=translations/$PACKAGE
PO=$PODIR/$PACKAGE-
CREDITS=res/values/translators.xml
download() {
FN=launchpad-$(date +%F).tar.gz
pushd "$TRAN"
wget "$1" -O "$FN"
tar xvzf "$FN"
mv translations/*.po $PACKAGE/
rename -f 's/@[^.]*//' $PACKAGE/*.po
popd
}
translate_xml2pot() {
if [ -f $POT ] ; then
xml2po -a -u $POT $RES/strings.xml
else
xml2po -a -o $POT $RES/strings.xml
fi
}
translate_po2xml() {
if [ ! -d "translations/" ] ; then
echo "You need to download the translations package from launchpad first."
echo "Get it from https://translations.launchpad.net/$PACKAGE and store"
echo "the .po files as $PO##.po"
exit 1
fi
for po in $PO*.po; do
lang=${po##$PO}
lang=${lang%%.po} # strip .po
lang=${lang/_/-r} # fix up lang_Locale -> lang-rLocale
dir=$RES-$lang
# fix Java f'ups <http://developer.android.com/reference/java/util/Locale.html>
[ "$lang" == "he" ] && dir=$RES-iw
[ "$lang" == "id" ] && dir=$RES-in
[ "$lang" == "yi" ] && dir=$RES-ji
echo $lang: $dir
mkdir -p $dir
xml2po -a -l $lang -p $po $RES/strings.xml | sed "s/'/\\\\'/g" > $dir/strings.xml
done
sed -i 's/\\\\'\''/\\'\''/g' res/values-*/strings.xml
[ -f $CREDITS ] && {
cat <<EOF
<?xml version="1.0" encoding="utf-8"?>
<!-- AUTOGENERATED BY xml2po.sh! DO NOT CHANGE MANUALLY! -->
<!-- APRSdroid translators. Autogenerated by xml2po.sh -->
<resources>
<string name="translation_credits">\\n
$(cat translations/$PACKAGE/$PACKAGE-*.po | awk -F ': | <' '/Last-Translator:/ { if ($2 != "FULL NAME") { print $2 "\\n"; } }')
</string>
</resources>
EOF
} > $CREDITS
}
if [ "$1" = "xml2pot" ]; then
translate_xml2pot
elif [ -n "$1" ] ; then
download "$1"
translate_po2xml
else
translate_po2xml
fi