]> arthur.barton.de Git - ax-zsh.git/blobdiff - core/12_locale/12_locale.zprofile
10_keyboard: Add C-x,C-p shortcut for "push-line"
[ax-zsh.git] / core / 12_locale / 12_locale.zprofile
index 6d7e40f4f9995e20371f9b9d4805b4662fbdf673..5e7d8803815b92f47531ebbb56482f282bdff0fd 100644 (file)
@@ -5,6 +5,26 @@
 # manually enter data when the validation fails):
 [[ -z "$PS1" ]] && return 0
 
+# Make sure that LANG and LC_MESSAGES are either unset or set to something sane,
+# that is, follow the "xx_ZZ.*" syntax.
+fix_locale() {
+       local encoding locale
+
+       locale="$1:r"
+       encoding="$1:e"
+
+       if [[ -z "$1" || "$locale" =~ '.*_.*' || ${#locale%%_*} -ne 2 ]]; then
+               echo "$1"
+       else
+               locale="${locale:0:2}_${locale:0:2:u}"
+               [[ -n "$encoding" ]] && locale="$locale.$encoding"
+               echo "$locale"
+       fi
+}
+[[ -n "$LANG" ]] && LANG=$(fix_locale "$LANG")
+[[ -n "$LC_MESSAGES" ]] && LANG=$(fix_locale "$LC_MESSAGES")
+unfunction fix_locale
+
 # Validate the locale(7) settings in interactive shells and try to mimic the
 # tset(1) behaviour.
 while true; do
@@ -12,7 +32,7 @@ while true; do
        [[ "$lc_messages" = '"C"' && "$LANG" != 'C' && "$LC_ALL" != 'C' ]] && lc_messages=$LANG
        lc_messages=$lc_messages:gs/\"//
        locale=$lc_messages:r
-       [[ "$OSTYPE" = 'linux-gnu' && $locale != 'C' ]] \
+       [[ ( "$OSTYPE" = 'linux-gnu' || "$OSTYPE" = 'cygwin') && $locale != 'C' ]] \
                && encoding=$lc_messages:e:l:gs/-// \
                || encoding=$lc_messages:e
        [[ -n "$encoding" ]] && locale="$locale.$encoding"
@@ -38,5 +58,14 @@ while true; do
                unset LANGUAGE LC_ALL LC_MESSAGES
        fi
 done
-
 unset lc_messages locale encoding
+
+case "$LANG" in
+       *_*)
+               # LANG contains at least one "_" ("aa_BB" form).
+               if [[ -z "$LANGUAGE" ]]; then
+                       # But LANGUAGE isn't set, so set it automatically to
+                       # "aa_BB:aa" form.
+                       export LANGUAGE=${LANG%.*}:${${LANG%.*}%_*}
+               fi
+esac