#!/bin/bash -l
#############################################################
# Copyright (C) 2026, PCLinuxOS <https://www.pclinuxos.com>
# Released under GPL licence (version 2 or later)
# by pinoc <vogtpet@gmail.com>
#############################################################
#     addlocale
#
# Purpose: add a non-English locale to a PCLinuxOS system 
# 
# Requirements: 
#  - PCLinuxOS installation
#  - working dnf & Internet connection
#  - zenity, tee, bc, awk, wget, sed, bash, xz, curl
#
# Version: 4.6-6 (2026-03-28)
# 
# more information can be found at: 
# https://pclosusers.com/wiki/index.php?title=Localization_Manager
#############################################################
# i18n - Internationalization 
#=================================================
export TEXTDOMAIN=addlocale
export TEXTDOMAINDIR="/usr/share/locale"
export LC_NUMERIC="en_US.UTF-8"

# define dialog title, icon, etc.
#=================================================
WICON='/usr/share/pixmaps/addlocale.png' && TITLE="addlocale 4.6"
sysarch=`getconf LONG_BIT`
ZEN2="/usr/bin/zenity --no-wrap --window-icon="$WICON
ZEN3="zenity --window-icon="$WICON

if [ -d "/union" ]; then
    $ZEN2 --title="AddLocale" --info --text=$"Please run this program after installation!"
  exit 0
fi

#set default parameters:
VERBOSE=0
UPDATETEST=1

#read parameters from command line
#=================================================
for i in $*
do
   case $i in
       --debug)
       VERBOSE=1
       ;;
       --no-updatetest)
       UPDATETEST=0
       ;;
       --help)
       echo "usage: $0 --debug --no-updatetest"
       echo "--debug: verbose output for debugging"
       echo "--no-updatetest: skip test if system is fully updated"
       echo "--help: show options"
       exit
       ;;
       *)
       # unknown option
       echo "Error: unknown option"
       echo "usage: $0 --help"
       exit
       ;;
   esac
done

# Check if not root
#=================================================
if [ "$USER" != "root" ]; then
  echo "Please run this script from the start menu or as root (su -)!"
  exit 0
fi


# verbose output for debugging
if [ $VERBOSE -eq 1 ]; then set -xv;fi


# check for DNF
#=================================================
if [ ! -f /usr/bin/dnf ]; then
  MSG=$"addlocale requires the DNF package manager, please install it.\n\nExiting..."
  $ZEN2 --title="$TITLE" --error --text "$MSG"
  exit 0
fi


# check if we run a pclos kernel
#=================================================
if [ -z "`uname -r |grep pclos`" ]; then
  MSG=$"addlocale requires a 'pclos'-kernel.\n\nExiting..."
  $ZEN2 --title="$TITLE" --error --text "$MSG"
  exit 0
fi

# check for proper openssl-setup, maybe required for some LO-servers
if [ ! -d /etc/openssl ];then 
  mkdir /etc/openssl
  ln -s /etc/ssl/certs/ /etc/openssl/certs
fi

# initialize the log-file, check for web browser and addlocale version
#======================================================================
almil="/tmp/addlocale-install.log"
echo "addlocale installation log file:" > $almil ; date >> $almil

# currently installed addlocale version
rpm -qa addlocale >> $almil


# get system users
#=================================================
SYSUSERS=$(grep [0-9][0-9][0-9]:.*/home /etc/passwd | grep -f /etc/shells | cut -d: -f1)

# check for KDE session, KDE4, KDE5, e17
#=================================================
KSM=`pidof ksmserver`
if [ "${#KSM}" == "0" ];then HAS_KDESESSION="0"; else HAS_KDESESSION="1"; fi
if [ `rpm -qa lib64kf5notifyconfig5 lib64kf5threadweaver5|wc -l` -gt 0 ];then HAS_KDE5="1"; else HAS_KDE5="0";fi 
if [ `rpm -qa kdebase4-core kde-baseapps-core|wc -l` -gt 0 ];then HAS_KDE4="1"; else HAS_KDE4="0";fi 

if  [ "$HAS_KDE4" == "1" ];then 
  MSG=$"KDE4 is no longer supported in PCLinuxOS. \nPlease do a fresh installation from a current KDE6 or Mate iso.\n\nExiting..."
  if [ -r /usr/bin/zenity ]; then 
    $ZEN2 --title "$TITLE" --error --text "$MSG"
  else
    Xdialog --title "$TITLE" --left --msgbox "$MSG" 20 70
  fi
  exit 0
fi
if  [ "$HAS_KDE5" == "1" ];then
  MSG=$"KDE5 is no longer supported in PCLinuxOS. \nPlease do a fresh installation from a current KDE6 or Mate iso.\n\nExiting..."
  if [ -r /usr/bin/zenity ]; then
    $ZEN2 --title "$TITLE" --error --text "$MSG"
  else
    Xdialog --title "$TITLE" --left --msgbox "$MSG" 20 70
  fi
  exit 0
fi

if [ $sysarch -eq 32 ]; then
  MSG=$"32bit is no longer supported in PCLinuxOS.\n\nExiting..."
  if [ -r /usr/bin/zenity ]; then 
    $ZEN2 --title "$TITLE" --error --text "$MSG"
  else
    Xdialog --title "$TITLE" --left --msgbox "$MSG" 20 70
  fi
  exit 0
fi


if [ "$HAS_KDESESSION" == "1" ];then
 INP11=".config/kdeglobals"
 INP12=".config/kdeglobals_AL"
fi
if [ -d "/etc/skel/.e" ]; then HAS_E17="1"; else HAS_E17="0";fi


# Check for available disk space
#=================================================
FREE=`df -k |grep "/$" |awk '{print$4}'`
if [ $FREE -lt 260000 ]; then # we need 250MB for localization
  MSG=$"Insufficient disk space to add a new locale.\n\nExiting..."
  if [ -r /usr/bin/zenity ]; then 
    $ZEN2 --title "$TITLE" --error --text "$MSG"
  else
    Xdialog --title "$TITLE" --left --msgbox "$MSG" 20 70
  fi
  exit 0
fi

# ensure we have at least a 2023 release
#=======================================================
QQ=`cat /etc/pclinuxos-release`
declare -i PCLOSVERSION
PCLOSVERSION=$(echo $QQ | sed 's/.* \(20[0-9][0-9]\) .*/\1/')
if [ $PCLOSVERSION -lt 2023 ];then
  MSG=$"addlocale requires a PCLinuxOS release of 2023 or later.\nPlease install from the latest PCLinuxOS liveCD \n, then fully update your installation, and then run \naddlocale again on the installed and fully updated system.\n\nExiting..."
  if [ -r /usr/bin/zenity ]; then 
    $ZEN2 --title "$TITLE" --error --text "$MSG"
  else
    Xdialog --title "$TITLE" --left --msgbox "$MSG" 20 70
  fi
  exit 0
fi

