#
# Try to autodetect UTF-8 capable terminal line
#
if type -p testutf8 > /dev/null 2>&1 ; then
    testutf8
    ret="$?"
    if test -n "$LANG" ; then
	if   test "$ret" -eq 2 ; then
	    case "$LANG" in
	    POSIX)   ;;
	    *.UTF-8) ;;
	    *)	 LANG=${LANG%[.@]*}.UTF-8
	    esac
	elif test "$ret" -eq 1 ; then
	    case "$LANG" in
	    *.UTF-8) LANG=${LANG%[.@]*} ;;
	    *)	     ;;
	    esac
	fi
    fi
    for lc in LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE	\
	      LC_MONETARY LC_MESSAGES LC_PAPER LC_NAME	\
	      LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT	\
	      LC_IDENTIFICATION LC_ALL
    do
	eval val="\$$lc"
	test -n "$val" || continue
	if   test "$ret" -eq 2 ; then
	    case "$val" in
	    POSIX)	;;
	    *.UTF-8)	;;
	    *)		eval $lc=\${val%[.@]*}.UTF-8
	    esac
	elif test "$ret" -eq 1 ; then
	    case "$val" in
	    *.UTF-8)	eval $lc=\${val%[.@]*} ;;
	    esac
	fi
    done
    unset ret val
fi
