#!/bin/bash
# ==============================================================================
# karch module: locale
# Phase 2 (chroot) — Configure locales: en_AU, en_US, ja_JP
# ==============================================================================

run_locale() {
    msg_info "Configuring locales..."

    local locale_gen="/etc/locale.gen"

    # Uncomment the required locales (handle optional space after #)
    sed -i 's/^#\s*\(en_AU.UTF-8 UTF-8\)/\1/' "$locale_gen"
    sed -i 's/^#\s*\(en_US.UTF-8 UTF-8\)/\1/' "$locale_gen"
    sed -i 's/^#\s*\(ja_JP.UTF-8 UTF-8\)/\1/' "$locale_gen"

    # Generate locales
    msg_info "Generating locales..."
    locale-gen

    # Set system locale
    echo "LANG=en_AU.UTF-8" > /etc/locale.conf

    msg_ok "Locales configured: en_AU.UTF-8 (system), en_US.UTF-8, ja_JP.UTF-8"

    dialog_msgbox "Locale" \
        "Locales generated:\n\n  • en_AU.UTF-8 (system default)\n  • en_US.UTF-8\n  • ja_JP.UTF-8"

    return 0
}
