#!/bin/sh
#
# Tazlocale: SliTaz GNU/Linux locale setting using dialog boxes.
# Configuration file is : /etc/locale.conf
#
# 2007/11/04 <pankso@slitaz.org> - GNU gpl.
#
: ${DIALOG=dialog}

# Script functions.
status()
{
	local CHECK=$?
	echo -en "\\033[70G[ "
	if [ $CHECK = 0 ]; then
		echo -en "\\033[1;33mOK"
	else
		echo -en "\\033[1;31mFailed"
	fi
	echo -e "\\033[0;39m ]"
}

# Check if user is root.
#
if test $(id -u) != 0; then
  echo ""
  echo "You must be root to run `basename $0`!"
  echo "Type su and root password to become super-user."
  echo ""
  exit 1
fi

# Dialog menu.
#
exec 3>&1
value=`$DIALOG  --clear \
    --title " SliTaz locale configuration " \
    --menu \
"Slctionnez votre langue - Select your language." 15 70 5 \
"fr_CH" "Franais Suisse." \
"fr_FR" "Franais France." \
"en" "English (POSIX)." \
2>&1 1>&3`
retval=$?
exec 3>&-

case $retval in
  0)
    echo -n "$value selected... " 
    status ;;
  1)
    echo "Cancel pressed."
    exit 0 ;;
  255)
    if test -n "$value"; then
      echo "$value"
    else
      echo "ESC pressed."
      exit 0
    fi ;;
esac

# Now we can creat /etc/locale.conf.
#
case $value in
  fr_CH)
    echo "Paramtrage de la langue pour le franais Suisse..."
    echo -n "Cration du fichier de configuration : /etc/locale.conf"
    echo "LANG=fr_CH" > /etc/locale.conf
    echo "LC_ALL=fr_CH" >> /etc/locale.conf
    status ;;
  fr_FR)
    echo "Paramtrage de la langue pour le franais France..."
    echo -n "Cration du fichier de configuration : /etc/locale.conf"
    echo "LANG=fr_FR" > /etc/locale.conf
    echo "LC_ALL=fr_FR" >> /etc/locale.conf
    status ;;
  en)
    echo "Setting language to English (POSIX)... "
    echo -n "Creating configuration file : /etc/locale.conf"
    echo "LANG=POSIX" > /etc/locale.conf
    echo "LC_ALL=POSIX" >> /etc/locale.conf
    status ;;
esac

if [ -f "/etc/locale.conf" ]; then
	. /etc/locale.conf
	export LANG LC_ALL
fi

exit 0
