Peppermint-Classic-Build-Files/PeppermintOS-Classic-i386/config/includes.chroot/usr/bin/simple-language-selector

118 lines
3.2 KiB
Plaintext
Raw Normal View History

#!/bin/bash
# Check if the script is run as root
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root."
exit 1
fi
# Define the available language options with corresponding locale codes
language_options=(
"Afrikaans=af_ZA.UTF-8"
"Albanian=sq_AL.UTF-8"
"Arabic=ar_SA.UTF-8"
"Armenian=hy_AM.UTF-8"
"Azerbaijani=az_AZ.UTF-8"
"Basque=eu_ES.UTF-8"
"Belarusian=be_BY.UTF-8"
"Bengali=bn_BD.UTF-8"
"Bosnian=bs_BA.UTF-8"
"Bulgarian=bg_BG.UTF-8"
"Catalan=ca_ES.UTF-8"
"Chinese (Simplified)=zh_CN.UTF-8"
"Chinese (Traditional)=zh_TW.UTF-8"
"Croatian=hr_HR.UTF-8"
"Czech=cs_CZ.UTF-8"
"Danish=da_DK.UTF-8"
"Dutch=nl_NL.UTF-8"
"English=en_US.UTF-8"
"Esperanto=eo.UTF-8"
"Estonian=et_EE.UTF-8"
"Finnish=fi_FI.UTF-8"
"French=fr_FR.UTF-8"
"Galician=gl_ES.UTF-8"
"Georgian=ka_GE.UTF-8"
"German=de_DE.UTF-8"
"Greek=el_GR.UTF-8"
"Gujarati=gu_IN.UTF-8"
"Hebrew=he_IL.UTF-8"
"Hindi=hi_IN.UTF-8"
"Hungarian=hu_HU.UTF-8"
"Icelandic=is_IS.UTF-8"
"Indonesian=id_ID.UTF-8"
"Irish=ga_IE.UTF-8"
"Italian=it_IT.UTF-8"
"Japanese=ja_JP.UTF-8"
"Kannada=kn_IN.UTF-8"
"Kazakh=kk_KZ.UTF-8"
"Korean=ko_KR.UTF-8"
"Latvian=lv_LV.UTF-8"
"Lithuanian=lt_LT.UTF-8"
"Macedonian=mk_MK.UTF-8"
"Malayalam=ml_IN.UTF-8"
"Marathi=mr_IN.UTF-8"
"Mongolian=mn_MN.UTF-8"
"Norwegian Bokmål=nb_NO.UTF-8"
"Norwegian Nynorsk=nn_NO.UTF-8"
"Persian=fa_IR.UTF-8"
"Polish=pl_PL.UTF-8"
"Portuguese=pt_PT.UTF-8"
"Romanian=ro_RO.UTF-8"
"Russian=ru_RU.UTF-8"
"Serbian=sr_RS.UTF-8"
"Sinhala=si_LK.UTF-8"
"Slovak=sk_SK.UTF-8"
"Slovenian=sl_SI.UTF-8"
"Spanish=es_ES.UTF-8"
"Swedish=sv_SE.UTF-8"
"Tamil=ta_IN.UTF-8"
"Telugu=te_IN.UTF-8"
"Thai=th_TH.UTF-8"
"Turkish=tr_TR.UTF-8"
"Ukrainian=uk_UA.UTF-8"
"Urdu=ur_PK.UTF-8"
"Uzbek=uz_UZ.UTF-8"
"Vietnamese=vi_VN.UTF-8"
"Welsh=cy_GB.UTF-8"
)
# Extract language names from language_options
language_names=()
for option in "${language_options[@]}"; do
language_names+=("$(echo "$option" | cut -d '=' -f 1)")
done
# Display language selection dialog using Zenity
selected_language=$(zenity --list \
--title="$(gettext "Language Selection")" \
--column="$(gettext "Select Language")" \
--width=500 --height=700 \
"${language_names[@]}")
# Check if a language was selected
if [[ -n $selected_language ]]; then
# Find the corresponding locale code for the selected language
locale_code=""
for option in "${language_options[@]}"; do
if [[ $selected_language == $(echo "$option" | cut -d '=' -f 1) ]]; then
locale_code=$(echo "$option" | cut -d '=' -f 2)
break
fi
done
if [[ -n $locale_code ]]; then
# Update the system-wide language settings
/usr/sbin/update-locale LC_ALL=$locale_code
# Prompt to restart the system for changes to take effect
zenity --info --text="$(gettext "Language set to") $selected_language. $(gettext "Please restart your system for the changes to take effect.")"
else
# Display an error message if the selected language is invalid
zenity --error --text="$(gettext "Invalid language selected.")"
fi
else
# Display an error message if no language was selected
zenity --error --text="$(gettext "No language selected.")"
fi
exit 0