# check for working internet connection
#=================================================
cd /tmp && /bin/rm -f index.html* inet.log*
( wget --timeout=20 http://www.google.com/index.html -o inet.log ) 2>&1 | $ZEN3 --title="$TITLE" --progress --text=$"Testing your Internet connection..." --no-cancel --pulsate --auto-close

if [ -f /tmp/index.html ]; then
  echo
  echo Internet connection working
  echo
  # check inet.log to see if we are in Thailand
  # INTHAI=`cat inet.log |grep 'Location: http://www.google.co.th/index.html'|wc -l`
  /bin/rm -f index.html* inet.log*
else
  MSG=$"Problem accessing the Internet\! You have either:\n a) no Internet connection, too bad :-(, or\n b) you use a proxy sever, or \n c) you have a dns-lookup error.\n\nNote: If you are sure that your Internet connection works fine then you could try to reconfigure it:\n\n b) Configure your proxy server:\n=================================\nopen a konsole and enter:\n      export http_proxy=http://proxy.example.com:8080\nReplace with the name of your proxy server. Then in the same konsole enter:  addlocale \n\n c) Configure your Internet to use OpenDNS:\n=================================\n1. Open PCLinuxOS Control Center 'Configure Your Computer'\n2. Select 'Network and Internet' -> 'Network Center', open your network connection and click the button 'Configure' \n3. Uncheck 'Get DNS servers from DHCP'.\n     In the box for DNS Server 1 enter: 208.67.222.222 \
  \n     In the box for DNS Server 2 enter: 208.67.220.220 \nClick on 'OK' at the bottom right to close this dialog window. \n4. Back in the Network Center window click on 'Disconnect', wait for it to finish, then click on 'Connect'. \n5. Your Internet connection is now configured to use OpenDNS. Close all open PCC-windows and start addlocale again. \n\nNote: these OpenDNS configuration steps have been saved to the file 'OpenDNS_howto.txt' in your HOME-directory.\nExiting..."
  $ZEN2 --title="$TITLE" --info --text "$MSG"

  # output the OpenDNS config info
  INP1=/root/OpenDNS_howto.txt
  echo "Steps to reconfigure your Internet connection" > $INP1
  echo " " >> $INP1
  echo "a) using your proxy server:" >> $INP1
  echo "============================================ " >> $INP1
  echo "open a konsole and enter: " >> $INP1
  echo "   export http_proxy=http://proxy.example.com:8080" >> $INP1
  echo "Replace with the name of your proxy server. " >> $INP1
  echo "Then in the same konsole enter the command of your application, i.e:  addlocale  " >> $INP1
  echo " " >> $INP1
  echo "b) using OpenDNS (http://www.opendns.com/):" >> $INP1
  echo "============================================ " >> $INP1
  echo "1. Open PCLinuxOS Control Center 'Configure Your Computer'." >> $INP1
  echo "2. Select 'Network and Internet' -> 'Network Center', open your network connection and click the button 'Configure'" >> $INP1
  echo "3. Uncheck 'Get DNS servers from DHCP'" >> $INP1
  echo "        In the box for DNS Server 1 enter: 208.67.222.222" >> $INP1
  echo "        In the box for DNS Server 1 enter: 208.67.220.220" >> $INP1
  echo "   Finally click on the OK button at the bottom right to close this dialog window.   " >> $INP1
  echo "4. Back in the Network Center window click on 'Disconnect', wait for it to finish, then click on 'Connect'." >> $INP1
  echo "5. Your Internet connection is now configured to use OpenDNS. Close all open PCC-windows." >> $INP1

  /bin/cp -f $INP1 /etc/skel/OpenDNS_howto.txt
  if [ -d /etc/skel_fm ];then /bin/cp -f $INP1 /etc/skel_fm/OpenDNS_howto.txt; fi
  if [ -d /etc/skel_default ];then /bin/cp -f $INP1 /etc/skel_default/OpenDNS_howto.txt; fi
  if [ -d /etc/skel-orig ];then /bin/cp -f $INP1 /etc/skel-orig/OpenDNS_howto.txt; fi

  for idx in $SYSUSERS
    do
    INP2=/home/$idx/OpenDNS_howto.txt
    /bin/cp -f $INP1 $INP2 && chown $idx:`id -gn $idx` $INP2
  done
  /bin/rm -f index.html* inet.log*
  exit 0
fi

# count active repos, it must have:  x86_64, kde6, xfce4, mate
cd /tmp && /bin/rm -f tt1.txt tt2.txt
ls /var/cache/libdnf5|awk -F "-" '{print$1}'|uniq > tt1.txt


# check for kde5
r1=$(cat tt1.txt|grep -c 'kde5')

if [ $r1 -eq 1 ];then
  $ZEN2 --title="$TITLE" --error --text=$"Package manager repository kde5 is not valid.\nValid repository are: x86_64, kde6, xfce4, mate.\nOnce fixed, update your system and run addlocale again.\n\nExiting..."
  exit 0
fi

cat tt1.txt |tr " " "\n" > tt2.txt

if [ `grep -cE 'x86_64|kde6|mate|xfce4' tt2.txt` -ne 4 ];then
  $ZEN2 --title="$TITLE" --error --text=$"Package manager repositories are not configured properly.\nThey must contain the sections: x86_64, kde6, xfce4, mate.\nOnce fixed, update your system and run addlocale again.\n\nExiting..."
  exit 0
fi

# clean up
/bin/rm -f tt1.txt tt2.txt


# check that package managers are closed
#=================================================
### if [ -n "`pidof $idx`" ];then
for idx in synaptic kpackage apt-get dnf dnf5_launcher
do 
 if [ "`ps -ef|grep -w $idx | wc -l`" -ge 2 ];then
  $ZEN2 --title="$TITLE" --error --text=$"Please close your package manager '$idx' and then run addlocale again.\n\nExiting..."
  exit 0
 fi
done


# Explain what we want to do
#=================================================
MSG=$"                         Welcome to addlocale\!\n\nThis script will add one (1) new locale to the existing English locale \nof your system. The new locale will be set as the default locale for \nroot, all existing users, and potential new users on the system. \n=======================================\nPlease note:\n=======================================\n* Addlocale will not translate anything but simply applies\n   already available translations. Depending on the choosen\n   locale and the associated translations some applications\n   may be only partial, or even not at all, in the new language.\n* To add more than one locale run this script again. Then\n   choose your preferred locale from the list of available\n   languages in the KDE and the PCLinuxOS Control Center or \n   from the Language tabulator at the GNOME login screen.\n* The default locale English (US) is never removed and can \n   always be restored by running addlocale with the default\n   settings.\n* Please use the program 'lomanager' for any LibreOffice \n   related task, such as install, upgrade, localize, fix, or uninstall\n   LibreOffice."

$ZEN2 --title "$TITLE" --info --text "$MSG"

$ZEN2 --title "$TITLE" --question --text $"Before we begin please ensure that all other users \nare logged out and EXIT all open applications \!\!\!\n\nIf this is the case, press Yes to start adding the new \nlocale, else press No to exit this script."
if [ "$?" == "1" ]; then
  $ZEN2 --title "$TITLE" --info --text=$"You chose to exit. \nNo changes were applied to your system."
  exit 0
fi

# Select new locale (all kde3/4 languages: 86 = 85 + default en_US)
#================================================================
# KDE4: 65 (64 + default en_US; 7 per line)
# Chhattisgarhi, Frisian, Gujarati, Kannada, Kashubian, Kazakh, Khmer,
# Kurdish, Maithili, Malayalam, Marathi, Nepali
# Arabic, Basque, Belarusian, Bengali, Bulgarian, Catalan, Chinese (simplified),
# Chinese (traditional), Croatian, Czech, Danish, Dutch, English (GB), English (US),
# Esperanto, Estonian, Farsi, Finnish, French, Gaelic, Galician,
# German, Greek, Hebrew, Hindi, Hungarian, Icelandic, Indonesian, Italian,
# Japanese, Korean, Latvian, Lithuanian, Macedonian, Norwegian (Bokmaal), Norwegian (Nynorsk),
# Polish, Portuguese (Brazil), Portuguese (Portugal), Punjabi, Romanian, Russian, Low Saxon,
# Serbian, Slovak, Slovenian, Spanish, Swedish, Tajik, Thai,
# Turkish, Ukrainian, Walloon
#

# non KDE4: 73 (72 + default en_US; 7 per line)
# Afrikaans, Azeri, Breton, Bosnian, Faroese, Indonesian, Lao,
# Malay, Maltese, Mongolian, Saami, Upper Sorbian, Sotho, Swati,
# Tamil, Uzbek, Venda, Vietnamese, Welsh, Xhosa, Zulu
# Arabic, Basque, Belarusian, Bengali, Bulgarian, Catalan, Chinese (simplified),
# Chinese (traditional), Croatian, Czech, Danish, Dutch, English (GB), English (US),
# Esperanto, Estonian, Farsi, Finnish, French, Gaelic, Galician,
# German, Greek, Hebrew, Hindi, Hungarian, Icelandic, Italian,
# Japanese, Korean, Latvian, Lithuanian, Macedonian, Norwegian (Bokmaal), Norwegian (Nynorsk),
# Polish, Portuguese (Brazil), Portuguese (Portugal), Punjabi, Romanian, Russian, Low Saxon,
# Serbian, Slovak, Slovenian, Spanish, Swedish, Tajik, Thai,
# Turkish, Ukrainian, Walloon
#
#  (all kde3/4 languages: 86 = 85 + default en_US)
# ======================================================
# KDE4/5-only: 12 (7 per line)
# Chhattisgarhi, Frisian, Gujarati, Kannada, Kashubian, Kazakh, Khmer,
# Kurdish, Maithili, Malayalam, Marathi, Nepali
#
# KDE3-only: 21 (7 per line)
# Afrikaans, Azeri, Breton, Bosnian, Faroese, Indonesian, Lao,
# Malay, Maltese, Mongolian, Saami, Upper Sorbian, Sotho, Swati,
# Tamil, Uzbek, Venda, Vietnamese, Welsh, Xhosa, Zulu
#
# KDE3 and KDE4: 52 (7 per line)
# Arabic, Basque, Belarusian, Bengali, Bulgarian, Catalan, Chinese (simplified),
# Chinese (traditional), Croatian, Czech, Danish, Dutch, English (GB), English (US),
# Esperanto, Estonian, Farsi, Finnish, French, Gaelic, Galician,
# German, Greek, Hebrew, Hindi, Hungarian, Icelandic, Italian,
# Japanese, Korean, Latvian, Lithuanian, Macedonian, Norwegian (Bokmaal), Norwegian (Nynorsk),
# Polish, Portuguese (Brazil), Portuguese (Portugal), Punjabi, Romanian, Russian, Low Saxon,
# Serbian, Slovak, Slovenian, Spanish, Swedish, Tajik, Thai,
# Turkish, Ukrainian, Walloon
#

# if KDE4 is installed, and even if we do not run a KDE session, then we must constrain the 
# possible language translations to those of KDE4 as otherwise the kde-l10n can not be found
# for languages which are not available for KDE4
#  FALSE "Interlingua" and "Valencia" disabled cause no locales-ia exist
#
if [ "$HAS_KDESESSION" == "1" ];then
  # these are all kde-l10n- languages in KDE5: 67 = 66 + default en_US
  AL_LANG=$($ZEN3 --title "$TITLE" --list --text $"Please select the new KDE-locale or press Cancel to quit" --width 400 --height 500  --list  --radiolist  --column $"Select" --column $"New locale (country settings)" TRUE "English (US) [Select to restore default]" FALSE "Arabic (Egypt)" FALSE "Basque" FALSE "Belarusian" FALSE "Bengali (India)" FALSE "Bosnian" FALSE "Bulgarian" FALSE "Catalan" FALSE "Chhattisgarhi" FALSE "Chinese (simplified)" FALSE "Chinese (traditional)" FALSE "Croatian" FALSE "Czech" FALSE "Danish" FALSE "Dutch" FALSE "English (GB)" FALSE "Esperanto" FALSE "Estonian" FALSE "Farsi" FALSE "Finnish" FALSE "French (France)" FALSE "Frisian" FALSE "Gaelic (Ireland)" FALSE "Galician" FALSE "German (Germany)" FALSE "Greek" FALSE "Gujarati" FALSE "Hebrew" FALSE "Hindi" FALSE "Hungarian" FALSE "Icelandic" \
  FALSE "Indonesian" FALSE "Italian" FALSE "Japanese" FALSE "Kannada" FALSE "Kashubian" FALSE "Kazakh" FALSE "Khmer" FALSE "Korean" FALSE "Kurdish" FALSE "Latvian" FALSE "Lithuanian" FALSE "Maithili" FALSE "Macedonian" FALSE "Malayalam" FALSE "Marathi" FALSE "Nepali" FALSE "Norwegian (Bokmaal)" FALSE "Norwegian (Nynorsk)" FALSE "Polish" FALSE "Portuguese (Brazil)" FALSE "Portuguese (Portugal)" FALSE "Punjabi" FALSE "Romanian" FALSE "Russian" FALSE "Low Saxon" FALSE "Serbian" FALSE "Slovak" FALSE "Slovenian" FALSE "Spanish (Spain)" FALSE "Swedish" FALSE "Tajik" FALSE "Thai" FALSE "Turkish" FALSE "Ukrainian" FALSE "Uyghur" FALSE "Walloon");
else
  # these are other non-kde5 languages: 73 = 72 + default en_US
  AL_LANG=$($ZEN3 --title "$TITLE" --list --text $"Please select the new locale or press Cancel to quit" --width 400 --height 500  --list  --radiolist  --column $"Select" --column $"New locale (country settings)" TRUE "English (US) [Select to restore default]" FALSE "Afrikaans" FALSE "Arabic (Egypt)" FALSE "Azeri" FALSE "Basque" FALSE "Belarusian" FALSE "Bengali (India)" FALSE "Breton" FALSE "Bosnian" FALSE "Bulgarian" FALSE "Catalan" FALSE "Chinese (simplified)" FALSE "Chinese (traditional)" FALSE "Croatian" FALSE "Czech" FALSE "Danish" FALSE "Dutch" FALSE "English (GB)" FALSE "Esperanto" FALSE "Estonian" FALSE "Faroese" FALSE "Farsi" FALSE "Finnish" FALSE "French (France)" FALSE "Gaelic (Ireland)" FALSE "Galician" FALSE "German (Germany)" FALSE "Greek" FALSE "Hebrew" FALSE "Hindi" FALSE "Hungarian" FALSE "Icelandic" FALSE "Indonesian" FALSE "Italian" FALSE "Japanese" FALSE "Korean" FALSE "Lao" \
  FALSE "Latvian" FALSE "Lithuanian" FALSE "Macedonian" FALSE "Malay" FALSE "Maltese" FALSE "Mongolian" FALSE "Norwegian (Bokmaal)" FALSE "Norwegian (Nynorsk)" FALSE "Polish" FALSE "Portuguese (Brazil)" FALSE "Portuguese (Portugal)" FALSE "Punjabi" FALSE "Romanian" FALSE "Russian" FALSE "Saami" FALSE "Low Saxon" FALSE "Serbian" FALSE "Slovak" FALSE "Slovenian" FALSE "Sotho" FALSE "Spanish (Spain)" FALSE "Swati" FALSE "Swedish" FALSE "Tajik" FALSE "Tamil" FALSE "Thai" FALSE "Turkish" FALSE "Ukrainian" FALSE "Uzbek" FALSE "Venda" FALSE "Vietnamese" FALSE "Walloon" FALSE "Welsh" FALSE "Xhosa" FALSE "Zulu");
fi
# Quit if Cancel was pressed
if [ "$AL_LANG" == "" ]; then 
  $ZEN2 --title "$TITLE" --info --text=$"You chose to exit. \nNo changes were applied to your system."
  exit 0
fi

#+++++++++++++++++++++++++++++++++++++++++++++++++++++
# If selected, then restore the default locale en_US
#+++++++++++++++++++++++++++++++++++++++++++++++++++++
if [ "$AL_LANG" == "English (US) [Select to restore default]" ];  then
(
    AL_EXT1='en' && AL_EXT2='en_US' && AL_EXT41='lat0-16'
    if [ "$HAS_KDESESSION" == "1" ]; then
     INP11=".config/kdeglobals"
     INP12=".config/kdeglobals_AL"
    fi
    if [ -d "/etc/skel/.e" ]; then HAS_E17="1"; else HAS_E17="0";fi
    SYSUSERS=$(grep [0-9][0-9][0-9]:.*/home /etc/passwd | grep -f /etc/shells | cut -d: -f1)

    # 1) reset sysconfig
    #=============================
    # set the new language local
    INP1=/etc/sysconfig/i18n
    INP2=/etc/sysconfig/i18n_AL
    # backup the previous i18n
    /bin/cp -f $INP1 $INP2
    # set the new language local
    echo LC_TELEPHONE=$AL_EXT2.UTF-8 > $INP1
    echo LC_CTYPE=$AL_EXT2.UTF-8 >> $INP1
    echo LANGUAGE=$AL_EXT2.UTF-8:$AL_EXT2:$AL_EXT1 >> $INP1
    echo LC_MONETARY=$AL_EXT2.UTF-8 >> $INP1
    echo LC_ADDRESS=$AL_EXT2.UTF-8 >> $INP1
    echo LC_COLLATE=$AL_EXT2.UTF-8 >> $INP1
    echo LC_PAPER=$AL_EXT2.UTF-8 >> $INP1
    echo LC_NAME=$AL_EXT2.UTF-8 >> $INP1
    echo LC_NUMERIC=$AL_EXT2.UTF-8 >> $INP1
    echo SYSFONT=$AL_EXT41 >> $INP1
    echo LC_MEASUREMENT=$AL_EXT2.UTF-8 >> $INP1
    echo LC_TIME=$AL_EXT2.UTF-8 >> $INP1
    echo LANG=$AL_EXT2.UTF-8 >> $INP1
    echo LC_IDENTIFICATION=$AL_EXT2.UTF-8 >> $INP1
    echo LC_MESSAGES=$AL_EXT2.UTF-8 >> $INP1
    echo LC_ALL=  >> $INP1
    echo GDM_LANG=$AL_EXT2.UTF-8 >> $INP1
    echo GP_LANGUAGE=$AL_EXT1 >> $INP1

    # 2) reset login screen layout: (was only needed in KDE3)
    #=============================

    
    # reset KDE plasma stuff
    #==============================================
    if [ "$HAS_KDESESSION" == "1" ]; then
      INP1=/etc/skel/.config/plasma-locale-settings.sh
      # set the new language local
      echo export LANG=$AL_EXT2.UTF-8 > $INP1
      echo export LANGUAGE=$AL_EXT2 >> $INP1
      echo " "  >> $INP1

      INP2=/root/.config/plasma-locale-settings.sh && /bin/cp -f $INP1 $INP2 
      for idx in $SYSUSERS
        do
        INP2=/home/$idx/.config/plasma-locale-settings.sh
        /bin/cp -f $INP1 $INP2 && chown $idx:`id -gn $idx` $INP2
      done

      INP1=/etc/skel/.config/plasma-localerc
      echo "[Formats]" > $INP1
      echo "LANG=en_US.UTF-8" >> $INP1
      echo " "  >> $INP1
      echo "[Translations]" >> $INP1
      echo "LANGUAGE=en_US" >> $INP1
      echo " "  >> $INP1
      INP2=/root/.config/plasma-localerc && /bin/cp -f $INP1 $INP2 
      for idx in $SYSUSERS
        do
        INP2=/home/$idx/.config/plasma-localerc
        /bin/cp -f $INP1 $INP2 && chown $idx:`id -gn $idx` $INP2
      done
      
      INP1=/etc/skel/.config/user-dirs.locale
      echo "en_US" > $INP1
      INP2=/root/.config/user-dirs.locale && /bin/cp -f $INP1 $INP2 
      for idx in $SYSUSERS
        do
        INP2=/home/$idx/.config/user-dirs.locale
        /bin/cp -f $INP1 $INP2 && chown $idx:`id -gn $idx` $INP2
      done

    fi
     

    # 3)reset default boot language 
    #================================
    /usr/sbin/grub-gfxmenu --update-gfxmenu --lang=$AL_EXT1

    # 4) reset desktop for root and all users
    #=================================================
    # a) for root
    INP1=/root/$INP11
    if [ -e $INP1 ];then
     INP2=/root/$INP12
     # backup the current kdeglobals
     /bin/cp -f $INP1 $INP2
     if [ "$HAS_KDESESSION" == "1" ]; then
       sed -i '/Translations/,/^$/d' $INP1
       echo  >> $INP1
       echo [Translations] >> $INP1
       echo LANGUAGE=$AL_EXT2 >> $INP1
       echo  >> $INP1
     fi
    fi

    # delete any i18n-file if it exists in the home-folder
    /bin/rm -f /root/.i18n

    # delete the postaddlocale file if it exists
    /bin/rm -f /etc/skel/.kde4/Autostart/postaddlocale
    /bin/rm -f /root/.kde4/Autostart/postaddlocale
    /bin/rm -fr /root/.kde4/share/apps/kfileplaces
    /bin/rm -f /root/fcitx.pdf /etc/skel/fcitx.pdf

    # reset .bash_profile
    INP1=/root/.bash_profile
    sed -i '/added_by_addlocale/,/^$/d' $INP1
    sed -i '/LANG=/d' $INP1
    echo "export LANG=en_US.UTF-8" >> $INP1
    echo "export GDM_LANG=en_US.UTF-8" >> $INP1
    

    # set new language in Gnome home-account
    INP1=/root/.dmrc
    if [ `cat $INP1 | grep 'GNOME' | wc -l` == "1" ];then
      INP2=/root/.dmrc_AL
      # backup the current kdeglobals
      /bin/cp -f $INP1 $INP2
      if [ `cat $INP1 | grep 'Language' | wc -l` != "0" ];then
        sed -e "s/Language=.*/Language=$AL_EXT2.UTF-8/" $INP2 > $INP1
      else
        echo Language=$AL_EXT2.UTF-8 >> $INP1
      fi
    fi

    # b) for all users on the system
    for idx in $SYSUSERS
      do
       INP1=/home/$idx/$INP11
       if [ -e $INP1 ];then
         INP2=/home/$idx/$INP12
         # backup the current kdeglobals
         /bin/cp -f $INP1 $INP2
         if [ "$HAS_KDESESSION" == "1" ]; then
           sed -i '/Translations/,/^$/d' $INP1
           echo  >> $INP1
           echo [Translations] >> $INP1
           echo LANGUAGE=$AL_EXT2 >> $INP1
           echo  >> $INP1
         fi
         # reset permissions
         chown $idx:`id -gn $idx` $INP1
         chown $idx:`id -gn $idx` $INP2
       fi

      # delete any i18n-file if it exists in the home-folder
      /bin/rm -f /home/$idx/.i18n
      /bin/rm -fr /home/$idx/.kde4/share/apps/kfileplaces
      /bin/rm -f /home/$idx/.kde4/Autostart/postaddlocale
      /bin/rm -f /home/$idx/OpenOffice_Info.txt
      /bin/rm -f /home/$idx/Desktop/getopenoffice.desktop

      # reset .bash_profile
      INP1=/home/$idx/.bash_profile
      sed -i '/added_by_addlocale/,/^$/d' $INP1
      sed -i '/LANG=/d' $INP1
      echo "export LANG=en_US.UTF-8" >> $INP1
      echo "export GDM_LANG=en_US.UTF-8" >> $INP1
      chown $idx:`id -gn $idx` $INP1

      # set new language in Gnome home-account
      INP1=/home/$idx/.dmrc
      if [ `cat $INP1 | grep 'GNOME' | wc -l` == "1" ];then
        INP2=/home/$idx/.dmrc_AL
        # backup the current kdeglobals
        /bin/cp -f $INP1 $INP2
        if [ `cat $INP1 | grep 'Language' | wc -l` != "0" ];then
          sed -e "s/Language=.*/Language=$AL_EXT2.UTF-8/" $INP2 > $INP1
        else
          echo Language=$AL_EXT2.UTF-8 >> $INP1
        fi
        # reset permissions
        chown $idx:`id -gn $idx` $INP1
        chown $idx:`id -gn $idx` $INP2
      fi
    done

    # c) for new users on the system
    for idx in /etc/skel/.config/kdeglobals /usr/share/config/kdeglobals
    do
      INP1=$idx
      if [ -e $INP1 ];then
        INP2=$INP1'_AL'
        # backup the current kdeglobals
        /bin/cp -f $INP1 $INP2
         if [ "$HAS_KDESESSION" == "1" ]; then
           sed -i '/Translations/,/^$/d' $INP1
           echo  >> $INP1
           echo [Translations] >> $INP1
           echo LANGUAGE=$AL_EXT2 >> $INP1
           echo  >> $INP1
         fi
      fi
    done

    # reset .bash_profile
    INP1=/etc/skel/.bash_profile
    sed -i '/added_by_addlocale/,/^$/d' $INP1
    sed -i '/LANG=/d' $INP1
    echo "LANG=en_US.UTF-8" >> $INP1
    echo "GDM_LANG=en_US.UTF-8" >> $INP1

    /bin/rm -f /etc/skel/OpenOffice_Info.txt /root/OpenOffice_Info.txt
    /bin/rm -f /root/Desktop/getopenoffice.desktop
    
    # check if any LO-version is installed. If so, then inform about lomanager
    if [ `ls /usr/bin/libreoffice* 2>/dev/null |wc -l` -gt 0 ]; then
      # we have LO installed. Put the following info also in $HOME
      # so the user can read it later
      INP1=/root/LibreOffice_Info.txt
      echo "You have changed the localization of your system." > $INP1
      echo "" >> $INP1
      echo "- To select any added locale in LibreOffice go to:" >> $INP1
      echo "  Tools -> Options -> Language Settings -> Languages: User Interface" >> $INP1
      echo "  Then restart LibreOffice to apply the new locale." >> $INP1
      echo " " >> $INP1
      echo "- Please use the program 'lomanager' for any other" >> $INP1
      echo "  LibreOffice related task, such as install, upgrade, " >> $INP1
      echo "  localize, fix, or uninstall LibreOffice" >> $INP1
      echo "  " >> $INP1
      echo "More information on lomanager can be found at:  " >> $INP1
      echo "https://pclosusers.com/wiki/index.php?title=Localization_Manager" >> $INP1
      /bin/cp -f $INP1 /etc/skel/LibreOffice_Info.txt
      for idx in $SYSUSERS
        do
        INP2=/home/$idx/LibreOffice_Info.txt
        /bin/cp $INP1 $INP2 && chown $idx:`id -gn $idx` $INP2
      done
      $ZEN2 --title "$TITLE" --info --text=$"LibreOffice detected. \n\nPlease note:\n* to select any added LibreOffice locale go to:\n   Tools -> Options -> Language Settings\n            -> Languages: User Interface\n   Then restart LibreOffice to apply the new locale. \n\n* please use the program 'lomanager' for \n   any other LibreOffice related task.\n\nThis information is also available in the document \n'LibreOffice_Info.txt' in your Home folder."
    fi

    # e17 language information
    if [ $HAS_E17 == "1" ]; then
      # we have Enlightenement installed. Put the following info also in $HOME
      # so the user can read it later
      INP1=/root/addlocale_Enlightenment_Info.txt
      echo "You have changed the localization of your system." > $INP1
      echo "" >> $INP1
      echo "If you run a E17 (Enlightenment) desktop choose one of the following" >> $INP1
      echo "two options to switch to an installed AND E17-supported localization:" >> $INP1
      echo "" >> $INP1
      echo "a) StartMenu -> Settings -> Settings Panel:" >> $INP1
      echo "   in the top panel go to the right and select 'Language'" >> $INP1
      echo "   then 'Language Settings' and choose the language to use" >> $INP1
      echo "   press 'Apply', then 'Close' and again 'Close'." >> $INP1
      echo "   Finally logout and login in E17 to apply the new localization." >> $INP1
      echo "" >> $INP1
      echo "b) in e17, open a terminal and enter:" >> $INP1
      echo "     enlightenment_remote -lang-set "$AL_EXT1 >> $INP1
      echo "   Note: e17-supported languages can be found using:" >> $INP1
      echo "     enlightenment_remote -lang-list" >> $INP1
      echo "   Finally logout and login in E17 to apply the new localization." >> $INP1
      echo "" >> $INP1
      echo "More information on addlocale can be found at:  " >> $INP1
      echo "https://pclosusers.com/wiki/index.php?title=Localization_Manager" >> $INP1
      /bin/cp -f $INP1 /etc/skel/addlocale_Enlightenment_Info.txt
      for idx in $SYSUSERS
        do
        INP2=/home/$idx/addlocale_Enlightenment_Info.txt
        /bin/cp $INP1 $INP2 && chown $idx:`id -gn $idx` $INP2
      done
      $ZEN2 --title "$TITLE" --info --text=$"Enlightenment detected. \n\nPlease note the document 'addlocale_Enlightenment_Info.txt' in your Home folder."
    fi
    update-menus -n
) 2>&1 | $ZEN3 --title="$TITLE" --progress --pulsate --no-cancel --auto-close --width=400 --text=$"Resetting to default English (US)..."
    # reboot
    $ZEN2 --title="$TITLE" --info --text=$"System locale reset to default English (US).\nWe will now reboot to activate the changes."
    /sbin/init 6
  exit 0
fi

#+++++++++++++++++++++++++++++++++++++++++++++++++++++
# END of restore to the default locale en_US
#+++++++++++++++++++++++++++++++++++++++++++++++++++++

# test if system locale is en_US 
XX=`less /etc/sysconfig/i18n |grep ^LC_NAME=en_US.UTF-8 | wc -l`
if [ "$XX" != "1" ];then 
  $ZEN2 --title="$TITLE" --info --text=$"Please localise from the default English (US) system only.\n1) run addlocale and choose: English (US) [Select to restore default]\n2) run addlocale again and choose your new locale."
  exit 0
fi


# rpm toolchain test
#====================
rpmtest=`rpm -qa --version rpm | awk '{print$3}'`
if [ "$rpmtest" == "4.4.6" ];then 
  MSG=$"Please install a current version of PCLinuxOS. \n\nExiting..."
  $ZEN2 --title "$TITLE" --error --text "$MSG"
  exit 1
fi

echo "UPDATETEST: " $UPDATETEST >> $almil
if [ $UPDATETEST -eq 1 ];then
  # system uptodate test
  #=========================
  # update package info
  ( dnf upgrade -y|tee /tmp/AL_STEP00.log ) 2>&1 | $ZEN3 --title="$TITLE" --progress --pulsate --no-cancel --auto-close --width=400 --text $"Upgrading the system."

  systemok=0
  test=$(tail -n 1 /tmp/AL_STEP00.log)
  if [ "$test" = "Nothing to do." ] || [ "$test" = "Complete!" ] ; then
    systemok=1
  fi

  if [ $systemok -eq 0 ];then
    echo "System not uptodate or broken dependencies found" >> $almil
    $ZEN2 --title="$TITLE" --info --width=400 --text $"Please update your system.\n(more details: /tmp/AL_STEP00.log).\n\nExiting..."
    exit 1
  fi
  echo "System uptodate" >> $almil
else 
  echo "System uptodate test skipped" >> $almil
fi

# OK, now we are ready to go
# base URL for download of locale-lists/archives
#if [ $INTHAI -gt 0 ]; then
#  AL_HTTP="http://www.mirror.in.th/osarchive/pclinuxos/addlocale/"
#else
  AL_HTTP="https://ftp.nluug.nl/pub/os/Linux/distr/pclinuxos/pclinuxos/addlocale/"
#fi

# test if archives can be accessed
source=$AL_HTTP'de.txt'
HTTPstat=`curl -I --stderr /dev/null $source | head -1 | cut -d' ' -f2`
if [ $HTTPstat -ge 400 ]; then
  MSG=$"Language archive not found.\nPlease try again later. \n\nExiting..."
  $ZEN2 --title "$TITLE" --error --text "$MSG"
  echo "Language archive not found on nluug" >> $almil
  cd /tmp && /bin/rm -fR AL_* newloc
  exit 0
fi

#*************************************************
# assign the selected new locale
# defaults for language packages (corresponding to 
# the line # in table addlocale_i18n.ods)
AL_EXT4='0' # extra packages like fonts
AL_EXT5='1' # man-pages-$AL_EXT1
AL_EXT7='0' # tesseract
AL_EXT8='2' # myspell-$AL_EXT2
AL_EXT9='1' # aspell-$AL_EXT1
AL_EXT11='1' # firefox-$AL_EXT1
AL_EXT12='1' # thunderbird-$AL_EXT1
AL_EXT15='1' # calligra-l10n-$AL_EXT1
AL_EXT16='1' # koffice-l10n-$AL_EXT1
AL_EXT17='1' # gcompris-sounds-$AL_EXT1

# in ~/.config/kdeglobals
# AL_EXT30: the country code
# AL_EXT31: the language code
#
# installable languages: /etc/rpm/macros
#
# in /etc/sysconfig/i18n all should be $AL_EXT2.UTF-8
# AL_EXT40: LANGUAGE=   in i18n
AL_EXT41='lat0-16'  # default sysfont
# run draklocale at the end of the script:
# 0-not needed, 1-needed to properly setup i18n
AL_EXT50='0'

if [ "$AL_LANG" == "Afrikaans" ]; then
    AL_EXT1='af' && AL_EXT2='af_ZA' && AL_EXT5='0'
    AL_EXT12='0' && AL_EXT15='0'
    AL_EXT30='za' && AL_EXT31=$AL_EXT1 && AL_EXT40='af_ZA.UTF-8:af' && AL_EXT41='lat1-16'
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Arabic (Egypt)" ]; then
    AL_EXT1='ar' && AL_EXT2='ar_EG' && AL_EXT5='0' && AL_EXT7='ara' && AL_EXT8='ar_AR' && AL_EXT9='0' && AL_EXT15='0'
    AL_EXT4='fonts-ttf-arabic-farsi fonts-ttf-arabic-kacst fonts-ttf-arabic-arabeyes fonts-ttf-arabic icu acon'
    AL_EXT30='eg' && AL_EXT31=$AL_EXT1 && AL_EXT40='ar_EG.UTF-8:ar' && AL_EXT41=''
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Azeri" ]; then
    AL_EXT1='az' && AL_EXT2='az_AZ' && AL_EXT5='0'
    AL_EXT4='fonts-ttf-droid fonts-type1-cyrillic x11-font-cyrillic'
    AL_EXT11='0' && AL_EXT12='0' && AL_EXT15='0' && AL_EXT17='0'
    AL_EXT30='az' && AL_EXT31=$AL_EXT1 && AL_EXT40='az_AZ.UTF-8:az' && AL_EXT41='tiso09e'
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Basque" ]; then
    AL_EXT1='eu' && AL_EXT2='eu_ES' && AL_EXT5='0' && AL_EXT9='0'
    AL_EXT30='es' && AL_EXT31=$AL_EXT1 && AL_EXT40='eu_ES.UTF-8:eu'
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Belarusian" ]; then
    AL_EXT1='be' && AL_EXT2='be_BY' && AL_EXT5='0' && AL_EXT8='0' 
    AL_EXT4='fonts-ttf-droid fonts-type1-cyrillic app-defaults-be  x11-font-cyrillic'
    AL_EXT17='0' && AL_EXT15='0'
    AL_EXT30='by' && AL_EXT31=$AL_EXT1 && AL_EXT40='be_BY.UTF-8:be' && AL_EXT41='UniCyr_8x16'
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Bengali (India)" ]; then
    AL_EXT1='bn' && AL_EXT2='bn_IN' && AL_EXT5='0' && AL_EXT8='bn_BN'
    AL_EXT4='fonts-ttf-bengali fonts-ttf-gujarati icu'
    AL_EXT12='bn_BD' && AL_EXT15='0' && AL_EXT17='0'
    AL_EXT30='in' && AL_EXT31=$AL_EXT1 && AL_EXT40='bn_IN.UTF-8:bn' && AL_EXT41=''
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Bosnian" ]; then
    AL_EXT1='bs' && AL_EXT2='bs_BA' && AL_EXT5='0' && AL_EXT8='0' && AL_EXT9='0'
    AL_EXT4='fonts-ttf-droid fonts-type1-cyrillic x11-font-cyrillic'
    AL_EXT12='0' && AL_EXT17='0' 
    AL_EXT30='ba' && AL_EXT31=$AL_EXT1 && AL_EXT40='bs_BA.UTF-8:bs' && AL_EXT41='lat2-16'
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Breton" ]; then
    AL_EXT1='br' && AL_EXT2='br_FR' && AL_EXT5='0' && AL_EXT8='0' && AL_EXT15='0'
    AL_EXT30='fr' && AL_EXT31=$AL_EXT1 && AL_EXT40='br:fr_FR:fr'
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Bulgarian" ]; then
    AL_EXT1='bg' && AL_EXT2='bg_BG' && AL_EXT5='0' && AL_EXT7='bul' && AL_EXT15='0'
    AL_EXT4='fonts-ttf-droid fonts-type1-cyrillic x11-font-cyrillic'
    AL_EXT30='bg' && AL_EXT31=$AL_EXT1 && AL_EXT40='bg_BG.UTF-8:bg' && AL_EXT41='UniCyr_8x16'
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Catalan" ]; then
    AL_EXT1='ca' && AL_EXT2='ca_ES' && AL_EXT5='0' && AL_EXT7='cat' && AL_EXT17='0' 
    AL_EXT30='es' && AL_EXT31=$AL_EXT1 && AL_EXT40='ca:es_ES:es' 
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi
 
if [ "$AL_LANG" == "Chhattisgarhi" ]; then 
    AL_EXT1='hne' && AL_EXT2='hne_IN' && AL_EXT5='0' && AL_EXT8='0' 
    AL_EXT9='0' && AL_EXT11='0' && AL_EXT12='0' && AL_EXT15='0' && AL_EXT17='0'
    AL_EXT4='fonts-ttf-devanagari fonts-ttf-lohit fonts-ttf-gujarati icu locales-hi'
    AL_EXT30='in' && AL_EXT31=$AL_EXT1 && AL_EXT40='hi_IN.UTF-8:hi' && AL_EXT41=''
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Chinese (simplified)" ]; then
    AL_EXT1='zh' && AL_EXT2='zh_CN' && AL_EXT3='zh_CN.GB2312' && AL_EXT7='chi_sim' && AL_EXT8='0'
    AL_EXT4='taipeifonts zh-autoconvert zhcon scim-pinyin scim-tables-zh scim-chewing scim-bridge-gtk scim-bridge-qt4 scim-fcitx fcitx-qt4 fcitx-qt5 fcitx-qw fcitx-pinyin fcitx-gtk3 fcitx-table-chinese fcitx-configtool ttfprint fonts-ttf-wqy-microhei fonts-ttf-wqy-zenhei gcin'
    AL_EXT9='0' && AL_EXT11='2' && AL_EXT12='2' && AL_EXT15='2'
    AL_EXT30='cn' && AL_EXT31=$AL_EXT2 && AL_EXT40='zh_CN.GBK:zh_CN.GB2312:zh_CN:zh' && AL_EXT41=''
    wget $AL_HTTP$AL_EXT2".txt" -O /tmp/AL_REINSTALLLIST
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Chinese (traditional)" ]; then
    AL_EXT1='zh' && AL_EXT2='zh_TW' && AL_EXT3='zh_TW.Big5' && AL_EXT7='chi_tra' && AL_EXT8='0' && AL_EXT9='0'
    AL_EXT4='fonts-ttf-droid fonts-ttf-chinese taipeifonts bg5ps zh-autoconvert zhcon scim-pinyin scim-tables-zh scim-chewing scim-bridge-gtk scim-bridge-qt4 scim-fcitx fcitx-qt4 fcitx-qt5 fcitx-qw fcitx-pinyin fcitx-gtk3 fcitx-table-chinese fcitx-configtool ttfprint fonts-ttf-wqy-microhei fonts-ttf-wqy-zenhei gcin'
    AL_EXT11='2' && AL_EXT12='2' && AL_EXT15='2' && AL_EXT17='0'
    AL_EXT30='tw' && AL_EXT31=$AL_EXT2 && AL_EXT40='zh_TW.Big5:zh_TW:zh_HK:zh' && AL_EXT41=''
    wget $AL_HTTP$AL_EXT2".txt" -O /tmp/AL_REINSTALLLIST
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Croatian" ]; then
    AL_EXT1='hr' && AL_EXT2='hr_HR' && AL_EXT5='0'
    AL_EXT4='fonts-ttf-droid fonts-type1-cyrillic x11-font-cyrillic'
    AL_EXT12='0' && AL_EXT15='0' && AL_EXT17='0'
    AL_EXT30='hr' && AL_EXT31=$AL_EXT1 && AL_EXT40='hr_HR.UTF-8:hr' && AL_EXT41='lat2-16'
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Czech" ]; then
    AL_EXT1='cs' && AL_EXT2='cs_CZ' && AL_EXT4='app-defaults-cs' && AL_EXT7='ces'
    AL_EXT30='cz' && AL_EXT31=$AL_EXT1 && AL_EXT40='cs_CZ.UTF-8:cs' && AL_EXT41='lat2-16'
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Danish" ]; then
    AL_EXT1='da' && AL_EXT2='da_DK' && AL_EXT7='dan'
    AL_EXT30='dk' && AL_EXT31=$AL_EXT1 && AL_EXT40='da_DK.UTF-8:da'
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Dutch" ]; then
    AL_EXT1='nl' && AL_EXT2='nl_NL' && AL_EXT5='0' && AL_EXT7='nld'
    AL_EXT30='nl' && AL_EXT31=$AL_EXT1 && AL_EXT40='nl_NL.UTF-8:nl'
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "English (GB)" ]; then
    AL_EXT1='en' && AL_EXT2='en_GB' && AL_EXT5='0' && AL_EXT7='eng'
    AL_EXT11='2' && AL_EXT12='2' && AL_EXT15='0' && AL_EXT17='0'
    AL_EXT30='gb' && AL_EXT31=$AL_EXT2 && AL_EXT40='en_GB.UTF-8:en_GB:en'
    wget $AL_HTTP$AL_EXT2".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Esperanto" ]; then
    AL_EXT1='eo' && AL_EXT2='eo_XX' && AL_EXT5='0' && AL_EXT8='eo_EO'
    AL_EXT12='0' && AL_EXT15='0'
    AL_EXT30='C' && AL_EXT31=$AL_EXT1 && AL_EXT40='eo_XX.UTF-8:eo' && AL_EXT41='LatArCyrHeb-16'
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Estonian" ]; then
    AL_EXT1='et' && AL_EXT2='et_EE' && AL_EXT5='0' && AL_EXT17='0'
    AL_EXT4='fonts-ttf-droid'
    AL_EXT30='ee' && AL_EXT31=$AL_EXT1 && AL_EXT40='et_EE.UTF-8:et'
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Faroese" ]; then
    AL_EXT1='fo' && AL_EXT2='fo_FO' && AL_EXT5='0'
    AL_EXT11='0' && AL_EXT12='0' && AL_EXT15='0' && AL_EXT17='0'
    AL_EXT30='fo' && AL_EXT31=$AL_EXT1 && AL_EXT40='fo_FO.UTF-8:fo'
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Farsi" ]; then
    AL_EXT1='fa' && AL_EXT2='fa_IR' && AL_EXT5='0'
    AL_EXT9='0' && AL_EXT12='0' && AL_EXT15='0' && AL_EXT17='0'
    AL_EXT4='fonts-ttf-arabic-farsi fonts-ttf-arabic-kacst fonts-ttf-arabic-arabeyes fonts-ttf-arabic'
    AL_EXT30='ir' && AL_EXT31=$AL_EXT1 && AL_EXT40='fa_IR.UTF-8:fa' && AL_EXT41=''
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Finnish" ]; then
    AL_EXT1='fi' && AL_EXT2='fi_FI' && AL_EXT5='0' && AL_EXT7='fin'
    AL_EXT4='voikko-fi tmispell-voikko'
    AL_EXT30='fi' && AL_EXT31=$AL_EXT1 && AL_EXT40='fi_FI.UTF-8:fi'
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "French (France)" ]; then
    AL_EXT1='fr' && AL_EXT2='fr_FR' && AL_EXT7='fra'
    AL_EXT30='fr' && AL_EXT31=$AL_EXT1 && AL_EXT40='fr_FR.UTF-8:fr'
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Frisian" ]; then
    AL_EXT1='fy' && AL_EXT2='fy_NL' && AL_EXT5='0' 
    AL_EXT9='0' && AL_EXT15='0' && AL_EXT17='0'
    AL_EXT30='nl' && AL_EXT31=$AL_EXT1 && AL_EXT40='fy_NL.UTF-8:fy'
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Gaelic (Ireland)" ]; then
    AL_EXT1='ga' && AL_EXT2='ga_IE' && AL_EXT5='0' && AL_EXT4='app-defaults-ga locales-gu'
    AL_EXT11='2' && AL_EXT15='0' && AL_EXT17='0' 
    AL_EXT30='ie' && AL_EXT31=$AL_EXT1 && AL_EXT40='ga:en_IE:en_GB:en'
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Galician" ]; then
    AL_EXT1='gl' && AL_EXT2='gl_ES' && AL_EXT5='0' && AL_EXT17='0'
    AL_EXT30='es' && AL_EXT31=$AL_EXT1 && AL_EXT40='gl:es_ES:es'
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "German (Germany)" ]; then
    AL_EXT1='de' && AL_EXT2='de_DE' && AL_EXT7='deu'
    AL_EXT30='de' && AL_EXT31=$AL_EXT1 && AL_EXT40='de_DE.UTF-8:de'
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Greek" ]; then
    AL_EXT1='el' && AL_EXT2='el_GR' && AL_EXT5='0' && AL_EXT7='ell'
    AL_EXT4='fonts-ttf-droid fonts-ttf-Gentium fonts-ttf-mgopen fonts-type1-greek icu'
    AL_EXT30='gr' && AL_EXT31=$AL_EXT1 && AL_EXT40='el_GR.UTF-8:el' && ALT_EXT41='iso07u-16'
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Gujarati" ]; then 
    AL_EXT1='gu' && AL_EXT2='gu_IN' && AL_EXT5='0' && AL_EXT8='0'
    AL_EXT9='0' && AL_EXT11='2' && AL_EXT12='0' && AL_EXT15='0' && AL_EXT17='0'
    AL_EXT30='in' && AL_EXT31=$AL_EXT1 && AL_EXT40='gu_IN.UTF-8:gu' && ALT_EXT41='LatArCyrHeb-16'
    AL_EXT4='fonts-ttf-devanagari fonts-ttf-lohit fonts-ttf-gujarati icu'
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Hebrew" ]; then
    AL_EXT1='he' && AL_EXT2='he_IL' && AL_EXT5='0' && AL_EXT7='heb'
    AL_EXT4='fonts-type1-hebrew icu hspell ots' && AL_EXT15='0'
    AL_EXT30='il' && AL_EXT31=$AL_EXT1 && AL_EXT40='he_IL.UTF-8:he' && ALT_EXT41=''
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Hindi" ]; then
    AL_EXT1='hi' && AL_EXT2='hi_IN' && AL_EXT5='0' && AL_EXT7='hin' && AL_EXT12='0' && AL_EXT15='0'
    AL_EXT4='fonts-ttf-devanagari fonts-ttf-lohit fonts-ttf-gujarati icu' 
    AL_EXT30='in' && AL_EXT31=$AL_EXT1 && AL_EXT40='hi_IN.UTF-8:hi' && AL_EXT41=''
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Hungarian" ]; then
    AL_EXT1='hu' && AL_EXT2='hu_HU' && AL_EXT7='hun'
    AL_EXT30='hu' && AL_EXT31=$AL_EXT1 && AL_EXT40='hu_HU.UTF-8:hu' && ALT_EXT41='lat2-16'
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Icelandic" ]; then
    AL_EXT1='is' && AL_EXT2='is_IS' && AL_EXT5='0' && AL_EXT15='0' && AL_EXT17='0'
    AL_EXT30='is' && AL_EXT31=$AL_EXT1 && AL_EXT40='is_IS.UTF-8:is'
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Indonesian" ]; then
    AL_EXT1='id' && AL_EXT2='id_ID' && AL_EXT7='ind' && AL_EXT15='0'
    AL_EXT30='id' && AL_EXT31=$AL_EXT1 && AL_EXT40='id_ID.UTF-8:id'
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

