#!/bin/sh

SELF="$(realpath "$0")"
PODIR="$(dirname "$SELF")"
PROJECT_ROOT="$(dirname "$PODIR")"

cd "$PODIR"

echo "Creating POTFILES"
rm -v POTFILES

for i in $(find ../src | grep '\.*php$'); do
    echo $i >> POTFILES
done
if [ -f messages.pot ]; then
    JOIN="--join-existing"
else
    JOIN=""
fi
echo "extracting messages"

xgettext -f POTFILES -d mydevel.webroot -L PHP $JOIN --force-po -o messages.pot
if [ -z "$JOIN" ]; then
    sed -i s/charset=CHARSET/charset=UTF-8/g messages.pot
fi

for i in `cat LINGUAS`; do
    if [ ! -f $i.po ]; then
        cp messages.pot $i.po
    else
        msgmerge $i.po messages.pot
    fi
done


