#!/bin/sh

set -e

#
# Get ISO codes from the iso-codes package and extract translations
set -e
[ -r /usr/share/xml/iso-codes/iso_3166.xml ] || exit 1
rm -rf debian/iso-codes >/dev/null 2>&1
mkdir debian/iso-codes
for i in `find /usr/share/locale/ -name iso_3166.mo` ; do
  language=`echo $i | cut -f5 -d/`
  # Extract translations from the iso-codes package
  msgunfmt $i >debian/iso-codes/${language}.po 2>/dev/null
done

DATE="$(date +'%Y-%m-%d %H:%M%z')"
cat <<EOF >debian/iso-codes/en.po
msgid ""
msgstr ""
"Project-Id-Version: iso_3166 CVS\\n"
"Report-Msgid-Bugs-To: Alastair McKinstry <mckinstry@debian.org>\\n"
"POT-Creation-Date: $DATE\\n"
"PO-Revision-Date: $DATE\\n"
"MIME-Version: 1.0\\n"
"Content-Type: text/plain; charset=UTF-8\\n"
"Content-Transfer-Encoding: 8bit\\n"

EOF
./iso3166tab.py /usr/share/xml/iso-codes/iso_3166.xml \
  | perl -pe 's/.*?\t(.*)/msgid "$1"\nmsgstr "$1"\n/' \
  >>debian/iso-codes/en.po