#if [ "$AL_LANG" == "Interlingua" ]; then  ;; no locales yet!
#    AL_EXT1='ia' && AL_EXT2='ia_XX' && AL_EXT5='0' && AL_EXT8='0' && AL_EXT11='0'
#    AL_EXT12='0' && AL_EXT17='0'
#    AL_EXT30='C' && AL_EXT31=$AL_EXT1 && AL_EXT40='eo_XX.UTF-8:eo' && AL_EXT41='LatArCyrHeb-16'
#    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
#    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
#fi

if [ "$AL_LANG" == "Italian" ]; then
    AL_EXT1='it' && AL_EXT2='it_IT' && AL_EXT7='ita'
    AL_EXT30='it' && AL_EXT31=$AL_EXT1 && AL_EXT40='it_IT.UTF-8:it'
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Japanese" ]; then
    AL_EXT1='ja' && AL_EXT2='ja_JP' && AL_EXT7='jpn' && AL_EXT8='0'
    AL_EXT4='scim-anthy scim-canna scim-prime scim-skk scim-input-pad scim-tables-ja scim-uim scim-m17n scim-bridge-gtk scim-bridge-qt4 kakasi kterm mana perl-Text-Kakasi fonts-ttf-japanese fonts-ttf-japanese-extra fonts-ttf-japanese-ipamona fonts-ttf-japanese-mplus_ipagothic fonts-ttf-wqy-microhei fonts-ttf-wqy-zenhei '
    AL_EXT9='0' && AL_EXT17='0'
    AL_EXT30='jp' && AL_EXT31=$AL_EXT1 && AL_EXT40='ja_JP.UTF-8:ja' && AL_EXT41='' 
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Kannada" ]; then 
    AL_EXT1='kn' && AL_EXT2='kn_IN' && AL_EXT5='0' && AL_EXT8='0'
    AL_EXT9='0' && AL_EXT12='0' && AL_EXT15='0' && AL_EXT17='0'
    AL_EXT4='fonts-ttf-devanagari fonts-ttf-lohit fonts-ttf-gujarati fonts-ttf-kannada icu'
    AL_EXT30='in' && AL_EXT31=$AL_EXT1 && AL_EXT40='kn_IN.UTF-8:kn' && AL_EXT41=''
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Kashubian" ]; then 
    AL_EXT1='csb' && AL_EXT2='csb_PL' && AL_EXT5='0' && AL_EXT8='csb_CSB'
    AL_EXT11='0' && AL_EXT12='0' && AL_EXT15='0' && AL_EXT17='0'
    AL_EXT30='pl' && AL_EXT31=$AL_EXT1 && AL_EXT40='pl_PL.UTF-8:pl' && ALT_EXT41='lat2-16'
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Kazakh" ]; then 
    AL_EXT1='kk' && AL_EXT2='kk_KZ' && AL_EXT5='0' && AL_EXT8='0'
    AL_EXT9='0' && AL_EXT12='0' && AL_EXT17='0'
    AL_EXT4='fonts-ttf-droid fonts-type1-cyrillic x11-font-cyrillic'
    AL_EXT30='kz' && AL_EXT31=$AL_EXT1 && AL_EXT40='kk_KZ.UTF-8:kk' && ALT_EXT41='koi8-k'
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Khmer" ]; then 
    AL_EXT1='km' && AL_EXT2='km_KH' && AL_EXT5='0'
    AL_EXT9='0' && AL_EXT11='0' && AL_EXT12='0' && AL_EXT15='0' && AL_EXT17='0'
    AL_EXT30='kh' && AL_EXT31=$AL_EXT1 && AL_EXT40='km_KH.UTF-8:km'
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Korean" ]; then
    AL_EXT1='ko' && AL_EXT2='ko_KR' && AL_EXT7='kor' && AL_EXT8='0'
    AL_EXT4='fonts-ttf-droid fonts-ttf-korean scim-m17n scim-tables-ko scim-bridge-qt4 scim-hangul scim-pinyin scim-bridge-gtk scim-fcitx fcitx fonts-ttf-wqy-microhei fonts-ttf-wqy-zenhei'
    AL_EXT9='0' && AL_EXT15='0' && AL_EXT17='0'
    AL_EXT30='kr' && AL_EXT31=$AL_EXT1 && AL_EXT40='ko_KR.UTF-8:ko' && AL_EXT41='' && AL_EXT50='1'
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Kurdish" ]; then 
    AL_EXT1='ku' && AL_EXT2='ku_TR' && AL_EXT5='0'
    AL_EXT11='0' && AL_EXT12='0' && AL_EXT15='0' && AL_EXT17='0'
    AL_EXT4='fonts-ttf-droid fonts-type1-cyrillic x11-font-cyrillic'
    AL_EXT30='tr' && AL_EXT31=$AL_EXT1 && AL_EXT40='ku_TR.UTF-8:ku'
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Lao" ]; then
    AL_EXT1='lo' && AL_EXT2='lo_LA' && AL_EXT5='0' && AL_EXT8='0' 
    AL_EXT9='0' && AL_EXT11='0' && AL_EXT12='0' && AL_EXT15='0' && AL_EXT17='0'
    AL_EXT30='la' && AL_EXT31=$AL_EXT1 && AL_EXT40='lo_LA.UTF-8:lo' && AL_EXT41='' && AL_EXT50='1'
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Latvian" ]; then
    AL_EXT1='lv' && AL_EXT2='lv_LV' && AL_EXT5='0' && AL_EXT7='lav'
    AL_EXT4='fonts-ttf-droid' && AL_EXT15='0' && AL_EXT17='0'
    AL_EXT12='0' && AL_EXT30='lv' && AL_EXT31=$AL_EXT1 && AL_EXT40='lv_LV.UTF-8:lv' && AL_EXT41='tlat7'
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Lithuanian" ]; then
    AL_EXT1='lt' && AL_EXT2='lt_LT' && AL_EXT5='0' && AL_EXT7='lit' && AL_EXT15='0'
    AL_EXT4='fonts-ttf-droid' && AL_EXT17='0'
    AL_EXT30='lt' && AL_EXT31=$AL_EXT1 && AL_EXT40='lt_LT.UTF-8:lt' && AL_EXT41='tlat7'
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Macedonian" ]; then
    AL_EXT1='mk' && AL_EXT2='mk_MK' && AL_EXT5='0' && AL_EXT8='0'
    AL_EXT4='fonts-ttf-droid fonts-type1-cyrillic x11-font-cyrillic'
    AL_EXT17='0' && AL_EXT12='0' && AL_EXT15='0'
    AL_EXT30='mk' && AL_EXT31=$AL_EXT1 && AL_EXT40='mk_MK.UTF-8:mk' && AL_EXT41='UniCyr_8x16'
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Maithili" ]; then
    AL_EXT1='mai' && AL_EXT2='mai_IN' && AL_EXT5='0' && AL_EXT8='0'
    AL_EXT9='0' && AL_EXT12='0' && AL_EXT15='0' && AL_EXT17='0'
    AL_EXT4='fonts-ttf-devanagari fonts-ttf-lohit fonts-ttf-gujarati icu locales-hi'
    AL_EXT30='in' && AL_EXT31=$AL_EXT1 && AL_EXT40='mai_IN.UTF-8:mai'
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Malay" ]; then 
    AL_EXT1='ms' && AL_EXT2='ms_MY' && AL_EXT5='0' && AL_EXT11='0' 
    AL_EXT12='0' && AL_EXT15='0' && AL_EXT17='0'
    AL_EXT30='my' && AL_EXT31=$AL_EXT1 && AL_EXT40='ms_MY.UTF-8:ms'
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Malayalam" ]; then 
    AL_EXT1='ml' && AL_EXT2='ml_IN' && AL_EXT5='0' && AL_EXT8='0' 
    AL_EXT9='0' && AL_EXT12='0' && AL_EXT15='0' && AL_EXT17='0'
    AL_EXT4='fonts-ttf-tamil fonts-ttf-tscii fonts-ttf-gujarati fonts-ttf-malayalam fonts-bitmap-tscii icu'
    AL_EXT30='in' && AL_EXT31=$AL_EXT1 && AL_EXT40='ml_IN.UTF-8:ml'
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Maltese" ]; then
    AL_EXT1='mt' && AL_EXT2='mt_MT' && AL_EXT5='0' && AL_EXT8='0' 
    AL_EXT11='0' && AL_EXT12='0' && AL_EXT15='0' && AL_EXT17='0'
    AL_EXT30='mt' && AL_EXT31=$AL_EXT1 && AL_EXT40='mt_MT.UTF-8:mt' && AL_EXT41='LatArCyrHeb-16'
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Marathi" ]; then 
    AL_EXT1='mr' && AL_EXT2='mr_IN' && AL_EXT5='0'
    AL_EXT12='0' && AL_EXT15='0' 
    AL_EXT4='fonts-ttf-devanagari fonts-ttf-lohit fonts-ttf-gujarati icu'
    AL_EXT30='in' && AL_EXT31=$AL_EXT1 && AL_EXT40='mr_IN.UTF-8:mr'
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Mongolian" ]; then
    AL_EXT1='mn' && AL_EXT2='mn_MN' && AL_EXT5='0'
    AL_EXT4='fonts-ttf-droid fonts-type1-cyrillic x11-font-cyrillic'
    AL_EXT11='0' && AL_EXT12='0' && AL_EXT15='0' && AL_EXT17='0'
    AL_EXT30='mn' && AL_EXT31=$AL_EXT1 && AL_EXT40='mn_MN.UTF-8:mn' && AL_EXT41='koi8-k'
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Nepali" ]; then 
    AL_EXT1='ne' && AL_EXT2='ne_NP' && AL_EXT5='0' && AL_EXT9='0' 
    AL_EXT11='0' && AL_EXT17='0' && AL_EXT12='0' && AL_EXT15='0'
    AL_EXT4='fonts-ttf-devanagari fonts-ttf-lohit fonts-ttf-gujarati fonts-ttf-tibetan-ttmuni icu'
    AL_EXT30='np' && AL_EXT31=$AL_EXT1 && AL_EXT40='ne_NP.UTF-8:ne'
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Norwegian (Bokmaal)" ]; then
    AL_EXT1='nb' && AL_EXT2='nb_NO' && AL_EXT3='no' && AL_EXT5='0' && AL_EXT7='nor' && AL_EXT11='2'
    AL_EXT30='no' && AL_EXT31=$AL_EXT1 && AL_EXT40='nb' && AL_EXT12='2'
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Norwegian (Nynorsk)" ]; then
    AL_EXT1='nn' && AL_EXT2='nn_NO' && AL_EXT3='no' && AL_EXT5='0' && AL_EXT7='nor'
    AL_EXT11='2' && AL_EXT12='2' && AL_EXT15='nb'
    AL_EXT30='no' && AL_EXT31=$AL_EXT1 && AL_EXT40='nn:no@nynorsk:no_NY:no'
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Polish" ]; then
    AL_EXT1='pl' && AL_EXT2='pl_PL' && AL_EXT7='pol' && AL_EXT17='0'
    AL_EXT30='pl' && AL_EXT31=$AL_EXT1 && AL_EXT40='pl_PL.UTF-8:pl' && AL_EXT41='lat2-16'
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Portuguese (Portugal)" ]; then
    AL_EXT1='pt' && AL_EXT2='pt_PT' && AL_EXT3='pt_BR' && AL_EXT7='por'
    AL_EXT11='2' && AL_EXT12='2'
    AL_EXT30='pt' && AL_EXT31=$AL_EXT1 && AL_EXT40='pt_PT:pt'
    wget $AL_HTTP$AL_EXT2".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Portuguese (Brazil)" ]; then
    AL_EXT1='pt' && AL_EXT2='pt_BR' && AL_EXT7='por'
    AL_EXT11='2' && AL_EXT15='2' && AL_EXT12='2'
    AL_EXT30='br' && AL_EXT31=$AL_EXT2 && AL_EXT40='pt_BR:pt' && AL_EXT41='lat1-16'
    wget $AL_HTTP$AL_EXT2".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Punjabi" ]; then
    AL_EXT1='pa' && AL_EXT2='pa_IN' && AL_EXT5='0' && AL_EXT8='pa_PA'
    AL_EXT4='fonts-ttf-devanagari fonts-ttf-lohit fonts-ttf-gujarati fonts-ttf-gurmukhi icu locales-gu'
    AL_EXT11='2' && AL_EXT12='0' && AL_EXT15='0'
    AL_EXT30='pk' && AL_EXT31=$AL_EXT1 && AL_EXT40='pa_IN.UTF-8:pa_IN:pa' && AL_EXT41=''
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Romanian" ]; then
    AL_EXT1='ro' && AL_EXT2='ro_RO' && AL_EXT5='0' && AL_EXT7='ron'
    AL_EXT4='fonts-ttf-droid fonts-type1-cyrillic x11-font-cyrillic'
    AL_EXT17='0' && AL_EXT15='0'
    AL_EXT30='ro' && AL_EXT31=$AL_EXT1 && AL_EXT40='ro_RO.UTF-8:ro' && AL_EXT41='lat2-16'
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Russian" ]; then
    AL_EXT1='ru' && AL_EXT2='ru_RU' && AL_EXT7='rus'
    AL_EXT4='fonts-ttf-droid fonts-type1-cyrillic app-defaults-ru x11-font-cyrillic'
    AL_EXT30='ru' && AL_EXT31=$AL_EXT1 && AL_EXT40='ru_RU.UTF-8:ru' && AL_EXT41='UniCyr_8x16'
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Saami" ]; then
    AL_EXT1='se' && AL_EXT2='se_NO' && AL_EXT5='0' && AL_EXT8='0'
    AL_EXT9='0' && AL_EXT11='0' && AL_EXT12='0' && AL_EXT15='0' && AL_EXT17='0'
    AL_EXT30='no' && AL_EXT31=$AL_EXT1 && AL_EXT40='se_NO.UTF-8:se' && AL_EXT41='LatArCyrHeb-16'
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Low Saxon" ]; then
    AL_EXT1='nds' && AL_EXT2='nds_DE' && AL_EXT5='0' && AL_EXT8='0'
    AL_EXT11='0' && AL_EXT12='0' && AL_EXT17='0'
    AL_EXT30='de' && AL_EXT31=$AL_EXT1 && AL_EXT40='nds_DE:nds'
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Serbian" ]; then
    AL_EXT1='sr' && AL_EXT2='sr_RS' && AL_EXT5='0' && AL_EXT7='srp' && AL_EXT8='0' && AL_EXT12='0' && AL_EXT15='0'
    AL_EXT4='fonts-ttf-droid fonts-type1-cyrillic x11-font-cyrillic'
    AL_EXT30='rs' && AL_EXT31=$AL_EXT1 && AL_EXT40='sr_RS.UTF-8:sr'
    AL_EXT41='UniCyr_8x16' 
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

