Internationalisation of bash scripts
I want to get the language locale so that I can call the relevant help function for the specific language. I can use locale
to get the LANG
or LANGUAGE
variable.
But need some assistance to implement the check with a conditional for a specific language.
locale
LANG=en_US.UTF-8
LANGUAGE=en_US
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC=en_GB.UTF-8
LC_TIME=en_GB.UTF-8
LC_COLLATE="en_US.UTF-8"
LC_MONETARY=en_GB.UTF-8
LC_MESSAGES="en_US.UTF-8"
LC_PAPER=en_GB.UTF-8
LC_NAME=en_GB.UTF-8
LC_ADDRESS=en_GB.UTF-8
LC_TELEPHONE=en_GB.UTF-8
LC_MEASUREMENT=en_GB.UTF-8
LC_IDENTIFICATION=en_GB.UTF-8
LC_ALL=
The following script could be part of your bash shellscript.
#!/bin/bash
function help_fr () {
echo "Francais"
}
#
function help_it () {
echo "Italiano"
}
#
function help_en () {
echo "English"
}
# main
curlang="${LANG:0:2}"
case "$curlang" in
fr)
help_fr
;;
it)
help_it
;;
*) # assuming default English
help_en
;;
esac