Blame Scripts/Bash/Functions/cli_getCurrentLocale.sh
|
|
4c79b5 |
#!/bin/bash
|
|
|
4c79b5 |
#
|
|
|
4c79b5 |
# cli_getCurrentLocale.sh -- This function checks LANG environment
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# specific. For example, if the locale 'en_GB' is the current one, it
|
|
|
4c79b5 |
|
|
|
4c79b5 |
#
|
|
|
7cd8e9 |
# Copyright (C) 2009, 2010 Alain Reguera Delgado
|
|
|
4c79b5 |
#
|
|
|
4c79b5 |
# This program is free software; you can redistribute it and/or
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
#
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# General Public License for more details.
|
|
|
4c79b5 |
#
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# along with this program; if not, write to the Free Software
|
|
|
4c79b5 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
4c79b5 |
# USA.
|
|
|
4c79b5 |
#
|
|
|
4c79b5 |
# ----------------------------------------------------------------------
|
|
|
418249 |
# $Id$
|
|
|
4c79b5 |
# ----------------------------------------------------------------------
|
|
|
4c79b5 |
|
|
|
4c79b5 |
function cli_getCurrentLocale {
|
|
|
4c79b5 |
|
|
|
4c79b5 |
local -a PATTERNS
|
|
|
4c79b5 |
local PATTERN=''
|
|
|
4c79b5 |
local CURRENTLOCALE=''
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# Define pattern for current locale using LL_CC.ENCODING format.
|
|
|
4c79b5 |
PATTERNS[0]=$LANG
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# Define pattern for current locale using LL_CC format.
|
|
|
4c79b5 |
PATTERNS[1]=$(echo $LANG | sed -r 's!(^[a-z]{2,3}_[A-Z]{2}).+$!\1!')
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# Define pattern for current locale using LL format.
|
|
|
4c79b5 |
PATTERNS[2]=$(echo $LANG | sed -r 's!^([a-z]{2,3}).+$!\1!')
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
for PATTERN in "${PATTERNS[@]}";do
|
|
|
4c79b5 |
CURRENTLOCALE=$(cli_getLocales | egrep $PATTERN)
|
|
|
4c79b5 |
if [[ $CURRENTLOCALE != '' ]];then
|
|
|
4c79b5 |
break
|
|
|
4c79b5 |
fi
|
|
|
4c79b5 |
done
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if [[ $CURRENTLOCALE == '' ]];then
|
|
|
4c79b5 |
CURRENTLOCALE='en'
|
|
|
4c79b5 |
fi
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
echo $CURRENTLOCALE | sort | uniq | head -n1
|
|
|
4c79b5 |
|
|
|
4c79b5 |
}
|