case $MODE in
    commandline)
        add_option "locale" "`eval_gettext "set the default locale"`" "advanced" "true"
        ;;
    configure)
        if [ -n "$option_locale_value" ]; then
            LOCALE="$option_locale_value"
        fi
        ;;
    before-install)
        # include locales in initial deboostrap
        if [ -z "$INCLUDE" ]; then
            INCLUDE="locales"
        else
            INCLUDE="$INCLUDE,locales"
        fi
        ;;
    install)
        for f in /etc/locale.gen /etc/default/locale \
            /etc/default/console-setup /etc/default/keyboard; do
            if [ -f "$f" ]; then
                cp "$f" "$ROOT/$f"
            fi
        done
        
        if [ -n "$LOCALE" ]; then
            export LANG=$(echo "$LOCALE" | awk '{print $1}')
            echo "$LOCALE" >> $ROOT/etc/locale.gen
            echo "LANG=$LANG" >> $ROOT/etc/default/locale
        fi

        if [ -f $ROOT/etc/locale.gen ] && [ -x $ROOT/usr/sbin/locale-gen ] ; then
            DEBIAN_FRONTEND=noninteractive DEBIAN_PRIORITY=critical LC_ALL=C chroot $ROOT /usr/sbin/locale-gen
        fi

        # set debian-installer/keymap question in the chroot if present on the server
        debian_installer_keymap="$(debconf-get-selections | grep debian-installer/keymap)" || true
        if [ -n "$debian_installer_keymap" ]; then
            echo "$debian_installer_keymap" | chroot $ROOT debconf-set-selections
        fi
        ;;
esac
