From fd7b8d7e8559d3e4de8d9d56bf1ac14cf29ca514 Mon Sep 17 00:00:00 2001 From: Nick A <60294463+technicks89@users.noreply.github.com> Date: Sat, 18 Jul 2026 11:13:10 -0400 Subject: [PATCH 1/5] Added a locale setup, kept the original US Local Setup in place --- core/tabs/utils/locale-setup.sh | 83 +++++++++++++++++++++++++++ core/tabs/utils/tab_data.toml | 6 ++ docs/content/userguide/walkthrough.md | 1 + 3 files changed, 90 insertions(+) create mode 100644 core/tabs/utils/locale-setup.sh diff --git a/core/tabs/utils/locale-setup.sh b/core/tabs/utils/locale-setup.sh new file mode 100644 index 000000000..93ddf81e1 --- /dev/null +++ b/core/tabs/utils/locale-setup.sh @@ -0,0 +1,83 @@ +#!/bin/sh -e + +. ../common-script.sh +. ../common-service-script.sh + +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" ;; + 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" ;; + 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" ;; + 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 + esac +} + +setLocale() { + if command_exists locale-gen; then + + iso=$(curl ifconfig.io/country_code | tr '[:upper:]' '[:lower:]') + suggested_locale=$(get_suggested_locale "$iso") + + while true; do + read -r -p "Detected locale: '$suggested_locale'. Press Enter to accept or type a new one (e.g. de_DE.UTF-8): " input + + if [ -z "$input" ]; then + LOCALE="$suggested_locale" + else + LOCALE="$input" + fi + + 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 + + # 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 + + echo "LC_ALL=${LOCALE}" | "$ESCALATION_TOOL" tee -a /etc/environment + echo "$LOCALE UTF-8" | "$ESCALATION_TOOL" tee -a /etc/locale.gen + echo "LANG=$LOCALE" | "$ESCALATION_TOOL" tee -a /etc/locale.conf + "$ESCALATION_TOOL" locale-gen $LOCALE + fi +} + +checkEnv +setLocale diff --git a/core/tabs/utils/tab_data.toml b/core/tabs/utils/tab_data.toml index 73065b4f1..ce44e020c 100644 --- a/core/tabs/utils/tab_data.toml +++ b/core/tabs/utils/tab_data.toml @@ -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" +description = "This allows the user to set their locale" +script = "locale-setup.sh" +task_list = "FM" + [[data]] name = "Ollama" description = "This utility is designed to manage ollama in your system" diff --git a/docs/content/userguide/walkthrough.md b/docs/content/userguide/walkthrough.md index e29ca9996..2bd2c9b2a 100644 --- a/docs/content/userguide/walkthrough.md +++ b/docs/content/userguide/walkthrough.md @@ -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 From 6ca16bde4e015c2c378e9a9352be09987f632db6 Mon Sep 17 00:00:00 2001 From: Nick A <60294463+technicks89@users.noreply.github.com> Date: Sat, 18 Jul 2026 11:30:07 -0400 Subject: [PATCH 2/5] Added a few extra locales --- core/tabs/utils/locale-setup.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/tabs/utils/locale-setup.sh b/core/tabs/utils/locale-setup.sh index 93ddf81e1..49d860ac5 100644 --- a/core/tabs/utils/locale-setup.sh +++ b/core/tabs/utils/locale-setup.sh @@ -13,6 +13,7 @@ get_suggested_locale() { 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" ;; @@ -26,11 +27,14 @@ get_suggested_locale() { 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" ;; From 0083377c4db5645c953c18c4fca575e4dfb094cd Mon Sep 17 00:00:00 2001 From: Nick A <60294463+technicks89@users.noreply.github.com> Date: Sat, 18 Jul 2026 11:37:17 -0400 Subject: [PATCH 3/5] Fixed POSIX compliance issue --- core/tabs/utils/locale-setup.sh | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/core/tabs/utils/locale-setup.sh b/core/tabs/utils/locale-setup.sh index 49d860ac5..34ab04d12 100644 --- a/core/tabs/utils/locale-setup.sh +++ b/core/tabs/utils/locale-setup.sh @@ -54,13 +54,9 @@ setLocale() { suggested_locale=$(get_suggested_locale "$iso") while true; do - read -r -p "Detected locale: '$suggested_locale'. Press Enter to accept or type a new one (e.g. de_DE.UTF-8): " input - - if [ -z "$input" ]; then - LOCALE="$suggested_locale" - else - LOCALE="$input" - fi + 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 *_**) @@ -79,7 +75,7 @@ setLocale() { echo "LC_ALL=${LOCALE}" | "$ESCALATION_TOOL" tee -a /etc/environment echo "$LOCALE UTF-8" | "$ESCALATION_TOOL" tee -a /etc/locale.gen echo "LANG=$LOCALE" | "$ESCALATION_TOOL" tee -a /etc/locale.conf - "$ESCALATION_TOOL" locale-gen $LOCALE + "$ESCALATION_TOOL" locale-gen "$LOCALE" fi } From c3c28d371fc21dc5bd96966b1e145607b1d93be1 Mon Sep 17 00:00:00 2001 From: Nick A <60294463+technicks89@users.noreply.github.com> Date: Mon, 20 Jul 2026 20:15:04 -0400 Subject: [PATCH 4/5] Fixed Tab_data permissions, Fixed documentation missing space, added timeout for iso lookup and defaulted to US if fails, addd conditional statements for modifying locale based on Copilot suggestions --- core/tabs/utils/locale-setup.sh | 25 +++++++++++++++++++------ core/tabs/utils/tab_data.toml | 2 +- docs/content/userguide/walkthrough.md | 2 +- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/core/tabs/utils/locale-setup.sh b/core/tabs/utils/locale-setup.sh index 34ab04d12..b6e842114 100644 --- a/core/tabs/utils/locale-setup.sh +++ b/core/tabs/utils/locale-setup.sh @@ -50,8 +50,8 @@ get_suggested_locale() { setLocale() { if command_exists locale-gen; then - iso=$(curl ifconfig.io/country_code | tr '[:upper:]' '[:lower:]') - suggested_locale=$(get_suggested_locale "$iso") + 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" @@ -72,10 +72,23 @@ setLocale() { echo "ERROR! Locale '$LOCALE' does not look valid. Please enter a locale like en_US.UTF-8." done - echo "LC_ALL=${LOCALE}" | "$ESCALATION_TOOL" tee -a /etc/environment - echo "$LOCALE UTF-8" | "$ESCALATION_TOOL" tee -a /etc/locale.gen - echo "LANG=$LOCALE" | "$ESCALATION_TOOL" tee -a /etc/locale.conf - "$ESCALATION_TOOL" locale-gen "$LOCALE" + if grep -q '^LC_ALL=' /etc/environment 2>/dev/null; then + "$ESCALATION_TOOL" sed -i "s/^LC_ALL=.*/LC_ALL=${LOCALE}/" /etc/environment + else + printf 'LC_ALL=%s\n' "$LOCALE" | "$ESCALATION_TOOL" tee -a /etc/environment >/dev/null + 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 } diff --git a/core/tabs/utils/tab_data.toml b/core/tabs/utils/tab_data.toml index ce44e020c..ea9c205a1 100644 --- a/core/tabs/utils/tab_data.toml +++ b/core/tabs/utils/tab_data.toml @@ -152,7 +152,7 @@ task_list = "PFM SS" name = "Locale Setup" description = "This allows the user to set their locale" script = "locale-setup.sh" -task_list = "FM" +task_list = "PFM" [[data]] name = "Ollama" diff --git a/docs/content/userguide/walkthrough.md b/docs/content/userguide/walkthrough.md index 2bd2c9b2a..c911454db 100644 --- a/docs/content/userguide/walkthrough.md +++ b/docs/content/userguide/walkthrough.md @@ -244,7 +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 +- **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 From a729863eaa3cc26f922949aa528761f8830b3f5a Mon Sep 17 00:00:00 2001 From: Nick A <60294463+technicks89@users.noreply.github.com> Date: Mon, 20 Jul 2026 20:47:00 -0400 Subject: [PATCH 5/5] Commited suggestions from coderabbitai --- core/tabs/utils/locale-setup.sh | 83 ++++++++++++++++----------------- core/tabs/utils/tab_data.toml | 5 ++ 2 files changed, 44 insertions(+), 44 deletions(-) diff --git a/core/tabs/utils/locale-setup.sh b/core/tabs/utils/locale-setup.sh index b6e842114..282136a1d 100644 --- a/core/tabs/utils/locale-setup.sh +++ b/core/tabs/utils/locale-setup.sh @@ -9,41 +9,41 @@ get_suggested_locale() { # 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 + us) printf "%b" "en_US.UTF-8" ;; + ca) printf "%b" "en_CA.UTF-8" ;; + cn) printf "%b" "zh_CN.UTF-8" ;; + by) printf "%b" "be_BY.UTF-8" ;; + ch) printf "%b" "de_CH.UTF-8" ;; + cz) printf "%b" "cs_CZ.UTF-8" ;; + de) printf "%b" "de_DE.UTF-8" ;; + dk) printf "%b" "da_DK.UTF-8" ;; + es) printf "%b" "es_ES.UTF-8" ;; + et) printf "%b" "et_EE.UTF-8" ;; + fa) printf "%b" "fa_IR.UTF-8" ;; + fi) printf "%b" "fi_FI.UTF-8" ;; + fr) printf "%b" "fr_FR.UTF-8" ;; + gb) printf "%b" "en_GB.UTF-8" ;; + gr) printf "%b" "el_GR.UTF-8" ;; + hu) printf "%b" "hu_HU.UTF-8" ;; + il) printf "%b" "he_IL.UTF-8" ;; + it) printf "%b" "it_IT.UTF-8" ;; + jp) printf "%b" "ja_JP.UTF-8" ;; + kr) printf "%b" "ko_KR.UTF-8" ;; + lt) printf "%b" "lt_LT.UTF-8" ;; + lv) printf "%b" "lv_LV.UTF-8" ;; + mk) printf "%b" "mk_MK.UTF-8" ;; + nl) printf "%b" "nl_NL.UTF-8" ;; + no) printf "%b" "nb_NO.UTF-8" ;; + ph) printf "%b" "en_PH.UTF-8" ;; + pl) printf "%b" "pl_PL.UTF-8" ;; + ro) printf "%b" "ro_RO.UTF-8" ;; + ru) printf "%b" "ru_RU.UTF-8" ;; + se) printf "%b" "sv_SE.UTF-8" ;; + sg) printf "%b" "en_SG.UTF-8" ;; + si) printf "%b" "sl_SI.UTF-8" ;; + tr) printf "%b" "tr_TR.UTF-8" ;; + ua) printf "%b" "uk_UA.UTF-8" ;; + *) printf "%b" "$default_locale" ;; # Default fallback esac } @@ -59,17 +59,12 @@ setLocale() { 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 - ;; + *[![:alnum:]_.@-]*|'') ;; + *.UTF-8) break ;; esac # If we reach here, the validation failed - echo "ERROR! Locale '$LOCALE' does not look valid. Please enter a locale like en_US.UTF-8." + printf "ERROR! Locale '%s' does not look valid. Please enter a locale like en_US.UTF-8." "${LOCALE}" done if grep -q '^LC_ALL=' /etc/environment 2>/dev/null; then @@ -87,7 +82,7 @@ setLocale() { fi "$ESCALATION_TOOL" locale-gen "${LOCALE}" else - echo "ERROR! locale-gen not found; cannot generate locales on this system." + printf "%b\n" "ERROR! locale-gen not found; cannot generate locales on this system." exit 1 fi } diff --git a/core/tabs/utils/tab_data.toml b/core/tabs/utils/tab_data.toml index ea9c205a1..748640e97 100644 --- a/core/tabs/utils/tab_data.toml +++ b/core/tabs/utils/tab_data.toml @@ -154,6 +154,11 @@ description = "This allows the user to set their locale" script = "locale-setup.sh" task_list = "PFM" +[[data.preconditions]] +matches = true +data = "command_exists" +values = [ "locale-gen" ] + [[data]] name = "Ollama" description = "This utility is designed to manage ollama in your system"