#!/bin/bash


#Comprobe if language was selected
lang_code=$(grep 'LANG=' /root/.codecheck | cut -d '=' -f 2) ;
if [ "${lang_code// /}" == "0" ]; then
if ((1)); then echo "/root/.language.sh" ; else
  lang=$(dialog --stdout --no-tags --no-cancel --timeout 10     \
	              --backtitle "System language selection"         \
	              --menu      "Choose your language:" 15 40 10    \
                            'en_US.UTF-8' "English"             \
                            'eo'          "Esperanto"           \
                            'es_ES.UTF-8' "Spanish"             \
                            'fr_FR.UTF-8' "French"              \
                            'gl_ES.UTF-8' "Galego"              \
                            'it_IT.UTF-8' "Italian"             \
                            'pl_PL.UTF-8' "Polish"              \
                            'pt_BR.UTF-8' "Brazilian Portuguese")
fi
  [ "${lang}" == "" ] && lang='en_US.UTF-8'

  #Copy locale in locale.conf
  echo "LANG=${lang}" > /etc/locale.conf

  #Put a new line confirm that language was selected
  sed -i "s/^LANG=.*/LANG=${lang}/" /root/.codecheck

	#Copy scripts to install in that language
  lang=${lang/_*/}
  ls /root/.scriptsInstallation/language/${lang}/ &> /dev/null || lang='en'
  cp -a /root/.scriptsInstallation/language/${lang}/* /root/.scriptsInstallation/
fi
