Check if a specific language is included in bash

My script must run a program with a specific language in order to work correctly, so I want it to check if this locale is accessible. I already used this hack, but I think there is a better way to do this.

grep ^ja_JP /etc/locale.gen &>/dev/null || echo >&2 "enable any of the japanese locales first" 
+4
source share
2 answers

man locale tells you that locale -a will list all available locales.

Instead, say:

 locale -a | grep -q ^ja_JP || echo "enable any of the japanese locales first" 
+4
source

locale -a should indicate all available locales:

 if locale -a | grep ^ja_JP ; then # locale installed... else # locale not installed... fi 
+4
source

All Articles