summaryrefslogtreecommitdiff
path: root/scripts/update_pot
blob: c72daac0ad211e760212a59c7ed0b6cfb15c84ae (plain)
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
#!/bin/sh

# This script is used for translations using .po files.
# It updates .pot files after changes in the original English
# .xml files.
# The script 'merge_xml' should be run before this script!

if [ "$1" = "--help" ] ; then
    echo "Usage: $0"
    exit 0
fi

if [ -z "`which xml2pot 2>/dev/null`"  ] ; then
   echo "ERR: xml2pot not found, please install the poxml package"
   exit 1
fi

BUILDDIR="./build"
if [ -z "$PO_USEBUILD" ] ; then
    WORKDIR="./integrated"
    PODIR="./po"
else
    WORKDIR="$BUILDDIR/build.po"
    PODIR="$BUILDDIR/build.po"
fi
SOURCEDIR="$WORKDIR/en"
RET=0

[ -d $SOURCE ] || exit 1
mkdir -p $PODIR/pot

for XML in `find $SOURCEDIR -name "*.xml"` ; do
    echo "Creating new POT file for $XML"
    POT=$(basename $XML .xml).pot

    # Let's also set a proper POT-Creation-Date
    xml2pot $XML | \
        sed "s/^.*POT-Creation-Date:.*$/\"POT-Creation-Date: $(date -u "+%F %R%z")\\\n\"/" \
        >$PODIR/pot/$POT.new
    RC=$?
    if [ $RC -ne 0 ] ; then
        RET=$RC
        echo "Error: error $RC while executing xml2pot"
    fi

    if [ ! -f $PODIR/pot/$POT ] ; then
        mv $PODIR/pot/$POT.new $PODIR/pot/$POT
    else
        if diff $PODIR/pot/$POT $PODIR/pot/$POT.new | grep "^[><]" | grep -qv "POT-Creation-Date: " ; then
            mv $PODIR/pot/$POT.new $PODIR/pot/$POT
        else
            # Revert changes if the only thing changed is the POT-Creation-Date
            rm $PODIR/pot/$POT.new
        fi
    fi
done

exit $RET