1 # AX-ZSH: Alex' Modular ZSH Configuration
2 # 12_locale.zprofile: Initialize locale settings
4 # This is only relevant for interactive shells (because the user has to
5 # manually enter data when the validation fails):
6 [[ -z "$PS1" ]] && return 0
8 # Validate the locale(7) settings in interactive shells and try to mimic the
11 lc_messages=$(locale 2>/dev/null | fgrep LC_MESSAGES | cut -d'=' -f2)
12 lc_messages=$lc_messages:gs/\"//
14 [[ "$OSTYPE" = 'linux-gnu' && $locale != 'C' ]] \
15 && encoding=$lc_messages:e:l:gs/-// \
16 || encoding=$lc_messages:e
17 [[ -n "$encoding" ]] && locale="$locale.$encoding"
18 [[ -z "$LANG$LANGUAGE$LC_ALL$LC_MESSAGES" ]] && unset lc_messages
20 if [[ -n "$LANG$LANGUAGE$LC_ALL$LC_MESSAGES" ]] && locale -a 2>/dev/null | grep "^$locale\$" >/dev/null; then
21 # The locale setting seems to be valid: one of the LANG,
22 # LANGUAGE, LC_ALL and/or LC_MESSAGES is set and the locale is
23 # included in "locale -a" output. Good!
27 echo "ax-zsh: unknown/unsupported locale ${lc_messages:-unknown}" >&2
29 while [[ -z "$locale" ]]; do
30 if ! read "locale?Locale? "; then
35 if [[ -n "$locale" ]]; then
37 unset LANGUAGE LC_ALL LC_MESSAGES
41 unset lc_messages locale encoding