#if [ "$AL_LANG" == "Sinhala" ]; then
#    AL_EXT1='si' && AL_EXT2='si_IN' && AL_EXT5='0' && AL_EXT8='0'
#    AL_EXT4='fonts-ttf-tamil fonts-ttf-tscii fonts-ttf-gujarati fonts-bitmap-tscii icu'
#    AL_EXT15='0' && AL_EXT17='0'
#    AL_EXT30='in' && AL_EXT31=$AL_EXT1 && AL_EXT40='ta_IN.UTF-8:ta' && AL_EXT41='tamil'
#    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
#    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
#fi

if [ "$AL_LANG" == "Slovak" ]; then
    AL_EXT1='sk' && AL_EXT2='sk_SK' && AL_EXT5='0' && AL_EXT7='slk' && AL_EXT17='0'
    AL_EXT30='sk' && AL_EXT31=$AL_EXT1 && AL_EXT40='sk_SK.UTF-8:sk' && AL_EXT41='lat2-16'
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Slovenian" ]; then
    AL_EXT1='sl' && AL_EXT2='sl_SI' && AL_EXT5='0' && AL_EXT7='slv' && AL_EXT15='0'
    AL_EXT30='si' && AL_EXT31=$AL_EXT1 && AL_EXT40='sl_SI.UTF-8:sl' && AL_EXT41='lat2-16'
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Upper Sorbian" ]; then
    AL_EXT1='hsb' && AL_EXT2='hsb_DE' && AL_EXT5='0' && AL_EXT8='0'
    AL_EXT11='0' && AL_EXT12='0' && AL_EXT15='0' && AL_EXT17='0'
    AL_EXT30='de' && AL_EXT31=$AL_EXT1 && AL_EXT40='hsb_DE.UTF-8:hsb'
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Sotho" ]; then
    AL_EXT1='nso' && AL_EXT2='nso_ZA' && AL_EXT5='0' && AL_EXT8='ns_ZA'
    AL_EXT9='0' && AL_EXT11='0' && AL_EXT12='0' && AL_EXT15='0'
    AL_EXT17='0' && AL_EXT30='za' && AL_EXT31='st:nso:en_ZA'
    AL_EXT40='nso_ZA.UTF-8:nso:st:en_ZA'
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Spanish (Spain)" ]; then
    AL_EXT1='es' && AL_EXT2='es_ES' && AL_EXT7='spa' && AL_EXT11='2' && AL_EXT12='2'
    AL_EXT30='es' && AL_EXT31=$AL_EXT1 && AL_EXT40='es_ES.UTF-8:es'
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Swati" ]; then
    AL_EXT1='ss' && AL_EXT2='ss_ZA' && AL_EXT5='0'
    AL_EXT9='0' && AL_EXT11='0' && AL_EXT12='0' && AL_EXT15='0' && AL_EXT17='0'
    AL_EXT30='za' && AL_EXT31=$AL_EXT1 && AL_EXT40='ss:en_ZA'
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Swedish" ]; then
    AL_EXT1='sv' && AL_EXT2='sv_SE' && AL_EXT5='0' && AL_EXT7='swe' && AL_EXT11='2' && AL_EXT12='2'
    AL_EXT30='se' && AL_EXT31=$AL_EXT1 && AL_EXT40='sv_SE.UTF-8:sv'
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Tajik" ]; then
    AL_EXT1='tg' && AL_EXT2='tg_TJ' && AL_EXT5='0' && AL_EXT8='0'
    AL_EXT9='0' && AL_EXT4='fonts-ttf-droid fonts-type1-cyrillic x11-font-cyrillic'
    AL_EXT11='0' && AL_EXT12='0' && AL_EXT15='0' && AL_EXT17='0'
    AL_EXT30='tj' && AL_EXT31=$AL_EXT1 && AL_EXT40='tg_TJ.UTF-8:tg' && AL_EXT41='koi8-k'
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Tamil" ]; then
    AL_EXT1='ta' && AL_EXT2='ta_IN' && AL_EXT5='0' && AL_EXT8='ta_TA'
    AL_EXT4='fonts-ttf-tamil fonts-ttf-tscii fonts-ttf-gujarati fonts-bitmap-tscii icu'
    AL_EXT12='ta_LK' && AL_EXT15='0' && AL_EXT17='0'
    AL_EXT30='in' && AL_EXT31=$AL_EXT1 && AL_EXT40='ta_IN.UTF-8:ta' && AL_EXT41='tamil'
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Thai" ]; then
    AL_EXT1='th' && AL_EXT2='th_TH' && AL_EXT5='0' && AL_EXT7='tha'
    AL_EXT9='0' && AL_EXT4='fonts-ttf-thai app-defaults-th cttex icu'
    AL_EXT4=$AL_EXT4' lib64thai-devel'
    AL_EXT12='0' && AL_EXT15='0'
    AL_EXT30='th' && AL_EXT31=$AL_EXT1 && AL_EXT40='th_TH.UTF-8:th' && AL_EXT41=''
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Turkish" ]; then
    AL_EXT1='tr' && AL_EXT2='tr_TR' && AL_EXT5='0' && AL_EXT7='tur' && AL_EXT8='0' && AL_EXT15='0'
    AL_EXT4='fonts-ttf-droid fonts-type1-cyrillic x11-font-cyrillic'
    AL_EXT30='tr' && AL_EXT31=$AL_EXT1 && AL_EXT40='tr_TR.UTF-8:tr' && AL_EXT41='lat5-16'
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Ukrainian" ]; then
    AL_EXT1='uk' && AL_EXT2='uk_UA' && AL_EXT5='0' && AL_EXT7='ukr' && AL_EXT17='0'
    AL_EXT4='fonts-ttf-droid fonts-type1-cyrillic app-defaults-uk x11-font-cyrillic'
    AL_EXT30='ua' && AL_EXT31=$AL_EXT1 && AL_EXT40='uk_UA.UTF-8:uk' && AL_EXT41='UniCyr_8x16'
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Uyghur" ]; then
    AL_EXT1='ug' && AL_EXT2='ug_CN' && AL_EXT5='0'
    AL_EXT4='fonts-ttf-droid fonts-type1-cyrillic x11-font-cyrillic'
    AL_EXT11='0' && AL_EXT12='0' && AL_EXT15='0' && AL_EXT17='0'
    AL_EXT30='ug' && AL_EXT31=$AL_EXT1 && AL_EXT40='ug_CN.UTF-8:ug' && AL_EXT41='lat5-16'
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Uzbek" ]; then
    AL_EXT1='uz' && AL_EXT2='uz_UZ' && AL_EXT5='0'
    AL_EXT4='fonts-ttf-droid fonts-type1-cyrillic x11-font-cyrillic'
    AL_EXT11='0' && AL_EXT12='0' && AL_EXT15='0' && AL_EXT17='0'
    AL_EXT30='uz' && AL_EXT31=$AL_EXT1 && AL_EXT40='uz' && AL_EXT41='koi8-k'
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Venda" ]; then
    AL_EXT1='ve' && AL_EXT2='ve_ZA' && AL_EXT5='0'
    AL_EXT9='0' && AL_EXT11='0' && AL_EXT12='0' && AL_EXT15='0' && AL_EXT17='0'
    AL_EXT30='za' && AL_EXT31='ven' && AL_EXT40='ve:ven:en_ZA'
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Vietnamese" ]; then
    AL_EXT1='vi' && AL_EXT2='vi_VN' && AL_EXT5='0' && AL_EXT7='vie' && AL_EXT8='vi_VI'
    AL_EXT4='scim-m17n scim-bridge-qt4 scim-bridge-gtk scim-hangul scim-pinyin scim-fcitx fcitx'
    AL_EXT15='0' && AL_EXT17='0' && AL_EXT30='vn' && AL_EXT31=$AL_EXT1
    AL_EXT40='vi_VN.UTF-8:vi' && AL_EXT41='tcvn8x16'
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Walloon" ]; then
    AL_EXT1='wa' && AL_EXT2='wa_BE' && AL_EXT5='0' && AL_EXT8='0' && AL_EXT11='0' 
    AL_EXT12='0' && AL_EXT15='0' && AL_EXT17='0'
    AL_EXT30='be' && AL_EXT31=$AL_EXT1 && AL_EXT40='wa:fr_BE:fr'
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Welsh" ]; then
    AL_EXT1='cy' && AL_EXT2='cy_GB' && AL_EXT5='0' && AL_EXT12='0' && AL_EXT15='0' && AL_EXT17='0'
    AL_EXT30='gb' && AL_EXT31='cy:en_GB' && AL_EXT40='cy:en_GB:en' && AL_EXT41=''
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Xhosa" ]; then
    AL_EXT1='xh' && AL_EXT2='xh_ZA' && AL_EXT5='0'
    AL_EXT9='0' && AL_EXT11='0' && AL_EXT12='0' && AL_EXT15='0' && AL_EXT17='0'
    AL_EXT30='za' && AL_EXT31=$AL_EXT1 && AL_EXT40='xh:en_ZA'
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

