3

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=
5
  • 1
    What kind of check? What specific language? Should many or all possible languages branch off to their own help functions? I guess you need either a case statement of if statement.
    – sudodus
    Nov 28 '21 at 3:26
  • 1
    For now I will have help functions in english, french and italian: help_en, help_fr, help_it. Could simply do comlang="$LANG". Would need to match en, fr, it in comlang with case then.
    – Fatipati
    Nov 28 '21 at 3:35
  • I think it closed prematurely.
    – bac0n
    Nov 30 '21 at 21:58
  • It is something that happens quite often. The curse of moderation and the eagerness to interfere !
    – Fatipati
    Dec 2 '21 at 8:50
  • Related: How to add localization support or you may use gettext.
    – bac0n
    Dec 2 '21 at 13:41
6

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
2
  • 1
    Many Thanks @sudodus
    – Fatipati
    Nov 28 '21 at 6:04
  • @Fatipati, I'm glad I could help you. You are welcome :-)
    – sudodus
    Nov 28 '21 at 6:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.