#!/bin/sh -e
#
# Test if the default ispell dictionary is set according to the
# default language set during installation of Skolelinux.
#
# Based on update-ispell-dictioary from the ispell package

if test -r /etc/skolelinux/config ; then
    mv /etc/skolelinux/config /etc/debian-edu/config
fi

if test -r /etc/debian-edu/config ; then
    . /etc/debian-edu/config
fi

# Standalone Main-Server do not install ispell dictionaries
if [ "$PROFILE" = Main-Server ] ; then
    exit 0
fi

get_default_ispell_dictionary () {
 current_default=`/usr/sbin/update-alternatives \
        --display ispell-dictionary.hash \
        | grep 999 \
        | sed 's+/usr/lib/ispell/++' \
        | sed 's/\.hash//' \
        | awk '{print $1}'`

 if [ -z $current_default ]
 then
  current_default='None'
 fi
}

map_locale_to_dictionary() {
    case "$1" in
	ca_*)
	    dict="catalan"
	    ;;
	da_*)
	    dict="dansk";
	    ;;
	de_*)
	    dict="ngerman"
	    ;;
	es_*)
	    dict="spanish"
	    ;;	    
	fi_*)
	    dict="finnish-large"
	    ;;
	fr_*)
	    dict="french"
	    ;;	    
	it_*)
	    dict="italian"
	    ;;
# Latvian doesn't yet have an ispell dictionary	    
# so as yet it doesn't make sense to test for it
#	lv_*)
#	    dict=""
#	    ;;
	nb_*|no_*)
	    dict="bokml";
	    ;;
#	nds_*)
#	    dict="unknown";
#	    ;;
	nl_*)
	    dict="dutch"
	    ;;
	nn_*)
	    dict="nynorsk";
	    ;;
	pl_PL)
	   dict="polish";
	   ;;
	    # Brazilian Portuguese dictionary
	pt_BR)
	   dict="brazilian";
	   ;;
	se_*)
	    # Northern Saami is not yet available
	    dict="bokml";
	    ;;
	sv_*)
	    dict="swedish"
	    ;;
	*)
	    # Accept the default if no default language is selected
	    dict="Unknown ispell dictionary";
	    ;;
    esac
}

get_default_ispell_dictionary

map_locale_to_dictionary $LOCALE

if test "$dict" != "$current_default" ; then
    echo "error: $0: Locale '$LOCALE' uses '$dict', but default is '$current_default'."
else
    echo "success: $0: Locale '$LOCALE' matches default '$current_default'."
fi
