echo "-- Building .pot file and updating translations ..."
POT=guayadeque.pot

cd src
find . -name "*.cpp" | xargs xgettext -d guayadeque -o ${POT} -C -k_ -kwxPLURAL:1,2
cat ../po/external.pot >>${POT}
mv ${POT} ../po

cd ../po

# The .po files carry no location comments; rewrite one only when its translatable content really
# changed (a new header date alone would keep every translation file dirty on every build).
find . -name "*.po" | while IFS= read -r pofile; do
    msgmerge -q -o ${pofile}.new ${pofile} --no-location ${POT}
    grep -v '^"POT-Creation-Date:' ${pofile} >${pofile}.oldstripped
    grep -v '^"POT-Creation-Date:' ${pofile}.new >${pofile}.newstripped
    if cmp -s ${pofile}.oldstripped ${pofile}.newstripped; then
        rm -f ${pofile}.new ${pofile}.oldstripped ${pofile}.newstripped
    else
        rm -f ${pofile}.oldstripped ${pofile}.newstripped
        mv ${pofile}.new ${pofile}
    fi
done

cd ..
