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

WORKDIR="./integrated"
SOURCEDIR="$WORKDIR/en"
PODIR="./po"

[ -d $SOURCE ] || exit 1

if [ -d "$PODIR" ] ; then
    echo "Deleting old .pot files..."
    for i in `find $PODIR/ -name "*.pot"` ; do
        rm $i
    done
fi

for XML in `find $SOURCEDIR -name "*.xml"` ; do
    echo "Creating new .pot file for $XML"
    SUBDIR=$(dirname $XML | sed "s:$SOURCEDIR::" | sed "s:^/::")
    POT=$(basename $XML .xml).pot

    mkdir -p $PODIR/$SUBDIR

    xml2pot $XML >$PODIR/$SUBDIR/$POT
done

exit 0
