#!/bin/sh

set -e

# Get ISO codes from the iso-codes package and extract translations

# Our apt has config to strip translations
wget http://archive.ubuntu.com/ubuntu/pool/main/i/iso-codes/iso-codes_3.79-1_all.deb
dpkg --extract iso-codes_3.79-1_all.deb /

rm -rf debian/iso-codes
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

# If no iso-codes translation is available for se, then use nb instead
if [ ! -f debian/iso-codes/se.po ] && [ -f debian/iso-codes/nb.po ]; then
	cp debian/iso-codes/nb.po debian/iso-codes/se.po
fi
