Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 96 additions & 0 deletions core/tabs/utils/locale-setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#!/bin/sh -e

. ../common-script.sh
. ../common-service-script.sh

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Remove service-manager initialization from locale setup

On systems that provide locale-gen but lack systemctl, rc-service, and sv—such as minimal containers or chroots—sourcing this helper immediately calls checkInitManager and exits before the locale prompt, even though this utility does not manage services. Source only common-script.sh here so every environment admitted by the catalog precondition can run the utility.

AGENTS.md reference: AGENTS.md:L87-L87

Useful? React with 👍 / 👎.


get_suggested_locale() {
key="$1"
default_locale="en_US.UTF-8"

# Use case statement to map keys to values (POSIX standard)
case "$key" in
us) echo "en_US.UTF-8" ;;
uk) echo "en_GB.UTF-8" ;;
ca) echo "en_CA.UTF-8" ;;
cf) echo "fr_CA.UTF-8" ;;
cn) echo "zh_CN.UTF-8" ;;
by) echo "be_BY.UTF-8" ;;
cz) echo "cs_CZ.UTF-8" ;;
de) echo "de_DE.UTF-8" ;;
dk) echo "da_DK.UTF-8" ;;
es) echo "es_ES.UTF-8" ;;
et) echo "et_EE.UTF-8" ;;
fa) echo "fa_IR.UTF-8" ;;
fi) echo "fi_FI.UTF-8" ;;
fr) echo "fr_FR.UTF-8" ;;
gr) echo "el_GR.UTF-8" ;;
hu) echo "hu_HU.UTF-8" ;;
il) echo "he_IL.UTF-8" ;;
it) echo "it_IT.UTF-8" ;;
jp) echo "ja_JP.UTF-8" ;;
kr) echo "ko_KR.UTF-8" ;;
lt) echo "lt_LT.UTF-8" ;;
lv) echo "lv_LV.UTF-8" ;;
mk) echo "mk_MK.UTF-8" ;;
nl) echo "nl_NL.UTF-8" ;;
no) echo "nb_NO.UTF-8" ;;
ph) echo "en_PH.UTF-8" ;;
pl) echo "pl_PL.UTF-8" ;;
ro) echo "ro_RO.UTF-8" ;;
ru) echo "ru_RU.UTF-8" ;;
se) echo "sv_SE.UTF-8" ;;
sg) echo "de_CH.UTF-8" ;;
si) echo "sl_SI.UTF-8" ;;
tr) echo "tr_TR.UTF-8" ;;
ua) echo "uk_UA.UTF-8" ;;
*) echo "$default_locale" ;; # Default fallback
Comment thread
technicks89 marked this conversation as resolved.
Outdated
esac
}