if [ "$AL_LANG" == "Zulu" ]; then
    AL_EXT1='zu' && AL_EXT2='zu_ZA' && AL_EXT5='0'
    AL_EXT11='0' && AL_EXT12='0' && AL_EXT15='0' && AL_EXT17='0'
    AL_EXT30='za' && AL_EXT31=$AL_EXT1 && AL_EXT40='zu:en_ZA' 
    wget $AL_HTTP$AL_EXT1".txt" -O /tmp/AL_REINSTALLLIST 
    REINSTALL=`cat /tmp/AL_REINSTALLLIST`
fi

# ensure we successfully get the mo-file archive from the server
# download the archive with continue option in case network or server fails

TITLE2=$"addlocale: downloading translation archive..."
cd /; dl_txt=$"Download speed:"; eta_txt=$"Estimated time:"; source=$AL_HTTP$AL_EXT2.tar.xz
/bin/rm -f $AL_EXT2.tar.xz /tmp/AL_STEP2.txt

# only continue if the archive is available 
HTTPstat=`curl -I --stderr /dev/null $source | head -1 | cut -d' ' -f2`
if [ $HTTPstat -eq 404 ]; then
  MSG=$"Language archive not found.\nPlease update addlocale to the latest version\nand then run the Localization Manager again. \n\nExiting..."
  $ZEN2 --title "$TITLE" --error --text "$MSG"
  echo "Language archive $AL_EXT2 not found on nluug" >> $almil
  cd /tmp && /bin/rm -fR AL_STEP* AL_REINSTALLLIST newloc
  exit 0
fi

SCRIPT_PID=$$
wget $source 2>&1 | tee /tmp/AL_STEP2.txt \
  | sed -u "s/.* \([0-9]\+%\)\ \+\([0-9.]\+.\) \(.*\)/\1\n# ${dl_txt} \\\t\\\t\2\/s\\\n${eta_txt}\\\t\\\t\3/" \
  | ( if `$ZEN3 --width 600 --progress --title="$TITLE2" --auto-close`; then
	echo 'Download of translation archive completed' >> $almil
      else
	kill `ps axo ucmd,pid,ppid | grep wget | awk "{ if ( \\$3 == $SCRIPT_PID ) { print \\$2 }}"`
	$ZEN2 --width 400 --title="$TITLE" --error --text=$"Download and installation canceled."
	/bin/rm -f /$AL_EXT2.tar.xz
        exit 1
      fi )

# check if successfully retrieved, if not delete the incomplete archive
### temporarily disable this check, there is a problem with redirecting
# XX=`cat /tmp/AL_STEP2.txt | grep "100%" | wc -l`
# if [ "$XX" != "1" ];then 
#   $ZEN2 --title="$TITLE" --error --text=$"The download of the translation archive is incomplete. \nThis may indicate a temporary server failure or other \nnetwork problem.\nPlease try running addlocale again a little later and we \nwill continue from whatever could be downloaded. \n\nExiting..."
#   echo "Language archive download failed" >> $almil
#   /bin/rm -f /$AL_EXT2.tar.xz
#   exit 0
# fi

if [ "$AL_LANG" == "Chinese (simplified)" ] || [ "$AL_LANG" == "Chinese (traditional)" ]; then
  wget $AL_HTTP$AL_EXT1"_fcitx.pdf" -O /root/fcitx.pdf
fi

#=======================  must-have packages ==========================
MUSTHAVE="coreutils-doc locales-en enca glib-gettextize glibc-i18ndata intltool libgdata-i18n perl-Text-CharWidth perl-Text-WrapI18N php-translit " 

# add locales
if [ "$AL_LANG" == "Norwegian (Bokmaal)" ] || [ "$AL_LANG" == "Norwegian (Nynorsk)" ] ;then
    MUSTHAVE=$MUSTHAVE'locales-'$AL_EXT3' '
   elif [ "$AL_LANG" == "English (GB)" ] || [ "$AL_LANG" == "Kashubian" ]; then
    MUSTHAVE=$MUSTHAVE
   elif [ "$AL_LANG" == "Sotho" ]; then
    MUSTHAVE=$MUSTHAVE'locales-nso locales-st '
   else
    MUSTHAVE=$MUSTHAVE'locales-'$AL_EXT1' '
fi

# add extra packages like fonts etc
if [ "$AL_EXT4" != "0" ];then
    MUSTHAVE=$MUSTHAVE$AL_EXT4' '
fi

# add kde-locale
#if [ "$HAS_KDESESSION" == "1" ]; then  # KDE5
#   if [ "$AL_LANG" == "Chinese (simplified)" ] || [ "$AL_LANG" == "Chinese (traditional)" ] || [ "$AL_LANG" == "English (GB)" ] || [ "$AL_LANG" == "Portuguese (Brazil)" ] || [ "$AL_LANG" == "Bengali (India)" ]; then
#     MUSTHAVE=$MUSTHAVE'kde-l10n-'$AL_EXT2' '
#   else
#     MUSTHAVE=$MUSTHAVE'kde-l10n-'$AL_EXT1' '
#   fi
  #MUSTHAVE=$MUSTHAVE'docbook-style-xsl docbook-dtd412-xml docbook-dtd42-xml docbook-dtd43-xml docbook-dtd44-xml docbook-dtd45-xml '
#  MUSTHAVE=$MUSTHAVE'docbook-style-xsl-doc docbook-dtds '
#fi

# add man-pages
#if [ "$AL_EXT5" == "1" ]; then 
# if [ "$AL_LANG" == "Portuguese (Portugal)" ];then
#   MUSTHAVE=$MUSTHAVE'man-pages-'$AL_EXT3' '
# elif [ "$AL_LANG" == "Portuguese (Brazil)" ]; then
#   MUSTHAVE=$MUSTHAVE'man-pages-'$AL_EXT2' '
# else
#   MUSTHAVE=$MUSTHAVE'man-pages-'$AL_EXT1' '
# fi
#fi 

# add myspell 
if [ "$AL_EXT8" == "2" ]; then 
  MUSTHAVE=$MUSTHAVE'myspell-'$AL_EXT2' '
elif [ "$AL_EXT8" != "0" ]; then
  MUSTHAVE=$MUSTHAVE'myspell-'$AL_EXT8' '
fi

# add aspell
if [ "$AL_EXT9" == "1" ]; then 
  MUSTHAVE=$MUSTHAVE'aspell-manual aspell-'$AL_EXT1' '
fi

# $AL_EXT11: Firefox
if [ -e /usr/bin/firefox ] && [ "$AL_EXT11" != "0" ]; then
 if [ "$AL_EXT11" == "2" ]; then
    MUSTHAVE=$MUSTHAVE'firefox-'$AL_EXT2' '
 else 
    MUSTHAVE=$MUSTHAVE'firefox-'$AL_EXT1' '
 fi
fi

# $AL_EXT12: Thunderbird
if [ -e /usr/bin/thunderbird ] && [ "$AL_EXT12" != "0" ]; then
  case "$AL_EXT12" in
  '1') 
  MUSTHAVE=$MUSTHAVE'thunderbird-'$AL_EXT1' ';;
  '2')
  MUSTHAVE=$MUSTHAVE'thunderbird-'$AL_EXT2' ';;
  *)
  MUSTHAVE=$MUSTHAVE'thunderbird-'$AL_EXT12' ';;
  esac
fi

# $AL_EXT15: calligra
# if [ -e /usr/bin/calligra ] && [ "$AL_EXT15" != "0" ]; then
#  if [ "$AL_EXT15" == "2" ]; then
#     MUSTHAVE=$MUSTHAVE'calligra-l10n-'$AL_EXT2' '
#  elif [ "$AL_LANG" == "Norwegian (Nynorsk)" ]; then
#     MUSTHAVE=$MUSTHAVE'calligra-l10n-nb '
#  else
#     MUSTHAVE=$MUSTHAVE'calligra-l10n-'$AL_EXT1' '
#  fi
# fi

# $AL_EXT17: gcompris 
# if [ -e /usr/bin/gcompris ] && [ "$AL_EXT17" != "0" ]; then
#  if [ "$AL_LANG" == "Portuguese (Brazil)" ] || [ "$AL_LANG" == "Chinese (simplified)" ]; then
#     MUSTHAVE=$MUSTHAVE'gcompris gcompris-sounds-'$AL_EXT2' '
#  else
#     MUSTHAVE=$MUSTHAVE'gcompris gcompris-sounds-'$AL_EXT1' '
#  fi
# fi

# php-pear:
# if [ -e /usr/share/pear/PEAR.php ]; then
#   MUSTHAVE=$MUSTHAVE'php-pear-I18N php-pear-I18Nv2 php-pear-I18N_UnicodeString php-pear-Numbers_Words '
# fi

if [ "$AL_EXT2" == "id_ID" ]; then
  MUSTHAVE=$MUSTHAVE'myspell-tet_ID aspell-tet '
fi

# now check for existing applications having locale-specific i18n, i10n, etc
# if found, add them to MUSTHAVE and remove them from REINSTALL
# write the stuff we need for the following loop to disk so it can be read from there from within the loop
# all this is done to get a progress bar working in zenity...
echo $AL_EXT1 > /tmp/AL_EXT1
echo $AL_EXT2 > /tmp/AL_EXT2
echo $MUSTHAVE > /tmp/AL_MUSTHAVE
echo $REINSTALL > /tmp/AL_REINSTALL


# loop over lang-packages:
(
AL_EXT1=`cat /tmp/AL_EXT1`
AL_EXT2=`cat /tmp/AL_EXT2`
MUSTHAVE=`cat /tmp/AL_MUSTHAVE` && MUSTHAVE=$MUSTHAVE' '
REINSTALL=`cat /tmp/AL_REINSTALL`

# 1) Language-specific packages
HAS_IT=`rpm -qa gimp` && INREINSTALL=0
for i in ca da de el es fr it ja ko nl nn ru sl sv zh; do if [ $i == "$AL_EXT1" ]; then INREINSTALL=1; fi; done
if [ -n "$HAS_IT" ] && [ $INREINSTALL == 1 ];then MUSTHAVE=$MUSTHAVE'gimp-help-'$AL_EXT1' '; fi 
REINSTALL=${REINSTALL/gimp-help-$AL_EXT1/}
echo "2"

HAS_IT=`rpm -qa pysycache` && INREINSTALL=0
for i in de en es fr it pt; do if [ $i == "$AL_EXT1" ]; then INREINSTALL=1; fi; done
if [ -n "$HAS_IT" ] && [ $INREINSTALL == 1 ];then MUSTHAVE=$MUSTHAVE'pysycache-lang-'$AL_EXT1' '; fi 
REINSTALL=${REINSTALL/pysycache-lang-$AL_EXT1/}
echo "4"

HAS_IT=`rpm -qa tesseract` && INREINSTALL=0
for i in ar bg ca cs da el de en es fi fr he hi hu id it ja ko lv lt nb nn nl pl pt ro ru sk sl sr sv th tr uk vi; do if [ $i == "$AL_EXT1" ]; then INREINSTALL=1; fi; done
for i in zh_CN zh_TW; do if [ $i == "$AL_EXT2" ]; then INREINSTALL=1; fi; done 
if [ -n "$HAS_IT" ] && [ $INREINSTALL == 1 ];then MUSTHAVE=$MUSTHAVE'tesseract-'$AL_EXT7' '; fi
REINSTALL=${REINSTALL/tesseract-$AL_EXT7/}
echo "6"

# HAS_IT=`rpm -qa abiword` && INREINSTALL=0
# for i in en fr pl; do if [ $i == "$AL_EXT1" ]; then INREINSTALL=1; fi; done
# if [ -n "$HAS_IT" ] && [ $INREINSTALL == 1 ];then MUSTHAVE=$MUSTHAVE'abiword-docs-'$AL_EXT1' '; fi
echo "8"

#
#  it is safer to reinstall also the already existing packages 
# in order to pick up newer translations as well
#
# if they were already installed before they can now be removed
# required MUSTHAVE rpms:
#echo $MUSTHAVE |sed 's/ /\n/g' > /tmp/AL_STEP110.lst
# MUSTHAVE rpms which are installed already
#rpm -qa --queryformat '%10{NAME}\n' $MUSTHAVE | sed 's/ //g' > /tmp/AL_STEP111.lst
# remove the installed ones from the list of needed ones
#for p in $(cat /tmp/AL_STEP111.lst); do sed -i /^$p$/d /tmp/AL_STEP110.lst;done 
#MUSTHAVE=`cat /tmp/AL_STEP110.lst | sort | tr '\n' ' '`
# 
# 

# the following ones should always be installed even if they were installed before because
# they may be needed for another new locale
# HAS_IT=`rpm -qa psi` && INREINSTALL=0
# for i in cs es fr mk pl pt ru vi; do if [ $i == "$AL_EXT1" ]; then INREINSTALL=1; fi; done
# if [ -n "$HAS_IT" ] && [ $INREINSTALL == 1 ];then MUSTHAVE=$MUSTHAVE'psi-i18n '; fi
# REINSTALL=${REINSTALL/psi-i18n/}
echo "10"

# HAS_IT=`rpm -qa skype` && INREINSTALL=0
# for i in cs fi hu no sk sv; do if [ $i == "$AL_EXT1" ]; then INREINSTALL=1; fi; done
# if [ -n "$HAS_IT" ] && [ $INREINSTALL == 1 ];then MUSTHAVE=$MUSTHAVE'skype-i18n '; fi
# REINSTALL=${REINSTALL/skype-i18n/}
# echo "12"

HAS_IT=`rpm -qa tinyerp-server` && INREINSTALL=0
# for i in $REINSTALL; do if [ $i == "tinyerp-i18n" ]; then INREINSTALL=1; fi; done
# if [ -n "$HAS_IT" ] && [ $INREINSTALL == 1 ];then MUSTHAVE=$MUSTHAVE'tinyerp-i18n '; fi
# REINSTALL=${REINSTALL/tinyerp-i18n/}
echo "15"

#HAS_IT=`rpm -qa eric` && INREINSTALL=0
#for i in cs_CZ de_DE es_ES fr_FR ru_RU tr_TR zh_CN; do if [ $i == "$AL_EXT2" ]; then INREINSTALL=1; fi; done
#if [ -n "$HAS_IT" ] && [ $INREINSTALL == 1 ];then MUSTHAVE=$MUSTHAVE'eric-i18n '; fi
#echo "18"

for idx in goocanvas transmission # gwenview
do 
 HAS_IT=`rpm -qa $idx` && INREINSTALL=0
 for i in $REINSTALL; do if [ "$i" == "$idx-i18n" ]; then INREINSTALL=1; fi; done
  if [ -n "$HAS_IT" ] && [ "$INREINSTALL" == "1" ]; then
   MUSTHAVE=$MUSTHAVE$idx'-i18n '
  fi
 REINSTALL=${REINSTALL/$idx-i18n/}
done 
echo "30"

# for idx in asunder #avidemux alsaplayer
# do
#  HAS_IT=`rpm -qa $idx` && INREINSTALL=0
#  for i in $REINSTALL; do if [ $i == "$idx-i10n" ]; then INREINSTALL=1; fi; done
#   if [ -n "$HAS_IT" ] && [ $INREINSTALL == 1 ];then
#    MUSTHAVE=$MUSTHAVE$idx'-i10n '
#   fi
#  REINSTALL=${REINSTALL/$idx-i10n/}
# done
echo "42"

# for idx in ayttm gnome-chemistry-utils  #epdfview
# do
#  HAS_IT=`rpm -qa $idx` && INREINSTALL=0
#  for i in $REINSTALL; do if [ $i == "$idx-i10n" ]; then INREINSTALL=1; fi; done
#   if [ -n "$HAS_IT" ] && [ $INREINSTALL == 1 ];then
#    MUSTHAVE=$MUSTHAVE$idx'-i10n '
#   fi
#  REINSTALL=${REINSTALL/$idx-i10n/}
# done
echo "54"

for idx in gtknetcat
do
 HAS_IT=`rpm -qa $idx` && INREINSTALL=0
 for i in $REINSTALL; do if [ $i == "$idx-i10n" ]; then INREINSTALL=1; fi; done
  if [ -n "$HAS_IT" ] && [ $INREINSTALL == 1 ];then 
   MUSTHAVE=$MUSTHAVE$idx'-i10n '
  fi 
 REINSTALL=${REINSTALL/$idx-i10n/}
done 
echo "66"

for idx in lxappearance #lxlauncher lxsession-edit
do
 HAS_IT=`rpm -qa $idx` && INREINSTALL=0
 for i in $REINSTALL; do if [ $i == "$idx-i10n" ]; then INREINSTALL=1; fi; done
  if [ -n "$HAS_IT" ] && [ $INREINSTALL == 1 ];then 
   MUSTHAVE=$MUSTHAVE$idx'-i10n '
  fi 
 REINSTALL=${REINSTALL/$idx-i10n/}
done 
echo "78"

for idx in obconf #openbox lxsession-lite
do
 HAS_IT=`rpm -qa $idx` && INREINSTALL=0
 for i in $REINSTALL; do if [ $i == "$idx-i10n" ]; then INREINSTALL=1; fi; done
  if [ -n "$HAS_IT" ] && [ $INREINSTALL == 1 ];then 
   MUSTHAVE=$MUSTHAVE$idx'-i10n '
  fi 
 REINSTALL=${REINSTALL/$idx-i10n/}
done 
echo "90"

for idx in pcmanfm spacefm #skoosh sylpheed
do
 HAS_IT=`rpm -qa $idx` && INREINSTALL=0
 for i in $REINSTALL; do if [ $i == "$idx-i10n" ]; then INREINSTALL=1; fi; done
  if [ -n "$HAS_IT" ] && [ $INREINSTALL == 1 ];then 
   MUSTHAVE=$MUSTHAVE$idx'-i10n '
  fi 
 REINSTALL=${REINSTALL/$idx-i10n/}
done 
echo "100"
echo $MUSTHAVE > /tmp/AL_MUSTHAVE_2
echo $REINSTALL > /tmp/AL_REINSTALL_2
)|$ZEN3 --title="$TITLE" --progress --auto-close --no-cancel --text=$"Testing for translatable packages..."

