Blame Scripts/Functions/cli_getCurrentLocale.sh

4c79b5
#!/bin/bash
4c79b5
#
4c79b5
# cli_getCurrentLocale.sh -- This function checks LANG environment
b88fde
# variable and returns the current locale information in the LL_CC
b88fde
# format.
4c79b5
#
7ac5a5
# Copyright (C) 2009-2011 The CentOS Project
fa95b1
#
fa95b1
# This program is free software; you can redistribute it and/or modify
fa95b1
# it under the terms of the GNU General Public License as published by
dcd347
# the Free Software Foundation; either version 2 of the License, or (at
dcd347
# your option) any later version.
fa95b1
#
74a058
# This program is distributed in the hope that it will be useful, but
74a058
# WITHOUT ANY WARRANTY; without even the implied warranty of
4c79b5
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
4c79b5
# General Public License for more details.
4c79b5
#
4c79b5
# You should have received a copy of the GNU General Public License
4c79b5
# along with this program; if not, write to the Free Software
dcd347
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
7ac5a5
#
4c79b5
# ----------------------------------------------------------------------
418249
# $Id$
4c79b5
# ----------------------------------------------------------------------
4c79b5
4c79b5
function cli_getCurrentLocale {
4c79b5
4c79b5
    local CURRENTLOCALE=''
f6b2ec
    local OPTION="$1"
4c79b5
b88fde
    # Redefine current locale using LL_CC format.
b88fde
    CURRENTLOCALE=$(echo $LANG | sed -r 's!(^[a-z]{2,3}_[A-Z]{2}).+$!\1!')
4c79b5
4c79b5
    # Define centos-art.sh script default current locale. If
4c79b5
    # centos-art.sh script doesn't support current system locale, use
b88fde
    # English language from United States as default current locale.
4c79b5
    if [[ $CURRENTLOCALE == '' ]];then
b88fde
        CURRENTLOCALE='en_US'
4c79b5
    fi
4c79b5
b88fde
    # Output current locale.    
f6b2ec
    case $OPTION in
4c79b5
f6b2ec
        '--langcode-only' )
f6b2ec
            echo "${CURRENTLOCALE}" | cut -d_ -f1
f6b2ec
            ;;
f6b2ec
f6b2ec
        '--langcode-and-countrycode'| * )
f6b2ec
            echo "${CURRENTLOCALE}"
f6b2ec
            ;;
f6b2ec
    esac
4c79b5
}