#! /bin/bash

set -o errexit

cd po
intltool-update --pot
mkdir ../gnome-patch-translation/new
cp -a *.pot ../gnome-patch-translation/new
cd ../gnome-patch-translation/new

eval POT=$(echo *)
POT=${POT%.pot}
cd ..
msgcomm --unique -o $POT-unique.pot old/$POT.pot new/$POT.pot
msgcomm --more-than=1 -o $POT-patch.pot $POT-unique.pot new/$POT.pot

rm -rf new old $POT-unique.pot

cd ../po

for PO in *.po ; do
    LNG=${PO%.po}
    if test -f /opt/gnome/share/gnome-patch-translation/$LNG.po ; then
	echo "Updating $PO using gnome-patch-translation compendium."
	msgmerge --compendium=/opt/gnome/share/gnome-patch-translation/$LNG.po -o $PO.new $PO $POT.pot
	mv $PO.new $PO
    fi
done
sed -i 's@#: \.\./@#: '$POT'/@' ../gnome-patch-translation/$POT-patch.pot
for PO in *.po ; do
    LNG=${PO%.po}
    echo "Creting fuzzy $PO for gnome-patch-translation."
    msgmerge -o ../gnome-patch-translation/$POT-$LNG.po $PO ../gnome-patch-translation/$POT-patch.pot
    sed -i 's@#: \.\./@#: '$POT'/@;/#~/,$d' ../gnome-patch-translation/$POT-$LNG.po
done

echo "================================================================="
echo " Translatable strings from patches were written to"
echo " gnome-patch-translation/. If you did any translabable string"
echo " change in any patch, please copy contents of this directory"
echo " to the gnome-patch-translation package, file"
echo " gnome-patch-translation-files.tar.bz2."
echo "================================================================="