# get back the changed parameters
MUSTHAVE=`cat /tmp/AL_MUSTHAVE_2` && MUSTHAVE=$MUSTHAVE' '
REINSTALL=`cat /tmp/AL_REINSTALL_2`

#cleanup the mess
/bin/rm -f /tmp/AL_*

#****************************************
# PART 1: install new locales and language dependent packages
#****************************************
#=================================================
# add the new locale to the system
# save the package list from step 1 to debug potential problems
echo $MUSTHAVE > /tmp/AL_STEP1.list

# SCRIPT_PID=$$
# ( echo $"addlocale: adding new language packages...";echo " "; echo 'IMPORTANT:  Do NOT press the Close button';echo "This window will close when the process has terminated."; echo " ";apt-get install --reinstall $MUSTHAVE -y; kill `ps axo ucmd,pid,ppid | grep $SCRIPT_PID |grep zenity |awk '{print$2}'` ) |tee /tmp/AL_STEP1.log | $ZEN2 --title="$TITLE" --text-info --width=700 --height=500

#( apt-get install --reinstall $MUSTHAVE -y|tee /tmp/AL_STEP1.log ) 2>&1 | $ZEN2 --title="$TITLE" --progress --pulsate --no-cancel --auto-close --width=500 --text=$"Downloading and adding new language packages...\n\t\t\t<b>This process can take several minutes\!</b>\n-> time for <span color='brown'><b>coffee</b></span> or a <span color='red'><b>bacon sandwich\!</b></span>\n\nOnce done this window will close and addlocale will continue."

# ensure cache is empty before downloading the packages
dnf clean all && dnf update -refresh && /bin/rm -f /tmp/AL_STEP1d.log

# old and working!
# sleep 4
#( apt-get install --reinstall --download-only $MUSTHAVE -y ) |tee /tmp/AL_STEP1d.log | $ZEN2 --title="$TITLE" --progress --pulsate --no-cancel --auto-close --width=500 --text=$"Downloading required language packages...\n\t\t\t<b>This process can take several minutes\!</b>\n-> time for <span color='brown'><b>coffee</b></span>, a <span color='red'><b>bacon sandwich\!</b></span>, or read about addlocale.\n\nOnce done this window will close and addlocale will continue."

# start downloading the needed files
rm -fr /tmp/AL_down
mkdir -p /tmp/AL_down
cd /tmp/AL_down
( dnf download --resolve $MUSTHAVE -y|tee /tmp/AL_STEP1d.log ) 2>&1 | $ZEN3 --title="$TITLE" --progress --pulsate --no-cancel --auto-close --width=400 --text $"Downloading required language packages."
fs=$(wc -c "/tmp/AL_STEP1d.log" | awk '{print $1}')

if [ $fs -eq 0 ];then
  $ZEN2 --title="$TITLE" --error --width=400 --text=$"Failure to download some language packages (package list: /tmp/AL_install.log).\n\nExiting..."
  echo $MUSTHAVE > /tmp/AL_install.log
  /bin/rm -f /$AL_EXT2.tar.xz /tmp/AL_STEP1d.log
  exit 1
fi


# install stuff

###( dnf install *.rpm -y|tee /tmp/AL_STEP5.log ) 2>&1 | $ZEN3 --title="$TITLE" --progress --pulsate --no-cancel --auto-close --width=400 --text $"Installing packages..."

rpm -Uvh --replacepkgs --test -v *.rpm &> /tmp/AL_order1
grep '  +' /tmp/AL_order1|awk -v FS='+' '{print $2}' > /tmp/AL_order2

# (re-)install each package in the ordered sequence and pipe to zenity progress
NP=$(wc -l /tmp/AL_order2|awk '{print $1}')
for file in $(cat /tmp/AL_order2);do i=$(grep -n $file /tmp/AL_order2|awk -v FS=':' '{print $1}'); echo $((100*$i/$NP));rpm -Uvh --replacepkgs ${file}.rpm|tee AL_X$i.log;done | $ZEN3 --title="$TITLE" --progress --no-cancel --auto-close --text "installing language packages..." --width=500

cd /
/bin/rm -fr /tmp/AL_down
/bin/rm -f /tmp/AL_*

#===============================================================================
# 1a) add new system language
#===============================================================================
# set the new language local
INP1=/etc/sysconfig/i18n
INP2=/etc/sysconfig/i18n_AL
# backup the previous i18n
/bin/cp -f $INP1 $INP2
# set the new language local
echo LC_TELEPHONE=$AL_EXT2.UTF-8 > $INP1
echo LC_CTYPE=$AL_EXT2.UTF-8 >> $INP1
echo LANGUAGE=$AL_EXT40:en_US:en >> $INP1
echo LC_MONETARY=$AL_EXT2.UTF-8 >> $INP1
echo LC_ADDRESS=$AL_EXT2.UTF-8 >> $INP1
echo LC_COLLATE=$AL_EXT2.UTF-8 >> $INP1
echo LC_PAPER=$AL_EXT2.UTF-8 >> $INP1
echo LC_NAME=$AL_EXT2.UTF-8 >> $INP1
echo LC_NUMERIC=$AL_EXT2.UTF-8 >> $INP1
if [ "$AL_EXT41" == "" ];then
  echo CONSOLE_NOT_LOCALIZED=yes >> $INP1
  echo GP_LANGUAGE=C >> $INP1
else
  echo SYSFONT=$AL_EXT41 >> $INP1
  echo GP_LANGUAGE=$AL_EXT1 >> $INP1
fi
echo LC_MEASUREMENT=$AL_EXT2.UTF-8 >> $INP1
echo LC_TIME=$AL_EXT2.UTF-8 >> $INP1
echo LANG=$AL_EXT2.UTF-8 >> $INP1
echo LC_ALL=  >> $INP1
echo LC_IDENTIFICATION=$AL_EXT2.UTF-8 >> $INP1
echo LC_MESSAGES=$AL_EXT2.UTF-8 >> $INP1
echo GDM_LANG=$AL_EXT2.UTF-8 >> $INP1

# add scim setup if needed
#=================================================
if [ "$AL_LANG" == "Chinese (simplified)" ] || [ "$AL_LANG" == "Chinese (traditional)" ] || [ "$AL_LANG" == "Japanese" ] || [ "$AL_LANG" == "Korean" ] || [ "$AL_LANG" == "Vietnamese" ]; then
  INP1=/usr/share/X11/xdm/Xsession && /bin/cp -f $INP1 /usr/share/X11/xdm/Xsession_old
  echo "#"'!/bin/bash -login' > $INP1
  echo " " >> $INP1
  echo export XMODIFIERS=@im=SCIM >> $INP1
  echo export GTK_IM_MODULE=scim-bridge >> $INP1
  echo export QT_IM_MODULE=xim >> $INP1
  echo " " >> $INP1
  echo "exec /etc/X11/Xsession "'$*'  >> $INP1
  echo " " >> $INP1
  echo "# Xsession ends here" >> $INP1
  chmod a+x $INP1

  INP1=/etc/xdg/autostart/scim.desktop
  echo "[Desktop Entry]" > $INP1
  echo "Type=Application" >> $INP1
  echo "Name=SCIM" >> $INP1
  echo "Comment=Smart Common Input Method platform" >> $INP1
  echo "Exec=scim -d" >> $INP1
  echo "Hidden=false" >> $INP1
  echo "X-GNOME-Autostart-enabled=true" >> $INP1

  # add scim to autostart
  if [ "$HAS_KDESESSION" == "1" ];then
    INP1=/etc/skel/.config/autostart/scim.desktop
    echo "[Desktop Entry]" > $INP1
    echo "Type=Application" >> $INP1
    echo "Name=SCIM" >> $INP1
    echo "Comment=Smart Common Input Method platform" >> $INP1
    echo "Exec=scim -d" >> $INP1
    echo "Hidden=false" >> $INP1
    echo "X-GNOME-Autostart-enabled=true" >> $INP1
    echo "Terminal=false" >> $INP1
    chmod a+x $INP1 && INP2=/root/.config/autostart/scim.desktop && /bin/cp -f $INP1 $INP2 
    for idx in $SYSUSERS
      do
      INP2=/home/$idx/.config/autostart/scim.desktop
      /bin/cp -f $INP1 $INP2 && chown $idx:`id -gn $idx` $INP2
    done
  fi
  
fi

# 1b) change or keep the keyboard layout...
#=================================================
drakkeyboard

# 1c) change KDE desktop for root and all users
#=================================================
# KDE config file: ~/.config/kdeglobals
# 1. set Country to $AL_EXT1
# 2. prepend the new locale: Language=$AL_EXT1:en_US
# 3. set system to metric: MeasureSystem=0 (1 <-> imperial) 
# 4. set page size to A4: PageSize=1 (2  <-> US letter)
# 5. add ~/.config/user-dirs.locale with en_US to trigger translation dialog
# a) for root
#
INP1=/root/$INP11
if [ -e $INP1 ];then
 INP2=/root/$INP12
 # backup the current kdeglobals
 /bin/cp -f $INP1 $INP2
 if [ "$HAS_KDESESSION" == "1" ]; then
   sed -i '/Translations/,/^$/d' $INP1
   echo  >> $INP1
   echo [Translations] >> $INP1
   echo LANGUAGE=$AL_EXT2 >> $INP1
   echo  >> $INP1
 fi
fi

INP1=/root/.bash_profile
sed -i '/added_by_addlocale/,/^$/d' $INP1
echo  >> $INP1
echo "# [added_by_addlocale]" >> $INP1
echo export LC_TELEPHONE=$AL_EXT2.UTF-8 >> $INP1
echo export LC_CTYPE=$AL_EXT2.UTF-8 >> $INP1
echo export LANGUAGE=$AL_EXT40:en_US:en >> $INP1
echo export LC_MONETARY=$AL_EXT2.UTF-8 >> $INP1
echo export LC_ADDRESS=$AL_EXT2.UTF-8 >> $INP1
echo export LC_COLLATE=$AL_EXT2.UTF-8 >> $INP1
echo export LC_PAPER=$AL_EXT2.UTF-8 >> $INP1
echo export LC_NAME=$AL_EXT2.UTF-8 >> $INP1
echo export LC_NUMERIC=$AL_EXT2.UTF-8 >> $INP1
if [ "$AL_EXT41" == "" ];then
  echo export CONSOLE_NOT_LOCALIZED=yes >> $INP1
  echo export GP_LANGUAGE=C >> $INP1
else
  echo export SYSFONT=$AL_EXT41 >> $INP1
  echo export GP_LANGUAGE=$AL_EXT1 >> $INP1
fi
echo export LC_MEASUREMENT=$AL_EXT2.UTF-8 >> $INP1
echo export LC_TIME=$AL_EXT2.UTF-8 >> $INP1
echo export LANG=$AL_EXT2.UTF-8 >> $INP1
echo export LC_IDENTIFICATION=$AL_EXT2.UTF-8 >> $INP1
echo export LC_MESSAGES=$AL_EXT2.UTF-8 >> $INP1
echo export LC_ALL= >> $INP1
echo export GDM_LANG=$AL_EXT2.UTF-8 >> $INP1
if [ "$AL_LANG" == "Chinese (simplified)" ] || [ "$AL_LANG" == "Chinese (traditional)" ]; then
  export GTK_IM_MODULE=fcitx >> $INP1
  export QT_IM_MODULE=fcitx >> $INP1
  export XMODIFIERS=@im=fcitx >> $INP1
  /bin/cp -f /usr/share/applications/fcitx.desktop /root/.config/autostart/fcitx.desktop
fi
echo  >> $INP1

# set new language in Gnome home-account
INP1=/root/.dmrc
if [ `cat $INP1 | grep 'GNOME' | wc -l` == "1" ];then
 INP2=/root/.dmrc_AL
 # backup the current kdeglobals
 /bin/cp -f $INP1 $INP2
 if [ `cat $INP1 | grep 'Language' | wc -l` != "0" ];then
  sed -e "s/Language=.*/Language=$AL_EXT2.UTF-8/" $INP2 > $INP1
 else
  echo Language=$AL_EXT2.UTF-8 >> $INP1
 fi
fi
# trigger translation dialog
echo en_US > /root/.config/user-dirs.locale

# b) for all users on the system
for idx in $SYSUSERS
  do
  /bin/rm -f /home/$idx/OpenOffice_Info.txt
  /bin/rm -f /home/$idx/Desktop/getopenoffice.desktop
    
  INP1=/home/$idx/$INP11
  if [ -e $INP1 ];then
   INP2=/home/$idx/$INP12
   # backup the current kdeglobals
   /bin/cp -f $INP1 $INP2
   if [ "$HAS_KDESESSION" == "1" ]; then
     sed -i '/Translations/,/^$/d' $INP1
     echo  >> $INP1
     echo [Translations] >> $INP1
     echo LANGUAGE=$AL_EXT2 >> $INP1
     echo  >> $INP1
   fi
   # reset permissions
   chown $idx:`id -gn $idx` $INP1
   chown $idx:`id -gn $idx` $INP2
  fi
 
  INP1=/home/$idx/.bash_profile
  sed -i '/added_by_addlocale/,/^$/d' $INP1
  echo  >> $INP1
  echo "# [added_by_addlocale]" >> $INP1
  echo export LC_TELEPHONE=$AL_EXT2.UTF-8 >> $INP1
  echo export LC_CTYPE=$AL_EXT2.UTF-8 >> $INP1
  echo export LANGUAGE=$AL_EXT40:en_US:en >> $INP1
  echo export LC_MONETARY=$AL_EXT2.UTF-8 >> $INP1
  echo export LC_ADDRESS=$AL_EXT2.UTF-8 >> $INP1
  echo export LC_COLLATE=$AL_EXT2.UTF-8 >> $INP1
  echo export LC_PAPER=$AL_EXT2.UTF-8 >> $INP1
  echo export LC_NAME=$AL_EXT2.UTF-8 >> $INP1
  echo export LC_NUMERIC=$AL_EXT2.UTF-8 >> $INP1
  if [ "$AL_EXT41" == "" ];then
    echo export CONSOLE_NOT_LOCALIZED=yes >> $INP1
    echo export GP_LANGUAGE=C >> $INP1
  else
    echo export SYSFONT=$AL_EXT41 >> $INP1
    echo export GP_LANGUAGE=$AL_EXT1 >> $INP1
  fi
  echo export LC_MEASUREMENT=$AL_EXT2.UTF-8 >> $INP1
  echo export LC_TIME=$AL_EXT2.UTF-8 >> $INP1
  echo export LANG=$AL_EXT2.UTF-8 >> $INP1
  echo export LC_IDENTIFICATION=$AL_EXT2.UTF-8 >> $INP1
  echo export LC_MESSAGES=$AL_EXT2.UTF-8 >> $INP1
  echo export LC_ALL= >> $INP1
  echo export GDM_LANG=$AL_EXT2.UTF-8 >> $INP1
  if [ "$AL_LANG" == "Chinese (simplified)" ] || [ "$AL_LANG" == "Chinese (traditional)" ]; then
    export GTK_IM_MODULE=fcitx >> $INP1
    export QT_IM_MODULE=fcitx >> $INP1
    export XMODIFIERS=@im=fcitx >> $INP1
    /bin/cp -f /usr/share/applications/fcitx.desktop /home/$idx/.config/autostart/fcitx.desktop
    /bin/cp -f /root/fcitx.pdf /home/$idx/fcitx.pdf
    chown $idx:`id -gn $idx` /home/$idx/.config/autostart/fcitx.desktop /home/$idx/fcitx.pdf
  fi
  echo  >> $INP1
  # reset permissions
  chown $idx:`id -gn $idx` $INP1

  # set new language in Gnome home-account
  INP1=/home/$idx/.dmrc
  if [ `cat $INP1 | grep 'GNOME' | wc -l` == "1" ];then
   INP2=/home/$idx/.dmrc_AL
   # backup the current kdeglobals
   /bin/cp -f $INP1 $INP2
   if [ `cat $INP1 | grep 'Language' | wc -l` != "0" ];then
    sed -e "s/Language=.*/Language=$AL_EXT2.UTF-8/" $INP2 > $INP1
   else
    echo Language=$AL_EXT2.UTF-8 >> $INP1
   fi
   # reset permissions
   chown $idx:`id -gn $idx` $INP1
   chown $idx:`id -gn $idx` $INP2
  fi
  # trigger translation dialog
  INP1=/home/$idx/.config/user-dirs.locale
  echo en_US > $INP1
  chown $idx:`id -gn $idx` $INP1
