diff --git a/README.md b/README.md index 8a2a0a9..2a58665 100644 --- a/README.md +++ b/README.md @@ -204,7 +204,7 @@ change the default without having to pass flags every time. ### 4.3. Locale shortcuts -The `[general]` key `SET_LOCALE` accepts a comma-separated list of +The `[lang]` key `SET_LOCALE` accepts a comma-separated list of `alias:locale` pairs. Each pair generates a function of that name at startup: ```ini @@ -214,6 +214,16 @@ SET_LOCALE = fr:fr_FR.UTF-8, us:en_US.UTF-8 This creates `setfr` and `setus`. Use `setlocale ` to switch to any installed locale directly. +Set `DEFAULT_LANG` to one of the defined aliases to activate that locale +automatically at login: + +```ini +DEFAULT_LANG = fr +``` + +If `DEFAULT_LANG` is set but does not match any alias in `SET_LOCALE`, a +warning is displayed and no locale change is applied. + ### 4.4. Prompt theming The prompt appearance is controlled by two mechanisms that are applied in order diff --git a/doc/profile.conf.example b/doc/profile.conf.example index 86a94c8..bcfb113 100755 --- a/doc/profile.conf.example +++ b/doc/profile.conf.example @@ -89,6 +89,11 @@ TERM=xterm-256color # creates setfr, setus, setes. #SET_LOCALE=fr:fr_FR.UTF-8,us:en_US.UTF-8 +# Alias to activate at login. Must match one of the aliases defined in SET_LOCALE above. +# Example: DEFAULT_LANG=fr → calls setfr at startup. +# Leave unset to keep the system default locale. +#DEFAULT_LANG=fr + # ============================================================================== [net] # dwl: Force a specific download tool (curl, wget, fetch). diff --git a/profile.sh b/profile.sh index 03bae09..84b3399 100644 --- a/profile.sh +++ b/profile.sh @@ -258,8 +258,18 @@ if [[ $INTERACTIVE ]]; then trap 'timer_start' DEBUG PROMPT_COMMAND='set_prompt' - # Set default language - setfr + # Set default language from DEFAULT_LANG config key (set in [general]). + # The value must match one of the alias names defined in SET_LOCALE so that + # the corresponding set function exists after build_locale_shortcuts. + if [[ -n "${DEFAULT_LANG:-}" ]]; then + local _lang_fn="set${DEFAULT_LANG}" + if declare -F "$_lang_fn" >/dev/null 2>&1; then + "$_lang_fn" + else + disp W "DEFAULT_LANG '$DEFAULT_LANG' has no matching locale shortcut (check SET_LOCALE in profile.conf)." + fi + unset _lang_fn + fi showinfo && printf "\n" check_updates -q disp I "Profile version $PROFVERSION chargé..."