~ubuntu-core-doc/ubuntu-docs/trusty

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
#!/bin/bash

# Ensure we're running from the ubuntu-docs project root directory
if [ ! -d ubuntu-help ]; then
    echo "ERROR: You must run this script from the ubuntu-docs project root directory."
    exit 1
fi

# Ensure the URL to the translation files tarball has been specified
if [ $# -lt 1 ]; then
    echo "Usage: $0 FILE"
    echo ""
    echo "    FILE         The tarball of .po files that Launchpad provides."
    exit 1
fi

# Location to store downloaded tarball
TMPDOCS="$1"

if [ ! -e "$TMPDOCS" ]; then
    echo "ERROR: File $TMPDOCS does not exist!"
    exit 1
fi

echo "Extracting translations from $TMPDOCS..."
tar -zxf "$TMPDOCS" --exclude='*.pot'

echo "Renaming translation files..."
POLANGS=""
for i in ./ubuntu-help/*/ubuntu-help-*.po; do
    OLDFILENAME=$i
    NEWFILENAME=$(basename $i | sed -e 's/^ubuntu-help-//')
    POLANG=$(basename $i .po | sed -e 's/^ubuntu-help-//')
    POLANGS="$POLANGS $POLANG"
    mkdir -p ./ubuntu-help/$POLANG
    mv $OLDFILENAME ./ubuntu-help/$POLANG/$NEWFILENAME
done

echo "Updating Makefile.am..."
cp ./ubuntu-help/Makefile.am ./ubuntu-help/Makefile.am.old
sed "s/HELP_LINGUAS = .*$/HELP_LINGUAS =$POLANGS/" ./ubuntu-help/Makefile.am.old > ./ubuntu-help/Makefile.am
rm -fr ./ubuntu-help/Makefile.am.old

echo "Done!"