#!/bin/sh

# Copyright © 2015-2022 Jakub Wilk <jwilk@jwilk.net>
#
# This file is part of pdf2djvu.
#
# pdf2djvu is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# pdf2djvu is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.

set -e -u

srcdir=$(dirname "$0")/..
pofiles=''
translators=''
if [ $# -eq 0 ]
then
    printf 'Usage: %s PO-FILE...\n' "$0" >&2
    exit 1
fi
for po in "$@"
do
    m1=$(msgattrib --only-fuzzy "$po")
    m2=$(msgattrib --untranslated "$po")
    if [ "$m1$m2" ]
    then
        pofiles="$pofiles;$po"
        translator=$(sed -n -e '/^"Last-Translator: \(.\+\)\\n"/ s//\1/p' "$po")
        translators="$translators;$translator"
    fi
done
IFS='()' read _ version _ < "$srcdir/doc/changelog"
printf '%s' "$translators" \
| tr ';' '\n' \
| LC_ALL=C sort -u \
| xargs -d '\n' printf '%s, ' \
| sed -e 's/^, /To: /; s/, $//'
printf '\n'
printf 'Subject: %s\n' "pdf2djvu $version: call for translations"
cat <<EOF

Hi pdf2djvu translators!

I'd like to release pdf2djvu $version soon, but this version introduces new strings that should be translated.
I need your help in updating the PO files.

You can download current versions of the PO files here:
EOF
(
    IFS=';'
    printf 'https://github.com/jwilk/pdf2djvu/raw/master/%s\n' ${pofiles#';'}
)
printf '\nThanks in advance!\n'

# vim:ts=4 sts=4 sw=4 et