setLocale() {
if command_exists locale-gen; then

iso=$(curl -4fsSL --max-time 5 https://ifconfig.io/country_code 2>/dev/null | tr '[:upper:]' '[:lower:]') || iso="us"
suggested_locale=$(get_suggested_locale "${iso}")

while true; do
printf "Detected locale: '%s'. Press Enter to accept or type a new one (e.g. de_DE.UTF-8): " "$suggested_locale"
read -r input
LOCALE="${input:-$suggested_locale}"

case "$LOCALE" in
*_**)
# Check 2: Must end with .UTF-8
if echo "$LOCALE" | grep -qE '\.UTF-8$'; then
# Found a likely valid locale format
break
fi
;;
esac
Comment on lines +61 to +64

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Validate the locale before persisting it

For any syntactically plausible but unsupported input such as en_UK.UTF-8, this check accepts the value, after which the script writes it to /etc/environment, /etc/locale.gen, and /etc/locale.conf before locale-gen reports failure. The failed run therefore leaves the system configured with an invalid locale; verify the value against the installed locale definitions before modifying any files.

Useful? React with 👍 / 👎.


# If we reach here, the validation failed
echo "ERROR! Locale '$LOCALE' does not look valid. Please enter a locale like en_US.UTF-8."
done

if grep -q '^LC_ALL=' /etc/environment 2>/dev/null; then
"$ESCALATION_TOOL" sed -i "s/^LC_ALL=.*/LC_ALL=${LOCALE}/" /etc/environment
Comment thread
technicks89 marked this conversation as resolved.
else
printf 'LC_ALL=%s\n' "$LOCALE" | "$ESCALATION_TOOL" tee -a /etc/environment >/dev/null
Comment on lines +70 to +73

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Do not persist LC_ALL as the system locale

For every successful run, writing LC_ALL to /etc/environment makes it override LANG and all category-specific LC_* settings in subsequent login sessions. Users therefore cannot change language or regional categories through desktop settings or per-user environment configuration; persist LANG as the default and leave LC_ALL unset.

Useful? React with 👍 / 👎.

fi
if ! grep -qxF "${LOCALE} UTF-8" /etc/locale.gen 2>/dev/null; then
printf '%s UTF-8\n' "$LOCALE" | "$ESCALATION_TOOL" tee -a /etc/locale.gen >/dev/null
fi
if grep -q '^LANG=' /etc/locale.conf 2>/dev/null; then
"$ESCALATION_TOOL" sed -i "s/^LANG=.*/LANG=${LOCALE}/" /etc/locale.conf
else
printf 'LANG=%s\n' "$LOCALE" | "$ESCALATION_TOOL" tee -a /etc/locale.conf >/dev/null
fi
"$ESCALATION_TOOL" locale-gen "${LOCALE}"
else
echo "ERROR! locale-gen not found; cannot generate locales on this system."
exit 1
fi
Comment thread
technicks89 marked this conversation as resolved.
}

checkEnv

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Avoid installing an AUR helper during locale setup

On an Arch system without yay or paru, this unconditional checkEnv call reaches checkAURHelper, installs base-devel and git with pacman, clones yay-bin, and installs it before showing the locale prompt. That unrelated privileged package-management work is not disclosed by this utility's description or its sole PFM flag; initialize only the checks needed for locale configuration, or make AUR setup opt-in.

AGENTS.md reference: AGENTS.md:L110-L115

Useful? React with 👍 / 👎.

setLocale
6 changes: 6 additions & 0 deletions core/tabs/utils/tab_data.toml
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ description = "This utility is designed to enable Num Lock at boot, rather than
script = "numlock.sh"
task_list = "PFM SS"

[[data]]
name = "Locale Setup"
Comment on lines +151 to +152

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Restore the catalog's alphabetical ordering

The top-level utility entries are ordered alphabetically, but inserting Locale Setup after Numlock on Startup places it out of sequence and propagates that ordering to the TUI and generated guide. Move this entry before Numlock or run the repository's TOML sorter.

AGENTS.md reference: AGENTS.md:L147-L148

Useful? React with 👍 / 👎.

description = "This allows the user to set their locale"
script = "locale-setup.sh"
task_list = "PFM"
Comment thread
technicks89 marked this conversation as resolved.
Comment on lines +154 to +155

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Disable multi-select for the interactive locale prompt

Because multi_select defaults to true, this state-changing utility can be queued with other commands even though it pauses for interactive input and modifies the machine's global locale. Mark the entry multi_select = false so it must be run independently as required for interactive and state-dependent operations.

AGENTS.md reference: AGENTS.md:L114-L115

Useful? React with 👍 / 👎.


[[data]]
name = "Ollama"
description = "This utility is designed to manage ollama in your system"
Expand Down
1 change: 1 addition & 0 deletions docs/content/userguide/walkthrough.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ https://github.com/ChrisTitusTech/dwm-titus

- **Bluetooth Manager**: This utility is designed to manage bluetooth in your system
- **Numlock on Startup**: This utility is designed to enable Num Lock at boot, rather than within desktop environments like KDE or GNOME
- **Locale Setup**: This allows the user to set their locale
- **Ollama**: This utility is designed to manage ollama in your system
- **Ranalama**: This utility is designed to manage ramalama in your system
- **Service Manager**: This utility is designed to manage services in your system
Expand Down