#!/bin/sh
# SPDX-FileCopyrightText: 2026 Dr. Tobias Quathamer <toddy@debian.org>
#
# SPDX-License-Identifier: GPL-3.0-or-later

set -eu

# Generate pot file for program messages
xgettext \
    --files-from=po/POTFILES.in \
    --output=po/isoquery.pot \
    --package-name=isoquery \
    --from-code=UTF-8 \
    --language=C \
    --keyword=_ \
    --keyword=N_ \
    --copyright-holder="Dr. Tobias Quathamer" \
    --msgid-bugs-address=toddy@debian.org \
    --add-comments

# Generate pot file for manpage
cat man/po4a.cfg.in | \
    sed -e \
    "s/@sourcedir@/man/g; s/@builddir@/man/g; s/@lang@/\$lang/g" \
    > man/po4a.cfg
po4a --no-translations man/po4a.cfg
rm -f man/po4a.cfg
sed -i -e "/^#: /d" man/isoquery-man.pot

# Update .po files for program messages
for i in po/*.po; do
	msgmerge --previous "$i" po/isoquery.pot > tmp.po && mv tmp.po "$i"
done

# Update .po files for manpage
for i in man/*.po; do
	msgmerge --previous --no-location "$i" man/isoquery-man.pot > tmp.po && mv tmp.po "$i"
done
