This LLM-generated script did the trick Gunnar, please try it:
#!/usr/bin/env bash
# ==============================================================================
# Script: set-regional-formats.sh
# Description: Configures regional formats and locale from the CLI, keeping
# PAM environment, AccountsService, and system defaults in sync.
# Usage: ./set-regional-formats.sh [TARGET_LOCALE] [SYSTEM_WIDE]
# Example: ./set-regional-formats.sh en_DK.UTF-8 --system
# ==============================================================================
set -euo pipefail
# Default to en_DK.UTF-8 (common ISO-style numbers/dates) if no argument
provided
TARGET_LOCALE="${1:-en_DK.UTF-8}"
APPLY_SYSTEM="${2:-}"
CURRENT_USER="$(whoami)"
USER_UID="$(id -u)"
echo "=== Regional Format CLI Configuration ==="
echo "Target Locale: ${TARGET_LOCALE}"
echo "User: ${CURRENT_USER} (UID: ${USER_UID})"
echo "-----------------------------------------"
# 1. Ensure the requested locale is generated
echo "[1/4] Generating locale on system if missing..."
if ! locale -a | grep -iq "^${TARGET_LOCALE//-}"; then
echo " Generating ${TARGET_LOCALE}..."
sudo locale-gen "${TARGET_LOCALE}"
else
echo " Locale ${TARGET_LOCALE} is already generated."
fi
# 2. Update AccountsService via D-Bus (Fixes GNOME GUI / language-selector sync)
echo "[2/4] Updating AccountsService via D-Bus..."
ACCOUNTSSERVICE_PATH="/org/freedesktop/Accounts/User${USER_UID}"
if busctl introspect org.freedesktop.Accounts "${ACCOUNTSSERVICE_PATH}"
>/dev/null 2>&1; then
# Set Formats via AccountsService
sudo gdbus call --system \
--dest org.freedesktop.Accounts \
--object-path "${ACCOUNTSSERVICE_PATH}" \
--method org.freedesktop.Accounts.User.SetFormatsLocale
"${TARGET_LOCALE}" >/dev/null
echo " Successfully updated AccountsService FormatsLocale to
${TARGET_LOCALE}."
else
echo " [Warning] AccountsService path not found. Skipping D-Bus
update."
fi
# 3. Update ~/.pam_environment for current user session compatibility
echo "[3/4] Writing configuration to ~/.pam_environment..."
PAM_ENV_FILE="${HOME}/.pam_environment"
# Remove existing regional entries to prevent duplication
if [[ -f "${PAM_ENV_FILE}" ]]; then
sed -i '/^LC_/d' "${PAM_ENV_FILE}"
sed -i '/^PAPERSIZE/d' "${PAM_ENV_FILE}"
fi
# Determine paper size standard based on locale
PAPER_SIZE="a4"
if [[ "${TARGET_LOCALE}" =~ ^(en_US|en_CA) ]]; then
PAPER_SIZE="letter"
fi
# Append clean regional format definitions
cat << EOF >> "${PAM_ENV_FILE}"
LC_NUMERIC DEFAULT=${TARGET_LOCALE}
LC_TIME DEFAULT=${TARGET_LOCALE}
LC_MONETARY DEFAULT=${TARGET_LOCALE}
LC_PAPER DEFAULT=${TARGET_LOCALE}
LC_NAME DEFAULT=${TARGET_LOCALE}
LC_ADDRESS DEFAULT=${TARGET_LOCALE}
LC_TELEPHONE DEFAULT=${TARGET_LOCALE}
LC_MEASUREMENT DEFAULT=${TARGET_LOCALE}
LC_IDENTIFICATION DEFAULT=${TARGET_LOCALE}
PAPERSIZE DEFAULT=${PAPER_SIZE}
EOF
echo " Updated ${PAM_ENV_FILE}."
# 4. Optional: Apply system-wide default (/etc/default/locale)
if [[ "${APPLY_SYSTEM}" == "--system" ]]; then
echo "[4/4] Applying system-wide locale via update-locale..."
sudo update-locale \
LC_NUMERIC="${TARGET_LOCALE}" \
LC_TIME="${TARGET_LOCALE}" \
LC_MONETARY="${TARGET_LOCALE}" \
LC_PAPER="${TARGET_LOCALE}" \
LC_NAME="${TARGET_LOCALE}" \
LC_ADDRESS="${TARGET_LOCALE}" \
LC_TELEPHONE="${TARGET_LOCALE}" \
LC_MEASUREMENT="${TARGET_LOCALE}" \
LC_IDENTIFICATION="${TARGET_LOCALE}"
echo " System-wide /etc/default/locale updated."
else
echo "[4/4] Skipping system-wide updates (Pass '--system' as 2nd parameter
to enable)."
fi
echo "-----------------------------------------"
echo "Done! Please log out and back in for changes to take full effect."
--
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/2035212
Title:
[Feature request]: Command line option
To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/language-selector/+bug/2035212/+subscriptions
--
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs