Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find out default language on Linux

Tags:

linux

posix

Is there a way to find out the default language of a Linux system from C? Is there a POSIX API for this? E.g. I'd like to have a string in human readable format, i.e. "German" or "Deutsch" on a German system, "French" or "Francais" on a French system etc. Is there something like this?

Thanks!

like image 937
Andy Avatar asked Dec 18 '25 08:12

Andy


2 Answers

To determine a current language on a system you can look at the following environment variables (sorted by priority in descending order):

  1. LANGUAGE
  2. LC_ALL
  3. LC_MESSAGES, LC_NUMERIC, LC_TIME, LC_COLLATE, and others
  4. LANG

Each of these variables has a special format: ll_CC, where the first two letters mean language code, the second two ones mean country code. Also an additional information like charset or variant may be specified. As exception, the first variable can contain list of language codes, and it works only if localization mechanism is enabled.

At least, gettext, the most popular translation framework in Unix-like OS, is guided by these rules.
https://gnu.org/software/gettext/manual/html_node/gettext_2.html#Locale-Environment-Variables

like image 74
mymedia Avatar answered Dec 20 '25 22:12

mymedia


Usually, the LANG environment variable contains that information in the format like "de_DE.UTF-8".

You can retrieve it using the getenv function.

EDIT:

For more sophisticated internationalization, you might want to look into gettext.

like image 33
cypheon Avatar answered Dec 20 '25 21:12

cypheon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!