done

#
# c) change the default for new users on the system
for idx in /etc/skel/.config/kdeglobals /usr/share/config/kdeglobals
do
  INP1=$idx
  if [ -e $INP1 ];then
    INP2=$INP1'_AL'
    # backup the current kdeglobals
    /bin/cp -f $INP1 $INP2
   if [ "$HAS_KDESESSION" == "1" ]; then
     sed -i '/Translations/,/^$/d' $INP1
     echo  >> $INP1
     echo [Translations] >> $INP1
     echo LANGUAGE=$AL_EXT2 >> $INP1
     echo  >> $INP1
   fi
  fi
done

# add new locale if machine is accessed remotely
INP1=/etc/skel/.bash_profile
sed -i '/added_by_addlocale/,/^$/d' $INP1
echo  >> $INP1
echo "# [added_by_addlocale]" >> $INP1
echo export LC_TELEPHONE=$AL_EXT2.UTF-8 >> $INP1
echo export LC_CTYPE=$AL_EXT2.UTF-8 >> $INP1
echo export LANGUAGE=$AL_EXT40:en_US:en >> $INP1
echo export LC_MONETARY=$AL_EXT2.UTF-8 >> $INP1
echo export LC_ADDRESS=$AL_EXT2.UTF-8 >> $INP1
echo export LC_COLLATE=$AL_EXT2.UTF-8 >> $INP1
echo export LC_PAPER=$AL_EXT2.UTF-8 >> $INP1
echo export LC_NAME=$AL_EXT2.UTF-8 >> $INP1
echo export LC_NUMERIC=$AL_EXT2.UTF-8 >> $INP1
if [ "$AL_EXT41" == "" ];then
  echo export CONSOLE_NOT_LOCALIZED=yes >> $INP1
  echo export GP_LANGUAGE=C >> $INP1
else
  echo export SYSFONT=$AL_EXT41 >> $INP1
  echo export GP_LANGUAGE=$AL_EXT1 >> $INP1
fi
echo export LC_MEASUREMENT=$AL_EXT2.UTF-8 >> $INP1
echo export LC_TIME=$AL_EXT2.UTF-8 >> $INP1
echo export LANG=$AL_EXT2.UTF-8 >> $INP1
echo export LC_IDENTIFICATION=$AL_EXT2.UTF-8 >> $INP1
echo export LC_MESSAGES=$AL_EXT2.UTF-8 >> $INP1
echo export LC_ALL= >> $INP1
echo export GDM_LANG=$AL_EXT2.UTF-8 >> $INP1
if [ "$AL_LANG" == "Chinese (simplified)" ] || [ "$AL_LANG" == "Chinese (traditional)" ]; then
  export GTK_IM_MODULE=fcitx >> $INP1
  export QT_IM_MODULE=fcitx >> $INP1
  export XMODIFIERS=@im=fcitx >> $INP1
  /bin/cp -f /usr/share/applications/fcitx.desktop /etc/skel/.config/autostart/
  /bin/cp -f /root/fcitx.pdf /etc/skel/fcitx.pdf
fi
echo  >> $INP1

echo en_US > /etc/skel/.config/user-dirs.locale
/bin/rm -f /etc/skel/OpenOffice_Info.txt /root/OpenOffice_Info.txt
/bin/rm -f /root/Desktop/getopenoffice.desktop

# new default grub language
#=================================================
# only if a translation exists for the choosen language, else English
/usr/sbin/grub-gfxmenu --update-gfxmenu --lang=$AL_EXT1
switch-themes -u

# extract the language-specific archive and copy the mo-files into the system
/bin/rm -fr /tmp/newloc && mkdir /tmp/newloc 
cd / && tar xfJ $AL_EXT2.tar.xz -C /tmp/newloc/ && /bin/rm -f /$AL_EXT2.tar.xz
cd /tmp/newloc/usr/share/locale/ && /bin/cp -afR * /usr/share/locale/

# 2a) set the boot language & bootsplash 
#=================================================
#http://osdir.com/ml/linux.mandrake.cooker.internationalization/2003-09/msg00117.html
# set new default boot language if a translation exists for the new locale, else English.
# Boot messages are read from /etc/locale/... instead of /usr/share/locale/... 
# unfortunately the trick "LANGUAGE=az rpm -Uv --force " does not work so we do it manually
for idx in $AL_EXT1 $AL_EXT2
do
 if [ -r /usr/share/locale/$idx/LC_MESSAGES/initscripts.mo ]; then
   mkdir -p /etc/locale/$idx/LC_MESSAGES/
   /bin/cp -f /usr/share/locale/$idx/LC_MESSAGES/initscripts.mo /etc/locale/$idx/LC_MESSAGES/
   if [ -r /usr/share/locale/$idx/LC_MESSAGES/bootsplash.mo ]; then
    /bin/cp -f /usr/share/locale/$idx/LC_MESSAGES/bootsplash.mo /etc/locale/$idx/LC_MESSAGES/
   fi
   # this should be done by each locale when installed or upgraded
   pushd /usr/share/locale/$idx/ > /dev/null && for j in LC_*
     do
       if [ -r $j -a ! -d $j ]; then
         /bin/cp -f $j /etc/locale/$idx/
       fi
     done && popd > /dev/null
     if [ -r /usr/share/locale/$idx/LC_MESSAGES/SYS_LC_MESSAGES ]; then
       /bin/cp -f /usr/share/locale/$idx/LC_MESSAGES/SYS_LC_MESSAGES /etc/locale/$idx/LC_MESSAGES/
     fi
   break
 fi
done

# fix for kaffeine
for idx in $AL_EXT1 $AL_EXT2
  do
  cd /usr/share/locale/$idx/LC_MESSAGES
  kaffeinefiles=$(ls kaffeine-*.mo 2>/dev/null | wc -l)
  if [ "$kaffeinefiles" -ge "1" ]; then
    foo=`ls -tr kaffeine-*.mo | tail -1` # get the latest kaffeine-XX.mo
    /bin/mv -f $foo kaffeine.mo
  fi
done

# check if any LO-version is installed. If so, then inform about lomanager
ls -l /usr/bin/libreoffice* 2>/dev/null 
if [ "$?" == "0" ]; then
  # some LO is installed. Put the following info also in $HOME
  # so the user can read it later
  INP1=/root/LibreOffice_Info.txt
  echo "You have changed the localization of your system." > $INP1
  echo "" >> $INP1
  echo "- To select any added locale in LibreOffice go to:" >> $INP1
  echo "  Tools -> Options -> Language Settings -> Languages: User Interface" >> $INP1
  echo "  Then restart LibreOffice to apply the new locale." >> $INP1
  echo " " >> $INP1
  echo "- Please use the program 'lomanager' for any other" >> $INP1
  echo "  LibreOffice related task, such as install, upgrade, " >> $INP1
  echo "  localize, fix, or uninstall LibreOffice" >> $INP1
  echo "  " >> $INP1
  echo "More information on lomanager can be found at:  " >> $INP1
  echo "https://pclosusers.com/wiki/index.php?title=LibreOffice_Manager" >> $INP1

  if [ -d /etc/skel_fm ];then 
    /bin/cp -f $INP1 /etc/skel_fm/LibreOffice_Info.txt
  fi
  if [ -d /etc/skel_default ];then 
    /bin/cp -f $INP1 /etc/skel_default/LibreOffice_Info.txt
  fi
  if [ -d /etc/skel-orig ];then
   /bin/cp -f $INP1 /etc/skel-orig/LibreOffice_Info.txt
  fi
  /bin/cp -f $INP1 /etc/skel/LibreOffice_Info.txt
  for idx in $SYSUSERS
    do
    INP2=/home/$idx/LibreOffice_Info.txt
    /bin/cp -f $INP1 $INP2 && chown $idx:`id -gn $idx` $INP2
  done
  $ZEN2 --title "$TITLE" --info --text=$"LibreOffice detected. \n\nPlease note:\n* to select any added LibreOffice locale go to:\n   Tools -> Options -> Language Settings\n            -> Languages: User Interface\n   Then restart LibreOffice to apply the new locale. \n\n* please use the program 'lomanager' for \n   any other LibreOffice related task.\n\nThis information is also available in the document \n'LibreOffice_Info.txt' in your Home folder."
fi

# e17 language information
if [ $HAS_E17 == "1" ]; then
  # we have Enlightenement installed. Put the following info also in $HOME
  # so the user can read it later
  INP1=/root/addlocale_Enlightenment_Info.txt
  echo "You have changed the localization of your system." > $INP1
  echo "" >> $INP1
  echo "If you run a E17 (Enlightenment) desktop choose one of the following" >> $INP1
  echo "two options to switch to an installed AND E17-supported localization:" >> $INP1
  echo "" >> $INP1
  echo "a) StartMenu -> Settings -> Settings Panel:" >> $INP1
  echo "   in the top panel go to the right and select 'Language'" >> $INP1
  echo "   then 'Language Settings' and choose the language to use" >> $INP1
  echo "   press 'Apply', then 'Close' and again 'Close'." >> $INP1
  echo "   Finally logout and login in E17 to apply the new localization." >> $INP1
  echo "" >> $INP1
  echo "b) in e17, open a terminal and enter:" >> $INP1
  echo "     enlightenment_remote -lang-set "$AL_EXT1 >> $INP1
  echo "   Note: e17-supported languages can be found using:" >> $INP1
  echo "     enlightenment_remote -lang-list" >> $INP1
  echo "   Finally logout and login in E17 to apply the new localization." >> $INP1
  echo "" >> $INP1
  echo "More information on addlocale can be found at:  " >> $INP1
  echo "https://pclosusers.com/wiki/index.php?title=Localization_Manager" >> $INP1

  if [ -d /etc/skel_fm ];then /bin/cp -f $INP1 /etc/skel_fm/addlocale_Enlightenment_Info.txt; fi
  if [ -d /etc/skel_default ];then /bin/cp -f $INP1 /etc/skel_default/addlocale_Enlightenment_Info.txt; fi
  if [ -d /etc/skel-orig ];then /bin/cp -f $INP1 /etc/skel-orig/addlocale_Enlightenment_Info.txt; fi

  /bin/cp -f $INP1 /etc/skel/addlocale_Enlightenment_Info.txt
  for idx in $SYSUSERS
    do
    INP2=/home/$idx/addlocale_Enlightenment_Info.txt
    /bin/cp -f $INP1 $INP2 && chown $idx:`id -gn $idx` $INP2
  done
  $ZEN2 --title "$TITLE" --info --text=$"Enlightenment detected. \n\nPlease note the document 'addlocale_Enlightenment_Info.txt' in your Home folder."
fi

update-menus -n
if [ "$AL_EXT50" == "1" ];then
  $ZEN2 --title="$TITLE" --info --timeout 4 --text=$"Please confirm the new system locale settings or amend them to your needs."
  draklocale
fi

# change/amend the system time-zone etc.
$ZEN2 --title="$TITLE" --info --timeout 4 --text=$"Please confirm the new system locale settings or amend them to your needs."
drakclock

if [ "$HAS_KDESESSION" == "1" ];then
  kcmshell6 kcm_keyboard
  # this file is normally written by kcmshell5 formats but we bypass it here 
  # because the language settings are not applied correctly
  INP1=/etc/skel/.config/plasma-locale-settings.sh
  # set the new language local
  echo export LC_TELEPHONE=$AL_EXT2.UTF-8 > $INP1
  echo export LC_CTYPE=$AL_EXT2.UTF-8 >> $INP1
  echo export LANGUAGE=$AL_EXT40:en_US:en >> $INP1
  echo export LC_MONETARY=$AL_EXT2.UTF-8 >> $INP1
  echo export LC_ADDRESS=$AL_EXT2.UTF-8 >> $INP1
  echo export LC_COLLATE=$AL_EXT2.UTF-8 >> $INP1
  echo export LC_PAPER=$AL_EXT2.UTF-8 >> $INP1
  echo export LC_NAME=$AL_EXT2.UTF-8 >> $INP1
  echo export LC_NUMERIC=$AL_EXT2.UTF-8 >> $INP1
  if [ "$AL_EXT41" == "" ];then
    echo export CONSOLE_NOT_LOCALIZED=yes >> $INP1
    echo export GP_LANGUAGE=C >> $INP1
  else
    echo export SYSFONT=$AL_EXT41 >> $INP1
    echo export GP_LANGUAGE=$AL_EXT1 >> $INP1
  fi
  echo export LC_MEASUREMENT=$AL_EXT2.UTF-8 >> $INP1
  echo export LC_TIME=$AL_EXT2.UTF-8 >> $INP1
  echo export LANG=$AL_EXT2.UTF-8 >> $INP1
  echo export LANGUAGE=$AL_EXT1:en_US >> $INP1
  echo export LC_ALL=  >> $INP1
  echo export LC_IDENTIFICATION=$AL_EXT2.UTF-8 >> $INP1
  echo export LC_MESSAGES=$AL_EXT2.UTF-8 >> $INP1
  echo export GDM_LANG=$AL_EXT2.UTF-8 >> $INP1

  INP2=/root/.config/plasma-locale-settings.sh && /bin/cp -f $INP1 $INP2 
  for idx in $SYSUSERS
    do
    INP2=/home/$idx/.config/plasma-locale-settings.sh
    /bin/cp -f $INP1 $INP2 && chown $idx:`id -gn $idx` $INP2
  done
  
  INP1=/etc/skel/.config/plasma-localerc
  echo "[Formats]" > $INP1
  echo "LANG=en_US.UTF-8" >> $INP1
  echo " "  >> $INP1
  echo "[Translations]" >> $INP1
  echo "LANGUAGE="$AL_EXT1:en_US >> $INP1
  INP2=/root/.config/plasma-localerc && /bin/cp -f $INP1 $INP2 
  for idx in $SYSUSERS
    do
    INP2=/home/$idx/.config/plasma-localerc
    /bin/cp -f $INP1 $INP2 && chown $idx:`id -gn $idx` $INP2
  done
      
  INP1=/etc/skel/.config/user-dirs.locale
  echo $AL_EXT2 > $INP1
  INP2=/root/.config/user-dirs.locale && /bin/cp -f $INP1 $INP2 
  for idx in $SYSUSERS
    do
    INP2=/home/$idx/.config/user-dirs.locale
    /bin/cp -f $INP1 $INP2 && chown $idx:`id -gn $idx` $INP2
  done
    
fi

if [ "$AL_LANG" == "Chinese (simplified)" ] || [ "$AL_LANG" == "Chinese (traditional)" ]; then
  $ZEN2 --title="$TITLE" --info --text=$"Please read fcitx.pdf in your HOME directory"
fi

# clean up
cd /tmp && /bin/rm -fR AL_* newloc 

# logout
$ZEN2 --title="$TITLE" --info --text=$"New system locale added successfully\!\nWe will now reboot to activate the changes.\n\nPlease note:\nIf your new locale is applicable in several countries, \nyou can amend it to your needs. Open a terminal \nand enter the command: draklocale"
/sbin/init 6
########################################################################

exit 0
