#!/bin/bash
PIS_SBIN="${PIS_SBIN:-/sbin}"
if [ -z "${PIS_LIBDIR:-}" ]; then
    case "$(uname -m)" in x86_64) PIS_LIBDIR=/usr/lib64/pis ;; *) PIS_LIBDIR=/usr/lib/pis ;; esac
fi
. "$PIS_LIBDIR/pis_lib" 2>/dev/null || . "$(dirname "$0")/pis_lib" || exit 1
pis_init || exit 1
items=()
while IFS= read -r locale_name; do items+=("$locale_name" ""); done < <(locale -a | sort)
choice=$(dialog --stdout --backtitle "$PIS_BACKTITLE" --title "Language and Country" \
    --menu "Select the system locale. Current: $(pis_state_read language_country)" 0 0 12 "${items[@]}") || exit 0
if pis_apply_locale "$choice"; then
    pis_info "Language and Country" "The system locale was set to '$choice'. Log in again to apply it to new sessions."
else
    pis_error "The locale could not be changed."
    exit 1
fi
