#!/bin/bash

##########################################################################################
##											##
## 				Forma de uso de este script				##
##											##
## Debe ejecutarse con permisos de root (su, sudo, gksu, gksudo)			##
##											##
## Este script fué realizado por el equipo de GALPon MiniNo <minino@galpon.org>		##
## Este script se publica SIN NINGUNA GARANTIA y bajo la Licencia Pública General GNU	##
## publicada por la Free Software Fundation.						##
##											##
##########################################################################################

## Defimos mensajes en función del local actual
case $LANG in
	es*)
		TIT1="Cambiar de idioma"
		MSG0="Seleccione el idioma que desea definir como predeterminado del sistema"
		MSG1="¿Desea que el"
		MSG11="sea el idioma predefinido de este ordenador?"
		TIT2="Configurando..."
		MSG2="Espere...
			\nEsto puede tardar un par de minutos"
		MSG3="La configuración ya ha sido modificada.
			\nSera preciso reiniciar el ordenador para que la nueva configuración de idioma tenga efecto.
			\nDesea reiniciar ahora?"
		TIT3="AVISO"
		MSG4="¿Confirma que quiere reiniciar?"
		TIT4="REINICIANDO"
		LBL="Reiniciar"
		MSG5="Se procede a reiniciar."
		;;
	gl*)
		TIT1="Cambiar de idioma"
		MSG0="Selecione o idioma que desexa definir como predeterminado do sistema"
		MSG1="¿Desexa que o"
		MSG11="sexa o idioma predefinido desta computadora?"
		TIT2="Configurando..."
		MSG2="Agarde...
			\nIsto pode tardar un par de minutos"
		MSG3="A configuración xa foi modificada.
			\nSera preciso reiniciar a computadora para que a nova configuración de idioma teña efecto."
		TIT3="AVISO"
		MSG4="Confirma que quere reiniciar?"
		TIT4="REINICIANDO"
		LBL="Reiniciar"
		MSG5="Procedese a reiniciar."
		;;
	pt_PT*)
		TIT1="Mudar a língua"
		MSG0=""
		MSG1="Deseja que o $IDIOMA seja a língua padrão deste computador?"
		TIT2="Configurando..."
		MSG2="Aguarde...
			\nIsto pode demorar dois minutos"
		MSG3="A configuração foi alterada.
			\nSerá necessário reiniciar o computador para a nova configuração de idioma para ter efeito."
		TIT3="Aviso"
		MSG4="Você deseja reiniciar?"
		TIT4=""
		LBL="Reiniciar"
		MSG5="Procedese a reiniciar."
		;;
	fr_FR*)
		TIT1="Changer de langue"
		MSG0=""
		MSG1="Voulez-vous que le $IDIOMA sois la langue par défaut de cet ordinateur?"
		TIT2="Configurant..."
		MSG2="Attendez...
			\nCe mai prendre deux minutes"
		MSG3="La configuration a été modifiée.
			\nAura besoin de redémarrer votre ordinateur pour le nouveau paramètre de langue pour prendre effet."
		TIT3="Avis"
		MSG4="Êtes-vous de redémarrer?"
		TIT4="REDÉMARRAGE"
		LBL="Redémarrer"
		MSG5="Procesus de redémarrage."
		;;
	*)
		TIT1="Change language"
		MSG0=""
		MSG1="Would you like that $IDIOMA is the default language of this computer?"
		TIT2="Configuring..."
		MSG2="Wait...
			\nThis can take two minutes"
		MSG3="The configuration has been changed.
			\nWill need to restart your computer to the new language setting to take effect.."
		TIT3="Cancel"
		MSG4="Are you want to restart?"
		TIT4="RESTARTING"
		LBL="Restart"
		MSG5="Is to Restart."
		;;
esac

LINGUA=$(Xdialog --title "$TIT1" --fill	\
	--icon $HOME/.icewm/icons/translate.xpm \
	--item-help \
	--radiolist "$MSG0" 0 0 0	\
	"es_ES" "Castellano de España"	off	"Variante española del castellano" \
	"gl_ES" "Galego"		on 	"O falado en Galicia, Europa" \
	2>&1)

#	"pt_PT" "Portugês de Portugal" 	off 	"Língua portuguesa opção para Portugal" \
#	"fr_FR"	"Français de France" 	off 	"Variante de la langue française pour la France" \
#	"en_EN" "English of England" 	off 	"English language option for England" \

case $? in
	0)
		case $LINGUA in
			es*)
				IDIOMA="CASTELLANO"
				;;
			gl*)
				IDIOMA="GALEGO"
				;;
			pt*)
				IDIOMA="PORTUGUÊS"
				;;
			fr*)
				IDIOMA="FRANÇAIS"
				;;
			en*)
				IDIOMA="ENGLISH"
				;;
		esac

		Xdialog --title "$TIT1" --fill \
			--icon $HOME/.icewm/icons/translate.xpm \
			--yesno "$MSG1 $IDIOMA $MSG11" 0 0
		case $? in
			0)	
				sudo echo "LANG=$LINGUA.UTF-8" > /etc/default/locale && 
				Xdialog --title "$TIT2" --ok-label "$LBL" \
					--default-no --fill \
					--icon $HOME/.icewm/icons/duda.xpm \
					--yesno "$MSG3" 0 0
				case $? in
					0)
						Xdialog --title "$TIT3" --ok-label "$LBL" \
							--default-no --fill \
							--icon $HOME/.icewm/icons/danger.xpm \
							--yesno "$MSG4" 0 0
						case $? in
							0)
								Xdialog --title "$TIT4..." --ok-label "$LBL" \
								--icon $HOME/.icewm/icons/importante.xpm \
								--infobox "$MSG5" 0 0 5000
								sudo shutdown -r now
								;;
						esac		
				esac
		esac
esac

#				sudo dpkg-reconfigure -u locales | 
#				Xdialog --title "$TIT2" --fill \
#				--icon $HOME/.cewm/icons/reloj.xpm \
#				--progress "$MSG2" 0 0 51 - && 
